From 0c0e1b4bf3ce0182b1786757785f33ddc850c343 Mon Sep 17 00:00:00 2001 From: yushi Date: Wed, 13 Nov 2024 18:30:50 +0800 Subject: [PATCH] fix invalid witness handling --- .../app/api/ada/lib/state-fetch/remoteFetcher.js | 2 +- packages/yoroi-extension/app/api/thunk.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js index 8ef431f6d5..36f6bff479 100644 --- a/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js +++ b/packages/yoroi-extension/app/api/ada/lib/state-fetch/remoteFetcher.js @@ -109,7 +109,7 @@ export const sendTx: ({| res: error.response?.data || null, } Logger.error(`${nameof(RemoteFetcher)}::${nameof(sendTx)} error: ${stringifyError(err)}`); - if (error.request.response.includes('Invalid witness')) { + if (JSON.stringify(error.response?.data ?? '').includes('InvalidWitnessesUTXOW')) { throw new InvalidWitnessError(); } throw new SendTransactionApiError(); diff --git a/packages/yoroi-extension/app/api/thunk.js b/packages/yoroi-extension/app/api/thunk.js index 8bdd30e91f..36addf731c 100644 --- a/packages/yoroi-extension/app/api/thunk.js +++ b/packages/yoroi-extension/app/api/thunk.js @@ -17,6 +17,7 @@ import { SendTransactionApiError, GenericApiError, IncorrectWalletPasswordError, + InvalidWitnessError, } from './common/errors'; import type { ResponseTicker } from './common/lib/state-fetch/types'; //import type { HandlerType } from '../../chrome/extension/background/handlers/yoroi/type'; @@ -233,11 +234,13 @@ export async function signAndBroadcastTransaction( type: SignAndBroadcastTransaction.typeTag, request: serializableRequest, }); + handleKnownSubmissionErrors(result); return handleWrongPassword(result, IncorrectWalletPasswordError); } export async function broadcastTransaction(request: BroadcastTransactionRequestType): Promise { const result = await callBackground({ type: BroadcastTransaction.typeTag, request }); + handleKnownSubmissionErrors(result); if (result?.error) { throw new Error(result.error); } @@ -484,3 +487,13 @@ function handleWrongPassword< } return result; } + +function handleKnownSubmissionErrors< + T: { error?: string, ... } +>( + result: T, +): void { + if (result.error?.includes('api.errors.invalidWitnessError')) { + throw new InvalidWitnessError() + } +}