aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
blob: b490a7fd7ce7bef84bf9562da075b3f6c2a8883c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const {
  multiplyCurrencies,
  subtractCurrencies,
} = require('../../../../../conversion-util')
const ethUtil = require('ethereumjs-util')

function calcMaxAmount ({ balance, gasTotal, selectedToken, tokenBalance }) {
    const { decimals } = selectedToken || {}
    const multiplier = Math.pow(10, Number(decimals || 0))

    return selectedToken
      ? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
      : subtractCurrencies(
        ethUtil.addHexPrefix(balance),
        ethUtil.addHexPrefix(gasTotal),
        { toNumericBase: 'hex' }
      )
}

module.exports = {
  calcMaxAmount,
}