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
11 changes: 9 additions & 2 deletions lib/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ export type PortfolioToken = {
balance: number
balanceUSD: number
symbol: string
network: string
}

export type PortfolioNetworkInfo = {
name: string
chainId: string
platformId: string
explorerUrl: string
iconUrls: string[]
}

export type PortfolioForNetwork = {
network: string
network: PortfolioNetworkInfo
tokens: PortfolioToken[]
}

Expand Down
16 changes: 12 additions & 4 deletions lib/utils/portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
PortfolioForNetwork,
ProcessAddressProps,
AuraResponse_01,
NetworkPortfolioLibResponse
NetworkPortfolioLibResponse,
PortfolioNetworkInfo
} from '../types'

export async function getPortfolioForNetwork(
Expand Down Expand Up @@ -47,7 +48,6 @@ export async function getPortfolioVelcroV3(
const tokens = resp.tokens
.filter((t) => t.amount > 0n)
.map((t) => {
const network = networks.find((n) => n.chainId === t.chainId) as Network
const balance = Number(t.amount) / Math.pow(10, t.decimals)
const priceUSD = (t.priceIn.find((p) => p.baseCurrency === 'usd') || { price: 0 })
.price
Expand All @@ -56,7 +56,6 @@ export async function getPortfolioVelcroV3(
symbol: t.symbol,
balance,
balanceUSD: balance * priceUSD,
network: network.name,
address: t.address
}
})
Expand All @@ -65,8 +64,17 @@ export async function getPortfolioVelcroV3(
continue
}

const matchedNetwork = networks.find((n) => n.chainId === resp.tokens[0].chainId) as Network
const networkInfo: PortfolioNetworkInfo = {
name: matchedNetwork.name,
chainId: matchedNetwork.chainId.toString(),
platformId: matchedNetwork.platformId,
explorerUrl: matchedNetwork.explorerUrl,
iconUrls: matchedNetwork.iconUrls || []
}

output.push({
network: tokens[0].network,
network: networkInfo,
tokens
})
}
Expand Down
3 changes: 1 addition & 2 deletions test/unit/portfolio.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,12 @@ describe('Portfolio unit tests', () => {
expect(res).toHaveLength(1)
expect(res[0]).toHaveProperty('network')
expect(res[0]).toHaveProperty('tokens')
expect(res[0].network).toEqual('Ethereum')
expect(res[0].network.name).toEqual('Ethereum')
expect(res[0].tokens).toHaveLength(1)

const mockedLibToken = mockedNetworkPortfolioResult.tokens[0]
expect(res[0].tokens[0].symbol).toEqual(mockedLibToken.symbol)
expect(res[0].tokens[0].address).toEqual(mockedLibToken.address)
expect(res[0].tokens[0].network).toEqual('Ethereum')

const expectedBalance =
Number(mockedLibToken.amount) / Math.pow(10, mockedLibToken.decimals)
Expand Down