Skip to content

Commit

Permalink
add linea mainnet (#354)
Browse files Browse the repository at this point in the history
* add linea mainnet

* fix: swtich to block-subgraph
  • Loading branch information
viet-nv authored Aug 3, 2023
1 parent 301c642 commit 1326942
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/components/TxnList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions src/constants/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export enum ChainId {
OASIS = 42262,
OPTIMISM = 10,
ZKSYNC = 324,
LINEA = 59144,
}

export type NETWORK_INFO = {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/contexts/PoolData.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/pages/PoolPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ function PoolPage({ poolAddress, history }) {
oneDayVolumeToken0,
oneDayVolumeToken1,
} = usePoolData(poolAddress)

const [[networkInfo]] = useNetworksInfo()

const prices = usePrices([token0?.id, token1?.id].filter(Boolean))
Expand Down
22 changes: 11 additions & 11 deletions src/utils/tokenLists.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand All @@ -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
Expand Down Expand Up @@ -74,14 +74,14 @@ export default async function getTokenList(listUrl: string, networkInfo: NETWORK
return json
}

if (!tokenListValidator(json)) {
const validationErrors: string =
tokenListValidator.errors?.reduce<string>((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<string>((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
}
Expand Down

0 comments on commit 1326942

Please sign in to comment.