Refactor executeTransaction to show notification after confirmation
This commit is contained in:
parent
7e9f988160
commit
83d8c190df
|
@ -1,4 +1,5 @@
|
|||
// @flow
|
||||
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json'
|
||||
import { getWeb3 } from '~/logic/wallets/getWeb3'
|
||||
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
|
||||
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
|
||||
|
@ -55,6 +56,7 @@ export const approveTransaction = async (
|
|||
}
|
||||
|
||||
export const executeTransaction = async (
|
||||
showNotification: Function,
|
||||
safeInstance: any,
|
||||
to: string,
|
||||
valueInWei: number | string,
|
||||
|
@ -75,20 +77,21 @@ export const executeTransaction = async (
|
|||
}
|
||||
|
||||
try {
|
||||
const receipt = await safeInstance.execTransaction(
|
||||
to,
|
||||
valueInWei,
|
||||
data,
|
||||
operation,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
ZERO_ADDRESS,
|
||||
ZERO_ADDRESS,
|
||||
sigs,
|
||||
{ from: sender },
|
||||
)
|
||||
const web3 = getWeb3()
|
||||
const contract = new web3.eth.Contract(GnosisSafeSol.abi, safeInstance.address)
|
||||
|
||||
const transactionHash = await contract.methods
|
||||
.execTransaction(to, valueInWei, data, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
|
||||
.send({
|
||||
from: sender,
|
||||
})
|
||||
.once('transactionHash', (transactionHash) => {
|
||||
showNotification()
|
||||
})
|
||||
.on('error', (error) => {
|
||||
console.log('Tx error:', error)
|
||||
})
|
||||
.then(async (receipt) => {
|
||||
await saveTxToHistory(
|
||||
safeInstance,
|
||||
to,
|
||||
|
@ -96,12 +99,15 @@ export const executeTransaction = async (
|
|||
data,
|
||||
operation,
|
||||
nonce,
|
||||
receipt.tx, // tx hash,
|
||||
receipt.transactionHash,
|
||||
sender,
|
||||
TX_TYPE_EXECUTION,
|
||||
)
|
||||
|
||||
return receipt
|
||||
return receipt.transactionHash
|
||||
})
|
||||
|
||||
return transactionHash
|
||||
} catch (error) {
|
||||
/* eslint-disable */
|
||||
const executeDataUsedSignatures = safeInstance.contract.methods
|
||||
|
|
|
@ -33,8 +33,8 @@ const createTransaction = (
|
|||
let txHash
|
||||
try {
|
||||
if (isExecution) {
|
||||
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
|
||||
txHash = await executeTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from)
|
||||
const showNotification = () => openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
|
||||
txHash = await executeTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from)
|
||||
openSnackbar(notifications.AFTER_EXECUTION, 'success')
|
||||
} else {
|
||||
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
|
||||
|
|
Loading…
Reference in New Issue