diff --git a/common/libs/wallet/deterministic/ledger.ts b/common/libs/wallet/deterministic/ledger.ts index 2bc169a5..fbf093de 100644 --- a/common/libs/wallet/deterministic/ledger.ts +++ b/common/libs/wallet/deterministic/ledger.ts @@ -15,7 +15,14 @@ interface U2FError { }; } -type LedgerError = U2FError | Error | string; +interface ErrorWithId { + id: string; + message: string; + name: string; + stack: string; +} + +type LedgerError = U2FError | ErrorWithId | Error | string; export class LedgerWallet extends HardwareWallet { public static async getChainCode(dpath: string): Promise { @@ -100,6 +107,8 @@ async function makeApp() { const isU2FError = (err: LedgerError): err is U2FError => !!err && !!(err as U2FError).metaData; const isStringError = (err: LedgerError): err is string => typeof err === 'string'; +const isErrorWithId = (err: LedgerError): err is ErrorWithId => + err.hasOwnProperty('id') && err.hasOwnProperty('message'); function ledgerErrToMessage(err: LedgerError) { // https://developers.yubico.com/U2F/Libraries/Client_error_codes.html if (isU2FError(err)) { @@ -124,6 +133,13 @@ function ledgerErrToMessage(err: LedgerError) { return err; } + if (isErrorWithId(err)) { + // Browser doesn't support U2F + if (err.message.includes('U2F not supported')) { + return translateRaw('U2F_NOT_SUPPORTED'); + } + } + // Other return err.toString(); } diff --git a/common/translations/lang/en.json b/common/translations/lang/en.json index 42d23879..0da50420 100644 --- a/common/translations/lang/en.json +++ b/common/translations/lang/en.json @@ -655,6 +655,7 @@ "NETWORK": "Network", "NETWORK_2": "network", "PROVIDED_BY": "provided by", - "YOU_ARE_INTERACTING": "You are interacting with the" + "YOU_ARE_INTERACTING": "You are interacting with the", + "U2F_NOT_SUPPORTED": "The U2F standard that hardware wallets use does not seem to be supported by your browser. Please try again using Google Chrome." } }