Skip to content

Commit f43d802

Browse files
committed
fix: add specific error message for duplicate SRP imports
1 parent 86d1bd3 commit f43d802

File tree

3 files changed

+62
-11
lines changed

3 files changed

+62
-11
lines changed

app/components/Views/ImportNewSecretRecoveryPhrase/index.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,49 @@ describe('ImportNewSecretRecoveryPhrase', () => {
605605
mockAlert.mockRestore();
606606
});
607607

608+
it('displays error when import fails with duplicate account', async () => {
609+
const mockAlert = jest.spyOn(Alert, 'alert');
610+
mockImportNewSecretRecoveryPhrase.mockRejectedValueOnce(
611+
new Error(
612+
'KeyringController - The account you are trying to import is a duplicate',
613+
),
614+
);
615+
mockGetString.mockResolvedValue(valid12WordMnemonic);
616+
617+
const { getByTestId, getByText } = renderScreen(
618+
ImportNewSecretRecoveryPhrase,
619+
{ name: 'ImportNewSecretRecoveryPhrase' },
620+
{
621+
state: initialState,
622+
},
623+
);
624+
625+
const pasteButton = getByText(messages.import_from_seed.paste);
626+
627+
await act(async () => {
628+
await fireEvent.press(pasteButton);
629+
});
630+
631+
await waitFor(() => {
632+
const importButton = getByTestId(ImportSRPIDs.IMPORT_BUTTON);
633+
expect(importButton.props.disabled).toBe(false);
634+
});
635+
636+
const importButton = getByTestId(ImportSRPIDs.IMPORT_BUTTON);
637+
638+
await act(async () => {
639+
await fireEvent.press(importButton);
640+
});
641+
642+
await waitFor(() => {
643+
expect(mockAlert).toHaveBeenCalledWith(
644+
messages.import_new_secret_recovery_phrase.error_duplicate_account,
645+
);
646+
});
647+
648+
mockAlert.mockRestore();
649+
});
650+
608651
it('displays generic error when import fails', async () => {
609652
const mockAlert = jest.spyOn(Alert, 'alert');
610653
mockImportNewSecretRecoveryPhrase.mockRejectedValueOnce(

app/components/Views/ImportNewSecretRecoveryPhrase/index.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,24 @@ const ImportNewSecretRecoveryPhrase = () => {
238238

239239
navigation.navigate('WalletView');
240240
} catch (e) {
241-
if (
242-
(e as Error)?.message === 'This mnemonic has already been imported.'
243-
) {
244-
Alert.alert(
245-
strings('import_new_secret_recovery_phrase.error_duplicate_srp'),
246-
);
247-
} else {
248-
Alert.alert(
249-
strings('import_new_secret_recovery_phrase.error_title'),
250-
strings('import_new_secret_recovery_phrase.error_message'),
251-
);
241+
switch ((e as Error)?.message) {
242+
case 'This mnemonic has already been imported.':
243+
Alert.alert(
244+
strings('import_new_secret_recovery_phrase.error_duplicate_srp'),
245+
);
246+
break;
247+
case 'KeyringController - The account you are trying to import is a duplicate':
248+
Alert.alert(
249+
strings(
250+
'import_new_secret_recovery_phrase.error_duplicate_account',
251+
),
252+
);
253+
break;
254+
default:
255+
Alert.alert(
256+
strings('import_new_secret_recovery_phrase.error_title'),
257+
strings('import_new_secret_recovery_phrase.error_message'),
258+
);
252259
}
253260
setLoading(false);
254261
}

locales/languages/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3834,6 +3834,7 @@
38343834
"error_multiple_srp_word_error_3": " are incorrect or misspelled.",
38353835
"error_invalid_srp": "Invalid Secret Recovery Phrase",
38363836
"error_duplicate_srp": "This Secret Recovery Phrase has already been imported.",
3837+
"error_duplicate_account": "The account you are trying to import is a duplicate.",
38373838
"invalid_qr_code_title": "Invalid QR Code",
38383839
"invalid_qr_code_message": "The QR code does not contain a valid Secret Recovery Phrase",
38393840
"success_1": "Wallet",

0 commit comments

Comments
 (0)