Skip to content

Commit

Permalink
Make address:balance return balance in eth
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Oct 10, 2019
1 parent 801944d commit d461c12
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/commands/address/balance.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { NetworkCommand } from '../../base/network'
import { convert } from '../../helpers/convert'
import { Unit } from '../../types'

export default class BalanceCommand extends NetworkCommand {
static description = `Get the balance for the given address`
Expand Down Expand Up @@ -28,8 +30,9 @@ export default class BalanceCommand extends NetworkCommand {

const { getBalance } = await import('../../helpers/getBalance')
const balance = await getBalance(address, networkUrl)
const balanceInEth = convert(balance, Unit.Wei, Unit.Eth)

this.log(balance)
this.log(balanceInEth)
} catch (e) {
this.error(e.message, { exit: 1 })
}
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const convert = (amount: string, from: Unit, to: Unit): string => {
const scale = new Big(10).pow(exp)

if (to === Unit.Eth) {
return amountBN.mul(scale).toFixed(2)
return amountBN.mul(scale).toFixed(4)
}
return amountBN.mul(scale).toFixed(0)
}

0 comments on commit d461c12

Please sign in to comment.