(Feature) - #1656 Tx is sent to backend even if not signed (#1672)

* 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:
Agustin Pane 2020-12-09 14:02:09 -03:00 committed by GitHub
parent f161875902
commit 9175552488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 22 deletions

View File

@ -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,21 +211,22 @@ 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' } }))
if (err.code !== METAMASK_REJECT_CONFIRM_TX_ERROR_CODE) {
const executeDataUsedSignatures = safeInstance.methods const executeDataUsedSignatures = safeInstance.methods
.execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs) .execTransaction(to, valueInWei, txData, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
.encodeABI() .encodeABI()
const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from) const errMsg = await getErrorMessage(safeInstance.options.address, 0, executeDataUsedSignatures, from)
console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`) console.error(`Error creating the TX - an attempt to get the error message: ${errMsg}`)
} }
}
return txHash return txHash
} }

View File

@ -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}`)

View File

@ -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')
} }
} }
} }