From 176cac6d3fe0c3b6a5faadf10170f21107ea8462 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Mon, 25 Nov 2024 12:10:11 -0600 Subject: [PATCH] prevent backups on wallets which are damaged --- src/components/backup/useCreateBackup.ts | 14 ++++++++++++-- src/hooks/useWalletCloudBackup.ts | 15 ++++++++++----- src/languages/en_US.json | 3 ++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/components/backup/useCreateBackup.ts b/src/components/backup/useCreateBackup.ts index 5b02988e0c2..61202534389 100644 --- a/src/components/backup/useCreateBackup.ts +++ b/src/components/backup/useCreateBackup.ts @@ -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; @@ -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, diff --git a/src/hooks/useWalletCloudBackup.ts b/src/hooks/useWalletCloudBackup.ts index 3ef3d819ac6..5e95b736e60 100644 --- a/src/hooks/useWalletCloudBackup.ts +++ b/src/hooks/useWalletCloudBackup.ts @@ -1,4 +1,3 @@ -import lang from 'i18n-js'; import { values } from 'lodash'; import { useCallback } from 'react'; import { Linking } from 'react-native'; @@ -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: () => { @@ -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: () => { @@ -96,7 +95,7 @@ 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), }, ] ); @@ -104,6 +103,12 @@ export default function useWalletCloudBackup() { } } + 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(); diff --git a/src/languages/en_US.json b/src/languages/en_US.json index 902997e943f..467e95d67cc 100644 --- a/src/languages/en_US.json +++ b/src/languages/en_US.json @@ -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": {