Skip to content
1 change: 0 additions & 1 deletion app/components/UI/AssetOverview/AssetOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ const AssetOverview: React.FC<AssetOverviewProps> = ({
displayBuyButton={displayBuyButton}
displaySwapsButton={displaySwapsButton}
displayBridgeButton={displayBridgeButton}
chainId={chainId}
goToBridge={goToBridge}
goToSwaps={goToSwaps}
onBuy={onBuy}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ export const useSwapBridgeNavigation = ({

const candidateSourceToken =
tokenBase ?? bridgeNativeSourceTokenFormatted;
const sourceToken = isBridgeEnabledSource
let sourceToken = isBridgeEnabledSource
? candidateSourceToken
: undefined;

if (!sourceToken) {
return;
// fallback to ETH on mainnet
sourceToken = {
address: ethers.constants.AddressZero,
chainId: EthScope.Mainnet,
symbol: 'ETH',
decimals: 18,
};
}

const params: BridgeRouteParams = {
Expand Down
2 changes: 0 additions & 2 deletions app/components/UI/UrlAutocomplete/Result.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import Badge, {
} from '../../../component-library/components/Badges/Badge';
import { NetworkBadgeSource } from '../AssetOverview/Balance/Balance';
import AvatarToken from '../../../component-library/components/Avatars/Avatar/variants/AvatarToken';
import { isSwapsAllowed } from '../Swaps/utils';
import AppConstants from '../../../core/AppConstants';
import { selectCurrentCurrency } from '../../../selectors/currencyRateController';
import { addCurrencySymbol } from '../../../util/number';
Expand Down Expand Up @@ -51,7 +50,6 @@ export const Result: React.FC<ResultProps> = memo(

const swapsEnabled =
result.category === UrlAutocompleteCategory.Tokens &&
isSwapsAllowed(result.chainId) &&
AppConstants.SWAPS.ACTIVE;

const currentCurrency = useSelector(selectCurrentCurrency);
Expand Down
8 changes: 1 addition & 7 deletions app/components/Views/Asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import { mockTheme, ThemeContext } from '../../../util/theme';
import { addAccountTimeFlagFilter } from '../../../util/transactions';
import AssetOverview from '../../UI/AssetOverview';
import { getNetworkNavbarOptions } from '../../UI/Navbar';
import { isSwapsAllowed } from '../../UI/Swaps/utils';
import Transactions from '../../UI/Transactions';
import ActivityHeader from './ActivityHeader';
import {
Expand Down Expand Up @@ -80,7 +79,6 @@ import { isNonEvmChainId } from '../../../core/Multichain/utils';
import { isBridgeAllowed } from '../../UI/Bridge/utils';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { selectNonEvmTransactions } from '../../../selectors/multichain';
import { isEvmAccountType } from '@metamask/keyring-api';
///: END:ONLY_INCLUDE_IF
import { getIsSwapsAssetAllowed } from './utils';
import MultichainTransactionsView from '../MultichainTransactionsView/MultichainTransactionsView';
Expand Down Expand Up @@ -578,9 +576,6 @@ class Asset extends PureComponent {
const styles = createStyles(colors);
const asset = navigation && params;
const isSwapsFeatureLive = this.props.swapsIsLive;
const isSwapsNetworkAllowed = isPortfolioViewEnabled()
? isSwapsAllowed(asset.chainId)
: isSwapsAllowed(chainId);

const isSwapsAssetAllowed = getIsSwapsAssetAllowed({
asset,
Expand All @@ -591,8 +586,7 @@ class Asset extends PureComponent {
// Check if unified swaps is enabled
const isUnifiedSwapsEnabled = this.props.isUnifiedSwapsEnabled;

const displaySwapsButton =
isSwapsNetworkAllowed && isSwapsAssetAllowed && AppConstants.SWAPS.ACTIVE;
const displaySwapsButton = isSwapsAssetAllowed && AppConstants.SWAPS.ACTIVE;

const displayBridgeButton =
!isUnifiedSwapsEnabled &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const Default = Template.bind(
displayBuyButton: true,
displaySwapsButton: true,
displayBridgeButton: true,
chainId: '0x1' as const,
onBuy: () => null,
goToSwaps: () => null,
goToBridge: () => null,
Expand All @@ -52,7 +51,6 @@ export const NoBuyButton = Template.bind(
displayBuyButton: false,
displaySwapsButton: true,
displayBridgeButton: true,
chainId: '0x1' as const,
onBuy: () => null,
goToSwaps: () => null,
goToBridge: () => null,
Expand All @@ -67,7 +65,6 @@ export const NoSwapsButton = Template.bind(
displayBuyButton: true,
displaySwapsButton: false,
displayBridgeButton: true,
chainId: '0x1' as const,
onBuy: () => null,
goToSwaps: () => null,
goToBridge: () => null,
Expand All @@ -82,7 +79,6 @@ export const NoBridgeButton = Template.bind(
displayBuyButton: true,
displaySwapsButton: true,
displayBridgeButton: false,
chainId: '0x1' as const,
onBuy: () => null,
goToSwaps: () => null,
goToBridge: () => null,
Expand All @@ -97,7 +93,6 @@ export const NoButtons = Template.bind(
displayBuyButton: false,
displaySwapsButton: false,
displayBridgeButton: false,
chainId: '0x1' as const,
onBuy: () => null,
goToSwaps: () => null,
goToBridge: () => null,
Expand All @@ -112,7 +107,6 @@ export const FundActionMenuNavigation = Template.bind(
displayBuyButton: true,
displaySwapsButton: true,
displayBridgeButton: true,
chainId: '0x1' as const,
// No onBuy prop - will navigate to FundActionMenu
goToSwaps: () => null,
goToBridge: () => null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ import { selectCanSignTransactions } from '../../../../selectors/accountsControl
import { selectIsSwapsEnabled } from '../../../../core/redux/slices/bridge';
import Routes from '../../../../constants/navigation/Routes';
import useDepositEnabled from '../../../UI/Ramp/Deposit/hooks/useDepositEnabled';
import { CaipChainId, Hex } from '@metamask/utils';
import { RootState } from '../../../../reducers';

export interface AssetDetailsActionsProps {
displayBuyButton: boolean | undefined;
displaySwapsButton: boolean | undefined;
displayBridgeButton: boolean | undefined;
chainId: Hex | CaipChainId;
onBuy?: () => void;
goToSwaps: () => void;
goToBridge: () => void;
Expand All @@ -43,7 +41,6 @@ export const AssetDetailsActions: React.FC<AssetDetailsActionsProps> = ({
displayBuyButton,
displaySwapsButton,
displayBridgeButton,
chainId,
onBuy,
goToSwaps,
goToBridge,
Expand All @@ -59,7 +56,7 @@ export const AssetDetailsActions: React.FC<AssetDetailsActionsProps> = ({
const { styles } = useStyles(styleSheet, {});
const canSignTransactions = useSelector(selectCanSignTransactions);
const isSwapsEnabled = useSelector((state: RootState) =>
selectIsSwapsEnabled(state, chainId),
selectIsSwapsEnabled(state),
);
const { navigate } = useNavigation();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { fireEvent } from '@testing-library/react-native';
import { isSwapsAllowed } from '../../../components/UI/Swaps/utils';
import { selectCanSignTransactions } from '../../../selectors/accountsController';
import { selectChainId } from '../../../selectors/networkController';
import {
DeepPartial,
renderScreen,
Expand Down Expand Up @@ -138,17 +136,12 @@ jest.mock('../../../core/redux/slices/bridge', () => ({
selectAllBridgeableNetworks: jest.fn().mockReturnValue([]),
selectIsBridgeEnabledSource: jest.fn().mockReturnValue(true),
selectIsUnifiedSwapsEnabled: jest.fn().mockReturnValue(false),
selectIsSwapsLive: jest.fn().mockReturnValue(true),
}));

jest.mock('../../../selectors/tokenListController', () => ({
selectTokenList: jest.fn().mockReturnValue([]),
}));

jest.mock('../../../components/UI/Swaps/utils', () => ({
isSwapsAllowed: jest.fn().mockReturnValue(true),
}));

const mockGoToSwaps = jest.fn();
jest.mock('../../UI/Bridge/hooks/useSwapBridgeNavigation', () => ({
useSwapBridgeNavigation: () => ({
Expand Down Expand Up @@ -363,67 +356,6 @@ describe('TradeWalletActions', () => {
).toBeDefined();
});

it('should not show the swap button if the chain does not allow swaps', () => {
(isSwapsAllowed as jest.Mock).mockReturnValue(false);

const mockState: DeepPartial<RootState> = {
swaps: { '0x1': { isLive: false }, hasOnboarded: false, isLive: true },
engine: {
backgroundState: {
...backgroundState,
NetworkController: {
...mockNetworkState({
chainId: CHAIN_IDS.SEPOLIA,
id: 'sepolia',
nickname: 'Sepolia',
ticker: 'ETH',
}),
},
},
},
};

const { queryByTestId } = renderScreen(
TradeWalletActions,
{
name: 'TradeWalletActions',
},
{
state: mockState,
},
);

expect(
queryByTestId(WalletActionsBottomSheetSelectorsIDs.SWAP_BUTTON),
).toBeNull();
});

it.skip('should call the goToSwaps function when the Swap button is pressed', async () => {
(isSwapsAllowed as jest.Mock).mockReturnValue(true);
(selectChainId as unknown as jest.Mock).mockReturnValue('0x1');

const { getByTestId } = renderScreen(
TradeWalletActions,
{
name: 'TradeWalletActions',
},
{
state: mockInitialState,
},
);

fireEvent.press(
getByTestId(WalletActionsBottomSheetSelectorsIDs.SWAP_BUTTON),
);

// Wait for async operations
await new Promise((resolve) => setTimeout(resolve, 1000));

expect(mockOnDismiss).toHaveBeenCalled();
expect(mockGoToSwaps).toHaveBeenCalled();
expect(mockNavigate).toHaveBeenCalled();
});

it('should hide the earn button if there are no elements to show and pooled staking is disabled', () => {
(
selectStablecoinLendingEnabledFlag as jest.MockedFunction<
Expand Down Expand Up @@ -636,7 +568,6 @@ describe('TradeWalletActions', () => {
>
).mockReturnValue(true);
(selectCanSignTransactions as unknown as jest.Mock).mockReturnValue(false);
(isSwapsAllowed as jest.Mock).mockReturnValue(true);

const mockStateWithoutSigningAndStablecoinLendingEnabled: DeepPartial<RootState> =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
import { selectPerpsEnabledFlag } from '../../UI/Perps';
import { selectPredictEnabledFlag } from '../../UI/Predict';
import { EVENT_LOCATIONS as STAKE_EVENT_LOCATIONS } from '../../UI/Stake/constants/events';
import { isSwapsAllowed } from '../../UI/Swaps/utils';
import { MetaMetricsEvents, useMetrics } from '../../hooks/useMetrics';

import BottomShape from './components/BottomShape';
Expand Down Expand Up @@ -84,7 +83,7 @@ function TradeWalletActions() {
const tw = useTailwind();
const chainId = useSelector(selectChainId);
const isSwapsEnabled = useSelector((state: RootState) =>
selectIsSwapsEnabled(state, chainId),
selectIsSwapsEnabled(state),
);
const isPooledStakingEnabled = useSelector(selectPooledStakingEnabledFlag);

Expand Down Expand Up @@ -278,7 +277,7 @@ function TradeWalletActions() {
`px-0`,
)}
>
{AppConstants.SWAPS.ACTIVE && isSwapsAllowed(chainId) && (
{AppConstants.SWAPS.ACTIVE && (
<ActionListItem
label={strings('asset_overview.swap')}
description={strings('asset_overview.swap_description')}
Expand Down
1 change: 0 additions & 1 deletion app/components/Views/Wallet/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ describe('Wallet', () => {
displayBuyButton: expect.any(Boolean),
displaySwapsButton: expect.any(Boolean),
displayBridgeButton: expect.any(Boolean),
chainId: expect.any(String),
goToBridge: expect.any(Function),
goToSwaps: expect.any(Function),
onReceive: expect.any(Function),
Expand Down
6 changes: 1 addition & 5 deletions app/components/Views/Wallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ import AppConstants from '../../../core/AppConstants';
import { selectIsUnifiedSwapsEnabled } from '../../../core/redux/slices/bridge';
import { getEther } from '../../../util/transactions';
import { isBridgeAllowed } from '../../UI/Bridge/utils';
import { isSwapsAllowed } from '../../UI/Swaps/utils';
///: BEGIN:ONLY_INCLUDE_IF(keyring-snaps)
import { useSendNonEvmAsset } from '../../hooks/useSendNonEvmAsset';
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -560,8 +559,7 @@ const Wallet = ({
///: END:ONLY_INCLUDE_IF

const displayBuyButton = true;
const displaySwapsButton =
AppConstants.SWAPS.ACTIVE && isSwapsAllowed(chainId);
const displaySwapsButton = AppConstants.SWAPS.ACTIVE;
const displayBridgeButton =
!isUnifiedSwapsEnabled &&
AppConstants.BRIDGE.ACTIVE &&
Expand Down Expand Up @@ -1253,7 +1251,6 @@ const Wallet = ({
displayBuyButton={displayBuyButton}
displaySwapsButton={displaySwapsButton}
displayBridgeButton={displayBridgeButton}
chainId={chainId}
goToBridge={goToBridge}
goToSwaps={goToSwaps}
onReceive={onReceive}
Expand Down Expand Up @@ -1301,7 +1298,6 @@ const Wallet = ({
route.params,
isCarouselBannersEnabled,
collectiblesEnabled,
chainId,
],
);
const renderLoader = useCallback(
Expand Down
Loading
Loading