Skip to content

Commit

Permalink
fix: correctly parse and format big values
Browse files Browse the repository at this point in the history
  • Loading branch information
nicosantangelo committed Jul 20, 2021
1 parent 13ce757 commit a4c880a
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions webapp/src/lib/mana.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import BN from 'bn.js'

let oneEthInMANA: BN | undefined
import { fromWei } from 'web3x-es/utils'

export function formatMANA(value: string) {
if (!oneEthInMANA) {
oneEthInMANA = new BN('1000000000000000000') // 10 ** 18
}
const mana = new BN(value).divRound(oneEthInMANA)
return mana.toNumber().toLocaleString()
return Number(fromWei(value, 'ether')).toLocaleString()
}

export function toMANA(num: number) {
Expand Down

0 comments on commit a4c880a

Please sign in to comment.