Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -53,30 +53,6 @@ const createStateOverrides = (
},
});

const createTestnetState = (): ReturnType<typeof createStateOverrides> =>
createStateOverrides({
useExternalServices: true,
selectedNetworkClientId: 'goerli',
networkConfigurationsByChainId: {
...mockState.metamask.networkConfigurationsByChainId,
'0x5': {
// Goerli testnet - not in allowed swaps chains
chainId: '0x5',
name: 'Goerli',
nativeCurrency: 'ETH',
defaultRpcEndpointIndex: 0,
rpcEndpoints: [
{
type: 'infura',
url: 'https://goerli.infura.io/v3/test',
networkClientId: 'goerli',
},
],
blockExplorerUrls: [],
},
},
});

const createStateWithoutExternalServices = (): ReturnType<
typeof createStateOverrides
> =>
Expand Down Expand Up @@ -205,11 +181,6 @@ describe('TransactionActivityEmptyState', () => {
ReturnType<typeof createStateOverrides> | Record<string, never>,
]
>([
[
'not a swaps chain',
{ account: accountWithSigning },
createTestnetState(),
],
[
'external services are disabled',
{ account: accountWithSigning },
Expand Down Expand Up @@ -245,7 +216,7 @@ describe('TransactionActivityEmptyState', () => {
expectSwapButtonState(true);
});

it('enables swap button for Solana networks even when isSwapsChain is false', () => {
it('enables swap button for all networks when signing and external services are enabled', () => {
jest
.spyOn(useMultichainSelectorHook, 'useMultichainSelector')
.mockReturnValue({
Expand All @@ -255,9 +226,9 @@ describe('TransactionActivityEmptyState', () => {
const props: Partial<TransactionActivityEmptyStateProps> = {
account: accountWithSigning,
};
const stateOverrides = createTestnetState();
const stateOverrides = createValidSwapState();
renderComponent(props, stateOverrides);
expectSwapButtonState(true); // Should be enabled due to Solana logic
expectSwapButtonState(true);
});

it('calls openBridgeExperience when swap button is clicked', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import { EthMethod } from '@metamask/keyring-api';
import { TabEmptyState } from '../../ui/tab-empty-state';
import { useI18nContext } from '../../../hooks/useI18nContext';
import { useTheme } from '../../../hooks/useTheme';
import { getUseExternalServices, getIsSwapsChain } from '../../../selectors';
import { getCurrentChainId } from '../../../../shared/modules/selectors/networks';
import { getUseExternalServices } from '../../../selectors';
import { MetaMetricsSwapsEventSource } from '../../../../shared/constants/metametrics';
import useBridging from '../../../hooks/bridge/useBridging';
import { ThemeType } from '../../../../shared/constants/preferences';
import { getMultichainNetwork } from '../../../selectors/multichain';
import { useMultichainSelector } from '../../../hooks/useMultichainSelector';
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';

export type TransactionActivityEmptyStateProps = {
/**
Expand All @@ -35,13 +31,6 @@ export const TransactionActivityEmptyState: React.FC<
account.methods.includes(EthMethod.SignTransaction) ||
account.methods.includes(EthMethod.SignUserOperation);
const isExternalServicesEnabled = useSelector(getUseExternalServices);
const chainId = useSelector(getCurrentChainId);
const isSwapsChain = useSelector((state) => getIsSwapsChain(state, chainId));

const { chainId: multichainChainId } = useMultichainSelector(
getMultichainNetwork,
account,
);

const { openBridgeExperience } = useBridging();

Expand All @@ -59,9 +48,7 @@ export const TransactionActivityEmptyState: React.FC<
}, [openBridgeExperience]);

// Determine if swap button should be enabled
const isSwapButtonEnabled =
multichainChainId === MultichainNetworks.SOLANA ||
(isSwapsChain && isSigningEnabled && isExternalServicesEnabled);
const isSwapButtonEnabled = isSigningEnabled && isExternalServicesEnabled;

return (
<TabEmptyState
Expand Down
69 changes: 23 additions & 46 deletions ui/components/app/wallet-overview/coin-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ type CoinButtonsProps = {
account: InternalAccount;
chainId: `0x${string}` | CaipChainId | number;
trackingLocation: string;
isSwapsChain: boolean;
isSigningEnabled: boolean;
isBridgeChain: boolean;
isBuyableChain: boolean;
classPrefix?: string;
iconButtonClassName?: string;
Expand All @@ -88,9 +86,7 @@ const CoinButtons = ({
account,
chainId,
trackingLocation,
isSwapsChain,
isSigningEnabled,
isBridgeChain,
isBuyableChain,
classPrefix = 'coin',
}: CoinButtonsProps) => {
Expand Down Expand Up @@ -120,11 +116,6 @@ const CoinButtons = ({
getSwapsDefaultToken(state, chainId.toString()),
);

// Pre-conditions
if (isSwapsChain && defaultSwapsToken === undefined) {
throw new Error('defaultSwapsToken is required');
}

///: BEGIN:ONLY_INCLUDE_IF(multichain)
const handleSendNonEvm = useHandleSendNonEvm();
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -159,11 +150,9 @@ const CoinButtons = ({
{ condition: !isSigningEnabled, message: 'methodNotSupported' },
],
swapButton: [
{ condition: !isSwapsChain, message: 'currentlyUnavailable' },
{ condition: !isSigningEnabled, message: 'methodNotSupported' },
],
bridgeButton: [
{ condition: !isBridgeChain, message: 'currentlyUnavailable' },
{ condition: !isSigningEnabled, message: 'methodNotSupported' },
],
};
Expand Down Expand Up @@ -360,33 +349,30 @@ const CoinButtons = ({

await setCorrectChain();

if (isSwapsChain) {
trackEvent({
event: MetaMetricsEventName.NavSwapButtonClicked,
category: MetaMetricsEventCategory.Swaps,
properties: {
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
// eslint-disable-next-line @typescript-eslint/naming-convention
token_symbol: 'ETH',
location: MetaMetricsSwapsEventSource.MainView,
text: 'Swap',
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
// eslint-disable-next-line @typescript-eslint/naming-convention
chain_id: chainId,
},
});
dispatch(setSwapsFromToken(defaultSwapsToken));
if (usingHardwareWallet) {
if (global.platform.openExtensionInBrowser) {
global.platform.openExtensionInBrowser(PREPARE_SWAP_ROUTE);
}
} else {
history.push(PREPARE_SWAP_ROUTE);
trackEvent({
event: MetaMetricsEventName.NavSwapButtonClicked,
category: MetaMetricsEventCategory.Swaps,
properties: {
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
// eslint-disable-next-line @typescript-eslint/naming-convention
token_symbol: 'ETH',
location: MetaMetricsSwapsEventSource.MainView,
text: 'Swap',
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
// eslint-disable-next-line @typescript-eslint/naming-convention
chain_id: chainId,
},
});
dispatch(setSwapsFromToken(defaultSwapsToken));
if (usingHardwareWallet) {
if (global.platform.openExtensionInBrowser) {
global.platform.openExtensionInBrowser(PREPARE_SWAP_ROUTE);
}
} else {
history.push(PREPARE_SWAP_ROUTE);
}
}, [
setCorrectChain,
isSwapsChain,
chainId,
isMultichainAccountsState2Enabled,
multichainChainId,
Expand Down Expand Up @@ -464,11 +450,7 @@ const CoinButtons = ({
}
<IconButton
className={`${classPrefix}-overview__button`}
disabled={
(!isSwapsChain && !isUnifiedUIEnabled) ||
!isSigningEnabled ||
!isExternalServicesEnabled
}
disabled={!isSigningEnabled || !isExternalServicesEnabled}
Icon={
displayNewIconButtons ? (
<Icon
Expand All @@ -492,18 +474,13 @@ const CoinButtons = ({
generateTooltip('swapButton', contents)
}
/>
{/* the bridge button is redundant if unified ui is enabled, testnet or non-bridge chain (unsupported) */}
{/* the bridge button is redundant if unified ui is enabled, testnet or for non-EVM accounts without external services */}
{isUnifiedUIEnabled ||
isTestnet ||
!isBridgeChain ||
isNonEvmAccountWithoutExternalServices ? null : (
<IconButton
className={`${classPrefix}-overview__button`}
disabled={
!isBridgeChain ||
!isSigningEnabled ||
isNonEvmAccountWithoutExternalServices
}
disabled={!isSigningEnabled || isNonEvmAccountWithoutExternalServices}
data-testid={`${classPrefix}-overview-bridge`}
Icon={
displayNewIconButtons ? (
Expand Down
6 changes: 0 additions & 6 deletions ui/components/app/wallet-overview/coin-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ export type CoinOverviewProps = {
className?: string;
classPrefix?: string;
chainId: CaipChainId | Hex;
isBridgeChain: boolean;
isBuyableChain: boolean;
isSwapsChain: boolean;
isSigningEnabled: boolean;
};

Expand Down Expand Up @@ -205,9 +203,7 @@ export const CoinOverview = ({
className,
classPrefix = 'coin',
chainId,
isBridgeChain,
isBuyableChain,
isSwapsChain,
isSigningEnabled,
}: CoinOverviewProps) => {
const enabledNetworks = useSelector(getEnabledNetworksByNamespace);
Expand Down Expand Up @@ -397,9 +393,7 @@ export const CoinOverview = ({
account,
trackingLocation: 'home',
chainId,
isSwapsChain,
isSigningEnabled,
isBridgeChain,
isBuyableChain,
classPrefix,
}}
Expand Down
6 changes: 0 additions & 6 deletions ui/components/app/wallet-overview/eth-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,20 @@ import { isEqual } from 'lodash';
import { getCurrentChainId } from '../../../../shared/modules/selectors/networks';
import {
isBalanceCached,
getIsSwapsChain,
getSelectedInternalAccount,
getSelectedAccountCachedBalance,
getIsBridgeChain,
} from '../../../selectors';
import { getIsNativeTokenBuyable } from '../../../ducks/ramps';
import { CoinOverview } from './coin-overview';

const EthOverview = ({ className }) => {
const isBridgeChain = useSelector(getIsBridgeChain);
const isBuyableChain = useSelector(getIsNativeTokenBuyable);
const balanceIsCached = useSelector(isBalanceCached);
const chainId = useSelector(getCurrentChainId);
const balance = useSelector(getSelectedAccountCachedBalance);

// FIXME: This causes re-renders, so use isEqual to avoid this
const account = useSelector(getSelectedInternalAccount, isEqual);
const isSwapsChain = useSelector(getIsSwapsChain);
const isSigningEnabled =
account.methods.includes(EthMethod.SignTransaction) ||
account.methods.includes(EthMethod.SignUserOperation);
Expand All @@ -37,8 +33,6 @@ const EthOverview = ({ className }) => {
classPrefix="eth"
chainId={chainId}
isSigningEnabled={isSigningEnabled}
isSwapsChain={isSwapsChain}
isBridgeChain={isBridgeChain}
isBuyableChain={isBuyableChain}
/>
);
Expand Down
13 changes: 1 addition & 12 deletions ui/components/app/wallet-overview/non-evm-overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { getMultichainSelectedAccountCachedBalance } from '../../../selectors/mu
import { getSelectedMultichainNetworkConfiguration } from '../../../selectors/multichain/networks';

import { getIsNativeTokenBuyable } from '../../../ducks/ramps';
import {
getIsSwapsChain,
getIsBridgeChain,
getSelectedInternalAccount,
} from '../../../selectors';
import { getSelectedInternalAccount } from '../../../selectors';
import { CoinOverview } from './coin-overview';

type NonEvmOverviewProps = {
Expand All @@ -21,11 +17,6 @@ const NonEvmOverview = ({ className }: NonEvmOverviewProps) => {
const account = useSelector(getSelectedInternalAccount);
const isNativeTokenBuyable = useSelector(getIsNativeTokenBuyable);

let isSwapsChain = false;
let isBridgeChain = false;
isSwapsChain = useSelector((state) => getIsSwapsChain(state, chainId));
isBridgeChain = useSelector((state) => getIsBridgeChain(state, chainId));

return (
<CoinOverview
account={account}
Expand All @@ -35,8 +26,6 @@ const NonEvmOverview = ({ className }: NonEvmOverviewProps) => {
className={className}
chainId={chainId}
isSigningEnabled={true}
isSwapsChain={isSwapsChain}
isBridgeChain={isBridgeChain}
isBuyableChain={isNativeTokenBuyable}
/>
);
Expand Down
9 changes: 0 additions & 9 deletions ui/pages/asset/components/asset-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ import { useMultichainSelector } from '../../../hooks/useMultichainSelector';
import { useTokenBalances } from '../../../hooks/useTokenBalances';
import {
getDataCollectionForMarketing,
getIsBridgeChain,
getIsMultichainAccountsState2Enabled,
getIsSwapsChain,
getMetaMetricsId,
getParticipateInMetaMetrics,
getSelectedAccountNativeTokenCachedBalanceByChainId,
Expand Down Expand Up @@ -117,11 +115,6 @@ const AssetPage = ({

const isNative = type === AssetType.native;

const isSwapsChain = useSelector((state) => getIsSwapsChain(state, chainId));
const isBridgeChain = useSelector((state) =>
getIsBridgeChain(state, chainId),
);

const isSigningEnabled =
selectedAccount.methods.includes(EthMethod.SignTransaction) ||
selectedAccount.methods.includes(EthMethod.SignUserOperation) ||
Expand Down Expand Up @@ -355,8 +348,6 @@ const AssetPage = ({
trackingLocation: 'asset-page',
isBuyableChain,
isSigningEnabled,
isSwapsChain,
isBridgeChain,
chainId,
}}
/>
Expand Down
Loading
Loading