Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/maskbook/src/plugins/Wallet/apis/debank.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
import type { NetworkType } from '@masknet/web3-shared'
import { resolveDebankChainName } from '../pipes'
import type { BalanceListResponse, HistoryResponse } from '../types'

const DEBANK_API = 'https://api.debank.com'

export async function getTransactionList(address: string, network: NetworkType) {
const response = await fetch(
`${DEBANK_API}/history/list?user_addr=${address.toLowerCase()}&chain=${resolveDebankChainName(network)}`,
)
export async function getTransactionList(address: string, chain: string) {
const response = await fetch(`${DEBANK_API}/history/list?user_addr=${address.toLowerCase()}&chain=${chain}`)
return (await response.json()) as HistoryResponse
}

export async function getAssetsList(address: string, network: NetworkType) {
export async function getAssetsList(address: string) {
const response = await fetch(`${DEBANK_API}/token/balance_list?user_addr=${address.toLowerCase()}`)
return (await response.json()) as BalanceListResponse
}
4 changes: 2 additions & 2 deletions packages/maskbook/src/plugins/Wallet/apis/zerion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ export async function getTransactionList(address: string, page?: number) {
})) as ZerionTransactionResponseBody
}

export async function getAssetsList(address: string) {
export async function getAssetsList(address: string, scope: string) {
return (await subscribeFromZerion(addressSocket, {
scope: ['assets'],
scope: [scope],
payload: {
address,
currency: 'usd',
Expand Down
14 changes: 14 additions & 0 deletions packages/maskbook/src/plugins/Wallet/pipes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,17 @@ export function resolveDebankChainName(network: NetworkType) {
return ''
}
}

export function resolveZerionAssetsScopeName(network: NetworkType) {
switch (network) {
case NetworkType.Ethereum:
return 'assets'
case NetworkType.Binance:
return 'bsc-assets'
case NetworkType.Polygon:
return 'polygon-assets'
default:
safeUnreachable(network)
return ''
}
}
5 changes: 3 additions & 2 deletions packages/maskbook/src/plugins/Wallet/services/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { EthereumAddress } from 'wallet.ts'
import * as DebankAPI from '../apis/debank'
import * as OpenSeaAPI from '../apis/opensea'
import * as ZerionAPI from '../apis/zerion'
import { resolveZerionAssetsScopeName } from '../pipes'
import { Asset, BalanceRecord, CollectibleProvider, PortfolioProvider, ZerionAddressAsset } from '../types'

export async function getAssetsListNFT(
Expand Down Expand Up @@ -86,13 +87,13 @@ export async function getAssetsList(
switch (provider) {
case PortfolioProvider.ZERION:
if (network !== NetworkType.Ethereum) return []
const { meta, payload } = await ZerionAPI.getAssetsList(address)
const { meta, payload } = await ZerionAPI.getAssetsList(address, resolveZerionAssetsScopeName(network))
if (meta.status !== 'ok') throw new Error('Fail to load assets.')
// skip NFT assets
const assetsList = values(payload.assets).filter((x) => x.asset.is_displayable && x.asset.icon_url)
return formatAssetsFromZerion(assetsList)
case PortfolioProvider.DEBANK:
const { data = [], error_code } = await DebankAPI.getAssetsList(address, network)
const { data = [], error_code } = await DebankAPI.getAssetsList(address)
if (error_code === 0) return formatAssetsFromDebank(data)
return []
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import * as DeBankAPI from '../apis/debank'
import * as ZerionApi from '../apis/zerion'
import { NetworkType, pow10 } from '@masknet/web3-shared'
import { resolveDebankChainName } from '../pipes'

export async function getTransactionList(
address: string,
Expand All @@ -23,7 +24,7 @@ export async function getTransactionList(
hasNextPage: boolean
}> {
if (provider === PortfolioProvider.DEBANK) {
const { data, error_code } = await DeBankAPI.getTransactionList(address, network)
const { data, error_code } = await DeBankAPI.getTransactionList(address, resolveDebankChainName(network))
if (error_code !== 0) throw new Error('Fail to load transactions.')
return {
transactions: fromDeBank(data),
Expand Down