2020-11-03 00:41:28 +01:00
|
|
|
import {
|
|
|
|
multiplyCurrencies,
|
|
|
|
subtractCurrencies,
|
|
|
|
} from '../../../../../helpers/utils/conversion-util'
|
2020-11-06 22:18:00 +01:00
|
|
|
import { addHexPrefix } from '../../../../../../../app/scripts/lib/util'
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
export function calcMaxAmount({ balance, gasTotal, sendToken, tokenBalance }) {
|
2020-05-29 19:46:10 +02:00
|
|
|
const { decimals } = sendToken || {}
|
2018-11-20 01:06:34 +01:00
|
|
|
const multiplier = Math.pow(10, Number(decimals || 0))
|
2018-04-11 16:21:54 +02:00
|
|
|
|
2020-05-29 19:46:10 +02:00
|
|
|
return sendToken
|
2020-11-03 00:41:28 +01:00
|
|
|
? multiplyCurrencies(tokenBalance, multiplier, {
|
2018-11-20 01:06:34 +01:00
|
|
|
toNumericBase: 'hex',
|
|
|
|
multiplicandBase: 16,
|
2020-11-13 07:08:18 +01:00
|
|
|
multiplierBase: 10,
|
2020-11-03 00:41:28 +01:00
|
|
|
})
|
2020-11-06 22:18:00 +01:00
|
|
|
: subtractCurrencies(addHexPrefix(balance), addHexPrefix(gasTotal), {
|
|
|
|
toNumericBase: 'hex',
|
2020-11-13 07:08:18 +01:00
|
|
|
aBase: 16,
|
|
|
|
bBase: 16,
|
2020-11-06 22:18:00 +01:00
|
|
|
})
|
2018-04-11 16:21:54 +02:00
|
|
|
}
|