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: Provide selector that enables cross-chain polling, regardless of network filter state #28662

Merged
merged 5 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import {
getCurrentChainId,
getCurrentNetwork,
getPreferences,
getChainIdsToPoll,
getShouldHideZeroBalanceTokens,
getSelectedAccount,
getAllChainsToPoll,
} from '../../../../../selectors';
import { getNetworkConfigurationsByChainId } from '../../../../../../shared/modules/selectors/networks';
import { useI18nContext } from '../../../../../hooks/useI18nContext';
Expand Down Expand Up @@ -49,7 +49,7 @@ const NetworkFilter = ({ handleClose }: SortControlProps) => {
const shouldHideZeroBalanceTokens = useSelector(
getShouldHideZeroBalanceTokens,
);
const allChainIDs = useSelector(getChainIdsToPoll);
const allChainIDs = useSelector(getAllChainsToPoll);
const { formattedTokensWithBalancesPerChain } = useGetFormattedTokensPerChain(
selectedAccount,
shouldHideZeroBalanceTokens,
Expand Down
20 changes: 20 additions & 0 deletions ui/selectors/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,26 @@ export const getAllEnabledNetworks = createDeepEqualSelector(
),
);

// USE THIS WITH CAUTION
// Only use this selector if you are absolutely sure that your UI component needs data from _all chains_ to compute a value. Else, use getChainsIdsToPoll
// An example of a component that should _not_ use this selector: the token list only needs to poll for chains based on the network filter, (potentially only one chain). In this case you would want to use getChainIdsToPoll
// An example of a component that should _need_ to use this selector: Aggregated balance that needs to display regardless of network filter selection (always needs to display aggregated balance regardless of chains that are selected)
// Leveraging this hook can cause expensive computation that is not needed in all cases, and should be optimized, where possible, to use getChainIdsToPoll instead
gambinish marked this conversation as resolved.
Show resolved Hide resolved
export const getAllChainsToPoll = createDeepEqualSelector(
getNetworkConfigurationsByChainId,
getCurrentChainId,
getIsTokenNetworkFilterEqualCurrentNetwork,
gambinish marked this conversation as resolved.
Show resolved Hide resolved
(networkConfigurations, currentChainId) => {
if (!process.env.PORTFOLIO_VIEW) {
return [currentChainId];
}

return Object.keys(networkConfigurations).filter(
(chainId) => chainId === currentChainId || !TEST_CHAINS.includes(chainId),
);
},
);

export const getChainIdsToPoll = createDeepEqualSelector(
getNetworkConfigurationsByChainId,
getCurrentChainId,
Expand Down
Loading