From 72cec2ebcb0a55a6e874884628f0900a32e29a48 Mon Sep 17 00:00:00 2001 From: Matthew Russell Date: Fri, 18 Nov 2022 02:24:04 -0600 Subject: [PATCH] fix: allow error message data from wallet to be displayed (#2157) --- libs/wallet/src/connectors/json-rpc-connector.ts | 16 ++++++++++------ .../vega-transaction-dialog.tsx | 7 ++++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/libs/wallet/src/connectors/json-rpc-connector.ts b/libs/wallet/src/connectors/json-rpc-connector.ts index db6c08329..0ffdc57e5 100644 --- a/libs/wallet/src/connectors/json-rpc-connector.ts +++ b/libs/wallet/src/connectors/json-rpc-connector.ts @@ -242,6 +242,16 @@ export class JsonRpcConnector implements VegaConnector { encodedTransaction: encodeTransaction(transaction), }); + if ('error' in result) { + // In the case of sending a tx, error code 3001 indicates that the + // user rejected the tx. Returning null will allow the dialog to close immediately + if (result.error.code === 3001) { + return null; + } else { + throw this.wrapError(result.error); + } + } + const parsedResult = SendTransactionSchema.safeParse(result); if (parsedResult.success) { @@ -252,12 +262,6 @@ export class JsonRpcConnector implements VegaConnector { signature: parsedResult.data.result.transaction.signature.value, }; } else { - // In the case of sending a tx, return null instead of throwing - // this indicates to the app that the user rejected the tx rather - // than it being a true error - if ('error' in result && result.error.code === 3001) { - return null; - } throw ClientErrors.INVALID_RESPONSE; } } diff --git a/libs/wallet/src/vega-transaction-dialog/vega-transaction-dialog.tsx b/libs/wallet/src/vega-transaction-dialog/vega-transaction-dialog.tsx index 9d9f72e4c..865da3aba 100644 --- a/libs/wallet/src/vega-transaction-dialog/vega-transaction-dialog.tsx +++ b/libs/wallet/src/vega-transaction-dialog/vega-transaction-dialog.tsx @@ -108,9 +108,10 @@ export const VegaDialog = ({ transaction }: VegaDialogProps) => { if (transaction.status === VegaTxStatus.Error) { content = (
-

{transaction.error && transaction.error.message}

- {transaction.error && transaction.error.data && ( -

{transaction.error.data}

+ {transaction.error && ( +

+ {transaction.error.message}: {transaction.error.data} +

)}
);