Skip to content

Commit

Permalink
fix default favorites
Browse files Browse the repository at this point in the history
  • Loading branch information
walmat committed Feb 13, 2025
1 parent 548ca50 commit 96bad47
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
22 changes: 20 additions & 2 deletions src/core/state/favorites/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import create from 'zustand';

import buildTimeNetworks from 'static/data/networks.json';
import { createStore } from '~/core/state/internal/createStore';
import { AddressOrEth } from '~/core/types/assets';
import { ChainId } from '~/core/types/chains';
Expand All @@ -9,6 +10,23 @@ type UpdateFavoritesArgs = {
chainId: ChainId;
};

const IS_DEV = process.env.IS_DEV === 'true';
const INTERNAL_BUILD = process.env.INTERNAL_BUILD === 'true';

const getInitialFavorites = () => {
return buildTimeNetworks.backendNetworks.networks.reduce(
(acc, network) => {
if (network.internal && !(INTERNAL_BUILD || IS_DEV)) return acc;

return {
...acc,
[network.id]: network.favorites.map((f) => f.address as AddressOrEth),
};
},
{} as Record<number, AddressOrEth[]>,
);
};

type UpdateFavoritesFn = ({ address, chainId }: UpdateFavoritesArgs) => void;

export interface FavoritesState {
Expand All @@ -20,7 +38,7 @@ export interface FavoritesState {

export const favoritesStore = createStore<FavoritesState>(
(set, get) => ({
favorites: {},
favorites: getInitialFavorites(),
setFavorites: (favorites) => set({ favorites }),
addFavorite: ({ address, chainId }: UpdateFavoritesArgs) => {
const { favorites } = get();
Expand Down Expand Up @@ -48,7 +66,7 @@ export const favoritesStore = createStore<FavoritesState>(
{
persist: {
name: 'favorites',
version: 7,
version: 8,
},
},
);
Expand Down
15 changes: 0 additions & 15 deletions src/core/state/networks/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import {
TransformedChain,
} from '~/core/types/chains';

const IS_DEV = process.env.IS_DEV === 'true';
const INTERNAL_BUILD = process.env.INTERNAL_BUILD === 'true';

const DEFAULT_PRIVATE_MEMPOOL_TIMEOUT = 2 * 60 * 1_000; // 2 minutes

export interface NetworkState {
Expand Down Expand Up @@ -97,7 +94,6 @@ interface NetworkActions {
>;
getBackendChainsByMainnetId: () => Record<number, BackendNetwork[]>;
getBackendChainIdsByMainnetId: () => Record<number, number[]>;
getDefaultFavorites: () => Record<number, AddressOrEth[]>;
getChain: (chainId: number) => TransformedChain | undefined;
getAllChains: (includeTestnets?: boolean) => Record<number, TransformedChain>;
getAllActiveRpcChains: (includeTestnets?: boolean) => Chain[];
Expand Down Expand Up @@ -788,17 +784,6 @@ export const networkStore = createQueryStore<
);
}),

getDefaultFavorites: createSelector(({ networks }) => {
return networks.backendNetworks.networks.reduce((acc, network) => {
if (network.internal && !(INTERNAL_BUILD || IS_DEV)) return acc;

return {
...acc,
[network.id]: network.favorites.map((f) => f.address as AddressOrEth),
};
}, {});
}),

getChain: createParameterizedSelector(({ mergedChainData }) => {
return (chainId) => {
return mergedChainData[chainId];
Expand Down

0 comments on commit 96bad47

Please sign in to comment.