Skip to content

Commit ebf4a3f

Browse files
committed
fix: poll gas estimates for fromChain
1 parent 0d609f7 commit ebf4a3f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

ui/pages/bridge/index.tsx

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React, { useContext, useEffect, useState } from 'react';
22
import { useDispatch, useSelector } from 'react-redux';
33
import { Route, Routes } from 'react-router-dom-v5-compat';
4+
import { type Hex } from '@metamask/utils';
45
import {
56
UnifiedSwapBridgeEventName,
6-
// TODO: update this with all non-EVM chains when bitcoin added.
7-
isSolanaChainId,
7+
formatChainIdToHex,
8+
isNonEvmChainId,
89
} from '@metamask/bridge-controller';
910
import { I18nContext } from '../../contexts/i18n';
1011
import { clearSwapsState } from '../../ducks/swaps/swaps';
@@ -21,7 +22,6 @@ import {
2122
ButtonIconSize,
2223
IconName,
2324
} from '../../components/component-library';
24-
import { getSelectedNetworkClientId } from '../../../shared/modules/selectors/networks';
2525
import useBridging from '../../hooks/bridge/useBridging';
2626
import {
2727
Content,
@@ -42,6 +42,7 @@ import { TextVariant } from '../../helpers/constants/design-system';
4242
import { useTxAlerts } from '../../hooks/bridge/useTxAlerts';
4343
import { getFromChain, getBridgeQuotes } from '../../ducks/bridge/selectors';
4444
import { useSafeNavigation } from '../../hooks/useSafeNavigation';
45+
import { getNetworkConfigurationIdByChainId } from '../../selectors';
4546
import PrepareBridgePage from './prepare/prepare-bridge-page';
4647
import AwaitingSignaturesCancelButton from './awaiting-signatures/awaiting-signatures-cancel-button';
4748
import AwaitingSignatures from './awaiting-signatures/awaiting-signatures';
@@ -69,8 +70,6 @@ const CrossChainSwap = ({ location }: CrossChainSwapProps) => {
6970
'isFromTransactionShield',
7071
);
7172

72-
const selectedNetworkClientId = useSelector(getSelectedNetworkClientId);
73-
7473
const resetControllerAndInputStates = async () => {
7574
await dispatch(resetBridgeState());
7675
};
@@ -79,10 +78,13 @@ const CrossChainSwap = ({ location }: CrossChainSwapProps) => {
7978

8079
// Get chain information to determine if we need gas estimates
8180
const fromChain = useSelector(getFromChain);
82-
// Only fetch gas estimates if the source chain is EVM (not Solana)
83-
const shouldFetchGasEstimates =
84-
// TODO: update this with all non-EVM chains when bitcoin added.
85-
fromChain?.chainId && !isSolanaChainId(fromChain.chainId);
81+
const isEvmChain = !isNonEvmChainId(fromChain.chainId);
82+
const networkClientIdsByHexChainId: Record<Hex, string> = useSelector(
83+
getNetworkConfigurationIdByChainId,
84+
);
85+
const selectedNetworkClientId = isEvmChain
86+
? networkClientIdsByHexChainId[formatChainIdToHex(fromChain.chainId)]
87+
: undefined;
8688

8789
useEffect(() => {
8890
dispatch(
@@ -106,7 +108,7 @@ const CrossChainSwap = ({ location }: CrossChainSwapProps) => {
106108
}, []);
107109

108110
// Needed for refreshing gas estimates (only for EVM chains)
109-
useGasFeeEstimates(selectedNetworkClientId, shouldFetchGasEstimates);
111+
useGasFeeEstimates(selectedNetworkClientId, isEvmChain);
110112
// Needed for fetching exchange rates for tokens that have not been imported
111113
useBridgeExchangeRates();
112114
// Emits events related to quote-fetching

0 commit comments

Comments
 (0)