-
{translate('SWAP_start_CTA')}
+
+ {translate('SWAP_start_CTA')}
+
diff --git a/common/containers/Tabs/Swap/components/SwapInfoHeader.js b/common/containers/Tabs/Swap/components/SwapInfoHeader.js
new file mode 100644
index 00000000..3d03620b
--- /dev/null
+++ b/common/containers/Tabs/Swap/components/SwapInfoHeader.js
@@ -0,0 +1,142 @@
+// @flow
+import React, { Component } from 'react';
+import { toFixedIfLarger } from 'utils/formatters';
+import translate from 'translations';
+import * as swapTypes from 'actions/swapTypes';
+import bityLogo from 'assets/images/logo-bity.svg';
+import { bityReferralURL } from 'config/data';
+
+export type StateProps = {
+ timeRemaining: string,
+ originAmount: number,
+ originKind: string,
+ destinationKind: string,
+ destinationAmount: number,
+ referenceNumber: string
+};
+
+export type ActionProps = {
+ restartSwap: () => swapTypes.RestartSwapAction
+};
+
+export default class SwapInfoHeader extends Component {
+ props: StateProps & ActionProps;
+
+ computedOriginDestinationRatio = () => {
+ return toFixedIfLarger(
+ this.props.destinationAmount / this.props.originAmount,
+ 6
+ );
+ };
+
+ isExpanded = () => {
+ const { referenceNumber, timeRemaining, restartSwap } = this.props;
+ return referenceNumber && timeRemaining && restartSwap;
+ };
+
+ computedClass = () => {
+ if (this.isExpanded()) {
+ return 'col-sm-3 order-info';
+ } else {
+ return 'col-sm-4 order-info';
+ }
+ };
+
+ render() {
+ const {
+ referenceNumber,
+ timeRemaining,
+ originAmount,
+ destinationAmount,
+ originKind,
+ destinationKind,
+ restartSwap
+ } = this.props;
+ return (
+
+
+
+
+
+
+ {translate('SWAP_information')}
+
+
+
+
+ {/*Amount to send */}
+ {!this.isExpanded() &&
+
+
+ {` ${toFixedIfLarger(originAmount, 6)} ${originKind}`}
+
+
+ {translate('SEND_amount')}
+
+
}
+
+ {/* Reference Number*/}
+ {this.isExpanded() &&
+
+
+ {referenceNumber}
+
+
+ {translate('SWAP_ref_num')}
+
+
}
+
+ {/*Time remaining*/}
+ {this.isExpanded() &&
+
+
+ {timeRemaining}
+
+
+ {translate('SWAP_time')}
+
+
}
+
+ {/*Amount to Receive*/}
+
+
+ {` ${toFixedIfLarger(destinationAmount, 6)} ${destinationKind}`}
+
+
+ {translate('SWAP_rec_amt')}
+
+
+
+ {/*Your rate*/}
+
+
+ {` ${toFixedIfLarger(
+ this.computedOriginDestinationRatio(),
+ 6
+ )} ${originKind}/${destinationKind} `}
+
+
+ {translate('SWAP_your_rate')}
+
+
+
+
+ );
+ }
+}
diff --git a/common/containers/Tabs/Swap/components/swapProgress.js b/common/containers/Tabs/Swap/components/SwapProgress.js
similarity index 56%
rename from common/containers/Tabs/Swap/components/swapProgress.js
rename to common/containers/Tabs/Swap/components/SwapProgress.js
index dbcbed7e..283abd39 100644
--- a/common/containers/Tabs/Swap/components/swapProgress.js
+++ b/common/containers/Tabs/Swap/components/SwapProgress.js
@@ -1,29 +1,24 @@
//flow
import React, { Component } from 'react';
-import PropTypes from 'prop-types';
import translate from 'translations';
-export default class SwapProgress extends Component {
- constructor(props) {
- super(props);
- }
+export type StateProps = {
+ numberOfConfirmations: number,
+ destinationKind: string,
+ originKind: string,
+ orderStep: number
+};
- static propTypes = {
- numberOfConfirmations: PropTypes.number.isRequired,
- destinationKind: PropTypes.string.isRequired,
- originKind: PropTypes.string.isRequired,
- activeStep: PropTypes.number.isRequired
- };
+export default class SwapProgress extends Component {
+ props: StateProps;
computedClass(i: number) {
- const { activeStep } = this.props;
+ const { orderStep } = this.props;
let cssClass = 'progress-item';
- if (activeStep > i) {
+ if (orderStep > i) {
cssClass += ' progress-true';
- } else if (i === activeStep) {
+ } else if (i === orderStep) {
cssClass += ' progress-active';
- } else {
- cssClass += '';
}
return cssClass;
}
@@ -35,25 +30,37 @@ export default class SwapProgress extends Component {
-
1
-
{translate('SWAP_progress_1')}
+
+ 1
+
+
+ {translate('SWAP_progress_1')}
+
-
2
+
+ 2
+
- {translate('SWAP_progress_2')}{originKind}...
+ {translate('SWAP_progress_2')}
+ {originKind}...
-
3
+
+ 3
+
{originKind} {translate('SWAP_progress_3')}
-
4
+
+ 4
+
- Sending your {destinationKind}
+ Sending your
+ {destinationKind}
Waiting for {numberOfConfirmations} confirmations...
@@ -61,7 +68,9 @@ export default class SwapProgress extends Component {
-
5
+
+ 5
+
Order Complete
diff --git a/common/containers/Tabs/Swap/components/currencySwap.js b/common/containers/Tabs/Swap/components/currencySwap.js
deleted file mode 100644
index 2090c1b4..00000000
--- a/common/containers/Tabs/Swap/components/currencySwap.js
+++ /dev/null
@@ -1,163 +0,0 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import translate from 'translations';
-import { combineAndUpper } from 'api/bity';
-
-class CoinTypeDropDown extends Component {
- constructor(props) {
- super(props);
- }
-
- static propTypes = {
- kind: PropTypes.any,
- onChange: PropTypes.any,
- kindOptions: PropTypes.any
- };
-
- render() {
- return (
-
-
-
- );
- }
-}
-
-export default class CurrencySwap extends Component {
- constructor(props) {
- super(props);
- this.state = {
- disabled: false
- };
- }
-
- static propTypes = {
- bityRates: PropTypes.any,
- originAmount: PropTypes.any,
- destinationAmount: PropTypes.any,
- originKind: PropTypes.string,
- destinationKind: PropTypes.string,
- destinationKindOptions: PropTypes.array,
- originKindOptions: PropTypes.array,
- originKindSwap: PropTypes.func,
- destinationKindSwap: PropTypes.func,
- originAmountSwap: PropTypes.func,
- destinationAmountSwap: PropTypes.func,
- partOneCompleteSwap: PropTypes.func
- };
-
- onClickStartSwap = () => {
- this.props.partOneCompleteSwap(true);
- };
-
- onChangeOriginAmount = amount => {
- let originAmountAsNumber = parseFloat(amount);
- if (originAmountAsNumber) {
- let pairName = combineAndUpper(
- this.props.originKind,
- this.props.destinationKind
- );
- let bityRate = this.props.bityRates[pairName];
- this.props.originAmountSwap(originAmountAsNumber);
- this.props.destinationAmountSwap(originAmountAsNumber * bityRate);
- } else {
- this.props.originAmountSwap('');
- this.props.destinationAmountSwap('');
- }
- };
-
- onChangeDestinationAmount(amount) {
- let destinationAmountAsNumber = parseFloat(amount);
- if (destinationAmountAsNumber) {
- this.props.destinationAmountSwap(destinationAmountAsNumber);
- let pairName = combineAndUpper(
- this.props.destinationKind,
- this.props.originKind
- );
- let bityRate = this.props.bityRates[pairName];
- this.props.originAmountSwap(destinationAmountAsNumber * bityRate);
- } else {
- this.props.originAmountSwap('');
- this.props.destinationAmountSwap('');
- }
- }
-
- async onChangeDestinationKind(event) {
- let newDestinationKind = event.target.value;
- this.props.destinationKindSwap(newDestinationKind);
- }
-
- async onChangeOriginKind(event) {
- let newOriginKind = event.target.value;
- this.props.originKindSwap(newOriginKind);
- }
-
- render() {
- const {
- originAmount,
- destinationAmount,
- originKind,
- destinationKind,
- destinationKindOptions,
- originKindOptions
- } = this.props;
-
- return (
-
- {translate('SWAP_init_1')}
- 0
- ? 'is-valid'
- : 'is-invalid'}`}
- type="number"
- placeholder="Amount"
- onChange={e => this.onChangeOriginAmount(e.target.value)}
- value={originAmount}
- />
-
-
-
- {translate('SWAP_init_2')}
-
- 0
- ? 'is-valid'
- : 'is-invalid'}`}
- type="number"
- placeholder="Amount"
- value={destinationAmount}
- onChange={e => this.onChangeDestinationAmount(e.target.value)}
- />
-
-
-
-
-
-
- );
- }
-}
diff --git a/common/containers/Tabs/Swap/components/onGoingSwapInformation.js b/common/containers/Tabs/Swap/components/onGoingSwapInformation.js
deleted file mode 100644
index f23bd26b..00000000
--- a/common/containers/Tabs/Swap/components/onGoingSwapInformation.js
+++ /dev/null
@@ -1,87 +0,0 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import { toFixedIfLarger } from 'utils/formatters';
-import translate from 'translations';
-
-export default class OnGoingSwapInformation extends Component {
- constructor(props) {
- super(props);
- }
-
- static propTypes = {
- referenceNumber: PropTypes.string.isRequired,
- timeRemaining: PropTypes.any, // FIXME
- originAmount: PropTypes.number.isRequired,
- originKind: PropTypes.string.isRequired,
- destinationKind: PropTypes.string.isRequired,
- destinationAmount: PropTypes.number.isRequired,
- restartSwap: PropTypes.func.isRequired
- };
-
- computedOriginDestinationRatio = () => {
- return toFixedIfLarger(
- this.props.destinationAmount / this.props.originAmount,
- 6
- );
- };
-
- render() {
- const {
- referenceNumber,
- timeRemaining,
- originAmount,
- originKind,
- destinationKind,
- restartSwap
- } = this.props;
- return (
-
-
-
-
-
- {translate('SWAP_information')}
-
-
-
-
-
{referenceNumber}
-
{translate('SWAP_ref_num')}
-
-
-
{timeRemaining}
-
- {translate('SWAP_time')}
-
-
-
-
{originAmount} {originKind}
-
{translate('SWAP_rec_amt')}
-
-
-
- {`${this.computedOriginDestinationRatio()} ${destinationKind}/${originKind}`}
-
-
{translate('SWAP_your_rate')}
-
-
-
- );
- }
-}
diff --git a/common/containers/Tabs/Swap/components/swapInformation.js b/common/containers/Tabs/Swap/components/swapInformation.js
deleted file mode 100644
index def61d99..00000000
--- a/common/containers/Tabs/Swap/components/swapInformation.js
+++ /dev/null
@@ -1,79 +0,0 @@
-import React, { Component } from 'react';
-import PropTypes from 'prop-types';
-import { toFixedIfLarger } from 'utils/formatters';
-import translate from 'translations';
-
-export default class SwapInformation extends Component {
- constructor(props) {
- super(props);
- }
-
- static propTypes = {
- originAmount: PropTypes.number.isRequired,
- destinationAmount: PropTypes.number.isRequired,
- originKind: PropTypes.string.isRequired,
- destinationKind: PropTypes.string.isRequired
- };
-
- computedOriginDestinationRatio = () => {
- return this.props.destinationAmount / this.props.originAmount;
- };
-
- render() {
- const {
- originAmount,
- originKind,
- destinationAmount,
- destinationKind
- } = this.props;
-
- return (
-
-
-
- {translate('SWAP_information')}
-
-
-
-
-
-
- {` ${toFixedIfLarger(originAmount, 6)} ${originKind}`}
-
-
{translate('SEND_amount')}
-
-
-
- {` ${toFixedIfLarger(destinationAmount, 6)} ${destinationKind}`}
-
-
{translate('SWAP_rec_amt')}
-
-
-
- {` ${toFixedIfLarger(
- this.computedOriginDestinationRatio(),
- 6
- )} ${originKind}/${destinationKind} `}
-
-
{translate('SWAP_your_rate')}
-
-
-
- );
- }
-}
diff --git a/common/containers/Tabs/Swap/index.js b/common/containers/Tabs/Swap/index.js
index bea2c188..0799aaa1 100644
--- a/common/containers/Tabs/Swap/index.js
+++ b/common/containers/Tabs/Swap/index.js
@@ -1,48 +1,63 @@
import React, { Component } from 'react';
-import CurrencySwap from './components/currencySwap';
-import SwapInformation from './components/swapInformation';
-import CurrentRates from './components/currentRates';
-import ReceivingAddress from './components/receivingAddress';
-import SwapProgress from './components/swapProgress';
-import OnGoingSwapInformation from './components/onGoingSwapInformation';
import { connect } from 'react-redux';
import * as swapActions from 'actions/swap';
-import PropTypes from 'prop-types';
+import * as swapTypes from 'actions/swapTypes';
+import CurrencySwap from './components/CurrencySwap';
+import CurrentRates from './components/CurrentRates';
+import ReceivingAddress from './components/ReceivingAddress';
+import SwapInfoHeader from './components/SwapInfoHeader';
+import SwapProgress from './components/SwapProgress';
+
+type ReduxStateProps = {
+ step: string,
+ destinationAddress: string,
+ destinationKind: string,
+ originKind: string,
+ destinationKindOptions: String[],
+ originKindOptions: String[],
+ bityRates: boolean,
+ originAmount: ?number,
+ destinationAmount: ?number,
+ // PART 3
+ referenceNumber: string,
+ timeRemaining: string,
+ numberOfConfirmation: number,
+ orderStep: number,
+ orderStarted: boolean
+};
+
+type ReduxActionProps = {
+ changeStepSwap: (value: number) => swapTypes.ChangeStepSwapAction,
+ originKindSwap: (value: string) => swapTypes.OriginKindSwapAction,
+ destinationKindSwap: (value: string) => swapTypes.DestinationKindSwapAction,
+ originAmountSwap: (value: ?number) => swapTypes.OriginAmountSwapAction,
+ destinationAmountSwap: (
+ value: ?number
+ ) => swapTypes.DestinationAmountSwapAction,
+ loadBityRatesSwap: () => swapTypes.LoadBityRatesSwapAction,
+ destinationAddressSwap: (
+ value: ?string
+ ) => swapTypes.DestinationAddressSwapAction,
+ restartSwap: () => swapTypes.RestartSwapAction,
+ stopLoadBityRatesSwap: () => swapTypes.StopLoadBityRatesSwapAction,
+ // PART 3 (IGNORE FOR NOW)
+ referenceNumberSwap: typeof swapActions.referenceNumberSwap
+};
class Swap extends Component {
- constructor(props) {
- super(props);
- }
-
- static propTypes = {
- bityRates: PropTypes.any,
- originAmount: PropTypes.any,
- destinationAmount: PropTypes.any,
- originKind: PropTypes.string,
- partOneComplete: PropTypes.bool,
- destinationKind: PropTypes.string,
- destinationKindOptions: PropTypes.array,
- originKindOptions: PropTypes.array,
- destinationAddress: PropTypes.string,
- originKindSwap: PropTypes.func,
- destinationKindSwap: PropTypes.func,
- originAmountSwap: PropTypes.func,
- destinationAmountSwap: PropTypes.func,
- loadBityRates: PropTypes.func,
- partOneCompleteSwap: PropTypes.func,
- destinationAddressSwap: PropTypes.func,
- restartSwap: PropTypes.func,
- partTwoCompleteSwap: PropTypes.func,
- partTwoComplete: PropTypes.bool,
- stopLoadBityRates: PropTypes.func
- };
+ props: ReduxActionProps & ReduxStateProps;
componentDidMount() {
- this.props.loadBityRates();
+ this.props.loadBityRatesSwap();
+ }
+
+ componentWillUnmount() {
+ this.props.stopLoadBityRatesSwap();
}
render() {
let {
+ // STATE
bityRates,
originAmount,
destinationAmount,
@@ -50,21 +65,50 @@ class Swap extends Component {
destinationKind,
destinationKindOptions,
originKindOptions,
+ destinationAddress,
+ step,
+ referenceNumber,
+ timeRemaining,
+ numberOfConfirmations,
+ orderStep,
+ // ACTIONS
+ restartSwap,
+ stopLoadBityRatesSwap,
+ changeStepSwap,
originKindSwap,
destinationKindSwap,
originAmountSwap,
destinationAmountSwap,
- partOneComplete,
- partOneCompleteSwap,
destinationAddressSwap,
- destinationAddress,
- restartSwap,
- partTwoCompleteSwap,
- partTwoComplete,
- stopLoadBityRates
+ referenceNumberSwap
} = this.props;
- let wantToSwapMyProps = {
+ let ReceivingAddressProps = {
+ destinationKind,
+ destinationAddressSwap,
+ destinationAddress,
+ stopLoadBityRatesSwap,
+ changeStepSwap,
+ referenceNumberSwap
+ };
+
+ let SwapInfoHeaderProps = {
+ referenceNumber,
+ timeRemaining,
+ originAmount,
+ originKind,
+ destinationKind,
+ destinationAmount,
+ restartSwap,
+ numberOfConfirmations,
+ orderStep
+ };
+
+ const { ETHBTC, ETHREP, BTCETH, BTCREP } = bityRates;
+
+ const CurrentRatesProps = { ETHBTC, ETHREP, BTCETH, BTCREP };
+
+ const CurrencySwapProps = {
bityRates,
originAmount,
destinationAmount,
@@ -76,62 +120,22 @@ class Swap extends Component {
destinationKindSwap,
originAmountSwap,
destinationAmountSwap,
- partOneCompleteSwap
- };
-
- let yourInformationProps = {
- originAmount,
- destinationAmount,
- originKind,
- destinationKind
- };
-
- let receivingAddressProps = {
- destinationKind,
- destinationAddressSwap,
- destinationAddress,
- partTwoCompleteSwap,
- stopLoadBityRates
- };
-
- const referenceNumber = '2341asdfads';
- const timeRemaining = '2:30';
-
- let onGoingSwapInformationProps = {
- // from bity
- referenceNumber: referenceNumber,
- timeRemaining: timeRemaining,
- originAmount,
- originKind,
- destinationKind,
- destinationAmount,
- restartSwap,
- numberOfConfirmations: 3,
- activeStep: 2
+ changeStepSwap
};
return (
- {!partOneComplete &&
- !partTwoComplete &&
+ {step === 1 &&
-
-
-
}
- {partOneComplete &&
- !partTwoComplete &&
-
-
-
-
}
- {partOneComplete &&
- partTwoComplete &&
-
-
-
+
+
}
+ {(step === 2 || step === 3) &&
+ }
+ {step === 2 && }
+ {step === 3 && }
@@ -141,16 +145,20 @@ class Swap extends Component {
function mapStateToProps(state) {
return {
- partTwoComplete: state.swap.partTwoComplete,
+ step: state.swap.step,
destinationAddress: state.swap.destinationAddress,
- partOneComplete: state.swap.partOneComplete,
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
+ bityRates: state.swap.bityRates,
+ referenceNumber: state.swap.referenceNumber,
+ timeRemaining: state.swap.timeRemaining,
+ numberOfConfirmations: state.swap.numberOfConfirmations,
+ orderStep: state.swap.orderStep,
+ orderStarted: state.swap.orderStarted
};
}
diff --git a/common/reducers/swap.js b/common/reducers/swap.js
index cc655e56..4aee6c93 100644
--- a/common/reducers/swap.js
+++ b/common/reducers/swap.js
@@ -4,12 +4,12 @@ import {
SWAP_ORIGIN_AMOUNT,
SWAP_ORIGIN_KIND,
SWAP_UPDATE_BITY_RATES,
- SWAP_PART_ONE_COMPLETE,
SWAP_DESTINATION_ADDRESS,
SWAP_RESTART,
- SWAP_PART_TWO_COMPLETE
+ SWAP_STEP,
+ SWAP_REFERENCE_NUMBER
} from 'actions/swapConstants';
-import { combineAndUpper } from 'api/bity';
+import { combineAndUpper } from 'utils/formatters';
export const ALL_CRYPTO_KIND_OPTIONS = ['BTC', 'ETH', 'REP'];
@@ -24,10 +24,13 @@ const initialState = {
originKindOptions: ALL_CRYPTO_KIND_OPTIONS.filter(
element => element !== 'REP'
),
- partOneComplete: false,
- partTwoComplete: false,
+ step: 1,
bityRates: {},
- destinationAddress: ''
+ destinationAddress: '',
+ referenceNumber: '',
+ timeRemaining: '',
+ numberOfConfirmations: null,
+ orderStep: null
};
const buildDestinationAmount = (
@@ -101,16 +104,12 @@ export function swap(state = initialState, action) {
...action.value
}
};
- case SWAP_PART_ONE_COMPLETE:
+ case SWAP_STEP: {
return {
...state,
- partOneComplete: action.value
- };
- case SWAP_PART_TWO_COMPLETE:
- return {
- ...state,
- partTwoComplete: action.value
+ step: action.value
};
+ }
case SWAP_DESTINATION_ADDRESS:
return {
...state,
@@ -122,6 +121,14 @@ export function swap(state = initialState, action) {
...initialState,
bityRates: state.bityRates
};
+ case SWAP_REFERENCE_NUMBER:
+ return {
+ ...state,
+ referenceNumber: '2341asdfads',
+ timeRemaining: '2:30',
+ numberOfConfirmations: 3,
+ orderStep: 2
+ };
default:
return state;
}
diff --git a/common/utils/formatters.js b/common/utils/formatters.js
index d0db12c3..d5d84e17 100644
--- a/common/utils/formatters.js
+++ b/common/utils/formatters.js
@@ -5,6 +5,10 @@ export function toFixedIfLarger(number: number, fixedSize: number = 6): string {
return parseFloat(number.toFixed(fixedSize)).toString();
}
+export function combineAndUpper(...args: string[]) {
+ return args.reduce((acc, item) => acc.concat(item.toUpperCase()), '');
+}
+
// Use in place of angular number filter
export function formatNumber(number: Big, digits: number = 3): string {
let parts = number.toFixed(digits).split('.');