mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-25 11:28:51 +01:00
fix: Pass correct optimism chain id to gas estimation (#18478)
This commit is contained in:
parent
18ff108627
commit
f92e463a0f
@ -44,7 +44,10 @@ export default function MultilayerFeeMessage({
|
||||
useEffect(() => {
|
||||
const getEstimatedL1Fee = async () => {
|
||||
try {
|
||||
const result = await fetchEstimatedL1Fee(transaction);
|
||||
const result = await fetchEstimatedL1Fee(
|
||||
transaction.chainId,
|
||||
transaction.txParams,
|
||||
);
|
||||
setLayer1Total(result);
|
||||
} catch (e) {
|
||||
captureException(e);
|
||||
@ -75,7 +78,7 @@ export default function MultilayerFeeMessage({
|
||||
return (
|
||||
<div className="multi-layer-fee-message">
|
||||
<TransactionDetailItem
|
||||
key="total-item"
|
||||
key="total-item-gas-fee"
|
||||
detailTitle={t('gasFee')}
|
||||
detailTotal={layer1Total}
|
||||
detailText={feeTotalInFiat}
|
||||
@ -83,7 +86,7 @@ export default function MultilayerFeeMessage({
|
||||
flexWidthValues={plainStyle}
|
||||
/>
|
||||
<TransactionDetailItem
|
||||
key="total-item"
|
||||
key="total-item-total"
|
||||
detailTitle={t('total')}
|
||||
detailTotal={totalInEth}
|
||||
detailText={totalInFiat}
|
||||
|
@ -505,7 +505,7 @@ export const computeEstimatedGasLimit = createAsyncThunk(
|
||||
|
||||
let gasTotalForLayer1;
|
||||
if (isMultiLayerFeeNetwork) {
|
||||
gasTotalForLayer1 = await fetchEstimatedL1Fee({
|
||||
gasTotalForLayer1 = await fetchEstimatedL1Fee(chainId, {
|
||||
txParams: {
|
||||
gasPrice: draftTransaction.gas.gasPrice,
|
||||
gas: draftTransaction.gas.gasLimit,
|
||||
|
@ -19,14 +19,20 @@ const OPTIMISM_GAS_PRICE_ORACLE_ABI = [
|
||||
const OPTIMISM_GAS_PRICE_ORACLE_ADDRESS =
|
||||
'0x420000000000000000000000000000000000000F';
|
||||
|
||||
export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) {
|
||||
export default async function fetchEstimatedL1Fee(
|
||||
chainId,
|
||||
txMeta,
|
||||
ethersProvider,
|
||||
) {
|
||||
const networkId = Number(chainId);
|
||||
const provider = global.ethereumProvider
|
||||
? new Web3Provider(global.ethereumProvider, 10)
|
||||
? new Web3Provider(global.ethereumProvider, networkId)
|
||||
: ethersProvider;
|
||||
|
||||
if (process.env.IN_TEST) {
|
||||
provider.detectNetwork = async () => ({
|
||||
name: 'optimism',
|
||||
chainId: 10,
|
||||
chainId: networkId,
|
||||
});
|
||||
}
|
||||
const contract = new Contract(
|
||||
@ -36,7 +42,6 @@ export default async function fetchEstimatedL1Fee(txMeta, ethersProvider) {
|
||||
);
|
||||
const serializedTransaction =
|
||||
buildUnserializedTransaction(txMeta).serialize();
|
||||
|
||||
const result = await contract.getL1Fee(serializedTransaction);
|
||||
return result?.toHexString();
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ describe('fetchEstimatedL1Fee', () => {
|
||||
result: `0x0000000000000000000000000000000000000000000000000000${expectedGasFeeResult}`,
|
||||
});
|
||||
|
||||
const gasFee = await fetchEstimatedL1Fee({
|
||||
const gasFee = await fetchEstimatedL1Fee('10', {
|
||||
txParams: {
|
||||
gasPrice: '0xf4240',
|
||||
gas: '0xcf08',
|
||||
@ -43,7 +43,6 @@ describe('fetchEstimatedL1Fee', () => {
|
||||
data: null,
|
||||
type: '0x0',
|
||||
},
|
||||
chainId: '10',
|
||||
});
|
||||
expect(gasFee).toStrictEqual(`0x${expectedGasFeeResult}`);
|
||||
});
|
||||
|
@ -896,13 +896,12 @@ export default function ViewQuote() {
|
||||
try {
|
||||
let l1ApprovalFeeTotal = '0x0';
|
||||
if (approveTxParams) {
|
||||
l1ApprovalFeeTotal = await fetchEstimatedL1Fee({
|
||||
l1ApprovalFeeTotal = await fetchEstimatedL1Fee(chainId, {
|
||||
txParams: {
|
||||
...approveTxParams,
|
||||
gasPrice: addHexPrefix(approveTxParams.gasPrice),
|
||||
value: '0x0', // For approval txs we need to use "0x0" here.
|
||||
},
|
||||
chainId,
|
||||
});
|
||||
setMultiLayerL1ApprovalFeeTotal(l1ApprovalFeeTotal);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user