Skip to content

Commit 11d7623

Browse files
authored
Merge pull request #22 from AmbireTech/feat/change-portfolio-model-network-info
Change portfolio model, add more network info
2 parents d48011b + 4843e73 commit 11d7623

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

lib/types/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ export type PortfolioToken = {
1313
balance: number
1414
balanceUSD: number
1515
symbol: string
16-
network: string
16+
}
17+
18+
export type PortfolioNetworkInfo = {
19+
name: string
20+
chainId: string
21+
platformId: string
22+
explorerUrl: string
23+
iconUrls: string[]
1724
}
1825

1926
export type PortfolioForNetwork = {
20-
network: string
27+
network: PortfolioNetworkInfo
2128
tokens: PortfolioToken[]
2229
}
2330

lib/utils/portfolio.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import {
1111
PortfolioForNetwork,
1212
ProcessAddressProps,
1313
AuraResponse_01,
14-
NetworkPortfolioLibResponse
14+
NetworkPortfolioLibResponse,
15+
PortfolioNetworkInfo
1516
} from '../types'
1617

1718
export async function getPortfolioForNetwork(
@@ -47,7 +48,6 @@ export async function getPortfolioVelcroV3(
4748
const tokens = resp.tokens
4849
.filter((t) => t.amount > 0n)
4950
.map((t) => {
50-
const network = networks.find((n) => n.chainId === t.chainId) as Network
5151
const balance = Number(t.amount) / Math.pow(10, t.decimals)
5252
const priceUSD = (t.priceIn.find((p) => p.baseCurrency === 'usd') || { price: 0 })
5353
.price
@@ -56,7 +56,6 @@ export async function getPortfolioVelcroV3(
5656
symbol: t.symbol,
5757
balance,
5858
balanceUSD: balance * priceUSD,
59-
network: network.name,
6059
address: t.address
6160
}
6261
})
@@ -65,8 +64,17 @@ export async function getPortfolioVelcroV3(
6564
continue
6665
}
6766

67+
const matchedNetwork = networks.find((n) => n.chainId === resp.tokens[0].chainId) as Network
68+
const networkInfo: PortfolioNetworkInfo = {
69+
name: matchedNetwork.name,
70+
chainId: matchedNetwork.chainId.toString(),
71+
platformId: matchedNetwork.platformId,
72+
explorerUrl: matchedNetwork.explorerUrl,
73+
iconUrls: matchedNetwork.iconUrls || []
74+
}
75+
6876
output.push({
69-
network: tokens[0].network,
77+
network: networkInfo,
7078
tokens
7179
})
7280
}

test/unit/portfolio.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,12 @@ describe('Portfolio unit tests', () => {
8888
expect(res).toHaveLength(1)
8989
expect(res[0]).toHaveProperty('network')
9090
expect(res[0]).toHaveProperty('tokens')
91-
expect(res[0].network).toEqual('Ethereum')
91+
expect(res[0].network.name).toEqual('Ethereum')
9292
expect(res[0].tokens).toHaveLength(1)
9393

9494
const mockedLibToken = mockedNetworkPortfolioResult.tokens[0]
9595
expect(res[0].tokens[0].symbol).toEqual(mockedLibToken.symbol)
9696
expect(res[0].tokens[0].address).toEqual(mockedLibToken.address)
97-
expect(res[0].tokens[0].network).toEqual('Ethereum')
9897

9998
const expectedBalance =
10099
Number(mockedLibToken.amount) / Math.pow(10, mockedLibToken.decimals)

0 commit comments

Comments
 (0)