add processTransaction action

This commit is contained in:
Mikhail Mikheev 2019-07-05 17:25:41 +04:00
parent 07fe2dd5b1
commit d16f79f289
2 changed files with 38 additions and 2 deletions

View File

@ -53,8 +53,7 @@ const txStatusToLabel = {
awaiting_execution: 'Awaiting execution',
}
const isCancellationTransaction = (tx: Transaction, safeAddress: string) =>
!tx.value && tx.data === EMPTY_DATA && tx.recipient === safeAddress
const isCancellationTransaction = (tx: Transaction, safeAddress: string) => !tx.value && tx.data === EMPTY_DATA && tx.recipient === safeAddress
const ExpandedTx = ({

View File

@ -0,0 +1,37 @@
// @flow
import type { Dispatch as ReduxDispatch, GetState } from 'redux'
import { type Transaction } from '~/routes/safe/store/models/transaction'
import { userAccountSelector } from '~/logic/wallets/store/selectors'
import fetchTransactions from '~/routes/safe/store/actions/fetchTransactions'
import { type GlobalState } from '~/store'
import { getGnosisSafeInstanceAt } from '~/logic/contracts/safeContracts'
import { approveTransaction, executeTransaction, CALL } from '~/logic/safe/transactions'
const processTransaction = (
safeAddress: string,
tx: Transaction,
openSnackbar: Function,
shouldExecute?: boolean,
) => async (dispatch: ReduxDispatch<GlobalState>, getState: GetState<GlobalState>) => {
const state: GlobalState = getState()
const safeInstance = await getGnosisSafeInstanceAt(safeAddress)
const from = userAccountSelector(state)
const nonce = (await safeInstance.nonce()).toString()
let txHash
if (shouldExecute) {
openSnackbar('Transaction has been submitted', 'success')
txHash = await executeTransaction(safeInstance, tx.recipient, tx.value, tx.data, CALL, nonce, from)
openSnackbar('Transaction has been confirmed', 'success')
} else {
openSnackbar('Approval transaction has been submitted', 'success')
txHash = await approveTransaction(safeInstance, tx.recipient, tx.value, tx.data, CALL, nonce, from)
openSnackbar('Approval transaction has been confirmed', 'success')
}
dispatch(fetchTransactions(safeAddress))
return txHash
}
export default processTransaction