aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/send_/send-content/send-amount-row/amount-max-button
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
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')
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.component.js54
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.container.js36
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.selectors.js0
-rw-r--r--ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.utils.js22
4 files changed, 112 insertions, 0 deletions
diff --git a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.component.js b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
index e69de29bb..59a1fd6db 100644
--- a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
+++ b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.component.js
@@ -0,0 +1,54 @@
+import React, { Component } from 'react'
+import PropTypes from 'prop-types'
+
+export default class AmountMaxButton extends Component {
+
+ static propTypes = {
+ tokenBalance: PropTypes.string,
+ gasTotal: PropTypes.string,
+ balance: PropTypes.string,
+ selectedToken: PropTypes.object,
+ setAmountToMax: PropTypes.func,
+ setMaxModeTo: PropTypes.func,
+ maxModeOn: PropTypes.bool,
+ };
+
+ setAmountToMax = function () {
+ const {
+ balance,
+ tokenBalance,
+ selectedToken,
+ gasTotal,
+ setAmountToMax,
+ } = this.props
+
+ setAmountToMax({
+ tokenBalance,
+ selectedToken,
+ gasTotal,
+ setAmountToMax,
+ })
+ }
+
+ render () {
+ const { setMaxModeTo } = this.props
+
+ return (
+ <div
+ className='send-v2__amount-max'
+ onClick={(event) => {
+ event.preventDefault()
+ setMaxModeTo(true)
+ this.setAmountToMax()
+ }}
+ >
+ {!maxModeOn ? this.context.t('max') : '' ])}
+ </div>
+ );
+ }
+
+}
+
+AmountMaxButton.contextTypes = {
+ t: PropTypes.func,
+}
diff --git a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.container.js b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.container.js
index e69de29bb..572e1fc46 100644
--- a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.container.js
+++ b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.container.js
@@ -0,0 +1,36 @@
+import {
+ getSelectedToken,
+ getGasTotal,
+ getTokenBalance,
+ getSendFromBalance,
+} from '../../../send.selectors.js'
+import { getMaxModeOn } from '../send-amount-row.selectors.js'
+import { calcMaxAmount } from './amount-max-button.utils.js'
+import {
+ updateSendAmount,
+ setMaxModeTo,
+} from '../../../actions'
+import AmountMaxButton from './amount-max-button.component'
+
+export default connect(mapStateToProps, mapDispatchToProps)(SendToRow)
+
+function mapStateToProps (state) {
+
+ return {
+ selectedToken: getSelectedToken(state),
+ maxModeOn: getMaxModeOn(state),
+ gasTotal: getGasTotal(state),
+ tokenBalance: getTokenBalance(state),
+ balance: getSendFromBalance(state),
+ }
+}
+
+function mapDispatchToProps (dispatch) {
+ return {
+ setAmountToMax: maxAmountDataObject => {
+ updateSendErrors({ amount: null })
+ updateSendAmount(calcMaxAmount(maxAmountDataObject))
+ }
+ setMaxModeTo: bool => dispatch(setMaxModeTo(bool)),
+ }
+} \ No newline at end of file
diff --git a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.selectors.js b/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.selectors.js
deleted file mode 100644
index e69de29bb..000000000
--- a/ui/app/components/send_/send-content/send-amount-row/amount-max-button/amount-max-button.selectors.js
+++ /dev/null
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
+}