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: asset filtering by networks settings #1124

Merged
merged 2 commits into from
Nov 8, 2023
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
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
Loading