* Fix black notification * Fix executing tx even if the user rejected it * Fix hidden metamask error code * Fix proccessTransaction notifications and metamask sign reject handling
This commit is contained in:
parent
f161875902
commit
9175552488
|
@ -57,6 +57,7 @@ export interface CreateTransactionArgs {
|
||||||
type CreateTransactionAction = ThunkAction<Promise<void | string>, AppReduxState, DispatchReturn, AnyAction>
|
type CreateTransactionAction = ThunkAction<Promise<void | string>, AppReduxState, DispatchReturn, AnyAction>
|
||||||
type ConfirmEventHandler = (safeTxHash: string) => void
|
type ConfirmEventHandler = (safeTxHash: string) => void
|
||||||
type ErrorEventHandler = () => void
|
type ErrorEventHandler = () => void
|
||||||
|
export const METAMASK_REJECT_CONFIRM_TX_ERROR_CODE = 4001
|
||||||
|
|
||||||
const createTransaction = (
|
const createTransaction = (
|
||||||
{
|
{
|
||||||
|
@ -210,20 +211,21 @@ const createTransaction = (
|
||||||
? `${notificationsQueue.afterExecutionError.message} - ${err.message}`
|
? `${notificationsQueue.afterExecutionError.message} - ${err.message}`
|
||||||
: notificationsQueue.afterExecutionError.message
|
: notificationsQueue.afterExecutionError.message
|
||||||
|
|
||||||
console.error(`Error creating the TX: `, err)
|
|
||||||
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
|
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
|
||||||
|
|
||||||
if (pendingExecutionKey) {
|
if (pendingExecutionKey) {
|
||||||
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
|
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(enqueueSnackbar(errorMsg))
|
dispatch(enqueueSnackbar({ key: err.code, message: errorMsg, options: { persist: true, variant: 'error' } }))
|
||||||
|
|
||||||
const executeDataUsedSignatures = safeInstance.methods
|
if (err.code !== METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) {
|
||||||
.execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
|
const executeDataUsedSignatures = safeInstance.methods
|
||||||
.encodeABI()
|
.execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
|
||||||
const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from)
|
.encodeABI()
|
||||||
console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`)
|
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
|
return txHash
|
||||||
|
|
|
@ -97,7 +97,7 @@ const processTransaction = ({
|
||||||
const signature = await tryOffchainSigning(tx.safeTxHash, { ...txArgs, safeAddress }, hardwareWallet)
|
const signature = await tryOffchainSigning(tx.safeTxHash, { ...txArgs, safeAddress }, hardwareWallet)
|
||||||
|
|
||||||
if (signature) {
|
if (signature) {
|
||||||
dispatch(closeSnackbarAction(beforeExecutionKey))
|
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
|
||||||
|
|
||||||
await saveTxToHistory({ ...txArgs, signature })
|
await saveTxToHistory({ ...txArgs, signature })
|
||||||
// TODO: while we wait for the tx to be stored in the service and later update the tx info
|
// 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)
|
.send(sendParams)
|
||||||
.once('transactionHash', async (hash: string) => {
|
.once('transactionHash', async (hash: string) => {
|
||||||
txHash = hash
|
txHash = hash
|
||||||
dispatch(closeSnackbarAction(beforeExecutionKey))
|
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
|
||||||
|
|
||||||
pendingExecutionKey = dispatch(enqueueSnackbar(notificationsQueue.pendingExecution))
|
pendingExecutionKey = dispatch(enqueueSnackbar(notificationsQueue.pendingExecution))
|
||||||
|
|
||||||
|
@ -141,19 +141,19 @@ const processTransaction = ({
|
||||||
])
|
])
|
||||||
dispatch(fetchTransactions(safeAddress))
|
dispatch(fetchTransactions(safeAddress))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
dispatch(closeSnackbarAction(pendingExecutionKey))
|
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
|
||||||
await storeTx({ transaction: tx, safeAddress, dispatch, state })
|
await storeTx({ transaction: tx, safeAddress, dispatch, state })
|
||||||
console.error(e)
|
console.error(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('error', (error) => {
|
.on('error', (error) => {
|
||||||
dispatch(closeSnackbarAction(pendingExecutionKey))
|
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
|
||||||
storeTx({ transaction: tx, safeAddress, dispatch, state })
|
storeTx({ transaction: tx, safeAddress, dispatch, state })
|
||||||
console.error('Processing transaction error: ', error)
|
console.error('Processing transaction error: ', error)
|
||||||
})
|
})
|
||||||
.then(async (receipt) => {
|
.then(async (receipt) => {
|
||||||
if (pendingExecutionKey) {
|
if (pendingExecutionKey) {
|
||||||
dispatch(closeSnackbarAction(pendingExecutionKey))
|
dispatch(closeSnackbarAction({ key: pendingExecutionKey }))
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch(
|
dispatch(
|
||||||
|
@ -178,17 +178,16 @@ const processTransaction = ({
|
||||||
const errorMsg = err.message
|
const errorMsg = err.message
|
||||||
? `${notificationsQueue.afterExecutionError.message} - ${err.message}`
|
? `${notificationsQueue.afterExecutionError.message} - ${err.message}`
|
||||||
: notificationsQueue.afterExecutionError.message
|
: notificationsQueue.afterExecutionError.message
|
||||||
console.error(err)
|
|
||||||
|
|
||||||
if (txHash !== undefined) {
|
dispatch(closeSnackbarAction({ key: beforeExecutionKey }))
|
||||||
dispatch(closeSnackbarAction(beforeExecutionKey))
|
|
||||||
|
|
||||||
if (pendingExecutionKey) {
|
if (pendingExecutionKey) {
|
||||||
dispatch(closeSnackbarAction(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 executeData = safeInstance.methods.approveHash(txHash).encodeABI()
|
||||||
const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeData, from)
|
const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeData, from)
|
||||||
console.error(`Error executing the TX: ${errMsg}`)
|
console.error(`Error executing the TX: ${errMsg}`)
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import { getEIP712Signer } from './EIP712Signer'
|
import { getEIP712Signer } from './EIP712Signer'
|
||||||
import { ethSigner } from './ethSigner'
|
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
|
// 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)
|
// 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
|
break
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
// Metamask sign request error code
|
if (err.code === METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) {
|
||||||
if (err.code === 4001) {
|
throw err
|
||||||
throw new Error('User denied sign request')
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue