diff options
author | Dan <danjm.com@gmail.com> | 2017-10-23 04:14:03 +0800 |
---|---|---|
committer | Chi Kei Chan <chikeichan@gmail.com> | 2017-10-24 13:41:30 +0800 |
commit | e737a9565a6b78639b74511d026339c1b54bca1a (patch) | |
tree | 62ed4e91a0ea5835d90e4015f1c094f4ea27e7ca /ui/app/components/send/send-utils.js | |
parent | a7069acf2e93e9eae543bb84dfdda1f5e10b3e19 (diff) | |
download | tangerine-wallet-browser-e737a9565a6b78639b74511d026339c1b54bca1a.tar.gz tangerine-wallet-browser-e737a9565a6b78639b74511d026339c1b54bca1a.tar.zst tangerine-wallet-browser-e737a9565a6b78639b74511d026339c1b54bca1a.zip |
Improve customize gas modal error handling
Diffstat (limited to 'ui/app/components/send/send-utils.js')
-rw-r--r-- | ui/app/components/send/send-utils.js | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/ui/app/components/send/send-utils.js b/ui/app/components/send/send-utils.js new file mode 100644 index 000000000..bf096d610 --- /dev/null +++ b/ui/app/components/send/send-utils.js @@ -0,0 +1,39 @@ +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, +}
\ No newline at end of file |