Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/TransactionsFees/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import { EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
import Paragraph from 'src/components/layout/Paragraph'
import { getNetworkInfo } from 'src/config'
import { TransactionFailText } from 'src/components/TransactionFailText'
import { useSelector } from 'react-redux'
import { providerNameSelector } from 'src/logic/wallets/store/selectors'
import { sameString } from 'src/utils/strings'
import { WALLETS } from 'src/config/networks/network.d'

type TransactionFailTextProps = {
txEstimationExecutionStatus: EstimationStatus
Expand All @@ -20,6 +24,8 @@ export const TransactionFees = ({
isOffChainSignature,
txEstimationExecutionStatus,
}: TransactionFailTextProps): React.ReactElement | null => {
const providerName = useSelector(providerNameSelector)

let transactionAction
if (isCreation) {
transactionAction = 'create'
Expand All @@ -29,6 +35,11 @@ export const TransactionFees = ({
transactionAction = 'approve'
}

// FIXME this should be removed when estimating with WalletConnect correctly
if (!providerName || sameString(providerName, WALLETS.WALLET_CONNECT)) {
return null
}

return (
<>
<Paragraph>
Expand Down
6 changes: 5 additions & 1 deletion src/logic/contracts/safeContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ export const estimateGasForDeployingSafe = async (
const proxyFactoryData = proxyFactoryMaster.methods
.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
.encodeABI()
const gas = await calculateGasOf(proxyFactoryData, userAccount, proxyFactoryMaster.options.address)
const gas = await calculateGasOf({
data: proxyFactoryData,
from: userAccount,
to: proxyFactoryMaster.options.address,
})
const gasPrice = await calculateGasPrice()

return gas * parseInt(gasPrice, 10)
Expand Down
8 changes: 7 additions & 1 deletion src/logic/hooks/useEstimateTransactionGas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { Confirmation } from 'src/logic/safe/store/models/types/confirmation'
import { checkIfOffChainSignatureIsPossible } from 'src/logic/safe/safeTxSigner'
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
import { sameString } from 'src/utils/strings'
import { WALLETS } from 'src/config/networks/network.d'

export enum EstimationStatus {
LOADING = 'LOADING',
Expand Down Expand Up @@ -160,13 +161,17 @@ export const useEstimateTransactionGas = ({
const safeAddress = useSelector(safeParamAddressFromStateSelector)
const threshold = useSelector(safeThresholdSelector)
const safeVersion = useSelector(safeCurrentVersionSelector)
const { account: from, smartContractWallet } = useSelector(providerSelector)
const { account: from, smartContractWallet, name: providerName } = useSelector(providerSelector)

useEffect(() => {
const estimateGas = async () => {
if (!txData.length) {
return
}
// FIXME this should be removed when estimating with WalletConnect correctly
if (!providerName || sameString(providerName, WALLETS.WALLET_CONNECT)) {
return null
}

const isExecution = checkIfTxIsExecution(Number(threshold), preApprovingOwner, txConfirmations?.size, txType)
const isCreation = checkIfTxIsCreation(txConfirmations?.size || 0, txType)
Expand Down Expand Up @@ -245,6 +250,7 @@ export const useEstimateTransactionGas = ({
smartContractWallet,
safeTxGas,
txType,
providerName,
])

return gasEstimation
Expand Down
6 changes: 5 additions & 1 deletion src/logic/safe/transactions/gas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,9 @@ export const estimateGasForTransactionApproval = async ({
from,
})
const approveTransactionTxData = await safeInstance.methods.approveHash(txHash).encodeABI()
return calculateGasOf(approveTransactionTxData, from, safeAddress)
return calculateGasOf({
data: approveTransactionTxData,
from,
to: safeAddress,
})
}
10 changes: 8 additions & 2 deletions src/logic/wallets/ethTransactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ export const calculateGasPrice = async (): Promise<string> => {
}
}

export const calculateGasOf = async (data: string, from: string, to: string): Promise<number> => {
export const calculateGasOf = async (txConfig: {
to: string
from: string
data: string
gasPrice?: number
gas?: number
}): Promise<number> => {
const web3 = getWeb3()
try {
const gas = await web3.eth.estimateGas({ data, from, to })
const gas = await web3.eth.estimateGas(txConfig)

return gas * 2
} catch (err) {
Expand Down