MyCrypto/common/containers/Tabs/Swap/components/receivingAddress.js

71 lines
2.3 KiB
JavaScript
Raw Normal View History

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