Skip to content

Commit d909bde

Browse files
bergerondanjm
andauthored
fix(cherry-pick): use PORTFOLIO_VIEW flag to determine token list polling (#28585)
Cherry picks #28579 to 12.8.0 so chains aren't polled unnecessarily Co-authored-by: Dan J Miller <[email protected]>
1 parent 8e074a6 commit d909bde

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed

test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-background-state.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,7 @@
317317
"TokenListController": {
318318
"tokenList": "object",
319319
"tokensChainsCache": {
320-
"0x1": "object",
321-
"0x539": "object",
322-
"0xaa36a7": "object",
323-
"0xe705": "object",
324-
"0xe708": "object"
320+
"0x539": "object"
325321
},
326322
"preventPollingOnNetworkRestart": false
327323
},

test/e2e/tests/metrics/state-snapshots/errors-after-init-opt-in-ui-state.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@
175175
"nonRPCGasFeeApisDisabled": "boolean",
176176
"tokenList": "object",
177177
"tokensChainsCache": {
178-
"0x1": "object",
179-
"0x539": "object",
180-
"0xaa36a7": "object",
181-
"0xe705": "object",
182-
"0xe708": "object"
178+
"0x539": "object"
183179
},
184180
"preventPollingOnNetworkRestart": false,
185181
"tokens": "object",

ui/hooks/useTokenListPolling.test.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@ describe('useTokenListPolling', () => {
2222
jest.clearAllMocks();
2323
});
2424

25-
it('should poll for token lists on each chain when enabled, and stop on dismount', async () => {
25+
it('should poll the selected network when enabled, and stop on dismount', async () => {
2626
const state = {
2727
metamask: {
2828
isUnlocked: true,
2929
completedOnboarding: true,
3030
useExternalServices: true,
3131
useTokenDetection: true,
32+
selectedNetworkClientId: 'selectedNetworkClientId',
3233
networkConfigurationsByChainId: {
33-
'0x1': {},
34-
'0x89': {},
34+
'0x1': {
35+
chainId: '0x1',
36+
rpcEndpoints: [
37+
{
38+
networkClientId: 'selectedNetworkClientId',
39+
},
40+
],
41+
},
3542
},
3643
},
3744
};
@@ -43,19 +50,15 @@ describe('useTokenListPolling', () => {
4350

4451
// Should poll each chain
4552
await Promise.all(mockPromises);
46-
expect(tokenListStartPolling).toHaveBeenCalledTimes(2);
53+
expect(tokenListStartPolling).toHaveBeenCalledTimes(1);
4754
expect(tokenListStartPolling).toHaveBeenCalledWith('0x1');
48-
expect(tokenListStartPolling).toHaveBeenCalledWith('0x89');
4955

5056
// Stop polling on dismount
5157
unmount();
52-
expect(tokenListStopPollingByPollingToken).toHaveBeenCalledTimes(2);
58+
expect(tokenListStopPollingByPollingToken).toHaveBeenCalledTimes(1);
5359
expect(tokenListStopPollingByPollingToken).toHaveBeenCalledWith(
5460
'0x1_token',
5561
);
56-
expect(tokenListStopPollingByPollingToken).toHaveBeenCalledWith(
57-
'0x89_token',
58-
);
5962
});
6063

6164
it('should not poll before onboarding is completed', async () => {

ui/hooks/useTokenListPolling.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useSelector } from 'react-redux';
22
import {
3+
getCurrentChainId,
34
getNetworkConfigurationsByChainId,
45
getPetnamesEnabled,
56
getUseExternalServices,
@@ -17,6 +18,7 @@ import {
1718
import useMultiPolling from './useMultiPolling';
1819

1920
const useTokenListPolling = () => {
21+
const currentChainId = useSelector(getCurrentChainId);
2022
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId);
2123
const useTokenDetection = useSelector(getUseTokenDetection);
2224
const useTransactionSimulations = useSelector(getUseTransactionSimulations);
@@ -31,10 +33,14 @@ const useTokenListPolling = () => {
3133
useExternalServices &&
3234
(useTokenDetection || petnamesEnabled || useTransactionSimulations);
3335

36+
const chainIds = process.env.PORTFOLIO_VIEW
37+
? Object.keys(networkConfigurations)
38+
: [currentChainId];
39+
3440
useMultiPolling({
3541
startPolling: tokenListStartPolling,
3642
stopPollingByPollingToken: tokenListStopPollingByPollingToken,
37-
input: enabled ? Object.keys(networkConfigurations) : [],
43+
input: enabled ? chainIds : [],
3844
});
3945

4046
return {};

0 commit comments

Comments
 (0)