Skip to content

Commit

Permalink
Merge pull request #810 from D8-X/dev
Browse files Browse the repository at this point in the history
optional disable pools per chain (#808)
  • Loading branch information
c40003141 authored Dec 31, 2024
2 parents cbf7a86 + ceda7fc commit e115285
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import { triggerUserStatsUpdateAtom } from 'store/vault-pools.store';
import type { ExchangeInfoI, PerpetualDataI } from 'types/types';
import { getEnabledChainId } from 'utils/getEnabledChainId';
import { isEnabledChain } from 'utils/isEnabledChain';
import { isDisabledPool } from 'utils/isDisabledPool';

import styles from './Header.module.scss';
import { PageAppBar } from './Header.styles';
Expand Down Expand Up @@ -134,7 +135,8 @@ export const Header = memo(({ window }: HeaderPropsI) => {
...pool,
poolId,
};
});
})
.filter(({ poolId }) => !isDisabledPool(chainId, poolId));
setPools(pools);

setCollaterals(pools.map((pool) => pool.settleSymbol));
Expand Down Expand Up @@ -180,7 +182,7 @@ export const Header = memo(({ window }: HeaderPropsI) => {
setOracleFactoryAddr(data.oracleFactoryAddr);
setProxyAddr(data.proxyAddr);
},
[setPools, setCollaterals, setPerpetuals, setAllPerpetuals, setOracleFactoryAddr, setProxyAddr, traderAPI]
[chainId, setPools, setCollaterals, setPerpetuals, setAllPerpetuals, setOracleFactoryAddr, setProxyAddr, traderAPI]
);

useEffect(() => {
Expand Down
15 changes: 15 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,12 @@ const {
VITE_FIREBASE_APPID: firebaseAppId = '',
VITE_FIREBASE_MEASUREMENTID: firebaseMeasurementId = '',
VITE_DEFAULT_MARKETS: defaultMarkets = '',
VITE_DISABLED_POOLS: disabledPools = '',
} = import.meta.env;

const URLS_SEPARATOR = ';';
const KEY_VALUE_SEPARATOR = '::';
const VALUES_SEPARATOR = ',';

function parseUrls(urlData: string): Record<string, string> {
if (!urlData) {
Expand All @@ -55,6 +57,18 @@ function splitNumbers(numbers: string): number[] {
return numbers.split(URLS_SEPARATOR).map(Number);
}

function parseNumbers(data: string): Record<string, number[]> {
if (!data) {
return {};
}
const allValues: Record<string, number[]> = {};
data.split(URLS_SEPARATOR).forEach((entry) => {
const parsed = entry.split(KEY_VALUE_SEPARATOR);
allValues[parsed[0]] = parsed[1].split(VALUES_SEPARATOR).map(Number);
});
return allValues;
}

export const config = {
projectId,
geonamesUsername,
Expand All @@ -73,6 +87,7 @@ export const config = {
showChallengeModal: showChallengeModal === 'true',
defaultTheme,
defaultMarket: parseUrls(defaultMarkets),
disabledPools: parseNumbers(disabledPools),
};

export const pagesConfig = {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/isDisabledPool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { config } from 'config';

export function isDisabledPool(chainId: number | undefined, poolId: number | undefined): chainId is number {
if (chainId === undefined || poolId === undefined || !config.disabledPools[chainId]) {
return false;
}
return config.disabledPools[chainId].includes(poolId);
}

0 comments on commit e115285

Please sign in to comment.