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

refactor: using shared worker for fetching assets balances #1666

Merged
merged 1 commit into from
Nov 25, 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
4 changes: 3 additions & 1 deletion packages/extension-polkagate/src/components/contexts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const ToastContext = React.createContext<({ show: (message: string) => void })>(
const UserAddedChainContext = React.createContext<UserAddedChains>({});
const GenesisHashOptionsContext = React.createContext<DropdownOption[]>([]);
const AccountIconThemeContext = React.createContext<AccountIconThemeContextType>({ accountIconTheme: undefined, setAccountIconTheme: noop });
const WorkerContext = React.createContext<Worker | undefined>(undefined);

export { AccountContext,
AccountIconThemeContext,
Expand All @@ -44,4 +45,5 @@ export { AccountContext,
SettingsContext,
SigningReqContext,
ToastContext,
UserAddedChainContext };
UserAddedChainContext,
WorkerContext };
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import React, { useCallback, useMemo, useState } from 'react';
import { getValue } from '@polkadot/extension-polkagate/src/popup/account/util';

import { AssetLogo, FormatPrice, ShowBalance } from '../../../components';
import { useApi, useNotifyOnChainChange, usePrices, useTranslation } from '../../../hooks';
import { useApi, useNotifyOnChainChange, usePrices, useSelectedChains, useTranslation } from '../../../hooks';
import getLogo2 from '../../../util/getLogo2';

interface Props {
Expand Down Expand Up @@ -120,6 +120,7 @@ function AOC ({ accountAssets, address, hideNumbers, mode = 'Detail', onclick, s

const api = useApi(address);
const pricesInCurrencies = usePrices();
const selectedChains = useSelectedChains();

useNotifyOnChainChange(address);

Expand All @@ -128,12 +129,14 @@ function AOC ({ accountAssets, address, hideNumbers, mode = 'Detail', onclick, s
const toggleAssets = useCallback(() => setShowMore(!showMore), [showMore]);

const assets = useMemo(() => {
if (accountAssets && accountAssets.length > 0) {
return accountAssets;
if (accountAssets && accountAssets.length > 0 && selectedChains) {
// filter non selected chains

return accountAssets.filter(({ genesisHash }) => selectedChains.includes(genesisHash));
} else {
return [undefined, undefined]; // two undefined to show two skeletons
}
}, [accountAssets]);
}, [accountAssets, selectedChains]);

const shouldShowCursor = useMemo(() => (mode === 'Detail' && accountAssets && accountAssets.length > 5) || (mode !== 'Detail' && accountAssets && accountAssets.length > 6), [accountAssets, mode]);

Expand Down
Loading
Loading