diff --git a/src/components/TransactionsFees/index.tsx b/src/components/TransactionsFees/index.tsx index c5e54f19..372c8b52 100644 --- a/src/components/TransactionsFees/index.tsx +++ b/src/components/TransactionsFees/index.tsx @@ -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 @@ -20,6 +24,8 @@ export const TransactionFees = ({ isOffChainSignature, txEstimationExecutionStatus, }: TransactionFailTextProps): React.ReactElement | null => { + const providerName = useSelector(providerNameSelector) + let transactionAction if (isCreation) { transactionAction = 'create' @@ -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 ( <> diff --git a/src/logic/contracts/safeContracts.ts b/src/logic/contracts/safeContracts.ts index 25550958..384fcc8e 100644 --- a/src/logic/contracts/safeContracts.ts +++ b/src/logic/contracts/safeContracts.ts @@ -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) diff --git a/src/logic/hooks/useEstimateTransactionGas.tsx b/src/logic/hooks/useEstimateTransactionGas.tsx index ba53f610..f3c33747 100644 --- a/src/logic/hooks/useEstimateTransactionGas.tsx +++ b/src/logic/hooks/useEstimateTransactionGas.tsx @@ -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', @@ -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) @@ -245,6 +250,7 @@ export const useEstimateTransactionGas = ({ smartContractWallet, safeTxGas, txType, + providerName, ]) return gasEstimation diff --git a/src/logic/safe/transactions/gas.ts b/src/logic/safe/transactions/gas.ts index 7e20aede..37f12655 100644 --- a/src/logic/safe/transactions/gas.ts +++ b/src/logic/safe/transactions/gas.ts @@ -272,5 +272,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, + }) } diff --git a/src/logic/wallets/ethTransactions.ts b/src/logic/wallets/ethTransactions.ts index 3067de09..87a702f2 100644 --- a/src/logic/wallets/ethTransactions.ts +++ b/src/logic/wallets/ethTransactions.ts @@ -50,10 +50,16 @@ export const calculateGasPrice = async (): Promise => { } } -export const calculateGasOf = async (data: string, from: string, to: string): Promise => { +export const calculateGasOf = async (txConfig: { + to: string + from: string + data: string + gasPrice?: number + gas?: number +}): Promise => { 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) {