1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

fix: Pass correct optimism chain id to gas estimation (#18478)

This commit is contained in:
Danica Shen 2023-04-06 12:50:52 +01:00 committed by GitHub
parent 18ff108627
commit f92e463a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 18 additions and 12 deletions

View File

@ -44,7 +44,10 @@ export default function MultilayerFeeMessage({
useEffect(() => { useEffect(() => {
const getEstimatedL1Fee = async () => { const getEstimatedL1Fee = async () => {
try { try {
const result = await fetchEstimatedL1Fee(transaction); const result = await fetchEstimatedL1Fee(
transaction.chainId,
transaction.txParams,
);
setLayer1Total(result); setLayer1Total(result);
} catch (e) { } catch (e) {
captureException(e); captureException(e);
@ -75,7 +78,7 @@ export default function MultilayerFeeMessage({
return ( return (
<div className="multi-layer-fee-message"> <div className="multi-layer-fee-message">
<TransactionDetailItem <TransactionDetailItem
key="total-item" key="total-item-gas-fee"
detailTitle={t('gasFee')} detailTitle={t('gasFee')}
detailTotal={layer1Total} detailTotal={layer1Total}
detailText={feeTotalInFiat} detailText={feeTotalInFiat}
@ -83,7 +86,7 @@ export default function MultilayerFeeMessage({
flexWidthValues={plainStyle} flexWidthValues={plainStyle}
/> />
<TransactionDetailItem <TransactionDetailItem
key="total-item" key="total-item-total"
detailTitle={t('total')} detailTitle={t('total')}
detailTotal={totalInEth} detailTotal={totalInEth}
detailText={totalInFiat} detailText={totalInFiat}

View File

@ -505,7 +505,7 @@ export const computeEstimatedGasLimit = createAsyncThunk(
let gasTotalForLayer1; let gasTotalForLayer1;
if (isMultiLayerFeeNetwork) { if (isMultiLayerFeeNetwork) {
gasTotalForLayer1 = await fetchEstimatedL1Fee({ gasTotalForLayer1 = await fetchEstimatedL1Fee(chainId, {
txParams: { txParams: {
gasPrice: draftTransaction.gas.gasPrice, gasPrice: draftTransaction.gas.gasPrice,
gas: draftTransaction.gas.gasLimit, gas: draftTransaction.gas.gasLimit,

View File

@ -19,14 +19,20 @@ const OPTIMISM_GAS_PRICE_ORACLE_ABI = [
const OPTIMISM_GAS_PRICE_ORACLE_ADDRESS = const OPTIMISM_GAS_PRICE_ORACLE_ADDRESS =
'0x420000000000000000000000000000000000000F'; '0x420000000000000000000000000000000000000F';
export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) { export default async function fetchEstimatedL1Fee(
chainId,
txMeta,
ethersProvider,
) {
const networkId = Number(chainId);
const provider = global.ethereumProvider const provider = global.ethereumProvider
? new Web3Provider(global.ethereumProvider, 10) ? new Web3Provider(global.ethereumProvider, networkId)
: ethersProvider; : ethersProvider;
if (process.env.IN_TEST) { if (process.env.IN_TEST) {
provider.detectNetwork = async () => ({ provider.detectNetwork = async () => ({
name: 'optimism', name: 'optimism',
chainId: 10, chainId: networkId,
}); });
} }
const contract = new Contract( const contract = new Contract(
@ -36,7 +42,6 @@ export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) {
); );
const serializedTransaction = const serializedTransaction =
buildUnserializedTransaction(txMeta).serialize(); buildUnserializedTransaction(txMeta).serialize();
const result = await contract.getL1Fee(serializedTransaction); const result = await contract.getL1Fee(serializedTransaction);
return result?.toHexString(); return result?.toHexString();
} }

View File

@ -33,7 +33,7 @@ describe('fetchEstimatedL1Fee', () => {
result: `0x0000000000000000000000000000000000000000000000000000${expectedGasFeeResult}`, result: `0x0000000000000000000000000000000000000000000000000000${expectedGasFeeResult}`,
}); });
const gasFee = await fetchEstimatedL1Fee({ const gasFee = await fetchEstimatedL1Fee('10', {
txParams: { txParams: {
gasPrice: '0xf4240', gasPrice: '0xf4240',
gas: '0xcf08', gas: '0xcf08',
@ -43,7 +43,6 @@ describe('fetchEstimatedL1Fee', () => {
data: null, data: null,
type: '0x0', type: '0x0',
}, },
chainId: '10',
}); });
expect(gasFee).toStrictEqual(`0x${expectedGasFeeResult}`); expect(gasFee).toStrictEqual(`0x${expectedGasFeeResult}`);
}); });

View File

@ -896,13 +896,12 @@ export default function ViewQuote() {
try { try {
let l1ApprovalFeeTotal = '0x0'; let l1ApprovalFeeTotal = '0x0';
if (approveTxParams) { if (approveTxParams) {
l1ApprovalFeeTotal = await fetchEstimatedL1Fee({ l1ApprovalFeeTotal = await fetchEstimatedL1Fee(chainId, {
txParams: { txParams: {
...approveTxParams, ...approveTxParams,
gasPrice: addHexPrefix(approveTxParams.gasPrice), gasPrice: addHexPrefix(approveTxParams.gasPrice),
value: '0x0', // For approval txs we need to use "0x0" here. value: '0x0', // For approval txs we need to use "0x0" here.
}, },
chainId,
}); });
setMultiLayerL1ApprovalFeeTotal(l1ApprovalFeeTotal); setMultiLayerL1ApprovalFeeTotal(l1ApprovalFeeTotal);
} }