MyCrypto/common/containers/Tabs/Swap/index.js

127 lines
3.2 KiB
JavaScript
Raw Normal View History

2017-06-19 05:39:07 +00:00
import React, { Component } from 'react';
2017-06-12 01:02:39 +00:00
import WantToSwapMy from './components/wantToSwapMy';
import CurrentRates from './components/currentRates';
2017-06-19 05:39:07 +00:00
import { connect } from 'react-redux';
2017-06-12 01:02:39 +00:00
import {
2017-06-19 05:39:07 +00:00
SWAP_DESTINATION_AMOUNT_TO,
SWAP_DESTINATION_KIND_TO,
SWAP_ORIGIN_AMOUNT_TO,
SWAP_ORIGIN_KIND_TO,
SWAP_UPDATE_BITY_RATES_TO
2017-06-12 01:02:39 +00:00
} from 'actions/swap';
import PropTypes from 'prop-types';
import Bity from 'api/bity';
class Swap extends Component {
2017-06-19 05:39:07 +00:00
constructor(props) {
super(props);
this.bity = new Bity();
}
2017-06-12 01:02:39 +00:00
2017-06-19 05:39:07 +00:00
static propTypes = {
bityRates: PropTypes.any,
originAmount: PropTypes.any,
destinationAmount: PropTypes.any,
originKind: PropTypes.string,
destinationKind: PropTypes.string,
destinationKindOptions: PropTypes.array,
originKindOptions: PropTypes.array,
swapOriginKindTo: PropTypes.func,
swapDestinationKindTo: PropTypes.func,
swapOriginAmountTo: PropTypes.func,
swapDestinationAmountTo: PropTypes.func,
2017-06-19 05:39:57 +00:00
swapUpdateBityRatesTo: PropTypes.func
2017-06-19 05:39:07 +00:00
};
2017-06-12 01:02:39 +00:00
2017-06-19 05:39:07 +00:00
componentDidMount() {
let { bityRates } = this.props;
2017-06-19 04:56:32 +00:00
2017-06-19 05:39:07 +00:00
if (
!bityRates.ETHBTC ||
!bityRates.ETHREP ||
!bityRates.BTCETH ||
!bityRates.BTCREP
) {
this.bity.getAllRates().then(data => {
this.props.swapUpdateBityRatesTo(data);
});
2017-06-19 04:56:32 +00:00
}
2017-06-19 05:39:07 +00:00
}
2017-06-19 04:56:32 +00:00
2017-06-19 05:39:07 +00:00
render() {
let {
bityRates,
originAmount,
destinationAmount,
originKind,
destinationKind,
destinationKindOptions,
originKindOptions,
swapOriginKindTo,
swapDestinationKindTo,
swapOriginAmountTo,
2017-06-19 05:39:57 +00:00
swapDestinationAmountTo
2017-06-19 05:39:07 +00:00
} = this.props;
2017-06-12 01:02:39 +00:00
2017-06-19 05:39:07 +00:00
let wantToSwapMyProps = {
bityRates,
originAmount,
destinationAmount,
originKind,
destinationKind,
destinationKindOptions,
originKindOptions,
swapOriginKindTo,
swapDestinationKindTo,
swapOriginAmountTo,
2017-06-19 05:39:57 +00:00
swapDestinationAmountTo
2017-06-19 05:39:07 +00:00
};
2017-06-12 01:02:39 +00:00
2017-06-19 05:39:07 +00:00
return (
<section className="container" style={{ minHeight: '50%' }}>
<div className="tab-content">
<main className="tab-pane swap-tab">
<CurrentRates {...bityRates} />
<WantToSwapMy {...wantToSwapMyProps} />
</main>
</div>
</section>
);
}
2017-06-12 01:02:39 +00:00
}
function mapStateToProps(state) {
2017-06-19 05:39:07 +00:00
return {
originAmount: state.swap.originAmount,
destinationAmount: state.swap.destinationAmount,
originKind: state.swap.originKind,
destinationKind: state.swap.destinationKind,
destinationKindOptions: state.swap.destinationKindOptions,
originKindOptions: state.swap.originKindOptions,
bityRates: state.swap.bityRates
};
2017-06-12 01:02:39 +00:00
}
function mapDispatchToProps(dispatch) {
2017-06-19 05:39:07 +00:00
return {
swapOriginKindTo: originValue => {
dispatch(SWAP_ORIGIN_KIND_TO(originValue));
},
swapDestinationKindTo: destinationValue => {
dispatch(SWAP_DESTINATION_KIND_TO(destinationValue));
},
swapOriginAmountTo: originAmount => {
dispatch(SWAP_ORIGIN_AMOUNT_TO(originAmount));
},
swapDestinationAmountTo: destinationValue => {
dispatch(SWAP_DESTINATION_AMOUNT_TO(destinationValue));
},
swapUpdateBityRatesTo: bityRates => {
dispatch(SWAP_UPDATE_BITY_RATES_TO(bityRates));
2017-06-12 01:02:39 +00:00
}
2017-06-19 05:39:07 +00:00
};
2017-06-12 01:02:39 +00:00
}
2017-06-19 05:39:07 +00:00
export default connect(mapStateToProps, mapDispatchToProps)(Swap);