refactor processTransaction like createTrasnaction, so we reuse code for executing/approval txs

This commit is contained in:
mmv 2019-09-26 16:30:20 +04:00
parent 6702056709
commit 4dad9ce197
1 changed files with 35 additions and 69 deletions

View File

@ -52,48 +52,12 @@ const processTransaction = (
const sigs = generateSignaturesFromTxConfirmations(tx, approveAndExecute && userAddress)
let txHash
let transaction
if (shouldExecute) {
const transaction = await getExecutionTransaction(
safeInstance,
tx.recipient,
tx.value,
tx.data,
CALL,
nonce,
from,
sigs,
)
await transaction
.send({
from,
})
.once('transactionHash', (hash: string) => {
txHash = hash
openSnackbar('Transaction has been submitted', 'success')
})
.on('error', (error) => {
console.error('Tx error: ', error)
})
.then(async (receipt) => {
await saveTxToHistory(
safeInstance,
tx.recipient,
tx.value,
tx.data,
CALL,
nonce,
receipt.transactionHash,
from,
TX_TYPE_EXECUTION,
)
return receipt.transactionHash
})
openSnackbar('Transaction has been confirmed', 'success')
transaction = await getExecutionTransaction(safeInstance, tx.recipient, tx.value, tx.data, CALL, nonce, from, sigs)
} else {
const transaction = await getApprovalTransaction(safeInstance, tx.recipient, tx.value, tx.data, CALL, nonce, from)
transaction = await getApprovalTransaction(safeInstance, tx.recipient, tx.value, tx.data, CALL, nonce, from)
}
await transaction
.send({
@ -101,10 +65,13 @@ const processTransaction = (
})
.once('transactionHash', (hash) => {
txHash = hash
openSnackbar('Approval transaction has been submitted', 'success')
openSnackbar(
shouldExecute ? 'Transaction has been submitted' : 'Approval transaction has been submitted',
'success',
)
})
.on('error', (error) => {
console.error('Tx error: ', error)
console.error('Processing transaction error: ', error)
})
.then(async (receipt) => {
await saveTxToHistory(
@ -116,14 +83,13 @@ const processTransaction = (
nonce,
receipt.transactionHash,
from,
TX_TYPE_CONFIRMATION,
shouldExecute ? TX_TYPE_EXECUTION : TX_TYPE_CONFIRMATION,
)
return receipt.transactionHash
})
openSnackbar('Approval transaction has been confirmed', 'success')
}
openSnackbar(shouldExecute ? 'Transaction has been confirmed' : 'Approval transaction has been confirmed', 'success')
dispatch(fetchTransactions(safeAddress))