From 18508c3608643c957f18f77c0c0e4d5e3f454f00 Mon Sep 17 00:00:00 2001 From: Agustin Pane Date: Mon, 30 Nov 2020 16:02:31 -0300 Subject: [PATCH 01/84] Makes getGasEstimationTxResponse exportable --- src/logic/safe/transactions/gas.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logic/safe/transactions/gas.ts b/src/logic/safe/transactions/gas.ts index 92982f12c9..1af94841d1 100644 --- a/src/logic/safe/transactions/gas.ts +++ b/src/logic/safe/transactions/gas.ts @@ -130,7 +130,7 @@ export const getDataFromNodeErrorMessage = (errorMessage: string): string | unde } } -const getGasEstimationTxResponse = async (txConfig: { +export const getGasEstimationTxResponse = async (txConfig: { to: string from: string data: string From 34749fb6e62a03dd63f919cb4ede0b78576a2e0e Mon Sep 17 00:00:00 2001 From: Agustin Pane Date: Mon, 30 Nov 2020 16:03:37 -0300 Subject: [PATCH 02/84] Add check for failing txs on approveTxModal --- .../ExpandedTx/ApproveTxModal/index.tsx | 42 ++++++++++++++++++- .../ExpandedTx/ApproveTxModal/style.ts | 10 +++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/ApproveTxModal/index.tsx b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/ApproveTxModal/index.tsx index 7090aa742c..eb009f453a 100644 --- a/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/ApproveTxModal/index.tsx +++ b/src/routes/safe/components/Transactions/TxsTable/ExpandedTx/ApproveTxModal/index.tsx @@ -18,13 +18,16 @@ import Hairline from 'src/components/layout/Hairline' import Paragraph from 'src/components/layout/Paragraph' import Row from 'src/components/layout/Row' import { TX_NOTIFICATION_TYPES } from 'src/logic/safe/transactions' -import { estimateTxGasCosts } from 'src/logic/safe/transactions/gas' +import { estimateTxGasCosts, getGasEstimationTxResponse } from 'src/logic/safe/transactions/gas' import { formatAmount } from 'src/logic/tokens/utils/formatAmount' import { userAccountSelector } from 'src/logic/wallets/store/selectors' import processTransaction from 'src/logic/safe/store/actions/processTransaction' import { safeParamAddressFromStateSelector, safeThresholdSelector } from 'src/logic/safe/store/selectors' import { Transaction } from 'src/logic/safe/store/models/types/transaction' +import { getAccountFrom, getWeb3 } from 'src/logic/wallets/getWeb3' +import InfoIcon from 'src/assets/icons/info_red.svg' +import Img from 'src/components/layout/Img' const useStyles = makeStyles(styles) @@ -82,10 +85,28 @@ const ApproveTxModal = ({ const { description, title } = getModalTitleAndDescription(thresholdReached, isCancelTx) const oneConfirmationLeft = !thresholdReached && tx.confirmations.size + 1 === threshold const isTheTxReadyToBeExecuted = oneConfirmationLeft ? true : thresholdReached + const [txWillFail, setTxWillFail] = useState(false) useEffect(() => { let isCurrent = true + const checkIfTxWillFail = async () => { + try { + const web3 = getWeb3() + const from = await getAccountFrom(web3) + if (from) { + await getGasEstimationTxResponse({ + to: tx.recipient, + from, + data: tx.data as string, + }) + } + } catch (error) { + console.warn('The transaction will fail, it was not possible to estimate the amount of gas to execute the tx') + setTxWillFail(true) + } + } + const estimateGas = async () => { const estimatedGasCosts = await estimateTxGasCosts( safeAddress, @@ -94,6 +115,9 @@ const ApproveTxModal = ({ tx, approveAndExecute ? userAddress : undefined, ) + + await checkIfTxWillFail() + const gasCosts = fromTokenUnit(estimatedGasCosts, nativeCoin.decimals) const formattedGasCosts = formatAmount(gasCosts) if (isCurrent) { @@ -124,7 +148,13 @@ const ApproveTxModal = ({ } return ( - + {title} @@ -168,6 +198,14 @@ const ApproveTxModal = ({ } in this wallet to fund this confirmation.`} + {txWillFail && ( + + + Info Tooltip + This transaction will most likely fail. To save gas costs, collect rejections and cancel this transaction. + + + )}