1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-19 16:03:21 +01:00
metamask-extension/ui/app/pages/send/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js

23 lines
680 B
JavaScript
Raw Normal View History

2020-11-03 00:41:28 +01:00
import {
multiplyCurrencies,
subtractCurrencies,
} from '../../../../../helpers/utils/conversion-util'
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 }) {
const { decimals } = sendToken || {}
const multiplier = Math.pow(10, Number(decimals || 0))
2018-04-11 16:21:54 +02:00
return sendToken
2020-11-03 00:41:28 +01:00
? multiplyCurrencies(tokenBalance, multiplier, {
toNumericBase: 'hex',
multiplicandBase: 16,
multiplierBase: 10,
2020-11-03 00:41:28 +01:00
})
: subtractCurrencies(addHexPrefix(balance), addHexPrefix(gasTotal), {
toNumericBase: 'hex',
aBase: 16,
bBase: 16,
})
2018-04-11 16:21:54 +02:00
}