2020-01-09 04:34:58 +01:00
|
|
|
import { multiplyCurrencies, subtractCurrencies } from '../../../../../helpers/utils/conversion-util'
|
|
|
|
import ethUtil from 'ethereumjs-util'
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2020-01-09 04:34:58 +01:00
|
|
|
export 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
|
|
|
}
|