From aa11abb9c2ddec511caba97ba23d001976ec4443 Mon Sep 17 00:00:00 2001 From: yushi Date: Thu, 24 Oct 2024 18:41:45 +0800 Subject: [PATCH 1/3] fix wrong password handling --- packages/yoroi-extension/app/api/thunk.js | 2 +- .../chrome/extension/background/handlers/yoroi/connector.js | 2 +- .../chrome/extension/background/handlers/yoroi/transaction.js | 4 ++-- .../chrome/extension/background/handlers/yoroi/wallet.js | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/yoroi-extension/app/api/thunk.js b/packages/yoroi-extension/app/api/thunk.js index 55e4a7405b..1e5732db5b 100644 --- a/packages/yoroi-extension/app/api/thunk.js +++ b/packages/yoroi-extension/app/api/thunk.js @@ -475,7 +475,7 @@ function handleWrongPassword< result: T, passwordErrorClass: typeof Error ): T { - if (result.error === 'IncorrectWalletPasswordError') { + if (typeof result.error === 'string' && result.error.includes('api.errors.IncorrectPasswordError')) { throw new passwordErrorClass(); } if (result.error) { diff --git a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/connector.js b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/connector.js index 6cfcf85512..ca804b84c8 100644 --- a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/connector.js +++ b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/connector.js @@ -128,7 +128,7 @@ export const CreateAuthEntry: HandlerType< }); return result; } catch (error) { - return { error: error.name }; + return { error: error.message }; } }, }); diff --git a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/transaction.js b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/transaction.js index 1d2b57d6a5..0c4b223477 100644 --- a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/transaction.js +++ b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/transaction.js @@ -56,7 +56,7 @@ export const SignTransaction: HandlerType< ); return transactionHexReplaceWitnessSet(transactionHex, mergedWitnessSetHex); } catch (error) { - return { error: error.name }; + return { error: error.message }; } }, }); @@ -149,7 +149,7 @@ export const SignAndBroadcastTransaction: HandlerType< emitUpdateForTxSubmission(request.publicDeriverId); return { txId }; } catch (error) { - return { error: error.name }; + return { error: error.message }; } }); }, diff --git a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/wallet.js b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/wallet.js index 71724c3768..3bdce74838 100644 --- a/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/wallet.js +++ b/packages/yoroi-extension/chrome/extension/background/handlers/yoroi/wallet.js @@ -244,7 +244,7 @@ export const GetPrivateStakingKey: HandlerType< }); return stakingKey.to_hex(); } catch (error) { - return { error: error.name }; + return { error: error.message }; } }, }); From a88dedda28f827f2daab2519658b43905a7b43eb Mon Sep 17 00:00:00 2001 From: yushi Date: Tue, 29 Oct 2024 18:44:05 +0800 Subject: [PATCH 2/3] unmagic --- packages/yoroi-extension/app/api/thunk.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/thunk.js b/packages/yoroi-extension/app/api/thunk.js index 1e5732db5b..504c147b7f 100644 --- a/packages/yoroi-extension/app/api/thunk.js +++ b/packages/yoroi-extension/app/api/thunk.js @@ -475,7 +475,7 @@ function handleWrongPassword< result: T, passwordErrorClass: typeof Error ): T { - if (typeof result.error === 'string' && result.error.includes('api.errors.IncorrectPasswordError')) { + if (typeof result.error === 'string' && result.error.includes(IncorrectWalletPasswordError.id)) { throw new passwordErrorClass(); } if (result.error) { From 7fdae03a34d363b41255611a1da95c54914d6224 Mon Sep 17 00:00:00 2001 From: vantuz-subhuman Date: Tue, 29 Oct 2024 15:06:58 +0300 Subject: [PATCH 3/3] flow fix --- packages/yoroi-extension/app/api/common/errors.js | 7 ++++++- packages/yoroi-extension/app/api/thunk.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/yoroi-extension/app/api/common/errors.js b/packages/yoroi-extension/app/api/common/errors.js index 2294a642eb..f7ad30c725 100644 --- a/packages/yoroi-extension/app/api/common/errors.js +++ b/packages/yoroi-extension/app/api/common/errors.js @@ -199,9 +199,14 @@ export class GenericApiError extends LocalizableError { } export class IncorrectWalletPasswordError extends LocalizableError { + + static get errorId(): string { + return messages.incorrectWalletPasswordError.id; + } + constructor() { super({ - id: messages.incorrectWalletPasswordError.id, + id: IncorrectWalletPasswordError.errorId, defaultMessage: messages.incorrectWalletPasswordError.defaultMessage || '', }); } diff --git a/packages/yoroi-extension/app/api/thunk.js b/packages/yoroi-extension/app/api/thunk.js index 504c147b7f..31b0b0b09d 100644 --- a/packages/yoroi-extension/app/api/thunk.js +++ b/packages/yoroi-extension/app/api/thunk.js @@ -475,7 +475,7 @@ function handleWrongPassword< result: T, passwordErrorClass: typeof Error ): T { - if (typeof result.error === 'string' && result.error.includes(IncorrectWalletPasswordError.id)) { + if (typeof result.error === 'string' && result.error.includes(IncorrectWalletPasswordError.errorId)) { throw new passwordErrorClass(); } if (result.error) {