Skip to content

Commit 18f681b

Browse files
authored
Merge pull request #31 from AmbireTech/feat/fetch-portfolio-for-network-handle-errors
Handle errors when fetching portfolio for network
2 parents 5d5e2e9 + 7f6fa4e commit 18f681b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/types/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export type PortfolioLibToken = Pick<
66
>
77
export type NetworkPortfolioLibResponse = {
88
tokens: PortfolioLibToken[]
9+
error?: string | null
910
}
1011

1112
export type PortfolioToken = {

lib/utils/portfolio.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
NetworkPortfolioLibResponse,
1515
PortfolioNetworkInfo
1616
} from '../types'
17+
import { stringifyError } from '..'
1718

1819
export async function getPortfolioForNetwork(
1920
address: string,
@@ -28,7 +29,18 @@ export async function getPortfolioForNetwork(
2829
'https://relayer.ambire.com/velcro-v3'
2930
)
3031

31-
return portfolio.get(address, { baseCurrency: 'usd' })
32+
return portfolio
33+
.get(address, { baseCurrency: 'usd' })
34+
.then((data) => data)
35+
.catch((err) => {
36+
const error = stringifyError(err)
37+
console.error(`Error fetching portfolio for network ${network.name}: ${error}`)
38+
39+
return {
40+
tokens: [],
41+
error
42+
}
43+
})
3244
}
3345

3446
export async function getPortfolioVelcroV3(

0 commit comments

Comments
 (0)