aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/send-utils.js
blob: 6ec04a223b5581dab43f2f3c8120bce6d8c545c0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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,
    },
  )

  return balanceIsSufficient
}

module.exports = {
  isBalanceSufficient,
}