Skip to content

Commit

Permalink
fix some incoming provider checks and total wallet balance display
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Feb 12, 2025
1 parent dfd7129 commit 5c83fa7
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 20 deletions.
13 changes: 9 additions & 4 deletions src/core/resources/_selectors/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ export function selectorFilterByUserChains<T>({
.getState()
.getBackendChainIdsByMainnetId();
const { enabledChainIds } = networkStore.getState();
const allUserChainIds = Array.from(enabledChainIds)
const allChains = networkStore.getState().getAllChains();
const allUserChainIds = Object.keys(allChains)
.map((id) => {
const backendChainIds = chainIdsBasedOnMainnetId[id];
const chainId = Number(id);
const backendChainIds = chainIdsBasedOnMainnetId[chainId];
if (!enabledChainIds.has(chainId)) return [];

if (backendChainIds) {
return [...backendChainIds, id];
return [...backendChainIds, chainId];
}
return [id];
return [chainId];
})
.flat()
.filter(Boolean);
Expand All @@ -40,6 +44,7 @@ export function selectorFilterByUserChains<T>({
}
return acc;
}, {} as ParsedAssetsDictByChain);

return selector(filteredAssetsDictByChain);
}

Expand Down
14 changes: 8 additions & 6 deletions src/core/resources/assets/customNetworkAssets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,16 @@ async function customNetworkAssetsFunction({
})?.state?.data || {}) as Record<ChainId | number, ParsedAssetsDict>;

const activeChains = networkStore.getState().getAllActiveRpcChains();

const supportedMainnetChains = networkStore((state) =>
state.getBackendSupportedChains(),
const supportedMainnetChains = networkStore
.getState()
.getBackendSupportedChains();

const customChains = activeChains.filter(
(chain) =>
(testnetMode ? chain.testnet : !chain.testnet) &&
!supportedMainnetChains[chain.id],
);

const customChains = activeChains.filter((chain) =>
testnetMode ? chain.testnet : !chain.testnet,
);
if (customChains.length === 0) {
return cachedCustomNetworkAssets;
}
Expand Down
1 change: 0 additions & 1 deletion src/core/wagmi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ let wagmiConfig = createConfig({
});

const updateWagmiConfig = (chains: Chain[]) => {
console.log('updateWagmiConfig', chains);
wagmiConfig = createConfig({
chains: createChains(chains),
transports: createTransports(chains),
Expand Down
2 changes: 1 addition & 1 deletion src/entries/background/handlers/handleProviderRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export const handleProviderRequest = ({
appSessionsStore.getState().removeAppSession({ host }),
getChainNativeCurrency: (chainId: number) =>
networkStore.getState().getBackendSupportedChains(true)[chainId]
.nativeCurrency,
?.nativeCurrency,
getFeatureFlags: () => featureFlagsStore.getState().featureFlags,
getProvider: getProvider,
messengerProviderRequest: (request: ProviderRequestPayload) =>
Expand Down
2 changes: 0 additions & 2 deletions src/entries/popup/components/SwitchMenu/SwitchNetworkMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ export const SwitchNetworkMenu = ({
const triggerRef = useRef<HTMLDivElement>(null);
const { chains } = useUserChains();

console.log({ chains });

useKeyboardShortcut({
handler: (e: KeyboardEvent) => {
if (e.key === shortcuts.swap.OPEN_NETWORK_MENU.key) {
Expand Down
25 changes: 19 additions & 6 deletions src/entries/popup/hooks/useUserAssetsBalance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback } from 'react';
import { useCallback, useMemo } from 'react';
import { Address } from 'viem';

import { SupportedCurrencyKey } from '~/core/references';
Expand Down Expand Up @@ -71,15 +71,28 @@ export function useUserAssetsBalance(args?: {
},
);

const totalAssetsBalance =
totalAssetsBalanceKnownNetworks && totalAssetsBalanceCustomNetworks
? add(totalAssetsBalanceKnownNetworks, totalAssetsBalanceCustomNetworks)
: undefined;
const totalAssetsBalance = useMemo(() => {
if (totalAssetsBalanceKnownNetworks && totalAssetsBalanceCustomNetworks) {
return add(
totalAssetsBalanceKnownNetworks,
totalAssetsBalanceCustomNetworks,
);
}
if (totalAssetsBalanceKnownNetworks || totalAssetsBalanceCustomNetworks) {
return (
totalAssetsBalanceKnownNetworks || totalAssetsBalanceCustomNetworks
);
}
return undefined;
}, [totalAssetsBalanceKnownNetworks, totalAssetsBalanceCustomNetworks]);

return {
amount: totalAssetsBalance,
display: totalAssetsBalance
? convertAmountToNativeDisplay(totalAssetsBalance, currency || currentCurrency)
? convertAmountToNativeDisplay(
totalAssetsBalance,
currency || currentCurrency,
)
: undefined,
isLoading: knownNetworksIsLoading || customNetworksIsLoading,
};
Expand Down

0 comments on commit 5c83fa7

Please sign in to comment.