aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
diff options
context:
space:
mode:
authorDan <danjm.com@gmail.com>2018-04-11 22:21:54 +0800
committerDan <danjm.com@gmail.com>2018-04-11 22:21:54 +0800
commit59c887301aba5d746d669441ec78ef7ec5de3146 (patch)
tree3236b2e9acbcf45358ecaaf0e291a1a9505729b1 /ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
parentf4d8da927734b2dcd597d1cc833f9fe6ac59cc77 (diff)
downloadtangerine-wallet-browser-59c887301aba5d746d669441ec78ef7ec5de3146.tar.gz
tangerine-wallet-browser-59c887301aba5d746d669441ec78ef7ec5de3146.tar.zst
tangerine-wallet-browser-59c887301aba5d746d669441ec78ef7ec5de3146.zip
second commit
Diffstat (limited to 'ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js')
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
index e69de29bb..54aacc8d7 100644
--- a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
+++ b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js
@@ -0,0 +1,22 @@
+const {
+ multiplyCurrencies,
+ subtractCurrencies,
+} = require('../../../../conversion-util')
+const ethUtil = require('ethereumjs-util')
+
+function calcMaxAmount ({ balance, gasTotal, selectedToken, tokenBalance }) {
+ const { decimals } = selectedToken || {}
+ const multiplier = Math.pow(10, Number(decimals || 0))
+
+ return selectedToken
+ ? multiplyCurrencies(tokenBalance, multiplier, {toNumericBase: 'hex'})
+ : subtractCurrencies(
+ ethUtil.addHexPrefix(balance),
+ ethUtil.addHexPrefix(gasTotal),
+ { toNumericBase: 'hex' }
+ )
+}
+
+module.exports = {
+ calcMaxAmount
+}