Commit 7b7e4e61 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

chore: derive SupportedChainId from sdk-core (#6091)

* chore: derrive SupportedChainId from sdk-core

* fix

* fix more types

* wip

* Revert "wip"

This reverts commit dccd83f6ac565d71d0936c57c20f48b99f00d68e.

* Revert "fix more types"

This reverts commit 4f11b5a10cc78ad24c3a819720b3f12bc8970988.

* fix: use literal enum for derived types

* Update src/components/NetworkAlert/NetworkAlert.tsx
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>

---------
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>
parent e8936f50
......@@ -150,7 +150,10 @@ export function NetworkAlert() {
return null
}
const { label, logoUrl, bridge } = getChainInfo(chainId)
const chainInfo = getChainInfo(chainId)
if (!chainInfo) return null
const { label, logoUrl, bridge } = chainInfo
const textColor = TEXT_COLORS[chainId]
return bridge ? (
......
import { SupportedChainId as SdkSupportedChainId } from '@uniswap/sdk-core'
import { ALL_SUPPORTED_CHAIN_IDS, SupportedChainId } from './chains'
describe('chains', () => {
describe('ALL_SUPPORTED_CHAIN_IDS', () => {
it('derives from sdk-core', () => {
ALL_SUPPORTED_CHAIN_IDS.forEach((chainId) => {
const chainName = SupportedChainId[chainId]
expect(SdkSupportedChainId[chainId]).toBe(chainName)
})
})
it('contains all the values in the SupportedChainId enum', () => {
Object.values(SupportedChainId)
.filter((chainId) => typeof chainId === 'number')
......
/**
* List of all the networks supported by the Uniswap Interface
* TODO(INFRA-90): Eventually this may be derived from sdk-core.
/*
* SupportedChainId must be defined inline, without using @uniswap/sdk-core, so that its members are their own types
* {@see https://www.typescriptlang.org/docs/handbook/enums.html#union-enums-and-enum-member-types}. This allows the
* derived const arrays and their types (eg {@link L1_CHAIN_IDS}, {@link SupportedL1ChainId}) to be narrowed and used
* to enforce chain typing.
*
* Because this is not explicitly derived from @uniswap/sdk-core, there is a unit test to enforce conformance.
*/
export enum SupportedChainId {
MAINNET = 1,
......@@ -49,7 +53,7 @@ export const SUPPORTED_GAS_ESTIMATE_CHAIN_IDS = [
SupportedChainId.CELO,
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
]
] as const
/**
* Unsupported networks for V2 pool behavior.
......@@ -59,7 +63,7 @@ export const UNSUPPORTED_V2POOL_CHAIN_IDS = [
SupportedChainId.OPTIMISM,
SupportedChainId.ARBITRUM_ONE,
SupportedChainId.ARBITRUM_GOERLI,
]
] as const
export const TESTNET_CHAIN_IDS = [
SupportedChainId.GOERLI,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment