From 86b4cbcb185e16a64e6fb3dbe19cee372fbfa364 Mon Sep 17 00:00:00 2001 From: heisenberg Date: Fri, 24 May 2024 08:36:44 +0800 Subject: [PATCH] fix: alert --- .../src/assets/locales/en/messages.json | 6 +++++ .../ConnectLedger/ConnectLedger.tsx | 10 ++++++--- apps/mobile/src/core/apis/ledger.ts | 6 ++--- apps/mobile/src/utils/bluetoothPermissions.ts | 22 +++++++++++++++++++ 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/assets/locales/en/messages.json b/apps/mobile/src/assets/locales/en/messages.json index 92d251b35..5a9fc3967 100644 --- a/apps/mobile/src/assets/locales/en/messages.json +++ b/apps/mobile/src/assets/locales/en/messages.json @@ -2109,6 +2109,12 @@ "message": "Rabby Wallet uses bluetooth access to connect Ledger", "open_settings": "OK", "cancel": "Don't Allow" + }, + "update_firmware_alert": { + "title": "Ledger Firmware Outdated", + "message": "Check out how to update Ledger firmware from Ledger support", + "update": "Update", + "cancel": "Cancel" } } } diff --git a/apps/mobile/src/components/ConnectLedger/ConnectLedger.tsx b/apps/mobile/src/components/ConnectLedger/ConnectLedger.tsx index d4e07aca2..32c48490f 100644 --- a/apps/mobile/src/components/ConnectLedger/ConnectLedger.tsx +++ b/apps/mobile/src/components/ConnectLedger/ConnectLedger.tsx @@ -66,9 +66,13 @@ export const ConnectLedger: React.FC<{ console.log('checkEthApp isConnected error', err); return await checkEthApp(); } - toast.show( - err.message || t('page.newAddress.ledger.error.lockedOrNoEthApp'), - ); + + if (err.message !== LEDGER_ERROR_CODES.FIRMWARE_OR_APP_UPDATE_REQUIRED) { + toast.show( + err.message || t('page.newAddress.ledger.error.lockedOrNoEthApp'), + ); + } + setCurrentScreen('select'); console.error('checkEthApp', err); throw err; diff --git a/apps/mobile/src/core/apis/ledger.ts b/apps/mobile/src/core/apis/ledger.ts index be6531448..e37767a05 100644 --- a/apps/mobile/src/core/apis/ledger.ts +++ b/apps/mobile/src/core/apis/ledger.ts @@ -8,6 +8,7 @@ import { LedgerHDPathType } from '@rabby-wallet/eth-keyring-ledger/dist/utils'; import PQueue from 'p-queue/dist/index'; import { t } from 'i18next'; import { ledgerErrorHandler, LEDGER_ERROR_CODES } from '@/hooks/ledger/error'; +import { UpdateFirmwareAlert } from '@/utils/bluetoothPermissions'; let queue: PQueue; setTimeout(() => { @@ -158,9 +159,8 @@ export async function checkEthApp(cb: (result: boolean) => void) { const message = ledgerErrorHandler(e); if (message === LEDGER_ERROR_CODES.FIRMWARE_OR_APP_UPDATE_REQUIRED) { - throw new Error( - t('page.newAddress.ledger.error.firmwareOrAppUpdateRequired'), - ); + UpdateFirmwareAlert(); + throw new Error(message); } } const { appName } = await keyring.getAppAndVersion(); diff --git a/apps/mobile/src/utils/bluetoothPermissions.ts b/apps/mobile/src/utils/bluetoothPermissions.ts index 063013b36..0d088f7e0 100644 --- a/apps/mobile/src/utils/bluetoothPermissions.ts +++ b/apps/mobile/src/utils/bluetoothPermissions.ts @@ -59,6 +59,28 @@ export const showBluetoothPermissionsAlert = async () => { ); }; +export const UpdateFirmwareAlert = async () => { + Alert.alert( + i18n.t('bluetooth.update_firmware_alert.title'), + i18n.t('bluetooth.update_firmware_alert.message'), + [ + { + onPress: () => { + Linking.openURL( + 'https://support.ledger.com/hc/articles/360003117594-Ledger-device-firmware-update-FAQ', + ); + }, + text: i18n.t('bluetooth.update_firmware_alert.update'), + }, + { + onPress: () => null, + style: 'cancel', + text: i18n.t('bluetooth.update_firmware_alert.cancel'), + }, + ], + ); +}; + /** * Checks and requests bluetooth permissions for Android */