aboutsummaryrefslogblamecommitdiffstats
path: root/ui/app/components/send/send-utils.js
blob: bf096d610491a38dccb25a1f3470fb126d1e09a7 (plain) (tree)






































                                                                                 
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,
}