WA-234 Wait until transactions are mined
This commit is contained in:
parent
9d27d7a7a7
commit
704d6cc083
|
@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts'
|
|||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { type Safe } from '~/routes/safe/store/model/safe'
|
||||
import { sameAddress } from '~/wallets/ethAddresses'
|
||||
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions'
|
||||
import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
|
||||
|
||||
export const TX_NAME_PARAM = 'txName'
|
||||
export const TX_DESTINATION_PARAM = 'txDestination'
|
||||
|
@ -100,22 +100,25 @@ export const createTransaction = async (
|
|||
const gnosisSafe = await getSafeEthereumInstance(safeAddress)
|
||||
const valueInWei = web3.toWei(txValue, 'ether')
|
||||
const CALL = 0
|
||||
const gasPrice = await calculateGasPrice()
|
||||
|
||||
const thresholdIsOne = safe.get('threshold') === 1
|
||||
if (hasOneOwner(safe) || thresholdIsOne) {
|
||||
const txConfirmationData =
|
||||
gnosisSafe.contract.execTransactionIfApproved.getData(txDest, valueInWei, data, CALL, nonce)
|
||||
const txHash = await executeTransaction(txConfirmationData, user, safeAddress)
|
||||
checkReceiptStatus(txHash)
|
||||
|
||||
const gas = await calculateGasOf(txConfirmationData, user, safeAddress)
|
||||
const txHash =
|
||||
await gnosisSafe.execTransactionIfApproved(txDest, valueInWei, data, CALL, nonce, { from: user, gas, gasPrice })
|
||||
await checkReceiptStatus(txHash.tx)
|
||||
const executedConfirmations: List<Confirmation> = buildExecutedConfirmationFrom(safe.get('owners'), user)
|
||||
return storeTransaction(txName, nonce, txDest, txValue, user, executedConfirmations, txHash, safeAddress, safe.get('threshold'), data)
|
||||
}
|
||||
|
||||
const txConfirmationData =
|
||||
gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
|
||||
const txConfirmationHash = await executeTransaction(txConfirmationData, user, safeAddress)
|
||||
checkReceiptStatus(txConfirmationHash)
|
||||
const txData = gnosisSafe.contract.approveTransactionWithParameters.getData(txDest, valueInWei, data, CALL, nonce)
|
||||
const gas = await calculateGasOf(txData, user, safeAddress)
|
||||
const txConfirmationHash = await gnosisSafe
|
||||
.approveTransactionWithParameters(txDest, valueInWei, txData, CALL, nonce, { from: user, gas, gasPrice })
|
||||
await checkReceiptStatus(txConfirmationHash)
|
||||
|
||||
const confirmations: List<Confirmation> = buildConfirmationsFrom(safe.get('owners'), user, txConfirmationHash)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import { getGnosisSafeContract } from '~/wallets/safeContracts'
|
|||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { sameAddress } from '~/wallets/ethAddresses'
|
||||
import { EXECUTED_CONFIRMATION_HASH } from '~/routes/safe/component/AddTransaction/createTransactions'
|
||||
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions'
|
||||
import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
|
||||
|
||||
export const updateTransaction = (
|
||||
name: string,
|
||||
|
@ -51,8 +51,11 @@ const execTransaction = async (
|
|||
const web3 = getWeb3()
|
||||
const valueInWei = web3.toWei(txValue, 'ether')
|
||||
const txData = await gnosisSafe.contract.execTransactionIfApproved.getData(destination, valueInWei, data, CALL, nonce)
|
||||
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
|
||||
const gasPrice = await calculateGasPrice()
|
||||
|
||||
return executeTransaction(txData, executor, gnosisSafe.address)
|
||||
return gnosisSafe
|
||||
.execTransactionIfApproved(destination, valueInWei, txData, CALL, nonce, { from: executor, gas, gasPrice })
|
||||
}
|
||||
|
||||
const execConfirmation = async (
|
||||
|
@ -66,10 +69,13 @@ const execConfirmation = async (
|
|||
const CALL = getOperation()
|
||||
const web3 = getWeb3()
|
||||
const valueInWei = web3.toWei(txValue, 'ether')
|
||||
const txConfirmationData =
|
||||
await gnosisSafe.contract.approveTransactionWithParameters.getData(txDestination, valueInWei, data, CALL, nonce)
|
||||
const txData = await gnosisSafe.contract
|
||||
.approveTransactionWithParameters.getData(txDestination, valueInWei, data, CALL, nonce)
|
||||
const gas = await calculateGasOf(txData, executor, gnosisSafe.address)
|
||||
const gasPrice = await calculateGasPrice()
|
||||
|
||||
return executeTransaction(txConfirmationData, executor, gnosisSafe.address)
|
||||
return gnosisSafe
|
||||
.approveTransactionWithParameters(txDestination, valueInWei, data, CALL, nonce, { from: executor, gas, gasPrice })
|
||||
}
|
||||
|
||||
const updateConfirmations = (confirmations: List<Confirmation>, userAddress: string, txHash: string) =>
|
||||
|
@ -116,9 +122,9 @@ export const processTransaction = async (
|
|||
? await execTransaction(gnosisSafe, txDestination, txValue, nonce, userAddress, data)
|
||||
: await execConfirmation(gnosisSafe, txDestination, txValue, nonce, userAddress, data)
|
||||
|
||||
checkReceiptStatus(txHash)
|
||||
checkReceiptStatus(txHash.tx)
|
||||
|
||||
const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txHash
|
||||
const confirmationHash = thresholdReached ? EXECUTED_CONFIRMATION_HASH : txHash.tx
|
||||
const executedConfirmations: List<Confirmation> = updateConfirmations(tx.get('confirmations'), userAddress, confirmationHash)
|
||||
|
||||
return updateTransaction(
|
||||
|
@ -128,7 +134,7 @@ export const processTransaction = async (
|
|||
txValue,
|
||||
userAddress,
|
||||
executedConfirmations,
|
||||
thresholdReached ? txHash : '',
|
||||
thresholdReached ? txHash.tx : '',
|
||||
safeAddress,
|
||||
threshold,
|
||||
data,
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
import { getWeb3 } from '~/wallets/getWeb3'
|
||||
import { getGnosisSafeContract, getCreateDailyLimitExtensionContract } from '~/wallets/safeContracts'
|
||||
import { type DailyLimitProps } from '~/routes/safe/store/model/dailyLimit'
|
||||
import executeTransaction, { checkReceiptStatus } from '~/wallets/ethTransactions'
|
||||
import { checkReceiptStatus, calculateGasOf, calculateGasPrice } from '~/wallets/ethTransactions'
|
||||
|
||||
export const LIMIT_POSITION = 0
|
||||
export const SPENT_TODAY_POS = 1
|
||||
|
@ -44,9 +44,11 @@ const withdrawn = async (values: Object, safeAddress: string, userAccount: strin
|
|||
const value = web3.toWei(values[VALUE_PARAM], 'ether')
|
||||
|
||||
const dailyLimitData = dailyLimitModule.contract.executeDailyLimit.getData(0, destination, value)
|
||||
const gas = await calculateGasOf(dailyLimitData, userAccount, dailyLimitModule.address)
|
||||
const gasPrice = await calculateGasPrice()
|
||||
|
||||
const txHash = await executeTransaction(dailyLimitData, userAccount, dailyLimitModule.address)
|
||||
checkReceiptStatus(txHash)
|
||||
const txHash = await dailyLimitModule.executeDailyLimit(0, destination, value, { from: userAccount, gas, gasPrice })
|
||||
checkReceiptStatus(txHash.tx)
|
||||
}
|
||||
|
||||
export default withdrawn
|
||||
|
|
|
@ -51,22 +51,3 @@ export const calculateGasOf = async (data: Object, from: string, to: string) =>
|
|||
|
||||
return gas * 2
|
||||
}
|
||||
|
||||
const executeTransaction = async (data: Object, from: string, to: string) => {
|
||||
const web3 = getWeb3()
|
||||
|
||||
const gas = await calculateGasOf(data, from, to)
|
||||
|
||||
let gasPrice
|
||||
try {
|
||||
gasPrice = await calculateGasPrice()
|
||||
} catch (err) {
|
||||
gasPrice = await promisify(cb => web3.eth.getGasPrice(cb))
|
||||
}
|
||||
|
||||
return promisify(cb => web3.eth.sendTransaction({
|
||||
from, to, data, gas, gasPrice,
|
||||
}, cb))
|
||||
}
|
||||
|
||||
export default executeTransaction
|
||||
|
|
Loading…
Reference in New Issue