diff --git a/packages/dashboard/src/web3/context.ts b/packages/dashboard/src/web3/context.ts index f83c422da0ee..d97ac196dc69 100644 --- a/packages/dashboard/src/web3/context.ts +++ b/packages/dashboard/src/web3/context.ts @@ -13,7 +13,7 @@ import { } from '@masknet/web3-shared-evm' import { getProxyWebsocketInstance } from '@masknet/web3-shared-base' import { Services, Messages, PluginServices, PluginMessages } from '../API' -import { TokenListApi } from '@masknet/web3-providers' +import { TokenList } from '@masknet/web3-providers' export const Web3Context: Web3ProviderType = { allowTestnet: createSubscriptionFromAsync(Services.Settings.getWalletAllowTestChain, false, () => { @@ -95,7 +95,7 @@ export const Web3Context: Web3ProviderType = { getCollectionsNFT: PluginServices.Wallet.getCollectionsNFT, getAddressNamesList: PluginServices.Wallet.getAddressNames, getTransactionList: PluginServices.Wallet.getTransactionList, - fetchERC20TokensFromTokenLists: TokenListApi.fetchERC20TokensFromTokenLists, + fetchERC20TokensFromTokenLists: TokenList.fetchERC20TokensFromTokenLists, providerSocket: getProxyWebsocketInstance((info) => PluginMessages.Wallet.events.socketMessageUpdated.sendToAll(info), ), diff --git a/packages/mask/src/plugins/Avatar/hooks/useNFTContainerAtTwitter.ts b/packages/mask/src/plugins/Avatar/hooks/useNFTContainerAtTwitter.ts index dfea0104ccb5..27d6db06cbde 100644 --- a/packages/mask/src/plugins/Avatar/hooks/useNFTContainerAtTwitter.ts +++ b/packages/mask/src/plugins/Avatar/hooks/useNFTContainerAtTwitter.ts @@ -1,9 +1,9 @@ -import { UserNFTContainerAtTwitter } from '@masknet/web3-providers' +import { Twitter } from '@masknet/web3-providers' import { useAsyncRetry } from 'react-use' import type { AsyncState } from 'react-use/lib/useAsyncFn' export function useNFTContainerAtTwitter(screenName: string): AsyncState<{ address: string; token_id: string }> { return useAsyncRetry(async () => { - return UserNFTContainerAtTwitter.getUserNftContainer(screenName) - }, [UserNFTContainerAtTwitter, screenName]) + return Twitter.getUserNftContainer(screenName) + }, [Twitter, screenName]) } diff --git a/packages/mask/src/plugins/Wallet/services/tokenPrice.ts b/packages/mask/src/plugins/Wallet/services/tokenPrice.ts index f4815d7e6cad..4e82783b2d3c 100644 --- a/packages/mask/src/plugins/Wallet/services/tokenPrice.ts +++ b/packages/mask/src/plugins/Wallet/services/tokenPrice.ts @@ -4,7 +4,7 @@ import { startEffects } from '../../../../utils-pure' import { UPDATE_CHAIN_STATE_DELAY } from '../constants' import { currentTokenPricesSettings } from '../settings' import { uniq } from 'lodash-unified' -import { TokenPriceApi } from '@masknet/web3-providers' +import { TokenPrice } from '@masknet/web3-providers' const { run } = startEffects(import.meta.webpackHot) @@ -46,11 +46,7 @@ export async function updateTokenPrices() { const platforms = Object.keys(trackingContracts) await Promise.allSettled( platforms.map(async (platform) => { - const prices = await TokenPriceApi.getTokenPrices( - platform, - trackingContracts[platform], - CurrencyType.USD, - ) + const prices = await TokenPrice.getTokenPrices(platform, trackingContracts[platform], CurrencyType.USD) updateCurrentPrices(prices) }), ) @@ -76,7 +72,7 @@ export async function updateNativeTokenPrices() { // update chain state try { - const prices = await TokenPriceApi.getNativeTokenPrice(trackingNativeTokenIds, CurrencyType.USD) + const prices = await TokenPrice.getNativeTokenPrice(trackingNativeTokenIds, CurrencyType.USD) updateCurrentPrices(prices) } catch { // do nothing diff --git a/packages/mask/src/web3/context.ts b/packages/mask/src/web3/context.ts index 226645e72157..32ccac2b9982 100644 --- a/packages/mask/src/web3/context.ts +++ b/packages/mask/src/web3/context.ts @@ -33,7 +33,7 @@ import type { InternalSettings } from '../settings/createSettings' import { Flags } from '../../shared' import Services from '../extension/service' import { getProxyWebsocketInstance } from '@masknet/web3-shared-base' -import { TokenListApi, UserNFTContainerAtTwitter } from '@masknet/web3-providers' +import { TokenList, Twitter } from '@masknet/web3-providers' import type { ERC721 } from '@masknet/web3-contracts/types/ERC721' import type { AbiItem } from 'web3-utils' import ERC721ABI from '@masknet/web3-contracts/abis/ERC721.json' @@ -147,7 +147,7 @@ function createWeb3Context(disablePopup = false, isMask = false): Web3ProviderTy getAddressNamesList: async (identity: Parameters[0]) => { const addressNames = await WalletRPC.getAddressNames(identity) if (identity.identifier.network === 'twitter.com') { - const result = await UserNFTContainerAtTwitter.getUserNftContainer(identity.identifier.userId ?? '') + const result = await Twitter.getUserNftContainer(identity.identifier.userId ?? '') if (result?.type_name.toUpperCase() === 'ERC721') { const contractAddress = await getTokenOwner(result.address, result.token_id) if (contractAddress) @@ -164,7 +164,7 @@ function createWeb3Context(disablePopup = false, isMask = false): Web3ProviderTy return addressNames }, getTransactionList: WalletRPC.getTransactionList, - fetchERC20TokensFromTokenLists: TokenListApi.fetchERC20TokensFromTokenLists, + fetchERC20TokensFromTokenLists: TokenList.fetchERC20TokensFromTokenLists, providerSocket: getProxyWebsocketInstance((info) => WalletMessages.events.socketMessageUpdated.sendToAll(info)), } } diff --git a/packages/web3-providers/src/index.ts b/packages/web3-providers/src/index.ts index 388f66b6add3..c4e28fac5830 100644 --- a/packages/web3-providers/src/index.ts +++ b/packages/web3-providers/src/index.ts @@ -5,9 +5,9 @@ import { NFTScanAPI } from './NFTScan' import { NativeExplorerAPI } from './explorer' import { RSS3API } from './rss3' import { KeyValueAPI } from './kv' -import { UserNFTContainerAtTwitterAPI } from './UserNFTContainer' -import { TokenList } from './TokenList' -import { TokenPrice } from './TokenPrice' +import { TwitterAPI } from './twitter' +import { TokenListAPI } from './token-list' +import { TokenPriceAPI } from './token-price' export * from './types' export * from './opensea/utils' @@ -19,10 +19,10 @@ export const CoinGecko = new CoinGeckoAPI() export const Explorer = new NativeExplorerAPI() export const RSS3 = new RSS3API() export const KeyValue = new KeyValueAPI() -export const UserNFTContainerAtTwitter = new UserNFTContainerAtTwitterAPI() +export const Twitter = new TwitterAPI() -export const TokenListApi = new TokenList() -export const TokenPriceApi = new TokenPrice() +export const TokenList = new TokenListAPI() +export const TokenPrice = new TokenPriceAPI() // Method for provider proxy export { getOpenSeaNFTList, getOpenSeaCollectionList } from './opensea' diff --git a/packages/web3-providers/src/TokenList/index.ts b/packages/web3-providers/src/token-list/index.ts similarity index 90% rename from packages/web3-providers/src/TokenList/index.ts rename to packages/web3-providers/src/token-list/index.ts index 6e23a93b14f4..078c1614d6da 100644 --- a/packages/web3-providers/src/TokenList/index.ts +++ b/packages/web3-providers/src/token-list/index.ts @@ -7,14 +7,14 @@ import { getChainDetailed, } from '@masknet/web3-shared-evm' import { groupBy } from 'lodash-unified' -import type { TokenListAPI } from '../types' +import type { TokenListBaseAPI } from '../types' const NATIVE_TOKEN_ADDRESS_IN_1INCH = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' const fetchTokenList = memoizePromise( async (url: string) => { const response = await fetch(url, { cache: 'force-cache' }) - return response.json() as Promise + return response.json() as Promise }, (url) => url, ) @@ -28,7 +28,7 @@ async function fetch1inchERC20TokensFromTokenList( url: string, chainId = ChainId.Mainnet, ): Promise { - const tokens = ((await fetchTokenList(url)) as TokenListAPI.TokenObject).tokens + const tokens = ((await fetchTokenList(url)) as TokenListBaseAPI.TokenObject).tokens const _tokens = Object.values(tokens) return _tokens .filter((x) => x.address.toLowerCase() !== NATIVE_TOKEN_ADDRESS_IN_1INCH) @@ -49,7 +49,7 @@ async function fetchCommonERC20TokensFromTokenList( url: string, chainId = ChainId.Mainnet, ): Promise { - return ((await fetchTokenList(url)) as TokenListAPI.TokenList).tokens + return ((await fetchTokenList(url)) as TokenListBaseAPI.TokenList).tokens .filter( (x) => x.chainId === chainId && @@ -90,7 +90,7 @@ async function fetchERC20TokensFromTokenList(urls: string[], chainId = ChainId.M * @param chainId */ -export class TokenList implements TokenListAPI.Provider { +export class TokenListAPI implements TokenListBaseAPI.Provider { async fetchERC20TokensFromTokenLists(url: string[], chainId: ChainId) { const result = memoizePromise( async (urls: string[], chainId = ChainId.Mainnet): Promise => { diff --git a/packages/web3-providers/src/TokenPrice/index.ts b/packages/web3-providers/src/token-price/index.ts similarity index 78% rename from packages/web3-providers/src/TokenPrice/index.ts rename to packages/web3-providers/src/token-price/index.ts index 0151066d1f5b..43c6fb357756 100644 --- a/packages/web3-providers/src/TokenPrice/index.ts +++ b/packages/web3-providers/src/token-price/index.ts @@ -1,18 +1,18 @@ import type { CurrencyType } from '@masknet/plugin-infra' -import type { TokenPriceAPI } from '../types' +import type { TokenPriceBaseAPI } from '../types' const URL_BASE = 'https://api.coingecko.com/api/v3' -export class TokenPrice implements TokenPriceAPI.Provider { +export class TokenPriceAPI implements TokenPriceBaseAPI.Provider { async getTokenPrices(platform: string, contractAddresses: string[], currency: CurrencyType) { const addressList = contractAddresses.join(',') const requestPath = `${URL_BASE}/simple/token_price/${platform}?contract_addresses=${addressList}&vs_currencies=${currency}` - const prices = await fetch(requestPath).then((r) => r.json() as Promise) + const prices = await fetch(requestPath).then((r) => r.json() as Promise) return prices } async getNativeTokenPrice(tokenIds: string[], currency: CurrencyType) { const requestPath = `${URL_BASE}/simple/price?ids=${tokenIds.join(',')}&vs_currencies=${currency}` - const prices = await fetch(requestPath).then((r) => r.json() as Promise) + const prices = await fetch(requestPath).then((r) => r.json() as Promise) return prices } } diff --git a/packages/web3-providers/src/UserNFTContainer/index.ts b/packages/web3-providers/src/twitter/index.ts similarity index 94% rename from packages/web3-providers/src/UserNFTContainer/index.ts rename to packages/web3-providers/src/twitter/index.ts index 0578d51cbb8f..c44bdbbb7b6e 100644 --- a/packages/web3-providers/src/UserNFTContainer/index.ts +++ b/packages/web3-providers/src/twitter/index.ts @@ -1,6 +1,6 @@ import { escapeRegExp } from 'lodash-unified' import urlcat from 'urlcat' -import type { UserNFTContainerAPI } from '../types' +import type { TwitterBaseAPI } from '../types' function getScriptURL(content: string, name: string) { const matchURL = new RegExp( @@ -38,7 +38,7 @@ async function getUserNftContainer( ): Promise<{ data: { user: { - result: UserNFTContainerAPI.NFTContainer + result: TwitterBaseAPI.NFTContainer } } }> { @@ -83,7 +83,7 @@ async function getTokens() { } } -export class UserNFTContainerAtTwitterAPI implements UserNFTContainerAPI.Provider { +export class TwitterAPI implements TwitterBaseAPI.Provider { async getUserNftContainer( screenName: string, ): Promise<{ address: string; token_id: string; type_name: string } | undefined> { diff --git a/packages/web3-providers/src/types.ts b/packages/web3-providers/src/types.ts index 071bf45f4405..552fbece0567 100644 --- a/packages/web3-providers/src/types.ts +++ b/packages/web3-providers/src/types.ts @@ -348,7 +348,7 @@ export namespace SecurityAPI { } } -export namespace UserNFTContainerAPI { +export namespace TwitterBaseAPI { export interface NFTContainer { has_nft_avatar: boolean nft_avatar_metadata: AvatarMetadata @@ -394,7 +394,7 @@ export namespace UserNFTContainerAPI { } } -export namespace TokenListAPI { +export namespace TokenListBaseAPI { export interface Token { address: string chainId: number @@ -426,7 +426,7 @@ export namespace TokenListAPI { } } -export namespace TokenPriceAPI { +export namespace TokenPriceBaseAPI { export interface PriceRecord { [currency: string]: number }