@@ -10,14 +10,15 @@ import {
1010 isNonEvmChainId ,
1111 isValidQuoteRequest ,
1212 BRIDGE_QUOTE_MAX_RETURN_DIFFERENCE_PERCENTAGE ,
13- getNativeAssetForChainId ,
1413 isNativeAddress ,
1514 UnifiedSwapBridgeEventName ,
1615 type BridgeController ,
1716 isCrossChain ,
17+ formatChainIdToHex ,
1818 isBitcoinChainId ,
19+ getNativeAssetForChainId ,
1920} from '@metamask/bridge-controller' ;
20- import type { Hex } from '@metamask/utils' ;
21+ import { type CaipChainId , type Hex , parseCaipChainId } from '@metamask/utils' ;
2122import {
2223 setFromToken ,
2324 setFromTokenInputValue ,
@@ -81,7 +82,6 @@ import {
8182 isQuoteExpiredOrInvalid as isQuoteExpiredOrInvalidUtil ,
8283 safeAmountForCalc ,
8384} from '../utils/quote' ;
84- import { isNetworkAdded } from '../../../ducks/bridge/utils' ;
8585import MascotBackgroundAnimation from '../../swaps/mascot-background-animation/mascot-background-animation' ;
8686import { Column } from '../layout' ;
8787import useRamps from '../../../hooks/ramps/useRamps/useRamps' ;
@@ -115,6 +115,7 @@ import { useEnableMissingNetwork } from '../hooks/useEnableMissingNetwork';
115115import { BridgeInputGroup } from './bridge-input-group' ;
116116import { PrepareBridgePageFooter } from './prepare-bridge-page-footer' ;
117117import { DestinationAccountPickerModal } from './components/destination-account-picker-modal' ;
118+ import { NetworkConfiguration } from '@metamask/network-controller' ;
118119
119120const PrepareBridgePage = ( {
120121 onOpenSettings,
@@ -466,12 +467,12 @@ const PrepareBridgePage = ({
466467 return t ( 'swapSelectToken' ) ;
467468 } ;
468469
469- const getTokenOccurrences = ( chainId : Hex | undefined ) : number => {
470+ const getTokenOccurrences = ( chainId : Hex | CaipChainId | undefined ) : number => {
470471 if ( ! chainId ) {
471472 return MINIMUM_TOKEN_OCCURRENCES ;
472473 }
473474 return (
474- TOKEN_OCCURRENCES_MAP [ chainId as ChainId ] ?? MINIMUM_TOKEN_OCCURRENCES
475+ TOKEN_OCCURRENCES_MAP [ chainId as keyof typeof TOKEN_OCCURRENCES_MAP ] ?? MINIMUM_TOKEN_OCCURRENCES
475476 ) ;
476477 } ;
477478
@@ -500,11 +501,10 @@ const PrepareBridgePage = ({
500501 address : token . address ?? zeroAddress ( ) ,
501502 } ;
502503 dispatch ( setFromToken ( bridgeToken ) ) ;
503- dispatch ( setFromTokenInputValue ( null ) ) ;
504504 } }
505505 networkProps = { {
506- network : fromChain ,
507- networks : fromChains ,
506+ network : fromChain as NetworkConfiguration ,
507+ networks : fromChains as NetworkConfiguration [ ] ,
508508 onNetworkChange : ( networkConfig ) => {
509509 enableMissingNetwork ( networkConfig . chainId ) ;
510510 dispatch (
@@ -590,7 +590,14 @@ const PrepareBridgePage = ({
590590 disabled = {
591591 isSwitchingTemporarilyDisabled ||
592592 ! isValidQuoteRequest ( quoteRequest , false ) ||
593- ( toChain && ! isNetworkAdded ( toChain ) )
593+ // Check if the toChain is an enabled fromChain
594+ ( toChain &&
595+ ! fromChains . some (
596+ ( { chainId : fromChainId } ) =>
597+ fromChainId === toChain . chainId ||
598+ formatChainIdToCaip ( fromChainId ) ===
599+ formatChainIdToCaip ( toChain . chainId ) ,
600+ ) )
594601 }
595602 onClick = { ( ) => {
596603 dispatch ( setSelectedQuote ( null ) ) ;
@@ -604,10 +611,10 @@ const PrepareBridgePage = ({
604611 {
605612 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
606613 // eslint-disable-next-line @typescript-eslint/naming-convention
607- token_symbol_source : toToken ? .symbol ?? null ,
614+ token_symbol_source : toToken . symbol ,
608615 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
609616 // eslint-disable-next-line @typescript-eslint/naming-convention
610- token_symbol_destination : fromToken ? .symbol ?? null ,
617+ token_symbol_destination : fromToken . symbol ,
611618 // TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
612619 // eslint-disable-next-line @typescript-eslint/naming-convention
613620 token_address_source : toToken ?. assetId ,
@@ -656,12 +663,10 @@ const PrepareBridgePage = ({
656663 dispatch ( setToToken ( bridgeToken ) ) ;
657664 } }
658665 networkProps = { {
659- network : toChain ,
660- networks : toChains ,
666+ network : toChain as NetworkConfiguration ,
667+ networks : toChains as NetworkConfiguration [ ] ,
661668 onNetworkChange : ( networkConfig ) => {
662- if ( isNetworkAdded ( networkConfig ) ) {
663- enableMissingNetwork ( networkConfig . chainId ) ;
664- }
669+ enableMissingNetwork ( networkConfig . chainId ) ;
665670 dispatch ( setToChainId ( networkConfig . chainId ) ) ;
666671 } ,
667672 header : t ( 'yourNetworks' ) ,
0 commit comments