Usage of safeOperations abstraction when creating transactions

This commit is contained in:
apanizo 2018-08-05 13:14:50 +02:00
parent 087ace52c9
commit 842398ef57
1 changed files with 22 additions and 26 deletions

View File

@ -8,8 +8,9 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts'
import { getWeb3 } from '~/wallets/getWeb3' import { getWeb3 } from '~/wallets/getWeb3'
import { type Safe } from '~/routes/safe/store/model/safe' import { type Safe } from '~/routes/safe/store/model/safe'
import { sameAddress } from '~/wallets/ethAddresses' import { sameAddress } from '~/wallets/ethAddresses'
import { checkReceiptStatus, calculateGasOf, calculateGasPrice, EMPTY_DATA } from '~/wallets/ethTransactions' import { EMPTY_DATA } from '~/wallets/ethTransactions'
import { storeSubject } from '~/utils/localStorage/transactions' import { storeSubject } from '~/utils/localStorage/transactions'
import { executeTransaction, approveTransaction } from '~/wallets/safeOperations'
export const TX_NAME_PARAM = 'txName' export const TX_NAME_PARAM = 'txName'
export const TX_DESTINATION_PARAM = 'txDestination' export const TX_DESTINATION_PARAM = 'txDestination'
@ -93,39 +94,34 @@ export const getSafeEthereumInstance = async (safeAddress: string) => {
export const createTransaction = async ( export const createTransaction = async (
safe: Safe, safe: Safe,
txName: string, name: string,
txDest: string, to: string,
txValue: number, value: number,
nonce: number, nonce: number,
user: string, sender: string,
data: string = EMPTY_DATA, data: string = EMPTY_DATA,
) => { ) => {
const web3 = getWeb3() const web3 = getWeb3()
const owners = safe.get('owners')
const safeAddress = safe.get('address') const safeAddress = safe.get('address')
const gnosisSafe = await getSafeEthereumInstance(safeAddress) const threshold = safe.get('threshold')
const valueInWei = web3.toWei(txValue, 'ether') const valueInWei = web3.toWei(value, 'ether')
const CALL = 0 const CALL = 0
const gasPrice = await calculateGasPrice()
const thresholdIsOne = safe.get('threshold') === 1 const isExecution = hasOneOwner(safe) || threshold === 1
if (hasOneOwner(safe) || thresholdIsOne) { if (isExecution) {
const txConfirmationData = const txHash = await executeTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender)
gnosisSafe.contract.execTransactionIfApproved.getData(txDest, valueInWei, data, CALL, nonce) // TODO Remove when TX History service is fully integrated
const gas = await calculateGasOf(txConfirmationData, user, safeAddress) const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(owners, sender)
const txHash =
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice }) // TODO Remove when TX History service is fully integrated
await checkReceiptStatus(txHash.tx) return storeTransaction(name, nonce, to, value, sender, executedConfirmations, txHash, safeAddress, threshold, data)
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash.tx, safeAddress, safe.get('threshold'), data)
} }
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce) const txHash = await approveTransaction(safeAddress, to, valueInWei, data, CALL, nonce, sender)
const gas = await calculateGasOf(txData, user, safeAddress) // TODO Remove when TX History service is fully integrated
const txConfirmationHash = await gnosisSafe const confirmations: List<Confirmation> = buildConfirmationsFrom(owners, to, txHash)
.approveTransactionWithParameters(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
await checkReceiptStatus(txConfirmationHash.tx)
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash.tx) // TODO Remove when TX History service is fully integrated
return storeTransaction(name, nonce, to, value, sender, confirmations, '', safeAddress, threshold, data)
return storeTransaction(txName, nonce, txDest, txValue, user, confirmations, '', safeAddress, safe.get('threshold'), data)
} }