Skip to content

Commit

Permalink
fix: asset filtering by networks settings (#1124)
Browse files Browse the repository at this point in the history
Co-authored-by: Bruno Barbieri <1247834+brunobar79@users.noreply.github.com>
  • Loading branch information
2 people authored and BrodyHughes committed Nov 15, 2023
1 parent f1c2fb9 commit 8b7c479
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
7 changes: 5 additions & 2 deletions src/core/resources/_selectors/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ export function selectorFilterByUserChains<T>({
}): T {
const { userChains } = userChainsStore.getState();
const allUserChainIds = Object.keys(userChains)
.map((chainId) => chainIdMap[Number(chainId)])
.flat();
.map((chainId) =>
userChains[Number(chainId)] ? chainIdMap[Number(chainId)] : undefined,
)
.flat()
.filter(Boolean);
const filteredAssetsDictByChain = Object.keys(data).reduce((acc, key) => {
const chainKey = Number(key);
if (allUserChainIds.includes(chainKey) || isCustomChain(chainKey)) {
Expand Down
29 changes: 9 additions & 20 deletions src/core/state/userChains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,33 @@ import { ChainId } from '~/core/types/chains';

import { createStore } from '../internal/createStore';

type MainnetChainId =
| ChainId.mainnet
| ChainId.optimism
| ChainId.polygon
| ChainId.arbitrum
| ChainId.bsc
| ChainId.zora
| ChainId.base;

export interface UserChainsState {
/**
* Mainnet chains in network settings
*/
userChains: Record<MainnetChainId, boolean>;
userChains: Record<number, boolean>;
/**
* Mainnet chains ordered from network settings
*/
userChainsOrder: (MainnetChainId | number)[];
userChainsOrder: (number | number)[];
updateUserChain: ({
chainId,
enabled,
}: {
chainId: MainnetChainId;
chainId: number;
enabled: boolean;
}) => void;
updateUserChains: ({
chainIds,
enabled,
}: {
chainIds: MainnetChainId[];
chainIds: number[];
enabled: boolean;
}) => void;
updateUserChainsOrder: ({
userChainsOrder,
}: {
userChainsOrder: (MainnetChainId | number)[];
userChainsOrder: (number | number)[];
}) => void;
addUserChain: ({ chainId }: { chainId: ChainId }) => void;
removeUserChain: ({ chainId }: { chainId: ChainId }) => void;
Expand All @@ -51,12 +42,10 @@ const chains = SUPPORTED_MAINNET_CHAINS.reduce(
...acc,
[chain.id]: true,
}),
{} as Record<MainnetChainId, boolean>,
{} as Record<number, boolean>,
);

const userChainsOrder = Object.keys(chains).map(
(id) => Number(id) as MainnetChainId,
);
const userChainsOrder = Object.keys(chains).map((id) => Number(id) as number);

export const userChainsStore = createStore<UserChainsState>(
(set, get) => ({
Expand All @@ -69,8 +58,8 @@ export const userChainsStore = createStore<UserChainsState>(
acc[chainId] = enabled;
return acc;
},
{} as Record<MainnetChainId, boolean>,
) satisfies Record<MainnetChainId, boolean>;
{} as Record<number, boolean>,
) satisfies Record<number, boolean>;
set({
userChains: {
...userChains,
Expand Down

0 comments on commit 8b7c479

Please sign in to comment.