2017-06-27 03:27:26 +04:00
|
|
|
// @flow
|
2017-06-23 20:26:54 -05:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-07-03 19:16:20 -05:00
|
|
|
import { donationAddressMap } from 'config/data';
|
2017-07-02 00:49:06 -05:00
|
|
|
import { isValidBTCAddress, isValidETHAddress } from 'libs/validators';
|
2017-06-25 00:57:43 -05:00
|
|
|
import translate from 'translations';
|
2017-06-23 20:26:54 -05:00
|
|
|
|
2017-06-24 15:39:03 -05:00
|
|
|
export default class ReceivingAddress extends Component {
|
2017-06-23 20:26:54 -05:00
|
|
|
static propTypes = {
|
2017-06-24 01:09:44 -05:00
|
|
|
destinationKind: PropTypes.string.isRequired,
|
2017-07-02 00:45:22 -05:00
|
|
|
destinationAddressSwap: PropTypes.func.isRequired,
|
|
|
|
destinationAddress: PropTypes.string,
|
2017-07-08 22:51:14 -05:00
|
|
|
partTwoCompleteSwap: PropTypes.func,
|
|
|
|
stopLoadBityRates: PropTypes.func
|
2017-06-24 01:09:44 -05:00
|
|
|
};
|
|
|
|
|
2017-07-02 00:49:06 -05:00
|
|
|
onChangeDestinationAddress = (event: SyntheticInputEvent) => {
|
2017-06-24 01:09:44 -05:00
|
|
|
const value = event.target.value;
|
2017-07-02 00:45:22 -05:00
|
|
|
this.props.destinationAddressSwap(value);
|
2017-06-23 20:26:54 -05:00
|
|
|
};
|
|
|
|
|
2017-07-02 00:45:22 -05:00
|
|
|
onClickPartTwoComplete = () => {
|
2017-07-08 22:51:14 -05:00
|
|
|
this.props.stopLoadBityRates();
|
2017-07-02 00:45:22 -05:00
|
|
|
this.props.partTwoCompleteSwap(true);
|
|
|
|
};
|
|
|
|
|
2017-06-23 20:26:54 -05:00
|
|
|
render() {
|
2017-07-02 00:45:22 -05:00
|
|
|
const { destinationKind, destinationAddress } = this.props;
|
2017-06-24 01:09:44 -05:00
|
|
|
let validAddress;
|
|
|
|
// TODO - find better pattern here once currencies move beyond BTC, ETH, REP
|
|
|
|
if (this.props.destinationKind === 'BTC') {
|
2017-07-02 00:49:06 -05:00
|
|
|
validAddress = isValidBTCAddress(destinationAddress);
|
2017-06-24 01:09:44 -05:00
|
|
|
} else {
|
2017-07-02 00:49:06 -05:00
|
|
|
validAddress = isValidETHAddress(destinationAddress);
|
2017-06-24 01:09:44 -05:00
|
|
|
}
|
2017-06-23 20:26:54 -05:00
|
|
|
|
|
|
|
return (
|
|
|
|
<article className="swap-start">
|
|
|
|
<section className="swap-address block">
|
|
|
|
<section className="row">
|
|
|
|
<div className="col-sm-8 col-sm-offset-2 col-xs-12">
|
|
|
|
<label>
|
2017-06-25 00:57:43 -05:00
|
|
|
<span>{translate('SWAP_rec_add')}</span>
|
2017-06-23 20:34:13 -05:00
|
|
|
<strong> ({destinationKind})</strong>
|
2017-06-23 20:26:54 -05:00
|
|
|
</label>
|
|
|
|
<input
|
2017-06-24 01:09:44 -05:00
|
|
|
className={`form-control ${validAddress
|
|
|
|
? 'is-valid'
|
|
|
|
: 'is-invalid'}`}
|
2017-06-23 20:26:54 -05:00
|
|
|
type="text"
|
2017-07-02 00:45:22 -05:00
|
|
|
value={destinationAddress}
|
|
|
|
onChange={this.onChangeDestinationAddress}
|
2017-07-03 19:16:20 -05:00
|
|
|
placeholder={donationAddressMap[destinationKind]}
|
2017-06-23 20:26:54 -05:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<section className="row text-center">
|
2017-07-02 00:45:22 -05:00
|
|
|
<button
|
|
|
|
disabled={!validAddress}
|
|
|
|
onClick={this.onClickPartTwoComplete}
|
|
|
|
className="btn btn-primary btn-lg"
|
|
|
|
>
|
2017-06-25 00:57:43 -05:00
|
|
|
<span>{translate('SWAP_start_CTA')}</span>
|
2017-06-24 01:09:44 -05:00
|
|
|
</button>
|
2017-06-23 20:26:54 -05:00
|
|
|
</section>
|
|
|
|
</section>
|
|
|
|
</article>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|