Skip to content

Commit

Permalink
refactor: using shared worker for fetching assets balances (#1666)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick-1979 authored Nov 25, 2024
1 parent 2f43157 commit cbe564b
Show file tree
Hide file tree
Showing 14 changed files with 483 additions and 497 deletions.
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

0 comments on commit cbe564b

Please sign in to comment.