diff --git a/src/core/languages/_english.json b/src/core/languages/_english.json index fed1f0e574..4d872020f1 100644 --- a/src/core/languages/_english.json +++ b/src/core/languages/_english.json @@ -950,7 +950,9 @@ "waiting_for_trezor_connect": "Waiting for Trezor Connect", "continue_on_trezor_connect": "Please follow the instructions on the Trezor Connect window", "trezor_success": "Success!", - "you_can_close_this_window": "You can close this window" + "you_can_close_this_window": "You can close this window", + "ledger_locked_error": "Please make sure your ledger is unlocked and open the Ethereum app", + "check_ledger_disconnected": "Make sure your device is connected, unlocked and the ethereum app is open" }, "choose_wallet_group": { "title": "Choose wallet group", diff --git a/src/entries/popup/handlers/ledger.ts b/src/entries/popup/handlers/ledger.ts index 9e278737f1..551165f46e 100644 --- a/src/entries/popup/handlers/ledger.ts +++ b/src/entries/popup/handlers/ledger.ts @@ -11,6 +11,7 @@ import { getProvider } from '@wagmi/core'; import { ethers } from 'ethers'; import { Address } from 'wagmi'; +import { i18n } from '~/core/languages'; import { ChainId } from '~/core/types/chains'; import { walletAction } from './walletAction'; @@ -84,9 +85,12 @@ export async function signTransactionFromLedger( // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e: any) { if (e?.name === 'TransportStatusError' || e?.name === 'LockedDeviceError') { - alert( - 'Please make sure your ledger is unlocked and open the Ethereum app', - ); + alert(i18n.t('hw.ledger_locked_error')); + } else if ( + e?.name === 'TransportOpenUserCancelled' && + e?.message === 'Access denied to use Ledger device' + ) { + alert(i18n.t('hw.check_ledger_disconnected')); } else if (e?.message) { alert(e.message); } @@ -175,3 +179,20 @@ export async function signMessageByTypeFromLedger( throw new Error(`Message type ${messageType} not supported`); } } + +export const showLedgerDisconnectedAlertIfNeeded = (e: Error) => { + if ( + e.name === 'TransportOpenUserCancelled' && + e.message === 'Access denied to use Ledger device' + ) { + alert(i18n.t('hw.check_ledger_disconnected')); + } +}; + +export const isLedgerConnectionError = (e: Error) => { + return [ + 'TransportOpenUserCancelled', + 'TransportStatusError', + 'LockedDeviceError', + ].includes(e?.name); +}; diff --git a/src/entries/popup/pages/messages/RequestAccounts/index.tsx b/src/entries/popup/pages/messages/RequestAccounts/index.tsx index d50c76dcb4..ace3344cbc 100644 --- a/src/entries/popup/pages/messages/RequestAccounts/index.tsx +++ b/src/entries/popup/pages/messages/RequestAccounts/index.tsx @@ -54,9 +54,10 @@ export const RequestAccounts = ({ dappURL: appHost, dappName: appName, }); - } catch (e) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { logger.info('error connecting to dapp'); - logger.error(e as RainbowError); + logger.error(new RainbowError(e.name), { message: e.message }); } finally { setLoading(false); } diff --git a/src/entries/popup/pages/messages/SendTransaction/index.tsx b/src/entries/popup/pages/messages/SendTransaction/index.tsx index 8ad6126fce..57471619a7 100644 --- a/src/entries/popup/pages/messages/SendTransaction/index.tsx +++ b/src/entries/popup/pages/messages/SendTransaction/index.tsx @@ -22,6 +22,7 @@ import { TransactionStatus, TransactionType } from '~/core/types/transactions'; import { addNewTransaction } from '~/core/utils/transactions'; import { Row, Rows } from '~/design-system'; import { triggerAlert } from '~/design-system/components/Alert/util'; +import { showLedgerDisconnectedAlertIfNeeded } from '~/entries/popup/handlers/ledger'; import { useSendAsset } from '~/entries/popup/hooks/send/useSendAsset'; import { useAppMetadata } from '~/entries/popup/hooks/useAppMetadata'; import { useAppSession } from '~/entries/popup/hooks/useAppSession'; @@ -119,6 +120,9 @@ export function SendTransaction({ dappName: appName, }); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + showLedgerDisconnectedAlertIfNeeded(e); } finally { setWaitingForDevice(false); setLoading(false); diff --git a/src/entries/popup/pages/messages/SignMessage/index.tsx b/src/entries/popup/pages/messages/SignMessage/index.tsx index 18e1be3d91..06476034a0 100644 --- a/src/entries/popup/pages/messages/SignMessage/index.tsx +++ b/src/entries/popup/pages/messages/SignMessage/index.tsx @@ -9,6 +9,7 @@ import { RPCMethod } from '~/core/types/rpcMethods'; import { getSigningRequestDisplayDetails } from '~/core/utils/signMessages'; import { Box } from '~/design-system'; import { triggerAlert } from '~/design-system/components/Alert/util'; +import { showLedgerDisconnectedAlertIfNeeded } from '~/entries/popup/handlers/ledger'; import { useAppMetadata } from '~/entries/popup/hooks/useAppMetadata'; import { useAppSession } from '~/entries/popup/hooks/useAppSession'; import { useWallets } from '~/entries/popup/hooks/useWallets'; @@ -90,9 +91,11 @@ export function SignMessage({ }); } approveRequest(result); - } catch (e) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + showLedgerDisconnectedAlertIfNeeded(e); logger.info('error in sign message'); - logger.error(e as RainbowError); + logger.error(new RainbowError(e.name), { message: e.message }); } finally { setWaitingForDevice(false); setLoading(false); diff --git a/src/entries/popup/pages/send/index.tsx b/src/entries/popup/pages/send/index.tsx index 850571f5fd..0a6d0bbdd3 100644 --- a/src/entries/popup/pages/send/index.tsx +++ b/src/entries/popup/pages/send/index.tsx @@ -39,6 +39,7 @@ import { } from '../../components/ExplainerSheet/ExplainerSheet'; import { Navbar } from '../../components/Navbar/Navbar'; import { TransactionFee } from '../../components/TransactionFee/TransactionFee'; +import { isLedgerConnectionError } from '../../handlers/ledger'; import { getWallet, sendTransaction } from '../../handlers/wallet'; import { useSendAsset } from '../../hooks/send/useSendAsset'; import { useSendInputs } from '../../hooks/send/useSendInputs'; @@ -234,8 +235,11 @@ export function Send() { chainId, }); } - } catch (e) { - alert('Transaction failed'); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { + if (!isLedgerConnectionError(e)) { + alert('Transaction failed'); + } logger.error(new RainbowError('send: error executing send'), { message: (e as Error)?.message, }); diff --git a/src/entries/popup/pages/unlock/index.tsx b/src/entries/popup/pages/unlock/index.tsx index ddbfa010cd..8d895e21cd 100644 --- a/src/entries/popup/pages/unlock/index.tsx +++ b/src/entries/popup/pages/unlock/index.tsx @@ -43,6 +43,7 @@ export function Unlock() { setError(i18n.t('passwords.wrong_password')); setLoading(false); } + // eslint-disable-next-line @typescript-eslint/no-explicit-any } catch (e) { logger.info('Unlock error: exception while trying to unlock'); logger.error(e as RainbowError); diff --git a/src/entries/popup/pages/welcome/ImportOrCreateWallet.tsx b/src/entries/popup/pages/welcome/ImportOrCreateWallet.tsx index 73f6cc324d..246907e1bb 100644 --- a/src/entries/popup/pages/welcome/ImportOrCreateWallet.tsx +++ b/src/entries/popup/pages/welcome/ImportOrCreateWallet.tsx @@ -48,9 +48,10 @@ export function ImportOrCreateWallet() { const seedPhrase = await wallet.exportWallet(newWalletAddress, ''); setImportWalletSecrets([seedPhrase]); navigate(ROUTES.SEED_BACKUP_PROMPT); - } catch (e) { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + } catch (e: any) { logger.info('Onboarding error: creating new wallet failed'); - logger.error(e as RainbowError); + logger.error(new RainbowError(e?.name), { message: e?.message }); setLoading(false); } }, [loading, navigate, setCurrentAddress]);