Reformat: common/containers/Tabs/Swap/components/wantToSwapMy.js

This commit is contained in:
Daniel Ternyak 2017-06-19 00:37:17 -05:00
parent f0d00b3815
commit f32a2d6631

View File

@ -1,12 +1,11 @@
import React, {Component} from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import translate from 'translations'; import translate from 'translations';
import {combineAndUpper} from 'api/bity'; import { combineAndUpper } from 'api/bity';
class CoinTypeDropDown extends Component { class CoinTypeDropDown extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context) super(props, context);
} }
static propTypes = { static propTypes = {
@ -18,23 +17,23 @@ class CoinTypeDropDown extends Component {
render() { render() {
return ( return (
<span className="dropdown"> <span className="dropdown">
<select value={this.props.kind} <select
value={this.props.kind}
className="btn btn-default" className="btn btn-default"
onChange={this.props.onChange.bind(this)}> onChange={this.props.onChange.bind(this)}
{ >
this.props.kindOptions.map((obj, i) => { {this.props.kindOptions.map((obj, i) => {
return <option value={obj} key={i}>{obj}</option> return <option value={obj} key={i}>{obj}</option>;
}) })}
}
</select> </select>
</span> </span>
) );
} }
} }
export default class WantToSwapMy extends Component { export default class WantToSwapMy extends Component {
constructor(props, context) { constructor(props, context) {
super(props, context) super(props, context);
} }
static propTypes = { static propTypes = {
@ -50,23 +49,23 @@ export default class WantToSwapMy extends Component {
swapOriginAmountTo: PropTypes.func, swapOriginAmountTo: PropTypes.func,
swapDestinationAmountTo: PropTypes.func, swapDestinationAmountTo: PropTypes.func,
swapOriginKindAndDestinationKindAndDestinationOptionsTo: PropTypes.func swapOriginKindAndDestinationKindAndDestinationOptionsTo: PropTypes.func
}; };
onClickStartSwap() { onClickStartSwap() {}
} onChangeOriginAmount = amount => {
onChangeOriginAmount = (amount) => {
let originAmountAsNumber = parseFloat(amount); let originAmountAsNumber = parseFloat(amount);
if (originAmountAsNumber) { if (originAmountAsNumber) {
let pairName = combineAndUpper(this.props.originKind, this.props.destinationKind); let pairName = combineAndUpper(
this.props.originKind,
this.props.destinationKind
);
let bityRate = this.props.bityRates[pairName]; let bityRate = this.props.bityRates[pairName];
this.props.swapOriginAmountTo(originAmountAsNumber); this.props.swapOriginAmountTo(originAmountAsNumber);
this.props.swapDestinationAmountTo(originAmountAsNumber * bityRate) this.props.swapDestinationAmountTo(originAmountAsNumber * bityRate);
} else { } else {
this.props.swapOriginAmountTo(''); this.props.swapOriginAmountTo('');
this.props.swapDestinationAmountTo('') this.props.swapDestinationAmountTo('');
} }
}; };
@ -74,12 +73,15 @@ export default class WantToSwapMy extends Component {
let destinationAmountAsNumber = parseFloat(amount); let destinationAmountAsNumber = parseFloat(amount);
if (destinationAmountAsNumber) { if (destinationAmountAsNumber) {
this.props.swapDestinationAmountTo(destinationAmountAsNumber); this.props.swapDestinationAmountTo(destinationAmountAsNumber);
let pairName = combineAndUpper(this.props.destinationKind, this.props.originKind); let pairName = combineAndUpper(
this.props.destinationKind,
this.props.originKind
);
let bityRate = this.props.bityRates[pairName]; let bityRate = this.props.bityRates[pairName];
this.props.swapOriginAmountTo(destinationAmountAsNumber * bityRate) this.props.swapOriginAmountTo(destinationAmountAsNumber * bityRate);
} else { } else {
this.props.swapOriginAmountTo(''); this.props.swapOriginAmountTo('');
this.props.swapDestinationAmountTo('') this.props.swapDestinationAmountTo('');
} }
} }
@ -88,7 +90,9 @@ export default class WantToSwapMy extends Component {
this.props.swapDestinationKindTo(newDestinationKind); this.props.swapDestinationKindTo(newDestinationKind);
let pairName = combineAndUpper(this.props.originKind, newDestinationKind); let pairName = combineAndUpper(this.props.originKind, newDestinationKind);
let bityRate = this.props.bityRates[pairName]; let bityRate = this.props.bityRates[pairName];
this.props.swapDestinationAmountTo(parseFloat(this.props.originAmount) * bityRate) this.props.swapDestinationAmountTo(
parseFloat(this.props.originAmount) * bityRate
);
} }
async onChangeOriginKind(event) { async onChangeOriginKind(event) {
@ -98,7 +102,9 @@ export default class WantToSwapMy extends Component {
let destinationKind = store.getState().swap.destinationKind; let destinationKind = store.getState().swap.destinationKind;
let pairName = combineAndUpper(newOriginKind, destinationKind); let pairName = combineAndUpper(newOriginKind, destinationKind);
let bityRate = this.props.bityRates[pairName]; let bityRate = this.props.bityRates[pairName];
this.props.swapDestinationAmountTo(parseFloat(this.props.originAmount) * bityRate) this.props.swapDestinationAmountTo(
parseFloat(this.props.originAmount) * bityRate
);
} }
render() { render() {
@ -115,28 +121,39 @@ export default class WantToSwapMy extends Component {
<article className="swap-panel"> <article className="swap-panel">
<h1>{translate('SWAP_init_1')}</h1> <h1>{translate('SWAP_init_1')}</h1>
<input <input
className={`form-control ${(this.props.originAmount !== '' && this.props.originAmount > 0) ? 'is-valid' : 'is-invalid'}`} className={`form-control ${this.props.originAmount !== '' &&
this.props.originAmount > 0
? 'is-valid'
: 'is-invalid'}`}
type="number" type="number"
placeholder="Amount" placeholder="Amount"
onChange={(e) => this.onChangeOriginAmount(e.target.value)} onChange={e => this.onChangeOriginAmount(e.target.value)}
value={originAmount}/> value={originAmount}
/>
<CoinTypeDropDown kind={originKind} <CoinTypeDropDown
kind={originKind}
onChange={this.onChangeOriginKind.bind(this)} onChange={this.onChangeOriginKind.bind(this)}
kindOptions={originKindOptions}/> kindOptions={originKindOptions}
/>
<h1>{translate('SWAP_init_2')}</h1> <h1>{translate('SWAP_init_2')}</h1>
<input <input
className={`form-control ${(this.props.destinationAmount !== '' && this.props.destinationAmount > 0) ? 'is-valid' : 'is-invalid'}`} className={`form-control ${this.props.destinationAmount !== '' &&
this.props.destinationAmount > 0
? 'is-valid'
: 'is-invalid'}`}
type="number" type="number"
placeholder="Amount" placeholder="Amount"
value={destinationAmount} value={destinationAmount}
onChange={(e) => this.onChangeDestinationAmount(e.target.value)}/> onChange={e => this.onChangeDestinationAmount(e.target.value)}
/>
<CoinTypeDropDown kind={destinationKind} <CoinTypeDropDown
kind={destinationKind}
onChange={this.onChangeDestinationKind.bind(this)} onChange={this.onChangeDestinationKind.bind(this)}
kindOptions={destinationKindOptions}/> kindOptions={destinationKindOptions}
/>
<div className="col-xs-12 clearfix text-center"> <div className="col-xs-12 clearfix text-center">
<a onClick={this.onClickStartSwap} className="btn btn-info btn-lg"> <a onClick={this.onClickStartSwap} className="btn btn-info btn-lg">
@ -144,7 +161,6 @@ export default class WantToSwapMy extends Component {
</a> </a>
</div> </div>
</article> </article>
);
)
} }
} }