aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send/send-utils.js
diff options
context:
space:
mode:
authorDaniel Tsui <szehungdanieltsui@gmail.com>2017-11-08 08:35:18 +0800
committerGitHub <noreply@github.com>2017-11-08 08:35:18 +0800
commitda2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c (patch)
tree99151d2b40844d5e90a4175550a4b37950d6c744 /ui/app/components/send/send-utils.js
parent9f70762434deb1c973665a76623838289e655f22 (diff)
parentc57d504794b6020d42dcdabe08a13ed412450fc1 (diff)
downloadtangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar.gz
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar.bz2
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar.lz
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar.xz
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.tar.zst
tangerine-wallet-browser-da2e9b9765ca32e7439a2a5687e6c3d8ca8bb63c.zip
Merge pull request #2510 from danjm/NewUI-flat-token-balance
[NewUI] Improving gas precision and send (token) balance validation; max amount feature
Diffstat (limited to 'ui/app/components/send/send-utils.js')
-rw-r--r--ui/app/components/send/send-utils.js44
1 files changed, 37 insertions, 7 deletions
diff --git a/ui/app/components/send/send-utils.js b/ui/app/components/send/send-utils.js
index 6ec04a223..bd1197950 100644
--- a/ui/app/components/send/send-utils.js
+++ b/ui/app/components/send/send-utils.js
@@ -1,11 +1,17 @@
-const { addCurrencies, conversionGreaterThan } = require('../../conversion-util')
+const {
+ addCurrencies,
+ conversionUtil,
+ conversionGTE,
+} = require('../../conversion-util')
+const {
+ calcTokenAmount,
+} = require('../../token-util')
-function isBalanceSufficient ({
- amount,
- gasTotal,
+function isBalanceSufficient({
+ amount = '0x0',
+ gasTotal = '0x0',
balance,
primaryCurrency,
- selectedToken,
amountConversionRate,
conversionRate,
}) {
@@ -15,7 +21,7 @@ function isBalanceSufficient ({
toNumericBase: 'hex',
})
- const balanceIsSufficient = conversionGreaterThan(
+ const balanceIsSufficient = conversionGTE(
{
value: balance,
fromNumericBase: 'hex',
@@ -26,13 +32,37 @@ function isBalanceSufficient ({
value: totalAmount,
fromNumericBase: 'hex',
conversionRate: amountConversionRate,
- fromCurrency: selectedToken || primaryCurrency,
+ fromCurrency: primaryCurrency,
},
)
return balanceIsSufficient
}
+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,
}