Skip to content

Commit

Permalink
fix: alert
Browse files Browse the repository at this point in the history
  • Loading branch information
heisenberg-2077 committed May 24, 2024
1 parent face2d6 commit 86b4cbc
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions apps/mobile/src/assets/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
10 changes: 7 additions & 3 deletions apps/mobile/src/components/ConnectLedger/ConnectLedger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions apps/mobile/src/core/apis/ledger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions apps/mobile/src/utils/bluetoothPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 86b4cbc

Please sign in to comment.