Skip to content

Commit

Permalink
fix(cherry-pick): use PORTFOLIO_VIEW flag to determine chain polling (#…
Browse files Browse the repository at this point in the history
…28578)

Cherry picks #28504
to 12.8.0 so chains aren't polled unnecessarily

Co-authored-by: Dan J Miller <[email protected]>
  • Loading branch information
bergeron and danjm authored Dec 2, 2024
1 parent 0304023 commit 8e074a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion ui/hooks/useTokenDetectionPolling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSelector } from 'react-redux';
import {
getCurrentChainId,
getNetworkConfigurationsByChainId,
getUseTokenDetection,
} from '../selectors';
Expand All @@ -17,14 +18,19 @@ const useTokenDetectionPolling = () => {
const useTokenDetection = useSelector(getUseTokenDetection);
const completedOnboarding = useSelector(getCompletedOnboarding);
const isUnlocked = useSelector(getIsUnlocked);
const currentChainId = useSelector(getCurrentChainId);
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId);

const enabled = completedOnboarding && isUnlocked && useTokenDetection;

const chainIds = process.env.PORTFOLIO_VIEW
? Object.keys(networkConfigurations)
: [currentChainId];

useMultiPolling({
startPolling: tokenDetectionStartPolling,
stopPollingByPollingToken: tokenDetectionStopPollingByPollingToken,
input: enabled ? [Object.keys(networkConfigurations)] : [],
input: enabled ? [chainIds] : [],
});

return {};
Expand Down
10 changes: 8 additions & 2 deletions ui/hooks/useTokenRatesPolling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useSelector } from 'react-redux';
import {
getCurrentChainId,
getMarketData,
getNetworkConfigurationsByChainId,
getTokenExchangeRates,
Expand All @@ -16,10 +17,11 @@ import {
} from '../ducks/metamask/metamask';
import useMultiPolling from './useMultiPolling';

const useTokenRatesPolling = ({ chainIds }: { chainIds?: string[] } = {}) => {
const useTokenRatesPolling = () => {
// Selectors to determine polling input
const completedOnboarding = useSelector(getCompletedOnboarding);
const isUnlocked = useSelector(getIsUnlocked);
const currentChainId = useSelector(getCurrentChainId);
const useCurrencyRateCheck = useSelector(getUseCurrencyRateCheck);
const networkConfigurations = useSelector(getNetworkConfigurationsByChainId);

Expand All @@ -30,10 +32,14 @@ const useTokenRatesPolling = ({ chainIds }: { chainIds?: string[] } = {}) => {

const enabled = completedOnboarding && isUnlocked && useCurrencyRateCheck;

const chainIds = process.env.PORTFOLIO_VIEW
? Object.keys(networkConfigurations)
: [currentChainId];

useMultiPolling({
startPolling: tokenRatesStartPolling,
stopPollingByPollingToken: tokenRatesStopPollingByPollingToken,
input: enabled ? chainIds ?? Object.keys(networkConfigurations) : [],
input: enabled ? chainIds : [],
});

return {
Expand Down

0 comments on commit 8e074a6

Please sign in to comment.