Skip to content

Commit

Permalink
Merge pull request #168 from AstraProtocol/fix/nan-value-internal-tx
Browse files Browse the repository at this point in the history
fix: format number from wei
  • Loading branch information
Tien Dao authored Jul 26, 2023
2 parents 2ca3ade + b916674 commit 2e8b514
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion utils/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const ellipseLeftText = (address: string, to: number) => {
export const formatValueFromWei = (wei: string): string => {
if (parseFloat(wei) == 0) return '0'
if (parseFloat(wei) < CONFIG.APPROXIMATE_ZERO) return parseFloat(wei).toExponential()
if (parseFloat(wei) > 0) {
if (isInt(wei)) return numeral(wei).format('0,0')
return numeral(wei).format('0,0.00000')
}
return wei
}

Expand All @@ -56,7 +60,7 @@ export const getAmountFromBignumber = (value: number | string, decimals: string

export const convertBalanceToView = (value: number | string, decimals = '18'): string => {
const amount = formatValueFromWei(getAmountFromBignumber(value, decimals))
return isInt(amount) ? numeral(amount).format('0,0') : numeral(amount).format('0,0.00000')
return amount
}

export const calculateGasFee = (gasUsed: string, gasPrice: string): number => parseFloat(gasUsed) * parseFloat(gasPrice)
Expand Down

0 comments on commit 2e8b514

Please sign in to comment.