Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,6 @@ jobs:
check-workflows,
js-bundle-size-check,
sonar-cloud-quality-gate-status,
e2e-smoke-tests-android,
]
outputs:
ALL_JOBS_PASSED: ${{ steps.jobs-passed-status.outputs.ALL_JOBS_PASSED }}
Expand Down
1 change: 1 addition & 0 deletions .storybook/storybook.requires.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/components/Nav/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import { TokenSortBottomSheet } from '../../../components/UI/Tokens/TokensBottom
import ProfilerManager from '../../../components/UI/ProfilerManager';
import { TokenFilterBottomSheet } from '../../../components/UI/Tokens/TokensBottomSheet/TokenFilterBottomSheet';
import NetworkManager from '../../../components/UI/NetworkManager';
import AccountConnect from '../../../components/Views/AccountConnect';
import AccountPermissions from '../../../components/Views/AccountPermissions';
import { AccountPermissionsScreens } from '../../../components/Views/AccountPermissions/AccountPermissions.types';
import AccountPermissionsConfirmRevokeAll from '../../../components/Views/AccountPermissions/AccountPermissionsConfirmRevokeAll';
Expand Down Expand Up @@ -152,6 +151,7 @@ import { SmartAccountUpdateModal } from '../../Views/confirmations/components/sm
import { PayWithModal } from '../../Views/confirmations/components/modals/pay-with-modal/pay-with-modal';
import { PayWithNetworkModal } from '../../Views/confirmations/components/modals/pay-with-network-modal/pay-with-network-modal';
import { useMetrics } from '../../hooks/useMetrics';
import { State2AccountConnectWrapper } from '../../Views/MultichainAccounts/MultichainAccountConnect/State2AccountConnectWrapper';
import { SmartAccountModal } from '../../Views/MultichainAccounts/AccountDetails/components/SmartAccountModal/SmartAccountModal';

const clearStackNavigatorOptions = {
Expand Down Expand Up @@ -408,7 +408,7 @@ const RootModalFlow = (props: RootModalFlowProps) => (
/>
<Stack.Screen
name={Routes.SHEET.ACCOUNT_CONNECT}
component={AccountConnect}
component={State2AccountConnectWrapper}
/>
<Stack.Screen
name={Routes.SHEET.ACCOUNT_PERMISSIONS}
Expand Down
4 changes: 2 additions & 2 deletions app/components/UI/Bridge/hooks/useInitialDestToken/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
selectDestToken,
} from '../../../../../core/redux/slices/bridge';
import { useDispatch, useSelector } from 'react-redux';
import { DefaultSwapDestTokens } from '../../constants/default-swap-dest-tokens';
import { getDefaultDestToken } from '../../utils/tokenUtils';
import { selectChainId } from '../../../../../selectors/networkController';
import { BridgeViewMode, BridgeToken } from '../../types';
import { getNativeSourceToken } from '../useInitialSourceToken';
Expand Down Expand Up @@ -34,7 +34,7 @@ export const useInitialDestToken = (
}

const destTokenTargetChainId = initialSourceToken?.chainId ?? selectedChainId;
let defaultDestToken = DefaultSwapDestTokens[destTokenTargetChainId];
let defaultDestToken = getDefaultDestToken(destTokenTargetChainId);

// If the initial source token is the same as the default dest token, set the default dest token to the native token
if (
Expand Down
32 changes: 16 additions & 16 deletions app/components/UI/Bridge/hooks/useInitialSourceToken/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ import { CaipChainId, Hex } from '@metamask/utils';
import {
getNativeAssetForChainId,
isSolanaChainId,
formatChainIdToCaip,
formatChainIdToHex,
} from '@metamask/bridge-controller';
import { constants } from 'ethers';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { SolScope } from '@metamask/keyring-api';
import usePrevious from '../../../../hooks/usePrevious';
import {
selectIsEvmNetworkSelected,
selectSelectedNonEvmNetworkChainId,
} from '../../../../../selectors/multichainNetworkController';
///: END:ONLY_INCLUDE_IF

export const getNativeSourceToken = (chainId: Hex | CaipChainId) => {
const nativeAsset = getNativeAssetForChainId(chainId);
Expand Down Expand Up @@ -63,12 +63,7 @@ export const useInitialSourceToken = (
domainIsConnectedDapp,
networkName: selectedEvmNetworkName,
} = useNetworkInfo();
const {
onSetRpcTarget,
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
onNonEvmNetworkChange,
///: END:ONLY_INCLUDE_IF
} = useSwitchNetworks({
const { onSetRpcTarget, onNonEvmNetworkChange } = useSwitchNetworks({
domainIsConnectedDapp,
selectedChainId: selectedEvmChainId,
selectedNetworkName: selectedEvmNetworkName,
Expand Down Expand Up @@ -101,14 +96,19 @@ export const useInitialSourceToken = (
}

// Change network if necessary
if (initialSourceToken?.chainId && initialSourceToken?.chainId !== chainId) {
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
if (initialSourceToken?.chainId === SolScope.Mainnet) {
onNonEvmNetworkChange(initialSourceToken.chainId);
return;
}
///: END:ONLY_INCLUDE_IF
if (initialSourceToken?.chainId) {
// Convert both chain IDs to CAIP format for accurate comparison
const sourceCaipChainId = formatChainIdToCaip(initialSourceToken.chainId);
const currentCaipChainId = formatChainIdToCaip(chainId);

onSetRpcTarget(evmNetworkConfigurations[initialSourceToken.chainId as Hex]);
if (sourceCaipChainId !== currentCaipChainId) {
if (sourceCaipChainId === SolScope.Mainnet) {
onNonEvmNetworkChange(SolScope.Mainnet);
return;
}

const hexChainId = formatChainIdToHex(sourceCaipChainId);
onSetRpcTarget(evmNetworkConfigurations[hexChainId]);
}
}
};
44 changes: 36 additions & 8 deletions app/components/UI/Bridge/hooks/useSwapBridgeNavigation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { useCallback } from 'react';
import { useNavigation } from '@react-navigation/native';
import useGoToPortfolioBridge from '../useGoToPortfolioBridge';
import Routes from '../../../../../constants/navigation/Routes';
import { Hex } from '@metamask/utils';
import { Hex, CaipChainId } from '@metamask/utils';
import Engine from '../../../../../core/Engine';
import { useSelector } from 'react-redux';
import { selectChainId } from '../../../../../selectors/networkController';
import { BridgeToken, BridgeViewMode } from '../../types';
import { getNativeAssetForChainId } from '@metamask/bridge-controller';
import {
formatChainIdToHex,
getNativeAssetForChainId,
isSolanaChainId,
} from '@metamask/bridge-controller';
import { BridgeRouteParams } from '../../Views/BridgeView';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { SolScope } from '@metamask/keyring-api';
///: END:ONLY_INCLUDE_IF
import { SolScope, EthScope } from '@metamask/keyring-api';
import { ethers } from 'ethers';
import { MetaMetricsEvents, useMetrics } from '../../../../hooks/useMetrics';
import { getDecimalChainId } from '../../../../../util/networks';
Expand All @@ -25,6 +27,7 @@ import {
} from '../../../../../core/redux/slices/bridge';
import { RootState } from '../../../../../reducers';
import { trace, TraceName } from '../../../../../util/trace';
import { useCurrentNetworkInfo } from '../../../../hooks/useCurrentNetworkInfo';

export enum SwapBridgeNavigationLocation {
TabBar = 'TabBar',
Expand Down Expand Up @@ -55,14 +58,37 @@ export const useSwapBridgeNavigation = ({
selectIsBridgeEnabledSource(state, selectedChainId),
);
const isUnifiedSwapsEnabled = useSelector(selectIsUnifiedSwapsEnabled);
const currentNetworkInfo = useCurrentNetworkInfo();

// Bridge
const goToNativeBridge = useCallback(
(bridgeViewMode: BridgeViewMode) => {
// Determine effective chain ID - use home page filter network when no sourceToken provided
const getEffectiveChainId = (): CaipChainId | Hex => {
if (tokenBase) {
// If specific token provided, use its chainId
return tokenBase.chainId;
}

// No token provided - check home page filter network
const homePageFilterNetwork = currentNetworkInfo.getNetworkInfo(0);
if (
!homePageFilterNetwork?.caipChainId ||
currentNetworkInfo.enabledNetworks.length > 1
) {
// Fall back to mainnet if no filter or multiple networks
return EthScope.Mainnet;
}

return homePageFilterNetwork.caipChainId as CaipChainId;
};

const effectiveChainId = getEffectiveChainId();

let bridgeSourceNativeAsset;
try {
if (!tokenBase) {
bridgeSourceNativeAsset = getNativeAssetForChainId(selectedChainId);
bridgeSourceNativeAsset = getNativeAssetForChainId(effectiveChainId);
}
} catch (error) {
// Suppress error as it's expected when the chain is not supported
Expand All @@ -76,7 +102,9 @@ export const useSwapBridgeNavigation = ({
symbol: bridgeSourceNativeAsset.symbol,
image: bridgeSourceNativeAsset.iconUrl ?? '',
decimals: bridgeSourceNativeAsset.decimals,
chainId: selectedChainId,
chainId: isSolanaChainId(effectiveChainId) // TODO: refactor for other non-evm chains
? effectiveChainId
: formatChainIdToHex(effectiveChainId), // Use hex format for balance fetching compatibility, unless it's a Solana chain
}
: undefined;

Expand Down Expand Up @@ -118,13 +146,13 @@ export const useSwapBridgeNavigation = ({
},
[
navigation,
selectedChainId,
tokenBase,
sourcePage,
trackEvent,
createEventBuilder,
location,
isBridgeEnabledSource,
currentNetworkInfo,
],
);

Expand Down
Loading
Loading