-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/warning-color-outrange-position
- Loading branch information
Showing
12 changed files
with
3,727 additions
and
219 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { ChainId } from '@kyberswap/ks-sdk-core' | ||
import { useMemo } from 'react' | ||
import { useGetChainsConfigurationQuery } from 'services/ksSetting' | ||
|
||
import { MAINNET_NETWORKS, NETWORKS_INFO } from 'constants/networks' | ||
import { NetworkInfo } from 'constants/networks/type' | ||
import { useKyberswapGlobalConfig } from 'hooks/useKyberSwapConfig' | ||
|
||
export enum ChainState { | ||
NEW = 'new', | ||
ACTIVE = 'active', | ||
INACTIVE = 'inactive', | ||
MAINTENANCE = 'maintained', | ||
} | ||
|
||
export type ChainStateMap = { [chain in ChainId]: ChainState } | ||
|
||
const defaultData = MAINNET_NETWORKS.map(chainId => NETWORKS_INFO[chainId]) | ||
export default function useChainsConfig() { | ||
const { data } = useGetChainsConfigurationQuery() | ||
const globalConfig = useKyberswapGlobalConfig() | ||
|
||
return useMemo(() => { | ||
const hasConfig = !!data | ||
const chains: NetworkInfo[] = (data || defaultData).map(chain => { | ||
const chainId = +chain.chainId as ChainId | ||
const chainState = hasConfig ? globalConfig?.chainStates?.[chainId] : ChainState.ACTIVE | ||
return { | ||
...NETWORKS_INFO[chainId], | ||
...chain, // BE config | ||
chainId, | ||
state: chainState, | ||
} | ||
}) | ||
return { | ||
activeChains: chains.filter(e => [ChainState.ACTIVE, ChainState.NEW].includes(e.state)), | ||
supportedChains: chains.filter(e => | ||
[ChainState.ACTIVE, ChainState.NEW, ChainState.MAINTENANCE].includes(e.state), | ||
), | ||
} | ||
}, [data, globalConfig]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters