From f32a2d663160776c76dbde6f7c7ca30f7cf05088 Mon Sep 17 00:00:00 2001 From: Daniel Ternyak Date: Mon, 19 Jun 2017 00:37:17 -0500 Subject: [PATCH] Reformat: common/containers/Tabs/Swap/components/wantToSwapMy.js --- .../Tabs/Swap/components/wantToSwapMy.js | 274 +++++++++--------- 1 file changed, 145 insertions(+), 129 deletions(-) diff --git a/common/containers/Tabs/Swap/components/wantToSwapMy.js b/common/containers/Tabs/Swap/components/wantToSwapMy.js index fa9c1b24..5498e7aa 100644 --- a/common/containers/Tabs/Swap/components/wantToSwapMy.js +++ b/common/containers/Tabs/Swap/components/wantToSwapMy.js @@ -1,150 +1,166 @@ -import React, {Component} from 'react'; +import React, { Component } from 'react'; import PropTypes from 'prop-types'; import translate from 'translations'; -import {combineAndUpper} from 'api/bity'; - +import { combineAndUpper } from 'api/bity'; class CoinTypeDropDown extends Component { - constructor(props, context) { - super(props, context) - } + constructor(props, context) { + super(props, context); + } - static propTypes = { - kind: PropTypes.any, - onChange: PropTypes.any, - kindOptions: PropTypes.any - }; + static propTypes = { + kind: PropTypes.any, + onChange: PropTypes.any, + kindOptions: PropTypes.any + }; - render() { - return ( - - - - ) - } + render() { + return ( + + + + ); + } } export default class WantToSwapMy extends Component { - constructor(props, context) { - super(props, context) + constructor(props, context) { + super(props, context); + } + + static propTypes = { + bityRates: PropTypes.any, + originAmount: PropTypes.any, + destinationAmount: PropTypes.any, + originKind: PropTypes.string, + destinationKind: PropTypes.string, + destinationKindOptions: PropTypes.array, + originKindOptions: PropTypes.array, + swapOriginKindTo: PropTypes.func, + swapDestinationKindTo: PropTypes.func, + swapOriginAmountTo: PropTypes.func, + swapDestinationAmountTo: PropTypes.func, + swapOriginKindAndDestinationKindAndDestinationOptionsTo: PropTypes.func + }; + + onClickStartSwap() {} + + onChangeOriginAmount = amount => { + let originAmountAsNumber = parseFloat(amount); + if (originAmountAsNumber) { + let pairName = combineAndUpper( + this.props.originKind, + this.props.destinationKind + ); + let bityRate = this.props.bityRates[pairName]; + this.props.swapOriginAmountTo(originAmountAsNumber); + this.props.swapDestinationAmountTo(originAmountAsNumber * bityRate); + } else { + this.props.swapOriginAmountTo(''); + this.props.swapDestinationAmountTo(''); } + }; - static propTypes = { - bityRates: PropTypes.any, - originAmount: PropTypes.any, - destinationAmount: PropTypes.any, - originKind: PropTypes.string, - destinationKind: PropTypes.string, - destinationKindOptions: PropTypes.array, - originKindOptions: PropTypes.array, - swapOriginKindTo: PropTypes.func, - swapDestinationKindTo: PropTypes.func, - swapOriginAmountTo: PropTypes.func, - swapDestinationAmountTo: PropTypes.func, - swapOriginKindAndDestinationKindAndDestinationOptionsTo: PropTypes.func - - }; - - onClickStartSwap() { - + onChangeDestinationAmount(amount) { + let destinationAmountAsNumber = parseFloat(amount); + if (destinationAmountAsNumber) { + this.props.swapDestinationAmountTo(destinationAmountAsNumber); + let pairName = combineAndUpper( + this.props.destinationKind, + this.props.originKind + ); + let bityRate = this.props.bityRates[pairName]; + this.props.swapOriginAmountTo(destinationAmountAsNumber * bityRate); + } else { + this.props.swapOriginAmountTo(''); + this.props.swapDestinationAmountTo(''); } + } - onChangeOriginAmount = (amount) => { - let originAmountAsNumber = parseFloat(amount); - if (originAmountAsNumber) { - let pairName = combineAndUpper(this.props.originKind, this.props.destinationKind); - let bityRate = this.props.bityRates[pairName]; - this.props.swapOriginAmountTo(originAmountAsNumber); - this.props.swapDestinationAmountTo(originAmountAsNumber * bityRate) - } else { - this.props.swapOriginAmountTo(''); - this.props.swapDestinationAmountTo('') - } - }; + async onChangeDestinationKind(event) { + let newDestinationKind = event.target.value; + this.props.swapDestinationKindTo(newDestinationKind); + let pairName = combineAndUpper(this.props.originKind, newDestinationKind); + let bityRate = this.props.bityRates[pairName]; + this.props.swapDestinationAmountTo( + parseFloat(this.props.originAmount) * bityRate + ); + } - onChangeDestinationAmount(amount) { - let destinationAmountAsNumber = parseFloat(amount); - if (destinationAmountAsNumber) { - this.props.swapDestinationAmountTo(destinationAmountAsNumber); - let pairName = combineAndUpper(this.props.destinationKind, this.props.originKind); - let bityRate = this.props.bityRates[pairName]; - this.props.swapOriginAmountTo(destinationAmountAsNumber * bityRate) - } else { - this.props.swapOriginAmountTo(''); - this.props.swapDestinationAmountTo('') - } - } + async onChangeOriginKind(event) { + let newOriginKind = event.target.value; + this.props.swapOriginKindTo(newOriginKind); + // https://github.com/reactjs/redux/issues/1543#issuecomment-201399259 + let destinationKind = store.getState().swap.destinationKind; + let pairName = combineAndUpper(newOriginKind, destinationKind); + let bityRate = this.props.bityRates[pairName]; + this.props.swapDestinationAmountTo( + parseFloat(this.props.originAmount) * bityRate + ); + } - async onChangeDestinationKind(event) { - let newDestinationKind = event.target.value; - this.props.swapDestinationKindTo(newDestinationKind); - let pairName = combineAndUpper(this.props.originKind, newDestinationKind); - let bityRate = this.props.bityRates[pairName]; - this.props.swapDestinationAmountTo(parseFloat(this.props.originAmount) * bityRate) - } + render() { + const { + originAmount, + destinationAmount, + originKind, + destinationKind, + destinationKindOptions, + originKindOptions + } = this.props; - async onChangeOriginKind(event) { - let newOriginKind = event.target.value; - this.props.swapOriginKindTo(newOriginKind); - // https://github.com/reactjs/redux/issues/1543#issuecomment-201399259 - let destinationKind = store.getState().swap.destinationKind; - let pairName = combineAndUpper(newOriginKind, destinationKind); - let bityRate = this.props.bityRates[pairName]; - this.props.swapDestinationAmountTo(parseFloat(this.props.originAmount) * bityRate) - } + return ( +
+

{translate('SWAP_init_1')}

+ 0 + ? 'is-valid' + : 'is-invalid'}`} + type="number" + placeholder="Amount" + onChange={e => this.onChangeOriginAmount(e.target.value)} + value={originAmount} + /> - render() { - const { - originAmount, - destinationAmount, - originKind, - destinationKind, - destinationKindOptions, - originKindOptions - } = this.props; + - return ( -
-

{translate('SWAP_init_1')}

- 0) ? 'is-valid' : 'is-invalid'}`} - type="number" - placeholder="Amount" - onChange={(e) => this.onChangeOriginAmount(e.target.value)} - value={originAmount}/> +

{translate('SWAP_init_2')}

- + 0 + ? 'is-valid' + : 'is-invalid'}`} + type="number" + placeholder="Amount" + value={destinationAmount} + onChange={e => this.onChangeDestinationAmount(e.target.value)} + /> + -

{translate('SWAP_init_2')}

- - 0) ? 'is-valid' : 'is-invalid'}`} - type="number" - placeholder="Amount" - value={destinationAmount} - onChange={(e) => this.onChangeDestinationAmount(e.target.value)}/> - - - - -
- - ) - } +
+ + {translate('SWAP_init_CTA')} + +
+
+ ); + } }