mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-24 11:01:41 +01:00
39 lines
816 B
JavaScript
39 lines
816 B
JavaScript
|
const { addCurrencies, conversionGreaterThan } = require('../../conversion-util')
|
||
|
|
||
|
function isBalanceSufficient({
|
||
|
amount,
|
||
|
gasTotal,
|
||
|
balance,
|
||
|
primaryCurrency,
|
||
|
selectedToken,
|
||
|
amountConversionRate,
|
||
|
conversionRate,
|
||
|
}) {
|
||
|
const totalAmount = addCurrencies(amount, gasTotal, {
|
||
|
aBase: 16,
|
||
|
bBase: 16,
|
||
|
toNumericBase: 'hex',
|
||
|
})
|
||
|
|
||
|
const balanceIsSufficient = conversionGreaterThan(
|
||
|
{
|
||
|
value: balance,
|
||
|
fromNumericBase: 'hex',
|
||
|
fromCurrency: primaryCurrency,
|
||
|
conversionRate,
|
||
|
},
|
||
|
{
|
||
|
value: totalAmount,
|
||
|
fromNumericBase: 'hex',
|
||
|
conversionRate: amountConversionRate,
|
||
|
fromCurrency: selectedToken || primaryCurrency,
|
||
|
conversionRate: amountConversionRate,
|
||
|
},
|
||
|
)
|
||
|
|
||
|
return balanceIsSufficient
|
||
|
}
|
||
|
|
||
|
module.exports = {
|
||
|
isBalanceSufficient,
|
||
|
}
|