Skip to content

Commit

Permalink
prevent backups on wallets which are damaged
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Nov 25, 2024
1 parent e1569fa commit 176cac6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 12 additions & 2 deletions src/components/backup/useCreateBackup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Navigation, useNavigation } from '@/navigation';
import { InteractionManager } from 'react-native';
import { DelayedAlert } from '@/components/alerts';
import { useDispatch } from 'react-redux';
import * as i18n from '@/languages';

type UseCreateBackupProps = {
walletId?: string;
Expand Down Expand Up @@ -85,12 +86,21 @@ export const useCreateBackup = () => {

if (typeof walletId === 'undefined') {
if (!wallets) {
onError('Error loading wallets. Please try again.');
onError(i18n.t(i18n.l.back_up.errors.no_keys_found));
backupsStore.getState().setStatus(CloudBackupState.Error);
return;
}

const validWallets = Object.fromEntries(Object.entries(wallets).filter(([_, wallet]) => !wallet.damaged));

if (Object.keys(validWallets).length === 0) {
onError(i18n.t(i18n.l.back_up.errors.no_keys_found));
backupsStore.getState().setStatus(CloudBackupState.Error);
return;
}

backupAllWalletsToCloud({
wallets,
wallets: validWallets,
password,
onError,
onSuccess,
Expand Down
15 changes: 10 additions & 5 deletions src/hooks/useWalletCloudBackup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import lang from 'i18n-js';
import { values } from 'lodash';
import { useCallback } from 'react';
import { Linking } from 'react-native';
Expand Down Expand Up @@ -77,8 +76,8 @@ export default function useWalletCloudBackup() {
category: 'backup',
});
Alert.alert(
lang.t('modal.back_up.alerts.cloud_not_enabled.label'),
lang.t('modal.back_up.alerts.cloud_not_enabled.description'),
i18n.t(i18n.l.modal.back_up.alerts.cloud_not_enabled.label),
i18n.t(i18n.l.modal.back_up.alerts.cloud_not_enabled.description),
[
{
onPress: () => {
Expand All @@ -87,7 +86,7 @@ export default function useWalletCloudBackup() {
category: 'backup',
});
},
text: lang.t('modal.back_up.alerts.cloud_not_enabled.show_me'),
text: i18n.t(i18n.l.modal.back_up.alerts.cloud_not_enabled.show_me),
},
{
onPress: () => {
Expand All @@ -96,14 +95,20 @@ export default function useWalletCloudBackup() {
});
},
style: 'cancel',
text: lang.t('modal.back_up.alerts.cloud_not_enabled.no_thanks'),
text: i18n.t(i18n.l.modal.back_up.alerts.cloud_not_enabled.no_thanks),
},
]
);
return false;
}
}

const wallet = wallets?.[walletId];
if (wallet?.damaged) {
onError?.(i18n.t(i18n.l.back_up.errors.damaged_wallet));
return false;
}

// For Android devices without biometrics enabled, we need to ask for PIN
let userPIN: string | undefined;
const hasBiometricsEnabled = await getSupportedBiometryType();
Expand Down
3 changes: 2 additions & 1 deletion src/languages/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"generic": "Error while trying to backup. Error code: %{errorCodes}",
"no_keys_found": "No keys found. Please try again.",
"backup_not_found": "Backup not found. Please try again.",
"no_account_found": "Unable to retrieve backup files. Make sure you're logged in."
"no_account_found": "Unable to retrieve backup files. Make sure you're logged in.",
"damaged_wallet": "Unable to backup wallet. Missing keychain data."
},
"wrong_pin": "The PIN code you entered was incorrect and we can't make a backup. Please try again with the correct code.",
"already_backed_up": {
Expand Down

0 comments on commit 176cac6

Please sign in to comment.