Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cherry-pick): use PORTFOLIO_VIEW flag to determine chain polling #28578

Merged
merged 2 commits into from
Dec 2, 2024
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
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
Loading