Skip to content

Commit

Permalink
refactor ks setting use rtk query (#2170)
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenhoaidanh authored Aug 15, 2023
1 parent a860469 commit 4f8f59a
Show file tree
Hide file tree
Showing 29 changed files with 43 additions and 70 deletions.
9 changes: 7 additions & 2 deletions src/components/SearchModal/CurrencySearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ChangeEvent, KeyboardEvent, ReactNode, useCallback, useEffect, useMemo,
import { Trash } from 'react-feather'
import { usePrevious } from 'react-use'
import { Flex, Text } from 'rebass'
import { useImportTokenMutation } from 'services/ksSetting'
import styled from 'styled-components'

import Column from 'components/Column'
Expand All @@ -33,7 +34,7 @@ import { useRemoveUserAddedToken, useUserAddedTokens, useUserFavoriteTokens } fr
import { ButtonText, CloseIcon, TYPE } from 'theme'
import { filterTruthy, isAddress } from 'utils'
import { filterTokens } from 'utils/filtering'
import { importTokensToKsSettings, isTokenNative } from 'utils/tokenInfo'
import { isTokenNative } from 'utils/tokenInfo'

import CommonBases from './CommonBases'
import CurrencyList from './CurrencyList'
Expand Down Expand Up @@ -311,6 +312,7 @@ export function CurrencySearch({
}, [fetchFavoriteTokenFromAddress])

const abortControllerRef = useRef(new AbortController())
const [importTokensToKsSettings] = useImportTokenMutation()
const fetchListTokens = useCallback(
async (page?: number) => {
const nextPage = (page ?? pageCount) + 1
Expand Down Expand Up @@ -340,7 +342,9 @@ export function CurrencySearch({
chainId: String(rawToken.chainId),
address: rawToken.address,
},
])
]).catch(err => {
console.error('import token err', err)
})
}
} else if (tokens.length === 0 && isQueryValidSolanaAddress) {
// TODO: query tokens from Solana token db
Expand All @@ -361,6 +365,7 @@ export function CurrencySearch({
isQueryValidEVMAddress,
isQueryValidSolanaAddress,
pageCount,
importTokensToKsSettings,
],
)

Expand Down
3 changes: 2 additions & 1 deletion src/components/swapv2/TokenInfoV2/SingleTokenInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useTheme from 'hooks/useTheme'
import { TokenInfo } from 'hooks/useTokenInfo'
import { formattedNum } from 'utils'
import { formatDollarAmount } from 'utils/numbers'
import { escapeScriptHtml } from 'utils/string'

const NOT_AVAILABLE = '--'

Expand Down Expand Up @@ -270,7 +271,7 @@ const SingleTokenInfo = ({
className="desc"
ref={ref}
dangerouslySetInnerHTML={{
__html: description.replace(/\r\n\r\n/g, '<br><br>'),
__html: escapeScriptHtml(description.replace(/\r\n\r\n/g, '<br><br>')),
}}
/>
<InfoRowWrapper>
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/arbitrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import ARBITRUM from 'assets/networks/arbitrum-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +23,6 @@ const arbitrumInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/kybernetwork/arbitrum-blocks',
etherscanUrl: 'https://arbiscan.io',
etherscanName: 'Arbiscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.ARBITRUM}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/aurora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import AURORA from 'assets/networks/aurora-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +23,6 @@ const auroraInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://aurora-graph.kyberengineering.io/subgraphs/name/kybernetwork/aurora-blocks',
etherscanUrl: 'https://aurorascan.dev',
etherscanName: 'Aurora Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.AURORA}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/avax-testnet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import AVAX from 'assets/networks/avax-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const avaxTestnetInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/ducquangkstn/ethereum-block-fuji',
etherscanUrl: 'https://testnet.snowtrace.io',
etherscanName: 'Snowtrace',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.AVAXTESTNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'AVAX',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/avax.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import AVAX from 'assets/networks/avax-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -22,7 +21,6 @@ const avaxInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/ducquangkstn/avalache-blocks',
etherscanUrl: 'https://snowtrace.io',
etherscanName: 'Snowtrace',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.AVAXMAINNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'AVAX',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/bnb-testnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import BnbLogo from 'assets/images/bnb-logo.png'
import BSC from 'assets/networks/bsc-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +23,6 @@ const bnbTestnetInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/ducquangkstn/ethereum-blocks-bsctestnet',
etherscanUrl: 'https://testnet.bscscan.com',
etherscanName: 'BscScan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.BSCTESTNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'BNB',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/bnb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import BnbLogo from 'assets/images/bnb-logo.png'
import BSC from 'assets/networks/bsc-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const bnbInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/dynamic-amm/ethereum-blocks-bsc',
etherscanUrl: 'https://bscscan.com',
etherscanName: 'BscScan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.BSCMAINNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'BNB',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/bttc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import BTT from 'assets/networks/bttc.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const bttcInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://bttc-graph.kyberengineering.io/subgraphs/name/kybernetwork/bttc-blocks',
etherscanUrl: 'https://bttcscan.com',
etherscanName: 'Bttcscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.BTTC}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'BTT',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/cronos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'
import CRONOS_DARK from 'assets/networks/cronos-network-dark.svg'
import CRONOS from 'assets/networks/cronos-network.svg'
import CronosLogo from 'assets/svg/cronos-token-logo.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -25,7 +24,6 @@ const cronosInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/cronos-blocks',
etherscanUrl: 'https://cronoscan.com',
etherscanName: 'Cronos explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.CRONOS}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'CRO',
Expand Down
3 changes: 1 addition & 2 deletions src/constants/networks/ethereum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import Mainnet from 'assets/networks/mainnet-network.svg'
import { KS_SETTING_API, KYBER_DAO_STATS_API } from 'constants/env'
import { KYBER_DAO_STATS_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +24,6 @@ const ethereumInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/dynamic-amm/ethereum-blocks-ethereum',
etherscanUrl: 'https://etherscan.io',
etherscanName: 'Etherscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.MAINNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/fantom.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import FTM from 'assets/networks/fantom-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const fantomInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/kybernetwork/fantom-blocks',
etherscanUrl: 'https://ftmscan.com',
etherscanName: 'Ftmscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.FANTOM}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'FTM',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/görli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import Mainnet from 'assets/networks/mainnet-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +23,6 @@ const görliInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/dramacrypto/goerli-blocks',
etherscanUrl: 'https://goerli.etherscan.io',
etherscanName: 'Goerli Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.GÖRLI}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'gETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/linea-testnet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const lineaTestnetInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://thegraph.goerli.zkevm.consensys.net/subgraphs/name/kybernetwork/linea-blocks',
etherscanUrl: 'https://goerli.lineascan.build',
etherscanName: 'Linea Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.LINEA_TESTNET}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/linea.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const lineaInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://graph-query.linea.build/subgraphs/name/kybernetwork/linea-blocks',
etherscanUrl: 'https://lineascan.build',
etherscanName: 'Linea Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.LINEA}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/matic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import Polygon from 'assets/networks/polygon-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -22,7 +21,6 @@ const maticInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/dynamic-amm/ethereum-blocks-polygon',
etherscanUrl: 'https://polygonscan.com',
etherscanName: 'Polygonscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.MATIC}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'MATIC',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/mumbai.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import Polygon from 'assets/networks/polygon-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const mumbaiInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/piavgh/mumbai-blocks',
etherscanUrl: 'https://mumbai.polygonscan.com/',
etherscanName: 'Polygonscan',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.MUMBAI}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'MATIC',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/oasis.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import OASIS from 'assets/networks/oasis-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const oasisInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://oasis-graph.kyberengineering.io/subgraphs/name/kybernetwork/oasis-blocks',
etherscanUrl: 'https://explorer.emerald.oasis.dev',
etherscanName: 'Oasis Emerald Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.OASIS}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ROSE',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/optimism.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { ChainId } from '@kyberswap/ks-sdk-core'

import EthereumLogo from 'assets/images/ethereum-logo.png'
import OPTIMISM from 'assets/networks/optimism-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -24,7 +23,6 @@ const optimismInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://api.thegraph.com/subgraphs/name/ianlapham/uni-testing-subgraph',
etherscanUrl: 'https://optimistic.etherscan.io',
etherscanName: 'Optimistic Ethereum Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.OPTIMISM}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'ETH',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/solana-devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'
import { PublicKey } from '@solana/web3.js'

import Solana from 'assets/networks/solana-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { SolanaNetworkInfo } from 'constants/networks/type'

export const SelectedNetwork = WalletAdapterNetwork.Mainnet
Expand Down Expand Up @@ -39,7 +38,6 @@ const solanaInfo: SolanaNetworkInfo = {
limitOrder: { development: NOT_SUPPORT, production: NOT_SUPPORT },
coingeckoNetworkId: 'solana',
coingeckoNativeTokenId: 'solana',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.SOLANA_DEVNET}&isWhitelisted=${true}`,
defaultRpcUrl: 'https://api.devnet.solana.com',
openBookAddress: new PublicKey('srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX'),
dexToCompare: 'OrcaV2',
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/solana.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { WalletAdapterNetwork } from '@solana/wallet-adapter-base'
import { PublicKey } from '@solana/web3.js'

import Solana from 'assets/networks/solana-network.svg'
import { KS_SETTING_API } from 'constants/env'
import { SolanaNetworkInfo } from 'constants/networks/type'

export const SelectedNetwork = WalletAdapterNetwork.Mainnet
Expand Down Expand Up @@ -44,7 +43,6 @@ const solanaInfo: SolanaNetworkInfo = {
limitOrder: { development: NOT_SUPPORT, production: NOT_SUPPORT },
coingeckoNetworkId: 'solana',
coingeckoNativeTokenId: 'solana',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.SOLANA}&isWhitelisted=${true}`,
defaultRpcUrl: 'https://solana.kyberengineering.io',
openBookAddress: new PublicKey('srmqPvymJeFKQ4zGQed1GFppgkRHL9kaELCbyksJtPX'),
dexToCompare: 'OrcaV2',
Expand Down
1 change: 0 additions & 1 deletion src/constants/networks/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export interface NetworkInfo {
}
readonly coingeckoNetworkId: string | null //https://api.coingecko.com/api/v3/asset_platforms
readonly coingeckoNativeTokenId: string | null //https://api.coingecko.com/api/v3/coins/list
readonly tokenListUrl: string
readonly dexToCompare: string | null
readonly limitOrder: {
development: string | null
Expand Down
2 changes: 0 additions & 2 deletions src/constants/networks/velas.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ChainId } from '@kyberswap/ks-sdk-core'

import VELAS from 'assets/networks/velas-network.png'
import { KS_SETTING_API } from 'constants/env'
import { EVMNetworkInfo } from 'constants/networks/type'

const EMPTY = ''
Expand All @@ -23,7 +22,6 @@ const velasInfo: EVMNetworkInfo = {
defaultBlockSubgraph: 'https://velas-graph.kyberengineering.io/subgraphs/name/kybernetwork/velas-blocks',
etherscanUrl: 'https://evmexplorer.velas.com',
etherscanName: 'Velas EVM Explorer',
tokenListUrl: `${KS_SETTING_API}/v1/tokens?chainIds=${ChainId.VELAS}&isWhitelisted=${true}`,
bridgeURL: EMPTY,
nativeToken: {
symbol: 'VLX',
Expand Down
Loading

0 comments on commit 4f8f59a

Please sign in to comment.