2018-04-11 16:21:54 +02:00
|
|
|
const {
|
|
|
|
multiplyCurrencies,
|
|
|
|
subtractCurrencies,
|
2019-04-17 21:15:13 +02:00
|
|
|
} = require('../../../../../helpers/utils/conversion-util')
|
2018-04-11 16:21:54 +02:00
|
|
|
const ethUtil = require('ethereumjs-util')
|
|
|
|
|
|
|
|
function calcMaxAmount ({ balance, gasTotal, selectedToken, tokenBalance }) {
|
2018-11-20 01:06:34 +01:00
|
|
|
const { decimals } = selectedToken || {}
|
|
|
|
const multiplier = Math.pow(10, Number(decimals || 0))
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2018-11-20 01:06:34 +01:00
|
|
|
return selectedToken
|
|
|
|
? multiplyCurrencies(
|
|
|
|
tokenBalance,
|
|
|
|
multiplier,
|
|
|
|
{
|
|
|
|
toNumericBase: 'hex',
|
|
|
|
multiplicandBase: 16,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
: subtractCurrencies(
|
|
|
|
ethUtil.addHexPrefix(balance),
|
|
|
|
ethUtil.addHexPrefix(gasTotal),
|
|
|
|
{ toNumericBase: 'hex' }
|
|
|
|
)
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2018-04-27 02:38:14 +02:00
|
|
|
calcMaxAmount,
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|