11import React , { useContext , useEffect , useState } from 'react' ;
22import { useDispatch , useSelector } from 'react-redux' ;
33import { Route , Routes } from 'react-router-dom-v5-compat' ;
4+ import { type Hex } from '@metamask/utils' ;
45import {
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' ;
910import { I18nContext } from '../../contexts/i18n' ;
1011import { 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' ;
2525import useBridging from '../../hooks/bridge/useBridging' ;
2626import {
2727 Content ,
@@ -42,6 +42,7 @@ import { TextVariant } from '../../helpers/constants/design-system';
4242import { useTxAlerts } from '../../hooks/bridge/useTxAlerts' ;
4343import { getFromChain , getBridgeQuotes } from '../../ducks/bridge/selectors' ;
4444import { useSafeNavigation } from '../../hooks/useSafeNavigation' ;
45+ import { getNetworkConfigurationIdByChainId } from '../../selectors' ;
4546import PrepareBridgePage from './prepare/prepare-bridge-page' ;
4647import AwaitingSignaturesCancelButton from './awaiting-signatures/awaiting-signatures-cancel-button' ;
4748import 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