Skip to content

Commit c0fe468

Browse files
fix(send): load selected account assets across all networks (#47652)
## **Description** After a non-EVM network (e.g. Solana, Tron) is selected on the Home page, the Send network list only showed non-EVM networks. Send builds its network list from tokens that were loaded by the Home network filter, so EVM networks had no loaded assets. This change loads the selected account group's assets across all configured networks when the Send assets hook mounts, so the Send network list shows the full set of networks regardless of the Home filter. ## **Changelog** CHANGELOG entry: Fixed a bug where the Send network list only showed non-EVM networks after a non-EVM network was selected on the Home page ## **Related issues** Fixes: #47384 ## **Manual testing steps** 1. Go to Home and select a non-EVM network (e.g. Solana) in the network filter. 2. Switch to another account. 3. Click Send. 4. Open the network dropdown in the Send flow. 5. Verify the full list of networks is shown, including EVM networks such as Ethereum Mainnet. ## **Screenshots/Recordings** ### **Before** N/A ### **After** https://github.com/user-attachments/assets/80789ab6-ddad-4d88-b304-7c651432b8da ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Unable to generate summary. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1c6daf2. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 26c4cc9 commit c0fe468

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎ui/pages/confirmations/hooks/send/useSendAssets.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { useSelector } from 'react-redux';
22
import { renderHookWithProvider } from '../../../../../test/lib/render-helpers-navigate';
33
import mockState from '../../../../../test/data/mock-state.json';
44
import { getAllMultichainNetworkConfigurations } from '../../../../selectors/multichain/networks';
5+
import { getSelectedAccountGroup } from '../../../../selectors/multichain-accounts/account-tree';
56
import { type Asset } from '../../types/send';
67
import { useSendAssets } from './useSendAssets';
78
import * as useSendTokensModule from './useSendTokens';
89
import * as useSendNftsModule from './useSendNfts';
10+
import { useEnsureAccountGroupAssets } from './useEnsureAccountGroupAssets';
911

1012
jest.mock('react-redux', () => ({
1113
...jest.requireActual('react-redux'),
@@ -14,10 +16,16 @@ jest.mock('react-redux', () => ({
1416

1517
jest.mock('./useSendTokens');
1618
jest.mock('./useSendNfts');
19+
jest.mock('./useEnsureAccountGroupAssets', () => ({
20+
useEnsureAccountGroupAssets: jest.fn(),
21+
}));
1722

1823
const mockUseSelector = jest.mocked(useSelector);
1924
const mockUseSendTokens = jest.spyOn(useSendTokensModule, 'useSendTokens');
2025
const mockUseSendNfts = jest.spyOn(useSendNftsModule, 'useSendNfts');
26+
const mockUseEnsureAccountGroupAssets = jest.mocked(
27+
useEnsureAccountGroupAssets,
28+
);
2129

2230
// Mock network configurations with CAIP chain IDs
2331
// Note: 0x1 = 1 (Ethereum), 0x89 = 137 (Polygon), 0xaa36a7 = 11155111 (Sepolia)
@@ -61,10 +69,27 @@ describe('useSendAssets', () => {
6169
if (selector === getAllMultichainNetworkConfigurations) {
6270
return mockMultichainNetworkConfigurations;
6371
}
72+
if (selector === getSelectedAccountGroup) {
73+
return 'entropy:wallet1/group1';
74+
}
6475
return undefined;
6576
});
6677
});
6778

79+
it('loads the selected account group across every configured network', () => {
80+
mockUseSendTokens.mockReturnValue([]);
81+
mockUseSendNfts.mockReturnValue([]);
82+
83+
renderHookWithProvider(
84+
() => useSendAssets(),
85+
mockStateWithExternalServices,
86+
);
87+
88+
expect(mockUseEnsureAccountGroupAssets).toHaveBeenCalledWith(
89+
'entropy:wallet1/group1',
90+
);
91+
});
92+
6893
it('returns tokens and nfts from respective hooks', () => {
6994
const mockTokens: Asset[] = [
7095
{ id: 'token1', name: 'Token 1', chainId: '0x1' } as Asset,

‎ui/pages/confirmations/hooks/send/useSendAssets.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ import type { CaipChainId, Hex } from '@metamask/utils';
55
import { type Asset } from '../../types/send';
66
import { getUseExternalServices } from '../../../../selectors';
77
import { getAllMultichainNetworkConfigurations } from '../../../../selectors/multichain/networks';
8+
import { getSelectedAccountGroup } from '../../../../selectors/multichain-accounts/account-tree';
89
import { isEvmChainId } from '../../../../../shared/lib/asset-utils';
910
import { useSendTokens } from './useSendTokens';
1011
import { useSendNfts } from './useSendNfts';
12+
import { useEnsureAccountGroupAssets } from './useEnsureAccountGroupAssets';
1113

1214
type SendAssets = {
1315
nfts: Asset[];
@@ -22,6 +24,8 @@ export const useSendAssets = (
2224
options: UseSendAssetsOptions = {},
2325
): SendAssets => {
2426
const { includeNoBalance = false } = options;
27+
const selectedAccountGroupId = useSelector(getSelectedAccountGroup);
28+
useEnsureAccountGroupAssets(selectedAccountGroupId);
2529
const tokens = useSendTokens({ includeNoBalance });
2630
const nfts = useSendNfts();
2731
const useExternalServices = useSelector(getUseExternalServices);

0 commit comments

Comments
 (0)