Skip to content

Commit

Permalink
feat: add scroll scr token (#12082)
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask authored Jan 29, 2025
1 parent 7b80b45 commit f684b2a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
27 changes: 25 additions & 2 deletions packages/web3-hooks/evm/src/useOKXTokenList.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
import { OKX } from '@masknet/web3-providers'
import type { ChainId } from '@masknet/web3-shared-evm'
import { TokenType, type FungibleToken } from '@masknet/web3-shared-base'
import { ChainId, SchemaType } from '@masknet/web3-shared-evm'
import { skipToken, useQuery } from '@tanstack/react-query'

export function useOKXTokenList(chainId: ChainId | undefined, enabled = true) {
return useQuery({
enabled: enabled && !!chainId,
queryKey: ['okx-tokens', chainId],
queryFn: chainId ? () => OKX.getTokens(chainId) : skipToken,
queryFn:
chainId ?
async () => {
const list = await OKX.getTokens(chainId)
if (chainId === ChainId.Scroll && list && !list.some((x) => x.symbol === 'SCR')) {
const scrAddr = '0xd29687c813D741E2F938F4aC377128810E217b1b'
const SCR_Token: FungibleToken<ChainId, SchemaType> = {
id: scrAddr,
chainId: ChainId.Scroll,
type: TokenType.Fungible,
schema: SchemaType.ERC20,
address: scrAddr,
symbol: 'SCR',
name: 'Scroll',
decimals: 18,
logoURL:
'https://www.okx.com/cdn/web3/currency/token/small/534352-0xd29687c813d741e2f938f4ac377128810e217b1b-97?v=1738011884368',
}
return [...list, SCR_Token]
}
return list
}
: skipToken,
})
}
5 changes: 3 additions & 2 deletions packages/web3-providers/src/Web3/Base/apis/HubFungible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ export abstract class BaseHubFungible<ChainId, SchemaType> extends AbstractBaseH
initial?: BaseHubOptions<ChainId>,
): Promise<Array<FungibleToken<ChainId, SchemaType>>> {
const options = this.HubOptions.fill({ ...initial, chainId })
const providers = this.getProvidersFungible(initial)
const allProviders = this.getProvidersFungible(initial)
return queryClient.fetchQuery({
queryKey: ['get-fungible-token-list', options.chainId, initial],
queryFn: async () => {
const providers = allProviders.filter((x) => x.getNonFungibleTokenList)
return attemptUntil(
providers.map((x) => () => x.getFungibleTokenList?.(options.chainId)),
providers.map((x) => () => x.getFungibleTokenList!(options.chainId)),
EMPTY_LIST,
)
},
Expand Down

0 comments on commit f684b2a

Please sign in to comment.