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
16 changes: 16 additions & 0 deletions test/e2e/mock-e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -1006,6 +1006,22 @@ async function setupMocking(
};
});

await server
.forGet('https://client-config.api.cx.metamask.io/v1/flags')
.thenCallback(() => {
return {
ok: true,
statusCode: 200,
json: [
{
sendRedesign: {
enabled: false,
},
},
],
};
});
Comment on lines +1009 to +1023
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sendRedesign feature flag is currently used like a kill-switch. As we don't have redesigned send flow e2e tests for now, we want to disable the flow for all tests.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Mock Conflicts Cause Unpredictable Test Results

There are now two conflicting mocks for the feature flags endpoint (https://client-config.api.cx.metamask.io/v1/flags). The original mock uses withQuery() for specific flags, while the new one matches all GET requests and returns different data. This creates unpredictable test behavior and may break existing tests that rely on the original feature flags.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is not an issue if e2e tests passes - will wait and see


// On Ramp Content
const ON_RAMP_CONTENT = fs.readFileSync(ON_RAMP_CONTENT_PATH);
await server
Expand Down
7 changes: 6 additions & 1 deletion ui/components/app/assets/nfts/nft-details/nft-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ import {
} from '../../../../../../app/scripts/lib/util';
import useGetAssetImageUrl from '../../../../../hooks/useGetAssetImageUrl';
import { getImageForChainId } from '../../../../../selectors/multichain';
import { useRedesignedSendFlow } from '../../../../../pages/confirmations/hooks/useRedesignedSendFlow';
import useFetchNftDetailsFromTokenURI from '../../../../../hooks/useFetchNftDetailsFromTokenURI';
import { navigateToSendRoute } from '../../../../../pages/confirmations/utils/send';
import NftDetailInformationRow from './nft-detail-information-row';
Expand Down Expand Up @@ -129,6 +130,7 @@ export function NftDetailsComponent({
const trackEvent = useContext(MetaMetricsContext);
const currency = useSelector(getCurrentCurrency);
const selectedNativeConversionRate = useSelector(getConversionRate);
const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();

const nftNetworkConfigs = useSelector(getNetworkConfigurationsByChainId);
const nftChainNetwork = nftNetworkConfigs[nftChainId as Hex];
Expand Down Expand Up @@ -335,7 +337,10 @@ export function NftDetailsComponent({
}),
);
// We only allow sending one NFT at a time
navigateToSendRoute(history, { address: nft.address, chainId: nftChainId });
navigateToSendRoute(history, isSendRedesignEnabled, {
address: nft.address,
chainId: nftChainId,
});
};

const getDateCreatedTimestamp = (dateString: string) => {
Expand Down
7 changes: 5 additions & 2 deletions ui/components/app/wallet-overview/coin-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { getCurrentChainId } from '../../../../shared/modules/selectors/networks
import { MultichainNetworks } from '../../../../shared/constants/multichain/networks';
import { trace, TraceName } from '../../../../shared/lib/trace';
import { navigateToSendRoute } from '../../../pages/confirmations/utils/send';
import { useRedesignedSendFlow } from '../../../pages/confirmations/hooks/useRedesignedSendFlow';
///: BEGIN:ONLY_INCLUDE_IF(multichain)
import { useHandleSendNonEvm } from './hooks/useHandleSendNonEvm';
///: END:ONLY_INCLUDE_IF
Expand Down Expand Up @@ -107,6 +108,7 @@ const CoinButtons = ({
>;
const currentChainId = useSelector(getCurrentChainId);
const displayNewIconButtons = process.env.REMOVE_GNS;
const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();

// Multichain accounts feature flag and selected account group
const isMultichainAccountsState2Enabled = useSelector(
Expand Down Expand Up @@ -276,7 +278,7 @@ const CoinButtons = ({
);

///: BEGIN:ONLY_INCLUDE_IF(multichain)
if (!isEvmAccountType(account.type) && !process.env.SEND_REDESIGN_ENABLED) {
if (!isEvmAccountType(account.type) && !isSendRedesignEnabled) {
await handleSendNonEvm();
// Early return, not to let the non-EVM flow slip into the native send flow.
return;
Expand All @@ -290,11 +292,12 @@ const CoinButtons = ({
if (trackingLocation !== 'home') {
params = { chainId: chainId.toString() };
}
navigateToSendRoute(history, params);
navigateToSendRoute(history, isSendRedesignEnabled, params);
}, [
chainId,
account,
setCorrectChain,
isSendRedesignEnabled,
///: BEGIN:ONLY_INCLUDE_IF(multichain)
handleSendNonEvm,
///: END:ONLY_INCLUDE_IF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
updateSendAsset,
} from '../../../../ducks/send';
import { getNftImage } from '../../../../helpers/utils/nfts';
import { useRedesignedSendFlow } from '../../../../pages/confirmations/hooks/useRedesignedSendFlow';
import { navigateToSendRoute } from '../../../../pages/confirmations/utils/send';
import { NFT } from './types';

Expand Down Expand Up @@ -67,6 +68,7 @@ export function AssetPickerModalNftTab({
const nftsStillFetchingIndication = useSelector(
getNftIsStillFetchingIndication,
);
const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();

const { currentlyOwnedNfts } = useNfts({
overridePopularNetworkFilter: true,
Expand Down Expand Up @@ -128,7 +130,7 @@ export function AssetPickerModalNftTab({
skipComputeEstimatedGasLimit: false,
}),
);
navigateToSendRoute(history, {
navigateToSendRoute(history, isSendRedesignEnabled, {
address: nft.address,
chainId: nft.chainId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ jest.mock('lodash', () => ({
}),
}));

jest.mock(
'../../../../pages/confirmations/hooks/useRedesignedSendFlow',
() => ({
useRedesignedSendFlow: jest.fn().mockReturnValue({ enabled: false }),
}),
);

describe('AssetPickerModal', () => {
const useSelectorMock = useSelector as jest.Mock;
const useI18nContextMock = useI18nContext as jest.Mock;
Expand Down
8 changes: 5 additions & 3 deletions ui/pages/asset/components/token-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import { Asset } from '../types/asset';
import { getIsUnifiedUIEnabled } from '../../../ducks/bridge/selectors';
import { navigateToSendRoute } from '../../confirmations/utils/send';
import { isEvmChainId } from '../../../../shared/lib/asset-utils';
import { useRedesignedSendFlow } from '../../confirmations/hooks/useRedesignedSendFlow';

const TokenButtons = ({
token,
Expand All @@ -76,7 +77,7 @@ const TokenButtons = ({
const isMultichainAccountsState2Enabled = useSelector(
getIsMultichainAccountsState2Enabled,
);

const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();
const { chainId: multichainChainId } = useSelector(
getSelectedMultichainNetworkConfiguration,
);
Expand Down Expand Up @@ -194,7 +195,7 @@ const TokenButtons = ({
);

///: BEGIN:ONLY_INCLUDE_IF(multichain)
if (!isEvmAccountType(account.type) && !process.env.SEND_REDESIGN_ENABLED) {
if (!isEvmAccountType(account.type) && !isSendRedesignEnabled) {
await handleSendNonEvm();
// Early return, not to let the non-EVM flow slip into the native send flow.
return;
Expand All @@ -209,7 +210,7 @@ const TokenButtons = ({
details: token,
}),
);
navigateToSendRoute(history, {
navigateToSendRoute(history, isSendRedesignEnabled, {
address: token.address,
chainId: token.chainId,
});
Expand All @@ -231,6 +232,7 @@ const TokenButtons = ({
///: BEGIN:ONLY_INCLUDE_IF(multichain)
handleSendNonEvm,
///: END:ONLY_INCLUDE_IF
isSendRedesignEnabled,
]);

const isTestnet = useSelector(getMultichainIsTestnet);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ const render = (
return renderWithConfirmContextProvider(<WalletInitiatedHeader />, store);
};

jest.mock('../../../hooks/useRedesignedSendFlow', () => ({
useRedesignedSendFlow: jest.fn().mockReturnValue({ enabled: false }),
}));

describe('<WalletInitiatedHeader />', () => {
it('should match snapshot', () => {
const { container } = render();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ import { useI18nContext } from '../../../../../hooks/useI18nContext';
import { showSendTokenPage } from '../../../../../store/actions';
import { useConfirmContext } from '../../../context/confirm';
import { navigateToSendRoute } from '../../../utils/send';
import { useRedesignedSendFlow } from '../../../hooks/useRedesignedSendFlow';
import { AdvancedDetailsButton } from './advanced-details-button';

export const WalletInitiatedHeader = () => {
const t = useI18nContext();
const dispatch = useDispatch();
const history = useHistory();
const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();

const { currentConfirmation } = useConfirmContext<TransactionMeta>();

Expand Down Expand Up @@ -63,8 +65,8 @@ export const WalletInitiatedHeader = () => {
await dispatch(editExistingTransaction(assetType, id.toString()));
dispatch(clearConfirmTransaction());
dispatch(showSendTokenPage());
navigateToSendRoute(history);
}, [currentConfirmation, dispatch, history]);
navigateToSendRoute(history, isSendRedesignEnabled);
}, [currentConfirmation, dispatch, history, isSendRedesignEnabled]);

return (
<Box
Expand Down
79 changes: 68 additions & 11 deletions ui/pages/confirmations/hooks/useConfirmSendNavigation.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import mockState from '../../../../test/data/mock-state.json';
import { renderHookWithProvider } from '../../../../test/lib/render-helpers';
import * as ConfirmContext from '../context/confirm';

import { useRedesignedSendFlow } from './useRedesignedSendFlow';
import { useConfirmSendNavigation } from './useConfirmSendNavigation';

const mockUseRedesignedSendFlow = jest.mocked(useRedesignedSendFlow);

const mockHistory = {
goBack: jest.fn(),
push: jest.fn(),
Expand All @@ -23,34 +25,89 @@ jest.mock('react-redux', () => ({
},
}));

function renderHook() {
const { result } = renderHookWithProvider(
useConfirmSendNavigation,
mockState,
);
return result.current;
}
jest.mock('./useRedesignedSendFlow');

describe('useConfirmSendNavigation', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('result returns method navigateBackIfSend', () => {
const renderHook = () => {
const { result } = renderHookWithProvider(
useConfirmSendNavigation,
mockState,
);
return result.current;
};

it('returns navigateBackIfSend method', () => {
jest
.spyOn(ConfirmContext, 'useConfirmContext')
.mockReturnValue({} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: false });

const result = renderHook();

expect(result.navigateBackIfSend).toBeDefined();
});

// eslint-disable-next-line mocha/no-skipped-tests
it.skip('result returns method handleBack to goto previous page', () => {
it('does not navigate back when send redesign is disabled', () => {
jest.spyOn(ConfirmContext, 'useConfirmContext').mockReturnValue({
currentConfirmation: { origin: 'metamask', type: 'simpleSend' },
} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: false });

const result = renderHook();
result.navigateBackIfSend();

expect(mockHistory.goBack).not.toHaveBeenCalled();
});

it('navigates back when send redesign is enabled and confirmation is metamask simpleSend', () => {
jest.spyOn(ConfirmContext, 'useConfirmContext').mockReturnValue({
currentConfirmation: { origin: 'metamask', type: 'simpleSend' },
} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: true });

const result = renderHook();
result.navigateBackIfSend();

expect(mockHistory.goBack).toHaveBeenCalled();
});

it('does not navigate back when send redesign is enabled but origin is not metamask', () => {
jest.spyOn(ConfirmContext, 'useConfirmContext').mockReturnValue({
currentConfirmation: { origin: 'dapp', type: 'simpleSend' },
} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: true });

const result = renderHook();
result.navigateBackIfSend();

expect(mockHistory.goBack).not.toHaveBeenCalled();
});

it('does not navigate back when send redesign is enabled but type is not simpleSend', () => {
jest.spyOn(ConfirmContext, 'useConfirmContext').mockReturnValue({
currentConfirmation: { origin: 'metamask', type: 'contractInteraction' },
} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: true });

const result = renderHook();
result.navigateBackIfSend();

expect(mockHistory.goBack).not.toHaveBeenCalled();
});

it('does not navigate back when send redesign is enabled but both origin and type do not match', () => {
jest.spyOn(ConfirmContext, 'useConfirmContext').mockReturnValue({
currentConfirmation: { origin: 'dapp', type: 'contractInteraction' },
} as unknown as ConfirmContext.ConfirmContextType);
mockUseRedesignedSendFlow.mockReturnValue({ enabled: true });

const result = renderHook();
result.navigateBackIfSend();

expect(mockHistory.goBack).not.toHaveBeenCalled();
});
});
6 changes: 4 additions & 2 deletions ui/pages/confirmations/hooks/useConfirmSendNavigation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ import { useCallback } from 'react';
import { useHistory } from 'react-router-dom';

import { useConfirmContext } from '../context/confirm';
import { useRedesignedSendFlow } from './useRedesignedSendFlow';

export const useConfirmSendNavigation = () => {
const history = useHistory();
const { currentConfirmation } = useConfirmContext<TransactionMeta>();
const { enabled: isSendRedesignEnabled } = useRedesignedSendFlow();

const navigateBackIfSend = useCallback(() => {
if (!process.env.SEND_REDESIGN_ENABLED) {
if (!isSendRedesignEnabled) {
return;
}
const { origin, type } = currentConfirmation;
if (origin === 'metamask' && type === 'simpleSend') {
history.goBack();
}
}, [currentConfirmation, history]);
}, [currentConfirmation, history, isSendRedesignEnabled]);

return { navigateBackIfSend };
};
Loading
Loading