From a6da5fd4c3e9488e4134a782a884cb8992997aef Mon Sep 17 00:00:00 2001 From: Daniel <80175477+dan437@users.noreply.github.com> Date: Tue, 13 Dec 2022 18:28:05 +0100 Subject: [PATCH] Add Optimism's L1 fee for an approval tx into total L1 fee in Swaps (#16929) --- ui/pages/swaps/view-quote/view-quote.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/ui/pages/swaps/view-quote/view-quote.js b/ui/pages/swaps/view-quote/view-quote.js index f35be9c4f..56c4d598c 100644 --- a/ui/pages/swaps/view-quote/view-quote.js +++ b/ui/pages/swaps/view-quote/view-quote.js @@ -113,6 +113,7 @@ import { hexWEIToDecGWEI, toPrecisionWithoutTrailingZeros, } from '../../../../shared/lib/transactions-controller-utils'; +import { addHexPrefix } from '../../../../app/scripts/lib/util'; import { calcTokenValue } from '../../../../shared/lib/swaps-utils'; import fetchEstimatedL1Fee from '../../../helpers/utils/optimism/fetchEstimatedL1Fee'; import { sumHexes } from '../../../helpers/utils/transactions.util'; @@ -895,18 +896,30 @@ export default function ViewQuote() { } const getEstimatedL1Fee = async () => { try { - const result = await fetchEstimatedL1Fee(global.eth, { + const l1TradeFeeTotal = await fetchEstimatedL1Fee(global.eth, { txParams: unsignedTransaction, chainId, }); - setMultiLayerL1FeeTotal(result); + let l1ApprovalFeeTotal = '0x0'; + if (approveTxParams) { + l1ApprovalFeeTotal = await fetchEstimatedL1Fee(global.eth, { + txParams: { + ...approveTxParams, + gasPrice: addHexPrefix(approveTxParams.gasPrice), + value: '0x0', // For approval txs we need to use "0x0" here. + }, + chainId, + }); + } + const l1FeeTotal = sumHexes(l1TradeFeeTotal, l1ApprovalFeeTotal); + setMultiLayerL1FeeTotal(l1FeeTotal); } catch (e) { captureException(e); setMultiLayerL1FeeTotal(null); } }; getEstimatedL1Fee(); - }, [unsignedTransaction, isMultiLayerFeeNetwork, chainId]); + }, [unsignedTransaction, approveTxParams, isMultiLayerFeeNetwork, chainId]); useEffect(() => { if (currentSmartTransactionsEnabled && smartTransactionsOptInStatus) {