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

86 lines
2.6 KiB
JavaScript
Raw Normal View History

2017-06-26 23:27:26 +00:00
// @flow
import React, { Component } from 'react';
import * as swapTypes from 'actions/swapTypes';
import { donationAddressMap } from 'config/data';
2017-07-02 05:49:06 +00:00
import { isValidBTCAddress, isValidETHAddress } from 'libs/validators';
2017-06-25 05:57:43 +00:00
import translate from 'translations';
export type StateProps = {
destinationKind: string,
destinationAddress: string
};
export type ActionProps = {
destinationAddressSwap: (
value: ?string
) => swapTypes.DestinationAddressSwapAction,
changeStepSwap: (value: number) => swapTypes.ChangeStepSwapAction,
stopLoadBityRatesSwap: () => swapTypes.StopLoadBityRatesSwapAction
};
2017-06-24 20:39:03 +00:00
export default class ReceivingAddress extends Component {
props: StateProps & ActionProps;
2017-07-02 05:49:06 +00:00
onChangeDestinationAddress = (event: SyntheticInputEvent) => {
const value = event.target.value;
2017-07-02 05:45:22 +00:00
this.props.destinationAddressSwap(value);
};
2017-07-02 05:45:22 +00:00
onClickPartTwoComplete = () => {
this.props.stopLoadBityRatesSwap();
// temporarily here for testing purposes. will live in saga
this.props.referenceNumberSwap('');
this.props.changeStepSwap(3);
2017-07-02 05:45:22 +00:00
};
render() {
2017-07-02 05:45:22 +00: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-02 05:49:06 +00:00
validAddress = isValidBTCAddress(destinationAddress);
} else {
2017-07-02 05:49:06 +00: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>
<span>
{translate('SWAP_rec_add')}
</span>
<strong>
{' '}({destinationKind})
</strong>
</label>
<input
className={`form-control ${validAddress
? 'is-valid'
: 'is-invalid'}`}
type="text"
2017-07-02 05:45:22 +00:00
value={destinationAddress}
onChange={this.onChangeDestinationAddress}
placeholder={donationAddressMap[destinationKind]}
/>
</div>
</section>
<section className="row text-center">
2017-07-02 05:45:22 +00:00
<button
disabled={!validAddress}
onClick={this.onClickPartTwoComplete}
className="btn btn-primary btn-lg"
>
<span>
{translate('SWAP_start_CTA')}
</span>
</button>
</section>
</section>
</article>
);
}
}