Skip to content

Commit

Permalink
fix invalid witness handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yushih committed Nov 13, 2024
1 parent 9549677 commit 0c0e1b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions packages/yoroi-extension/app/api/thunk.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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<void> {
const result = await callBackground({ type: BroadcastTransaction.typeTag, request });
handleKnownSubmissionErrors(result);
if (result?.error) {
throw new Error(result.error);
}
Expand Down Expand Up @@ -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()
}
}

0 comments on commit 0c0e1b4

Please sign in to comment.