(Feature) Disable gas estimation for WalletConnect (#1790)

* Make calculateGasOf receive object param

* Disable estimation of gas feature for walletConnect

* Add FIXME to walletConnect estimation check

Co-authored-by: Daniel Sanchez <daniel.sanchez@gnosis.pm>
This commit is contained in:
Agustin Pane 2021-01-18 15:43:05 -03:00 committed by GitHub
parent 0d0acacd04
commit f79f37709f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 5 deletions

View File

@ -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 (
<>
<Paragraph>

View File

@ -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)

View File

@ -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

View File

@ -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,
})
}

View File

@ -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) {