Refactor executeTransaction to show notification after confirmation

This commit is contained in:
Germán Martínez 2019-09-13 12:14:03 +02:00
parent 7e9f988160
commit 83d8c190df
2 changed files with 33 additions and 27 deletions

View File

@ -1,4 +1,5 @@
// @flow // @flow
import GnosisSafeSol from '@gnosis.pm/safe-contracts/build/contracts/GnosisSafe.json'
import { getWeb3 } from '~/logic/wallets/getWeb3' import { getWeb3 } from '~/logic/wallets/getWeb3'
import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens' import { getStandardTokenContract } from '~/logic/tokens/store/actions/fetchTokens'
import { EMPTY_DATA } from '~/logic/wallets/ethTransactions' import { EMPTY_DATA } from '~/logic/wallets/ethTransactions'
@ -55,6 +56,7 @@ export const approveTransaction = async (
} }
export const executeTransaction = async ( export const executeTransaction = async (
showNotification: Function,
safeInstance: any, safeInstance: any,
to: string, to: string,
valueInWei: number | string, valueInWei: number | string,
@ -75,33 +77,37 @@ export const executeTransaction = async (
} }
try { try {
const receipt = await safeInstance.execTransaction( const web3 = getWeb3()
to, const contract = new web3.eth.Contract(GnosisSafeSol.abi, safeInstance.address)
valueInWei,
data,
operation,
0,
0,
0,
ZERO_ADDRESS,
ZERO_ADDRESS,
sigs,
{ from: sender },
)
await saveTxToHistory( const transactionHash = await contract.methods
safeInstance, .execTransaction(to, valueInWei, data, operation, 0, 0, 0, ZERO_ADDRESS, ZERO_ADDRESS, sigs)
to, .send({
valueInWei, from: sender,
data, })
operation, .once('transactionHash', (transactionHash) => {
nonce, showNotification()
receipt.tx, // tx hash, })
sender, .on('error', (error) => {
TX_TYPE_EXECUTION, console.log('Tx error:', error)
) })
.then(async (receipt) => {
await saveTxToHistory(
safeInstance,
to,
valueInWei,
data,
operation,
nonce,
receipt.transactionHash,
sender,
TX_TYPE_EXECUTION,
)
return receipt return receipt.transactionHash
})
return transactionHash
} catch (error) { } catch (error) {
/* eslint-disable */ /* eslint-disable */
const executeDataUsedSignatures = safeInstance.contract.methods const executeDataUsedSignatures = safeInstance.contract.methods

View File

@ -33,8 +33,8 @@ const createTransaction = (
let txHash let txHash
try { try {
if (isExecution) { if (isExecution) {
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success') const showNotification = () => openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')
txHash = await executeTransaction(safeInstance, to, valueInWei, txData, CALL, nonce, from) txHash = await executeTransaction(showNotification, safeInstance, to, valueInWei, txData, CALL, nonce, from)
openSnackbar(notifications.AFTER_EXECUTION, 'success') openSnackbar(notifications.AFTER_EXECUTION, 'success')
} else { } else {
openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success') openSnackbar(notifications.BEFORE_EXECUTION_OR_CREATION, 'success')