mirror of
https://github.com/status-im/safe-react.git
synced 2025-01-11 10:34:06 +00:00
(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:
parent
0d0acacd04
commit
f79f37709f
@ -3,6 +3,10 @@ import { EstimationStatus } from 'src/logic/hooks/useEstimateTransactionGas'
|
|||||||
import Paragraph from 'src/components/layout/Paragraph'
|
import Paragraph from 'src/components/layout/Paragraph'
|
||||||
import { getNetworkInfo } from 'src/config'
|
import { getNetworkInfo } from 'src/config'
|
||||||
import { TransactionFailText } from 'src/components/TransactionFailText'
|
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 = {
|
type TransactionFailTextProps = {
|
||||||
txEstimationExecutionStatus: EstimationStatus
|
txEstimationExecutionStatus: EstimationStatus
|
||||||
@ -20,6 +24,8 @@ export const TransactionFees = ({
|
|||||||
isOffChainSignature,
|
isOffChainSignature,
|
||||||
txEstimationExecutionStatus,
|
txEstimationExecutionStatus,
|
||||||
}: TransactionFailTextProps): React.ReactElement | null => {
|
}: TransactionFailTextProps): React.ReactElement | null => {
|
||||||
|
const providerName = useSelector(providerNameSelector)
|
||||||
|
|
||||||
let transactionAction
|
let transactionAction
|
||||||
if (isCreation) {
|
if (isCreation) {
|
||||||
transactionAction = 'create'
|
transactionAction = 'create'
|
||||||
@ -29,6 +35,11 @@ export const TransactionFees = ({
|
|||||||
transactionAction = 'approve'
|
transactionAction = 'approve'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME this should be removed when estimating with WalletConnect correctly
|
||||||
|
if (!providerName || sameString(providerName, WALLETS.WALLET_CONNECT)) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Paragraph>
|
<Paragraph>
|
||||||
|
@ -130,7 +130,11 @@ export const estimateGasForDeployingSafe = async (
|
|||||||
const proxyFactoryData = proxyFactoryMaster.methods
|
const proxyFactoryData = proxyFactoryMaster.methods
|
||||||
.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
|
.createProxyWithNonce(safeMaster.options.address, gnosisSafeData, safeCreationSalt)
|
||||||
.encodeABI()
|
.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()
|
const gasPrice = await calculateGasPrice()
|
||||||
|
|
||||||
return gas * parseInt(gasPrice, 10)
|
return gas * parseInt(gasPrice, 10)
|
||||||
|
@ -22,6 +22,7 @@ import { Confirmation } from 'src/logic/safe/store/models/types/confirmation'
|
|||||||
import { checkIfOffChainSignatureIsPossible } from 'src/logic/safe/safeTxSigner'
|
import { checkIfOffChainSignatureIsPossible } from 'src/logic/safe/safeTxSigner'
|
||||||
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
|
import { ZERO_ADDRESS } from 'src/logic/wallets/ethAddresses'
|
||||||
import { sameString } from 'src/utils/strings'
|
import { sameString } from 'src/utils/strings'
|
||||||
|
import { WALLETS } from 'src/config/networks/network.d'
|
||||||
|
|
||||||
export enum EstimationStatus {
|
export enum EstimationStatus {
|
||||||
LOADING = 'LOADING',
|
LOADING = 'LOADING',
|
||||||
@ -160,13 +161,17 @@ export const useEstimateTransactionGas = ({
|
|||||||
const safeAddress = useSelector(safeParamAddressFromStateSelector)
|
const safeAddress = useSelector(safeParamAddressFromStateSelector)
|
||||||
const threshold = useSelector(safeThresholdSelector)
|
const threshold = useSelector(safeThresholdSelector)
|
||||||
const safeVersion = useSelector(safeCurrentVersionSelector)
|
const safeVersion = useSelector(safeCurrentVersionSelector)
|
||||||
const { account: from, smartContractWallet } = useSelector(providerSelector)
|
const { account: from, smartContractWallet, name: providerName } = useSelector(providerSelector)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const estimateGas = async () => {
|
const estimateGas = async () => {
|
||||||
if (!txData.length) {
|
if (!txData.length) {
|
||||||
return
|
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 isExecution = checkIfTxIsExecution(Number(threshold), preApprovingOwner, txConfirmations?.size, txType)
|
||||||
const isCreation = checkIfTxIsCreation(txConfirmations?.size || 0, txType)
|
const isCreation = checkIfTxIsCreation(txConfirmations?.size || 0, txType)
|
||||||
@ -245,6 +250,7 @@ export const useEstimateTransactionGas = ({
|
|||||||
smartContractWallet,
|
smartContractWallet,
|
||||||
safeTxGas,
|
safeTxGas,
|
||||||
txType,
|
txType,
|
||||||
|
providerName,
|
||||||
])
|
])
|
||||||
|
|
||||||
return gasEstimation
|
return gasEstimation
|
||||||
|
@ -272,5 +272,9 @@ export const estimateGasForTransactionApproval = async ({
|
|||||||
from,
|
from,
|
||||||
})
|
})
|
||||||
const approveTransactionTxData = await safeInstance.methods.approveHash(txHash).encodeABI()
|
const approveTransactionTxData = await safeInstance.methods.approveHash(txHash).encodeABI()
|
||||||
return calculateGasOf(approveTransactionTxData, from, safeAddress)
|
return calculateGasOf({
|
||||||
|
data: approveTransactionTxData,
|
||||||
|
from,
|
||||||
|
to: safeAddress,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -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()
|
const web3 = getWeb3()
|
||||||
try {
|
try {
|
||||||
const gas = await web3.eth.estimateGas({ data, from, to })
|
const gas = await web3.eth.estimateGas(txConfig)
|
||||||
|
|
||||||
return gas * 2
|
return gas * 2
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user