1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 00:28:06 +01:00
metamask-extension/ui/app/components/send/send-utils.js

69 lines
1.2 KiB
JavaScript
Raw Normal View History

const {
addCurrencies,
conversionUtil,
conversionGTE,
} = require('../../conversion-util')
const {
calcTokenAmount,
} = require('../../token-util')
2017-11-09 23:23:10 +01:00
function isBalanceSufficient ({
amount = '0x0',
gasTotal = '0x0',
balance,
primaryCurrency,
amountConversionRate,
conversionRate,
}) {
const totalAmount = addCurrencies(amount, gasTotal, {
aBase: 16,
bBase: 16,
toNumericBase: 'hex',
})
2017-10-26 18:43:12 +02:00
const balanceIsSufficient = conversionGTE(
{
value: balance,
fromNumericBase: 'hex',
fromCurrency: primaryCurrency,
conversionRate,
},
{
value: totalAmount,
fromNumericBase: 'hex',
conversionRate: amountConversionRate,
fromCurrency: primaryCurrency,
},
)
return balanceIsSufficient
}
2017-11-09 23:23:10 +01:00
function isTokenBalanceSufficient ({
amount = '0x0',
tokenBalance,
decimals,
}) {
const amountInDec = conversionUtil(amount, {
fromNumericBase: 'hex',
})
const tokenBalanceIsSufficient = conversionGTE(
{
value: tokenBalance,
fromNumericBase: 'dec',
},
{
value: calcTokenAmount(amountInDec, decimals),
fromNumericBase: 'dec',
},
)
return tokenBalanceIsSufficient
}
module.exports = {
isBalanceSufficient,
isTokenBalanceSufficient,
2017-11-02 13:15:59 +01:00
}