Skip to content

Commit 140bc3f

Browse files
author
Nikolay Manchev
committed
feat: better way of pulling tokens per account
Using /tokens which is route dedicated to fetching tokens per account and has working pagination
1 parent fc26a37 commit 140bc3f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

projects/hashport/index.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,25 @@ const CONFIG = {
1919
hedera: '0.0.540219',
2020
}
2121

22-
const hederaTVL = async (address) => {
23-
const totalBalances = {}
22+
const hederaTokens = {}
23+
24+
const hederaTVL = async (address, paginationPath = '') => {
2425
try {
25-
const { balance } = await get(`${HEDERA_MIRROR_NODE_URL}/api/v1/accounts/${address}?limit=100&order=asc&transactiontype=cryptotransfer&transactions=true`)
26-
balance?.tokens.forEach(token => {
27-
// Note: We are filtering this token because its an old version of DOVE
28-
if(token.token_id === '0.0.624505') return
29-
totalBalances[`hedera:${token.token_id}`] = String(token.balance)
26+
let path = `/api/v1/accounts/${address}/tokens?limit=100&order=desc`
27+
if (paginationPath) {
28+
path = paginationPath
29+
}
30+
const { tokens, links } = await get(`${HEDERA_MIRROR_NODE_URL}${path}`)
31+
tokens.forEach(token => {
32+
hederaTokens[`hedera:${token.token_id}`] = String(token.balance)
3033
})
34+
if (links?.next) {
35+
return hederaTVL(address, links.next)
36+
}
3137
} catch (error) {
3238
log(error)
3339
}
34-
return totalBalances
40+
return hederaTokens
3541
}
3642

3743
const evmTVL = async (api, token, useCoValent = true) => {

0 commit comments

Comments
 (0)