diff --git a/src/logic/safe/store/actions/createTransaction.ts b/src/logic/safe/store/actions/createTransaction.ts index 23570126..0106e56f 100644 --- a/src/logic/safe/store/actions/createTransaction.ts +++ b/src/logic/safe/store/actions/createTransaction.ts @@ -57,6 +57,7 @@ export interface CreateTransactionArgs { type CreateTransactionAction = ThunkAction, AppReduxState, DispatchReturn, AnyAction> type ConfirmEventHandler = (safeTxHash: string) => void type ErrorEventHandler = () => void +export const METAMASK_REJECT_CONFIRM_TX_ERROR_CODE = 4001 const createTransaction = ( { @@ -210,20 +211,21 @@ const createTransaction = ( ? `${notificationsQueue.afterExecutionError.message} - ${err.message}` : notificationsQueue.afterExecutionError.message - console.error(`Error creating the TX: `, err) dispatch(closeSnackbarAction({ key: beforeExecutionKey })) if (pendingExecutionKey) { dispatch(closeSnackbarAction({ key: pendingExecutionKey })) } - dispatch(enqueueSnackbar(errorMsg)) + dispatch(enqueueSnackbar({ key: err.code, message: errorMsg, options: { persist: true, variant: 'error' } })) - const executeDataUsedSignatures = safeInstance.methods - .execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs) - .encodeABI() - const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from) - console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`) + if (err.code !== METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) { + const executeDataUsedSignatures = safeInstance.methods + .execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs) + .encodeABI() + const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from) + console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`) + } } return txHash diff --git a/src/logic/safe/store/actions/processTransaction.ts b/src/logic/safe/store/actions/processTransaction.ts index 7c513aeb..eced5a75 100644 --- a/src/logic/safe/store/actions/processTransaction.ts +++ b/src/logic/safe/store/actions/processTransaction.ts @@ -97,7 +97,7 @@ const processTransaction = ({ const signature = await tryOffchainSigning(tx.safeTxHash, { ...txArgs, safeAddress }, hardwareWallet) if (signature) { - dispatch(closeSnackbarAction(beforeExecutionKey)) + dispatch(closeSnackbarAction({ key: beforeExecutionKey })) await saveTxToHistory({ ...txArgs, signature }) // TODO: while we wait for the tx to be stored in the service and later update the tx info @@ -130,7 +130,7 @@ const processTransaction = ({ .send(sendParams) .once('transactionHash', async (hash: string) => { txHash = hash - dispatch(closeSnackbarAction(beforeExecutionKey)) + dispatch(closeSnackbarAction({ key: beforeExecutionKey })) pendingExecutionKey = dispatch(enqueueSnackbar(notificationsQueue.pendingExecution)) @@ -141,19 +141,19 @@ const processTransaction = ({ ]) dispatch(fetchTransactions(safeAddress)) } catch (e) { - dispatch(closeSnackbarAction(pendingExecutionKey)) + dispatch(closeSnackbarAction({ key: pendingExecutionKey })) await storeTx({ transaction: tx, safeAddress, dispatch, state }) console.error(e) } }) .on('error', (error) => { - dispatch(closeSnackbarAction(pendingExecutionKey)) + dispatch(closeSnackbarAction({ key: pendingExecutionKey })) storeTx({ transaction: tx, safeAddress, dispatch, state }) console.error('Processing transaction error: ', error) }) .then(async (receipt) => { if (pendingExecutionKey) { - dispatch(closeSnackbarAction(pendingExecutionKey)) + dispatch(closeSnackbarAction({ key: pendingExecutionKey })) } dispatch( @@ -178,17 +178,16 @@ const processTransaction = ({ const errorMsg = err.message ? `${notificationsQueue.afterExecutionError.message} - ${err.message}` : notificationsQueue.afterExecutionError.message - console.error(err) - if (txHash !== undefined) { - dispatch(closeSnackbarAction(beforeExecutionKey)) + dispatch(closeSnackbarAction({ key: beforeExecutionKey })) - if (pendingExecutionKey) { - dispatch(closeSnackbarAction(pendingExecutionKey)) - } + if (pendingExecutionKey) { + dispatch(closeSnackbarAction({ key: pendingExecutionKey })) + } - dispatch(enqueueSnackbar(errorMsg)) + dispatch(enqueueSnackbar({ key: err.code, message: errorMsg, options: { persist: true, variant: 'error' } })) + if (txHash) { const executeData = safeInstance.methods.approveHash(txHash).encodeABI() const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeData, from) console.error(`Error executing the TX: ${errMsg}`) diff --git a/src/logic/safe/transactions/offchainSigner/index.ts b/src/logic/safe/transactions/offchainSigner/index.ts index 6113d568..08e04803 100644 --- a/src/logic/safe/transactions/offchainSigner/index.ts +++ b/src/logic/safe/transactions/offchainSigner/index.ts @@ -1,5 +1,6 @@ import { getEIP712Signer } from './EIP712Signer' import { ethSigner } from './ethSigner' +import { METAMASK_REJECT_CONFIRM_TX_ERROR_CODE } from 'src/logic/safe/store/actions/createTransaction' // 1. we try to sign via EIP-712 if user's wallet supports it // 2. If not, try to use eth_sign (Safe version has to be >1.1.1) @@ -29,9 +30,8 @@ export const tryOffchainSigning = async (safeTxHash: string, txArgs, isHW: boole break } catch (err) { console.error(err) - // Metamask sign request error code - if (err.code === 4001) { - throw new Error('User denied sign request') + if (err.code === METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) { + throw err } } }