Skip to content

Commit

Permalink
normalize
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-aitlahcen committed Jun 4, 2024
1 parent d2a1c9e commit b1b8286
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions app/src/lib/queries/balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,26 @@ export function cosmosBalancesQuery({
`${restUrl}/cosmos/bank/v1beta1/balances/${address}`,
)
if (!response.ok) return []
const result = await response.json()
return result.balances
return (await response.json()).balances.map((x) => {
const decimals = (() => {
switch(x.denom[0]) {
case 'u': return 9
case 'm': return 6
default:
throw new Error("unknown unit prefix ${x}")
}
})()
const normalizedDenom = x.denom.slice(1)
return {
address: x.denom,
symbol: normalizedDenom.toUpperCase(),
balance: formatUnits(
BigInt(x.amount),
decimals
),
decimals
}
})
}
})
}

0 comments on commit b1b8286

Please sign in to comment.