From 13269424a5d4140916e80be45e6a34ed14d8ecf9 Mon Sep 17 00:00:00 2001 From: Nguyen Van Viet Date: Thu, 3 Aug 2023 14:33:45 +0700 Subject: [PATCH] add linea mainnet (#354) * add linea mainnet * fix: swtich to block-subgraph --- src/components/TxnList/index.js | 8 ++++---- src/constants/networks.ts | 24 ++++++++++++++++++++++++ src/contexts/PoolData.js | 3 ++- src/pages/PoolPage.js | 1 + src/utils/tokenLists.ts | 22 +++++++++++----------- 5 files changed, 42 insertions(+), 16 deletions(-) diff --git a/src/components/TxnList/index.js b/src/components/TxnList/index.js index 120d7dbb1..97f9304c9 100644 --- a/src/components/TxnList/index.js +++ b/src/components/TxnList/index.js @@ -299,11 +299,11 @@ function TxnList({ transactions, symbol0Override, symbol1Override, color }) { valueToCompareA = parseFloat(a[sortedColumn]) valueToCompareB = parseFloat(b[sortedColumn]) } - if (valueToCompareA > valueToCompareB) return (sortDirection ? -1 : 1) * 1 - if (valueToCompareA < valueToCompareB) return (sortDirection ? -1 : 1) * -1 + if (valueToCompareA > valueToCompareB) return (sortDirection ? -1 : 1) * -1 + if (valueToCompareA < valueToCompareB) return (sortDirection ? -1 : 1) * 1 - if (a.timestamp < b.timestamp) return 1 - if (a.timestamp > b.timestamp) return -1 + if (a.timestamp < b.timestamp) return -1 + if (a.timestamp > b.timestamp) return 1 if (a.amountUSD < b.amountUSD) return 1 if (a.amountUSD > b.amountUSD) return -1 diff --git a/src/constants/networks.ts b/src/constants/networks.ts index 9fe1474e7..828bb07de 100644 --- a/src/constants/networks.ts +++ b/src/constants/networks.ts @@ -37,6 +37,7 @@ export enum ChainId { OASIS = 42262, OPTIMISM = 10, ZKSYNC = 324, + LINEA = 59144, } export type NETWORK_INFO = { @@ -355,6 +356,29 @@ export const NETWORKS_INFO: { [key in ChainId]: NETWORK_INFO } = { tokensListUrl: 'https://raw.githubusercontent.com/KyberNetwork/ks-assets/main/tokenLists/zksync.tokenlist.json', isEnableBlockService: true, }, + + [ChainId.LINEA]: { + chainId: ChainId.LINEA, + icon: 'https://linea.build/apple-touch-icon.png', + name: 'Linea', + urlKey: 'linea', + priceRoute: 'linea', + blockServiceRoute: 'linea', + dmmSwapUrl: 'https://kyberswap.com/', + subgraphName: 'kybernetwork/kyberswap-classic-linea', + subgraphUrls: ['https://graph-query.linea.build/subgraphs/name/kybernetwork/kyberswap-classic-linea'], + subgraphBlockUrl: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks', + etherscanUrl: 'https://lineascan.build', + kncAddress: '', + wethAddress: '0xe5d7c2a44ffddf6b295a15c148167daaaf5cf34f', + defaultStartTime: 1690394855, + nativeTokenSymbol: 'ETH', + nativeTokenWrappedName: 'ETH (Wrapped)', + nativeTokenLogo: EthereumLogo, + etherscanLinkText: 'LINEA Explorer', + tokensListUrl: 'https://raw.githubusercontent.com/KyberNetwork/ks-assets/main/tokenLists/linea.tokenlist.json', + isEnableBlockService: false, + }, } export const NETWORKS_INFO_LIST: NETWORK_INFO[] = Object.values(NETWORKS_INFO) diff --git a/src/contexts/PoolData.js b/src/contexts/PoolData.js index c0241c2dd..a218238a4 100644 --- a/src/contexts/PoolData.js +++ b/src/contexts/PoolData.js @@ -567,8 +567,9 @@ export function usePoolData(poolAddress) { setError(true) } } + if (!poolData?.id && !error) { - if (poolAddress && ethPrice && isAddress(poolAddress)) { + if (poolAddress && isAddress(poolAddress)) { fetchData() } else { setError(true) diff --git a/src/pages/PoolPage.js b/src/pages/PoolPage.js index 61620add9..3d4b46c50 100644 --- a/src/pages/PoolPage.js +++ b/src/pages/PoolPage.js @@ -147,6 +147,7 @@ function PoolPage({ poolAddress, history }) { oneDayVolumeToken0, oneDayVolumeToken1, } = usePoolData(poolAddress) + const [[networkInfo]] = useNetworksInfo() const prices = usePrices([token0?.id, token1?.id].filter(Boolean)) diff --git a/src/utils/tokenLists.ts b/src/utils/tokenLists.ts index 1342cac03..c24379711 100644 --- a/src/utils/tokenLists.ts +++ b/src/utils/tokenLists.ts @@ -1,8 +1,8 @@ import { TokenList } from '@uniswap/token-lists' // override schema of uni for extend name length and additional info -import schema from './scheme.json' +// import schema from './scheme.json' // import schema from '@uniswap/token-lists/src/tokenlist.schema.json' -import Ajv from 'ajv' +// import Ajv from 'ajv' import { ChainId, NETWORK_INFO } from '../constants/networks' /** @@ -27,7 +27,7 @@ function uriToHttp(uri: string): string[] { } } -const tokenListValidator = new Ajv({ allErrors: true }).compile(schema) +// const tokenListValidator = new Ajv({ allErrors: true }).compile(schema) /** * Contains the logic for resolving a list URL to a validated token list @@ -74,14 +74,14 @@ export default async function getTokenList(listUrl: string, networkInfo: NETWORK return json } - if (!tokenListValidator(json)) { - const validationErrors: string = - tokenListValidator.errors?.reduce((memo, error) => { - const add = `${error.dataPath} ${error.message ?? ''}` - return memo.length > 0 ? `${memo}; ${add}` : `${add}` - }, '') ?? 'unknown error' - throw new Error(`Token list failed validation: ${validationErrors}`) - } + // if (!tokenListValidator(json)) { + // const validationErrors: string = + // tokenListValidator.errors?.reduce((memo, error) => { + // const add = `${error.dataPath} ${error.message ?? ''}` + // return memo.length > 0 ? `${memo}; ${add}` : `${add}` + // }, '') ?? 'unknown error' + // throw new Error(`Token list failed validation: ${validationErrors}`) + // } return json }