Skip to content

Commit

Permalink
Format numbers in overview chart
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed Jul 7, 2023
1 parent ed1a8fc commit 9c2954c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/web/src/composables/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,11 @@ export default function useContracts() {
const totalStaked = currentStaked.reduce((accumulator, currentValue) => accumulator.add(currentValue), ethers.BigNumber.from(0))
const totalStakedUSD = parseFloat(ethers.utils.formatEther(totalStaked)) * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))
const totalStakedETH = parseFloat(ethers.utils.formatEther(totalStaked))
const formattedTotalStakedUSD = formatNumber(totalStakedUSD)
const formattedTotalStakedETH = formatNumber(totalStakedETH)
return {
exchange: totalStakedETH.toFixed(2) + ' ETH',
usd: '$ ' + totalStakedUSD.toFixed(2)
exchange: formattedTotalStakedUSD + ' ETH',
usd: '$ ' + formattedTotalStakedETH
}
} catch (error) {
console.log('Error occurred while fetching stake:', error)
Expand Down Expand Up @@ -193,9 +195,11 @@ export default function useContracts() {
addresses.forEach((address) => { promises.push(getEthersBalance(address)) })
const totalWalletBalance = (await Promise.all(promises)).reduce((acc, curr) => acc + curr, 0)
const totalWalletBalanceUSD = totalWalletBalance * (await getCurrentPrice({ coin: 'ETH', currency: 'USD' }))
const formattedTotalWalletBalance = formatNumber(totalWalletBalance)
const formattedTotalWalletBalanceUSD = formatNumber(totalWalletBalanceUSD)
return {
exchange: totalWalletBalance.toFixed(2) + ' ETH',
usd: '$ ' + totalWalletBalanceUSD.toFixed(2)
exchange: formattedTotalWalletBalance + ' ETH',
usd: '$ ' + formattedTotalWalletBalanceUSD
}
}

Expand Down Expand Up @@ -296,4 +300,8 @@ export default function useContracts() {
refreshBreakdown,
withdraw
}
}

function formatNumber(number: number) {
return number.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,')
}

0 comments on commit 9c2954c

Please sign in to comment.