Consume new receivingAddressSwap action creator and receivingAddress state, validate receiving address input using Validator class.

This commit is contained in:
Daniel Ternyak 2017-06-24 01:09:44 -05:00
parent c77f8430c5
commit 28415cd0e8
2 changed files with 44 additions and 8 deletions

View File

@ -1,18 +1,39 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import { DONATION_ADDRESSES_MAP } from 'config/data'; import { DONATION_ADDRESSES_MAP } from 'config/data';
import Validator from 'libs/validator';
export default class YourReceiving extends Component { export default class YourReceiving extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.validator = new Validator();
this.state = {
validAddress: false
};
} }
static propTypes = { static propTypes = {
destinationKind: PropTypes.string.isRequired destinationKind: PropTypes.string.isRequired,
receivingAddressSwap: PropTypes.func.isRequired,
receivingAddress: PropTypes.string
};
onChangeReceivingAddress = event => {
const value = event.target.value;
this.props.receivingAddressSwap(value);
let validAddress;
// TODO - find better pattern here once currencies move beyond BTC, ETH, REP
if (this.props.destinationKind === 'BTC') {
validAddress = this.validator.isValidBTCAddress(value);
} else {
validAddress = this.validator.isValidETHAddress(value);
}
this.setState({ validAddress });
}; };
render() { render() {
const { destinationKind } = this.props; const { destinationKind, receivingAddress } = this.props;
const { validAddress } = this.state;
return ( return (
<article className="swap-start"> <article className="swap-start">
<section className="swap-address block"> <section className="swap-address block">
@ -23,16 +44,20 @@ export default class YourReceiving extends Component {
<strong> ({destinationKind})</strong> <strong> ({destinationKind})</strong>
</label> </label>
<input <input
className="form-control" className={`form-control ${validAddress
? 'is-valid'
: 'is-invalid'}`}
type="text" type="text"
value={receivingAddress}
onChange={this.onChangeReceivingAddress}
placeholder={DONATION_ADDRESSES_MAP[destinationKind]} placeholder={DONATION_ADDRESSES_MAP[destinationKind]}
/> />
</div> </div>
</section> </section>
<section className="row text-center"> <section className="row text-center">
<a className="btn btn-primary btn-lg"> <button disabled={!validAddress} className="btn btn-primary btn-lg">
<span>Start Swap</span> <span>Start Swap</span>
</a> </button>
</section> </section>
</section> </section>
</article> </article>

View File

@ -25,12 +25,14 @@ class Swap extends Component {
destinationKind: PropTypes.string, destinationKind: PropTypes.string,
destinationKindOptions: PropTypes.array, destinationKindOptions: PropTypes.array,
originKindOptions: PropTypes.array, originKindOptions: PropTypes.array,
receivingAddress: PropTypes.string,
originKindSwap: PropTypes.func, originKindSwap: PropTypes.func,
destinationKindSwap: PropTypes.func, destinationKindSwap: PropTypes.func,
originAmountSwap: PropTypes.func, originAmountSwap: PropTypes.func,
destinationAmountSwap: PropTypes.func, destinationAmountSwap: PropTypes.func,
updateBityRatesSwap: PropTypes.func, updateBityRatesSwap: PropTypes.func,
partOneCompleteSwap: PropTypes.func partOneCompleteSwap: PropTypes.func,
receivingAddressSwap: PropTypes.func
}; };
componentDidMount() { componentDidMount() {
@ -62,7 +64,9 @@ class Swap extends Component {
originAmountSwap, originAmountSwap,
destinationAmountSwap, destinationAmountSwap,
partOneComplete, partOneComplete,
partOneCompleteSwap partOneCompleteSwap,
receivingAddressSwap,
receivingAddress
} = this.props; } = this.props;
let wantToSwapMyProps = { let wantToSwapMyProps = {
@ -87,6 +91,12 @@ class Swap extends Component {
destinationKind destinationKind
}; };
let yourReceivingProps = {
destinationKind,
receivingAddressSwap,
receivingAddress
};
return ( return (
<section className="container" style={{ minHeight: '50%' }}> <section className="container" style={{ minHeight: '50%' }}>
<div className="tab-content"> <div className="tab-content">
@ -99,7 +109,7 @@ class Swap extends Component {
{partOneComplete && {partOneComplete &&
<div> <div>
<YourInformation {...yourInformationProps} /> <YourInformation {...yourInformationProps} />
<YourReceiving destinationKind={destinationKind} /> <YourReceiving {...yourReceivingProps} />
</div>} </div>}
</main> </main>
</div> </div>
@ -110,6 +120,7 @@ class Swap extends Component {
function mapStateToProps(state) { function mapStateToProps(state) {
return { return {
receivingAddress: state.swap.receivingAddress,
partOneComplete: state.swap.partOneComplete, partOneComplete: state.swap.partOneComplete,
originAmount: state.swap.originAmount, originAmount: state.swap.originAmount,
destinationAmount: state.swap.destinationAmount, destinationAmount: state.swap.destinationAmount,