2017-12-11 17:44:53 +00:00
|
|
|
import { showNotification as dShowNotification, TShowNotification } from 'actions/notifications';
|
2017-09-25 02:06:28 +00:00
|
|
|
import {
|
2017-12-11 17:44:53 +00:00
|
|
|
initSwap as dInitSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
bityOrderCreateRequestedSwap as dBityOrderCreateRequestedSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrderCreateRequestedSwap as dShapeshiftOrderCreateRequestedSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
changeStepSwap as dChangeStepSwap,
|
|
|
|
destinationAddressSwap as dDestinationAddressSwap,
|
|
|
|
restartSwap as dRestartSwap,
|
|
|
|
startOrderTimerSwap as dStartOrderTimerSwap,
|
|
|
|
startPollBityOrderStatus as dStartPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
startPollShapeshiftOrderStatus as dStartPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopLoadBityRatesSwap as dStopLoadBityRatesSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopLoadShapeshiftRatesSwap as dStopLoadShapeshiftRatesSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopOrderTimerSwap as dStopOrderTimerSwap,
|
|
|
|
stopPollBityOrderStatus as dStopPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollShapeshiftOrderStatus as dStopPollShapeshiftOrderStatus,
|
|
|
|
changeSwapProvider as dChangeSwapProvider,
|
2017-12-11 17:44:53 +00:00
|
|
|
TInitSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
TBityOrderCreateRequestedSwap,
|
|
|
|
TChangeStepSwap,
|
|
|
|
TDestinationAddressSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
TShapeshiftOrderCreateRequestedSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
TRestartSwap,
|
|
|
|
TStartOrderTimerSwap,
|
|
|
|
TStartPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
TStartPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
TStopLoadBityRatesSwap,
|
|
|
|
TStopOrderTimerSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
TStopPollBityOrderStatus,
|
|
|
|
TStopPollShapeshiftOrderStatus,
|
|
|
|
TChangeSwapProvider,
|
|
|
|
TStopLoadShapeshiftRatesSwap,
|
|
|
|
ProviderName
|
2017-09-25 02:06:28 +00:00
|
|
|
} from 'actions/swap';
|
2018-01-02 18:04:50 +00:00
|
|
|
import {
|
|
|
|
SwapInput,
|
|
|
|
NormalizedOptions,
|
|
|
|
NormalizedBityRates,
|
|
|
|
NormalizedShapeshiftRates
|
|
|
|
} from 'reducers/swap/types';
|
2017-09-25 02:06:28 +00:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { AppState } from 'reducers';
|
|
|
|
import CurrencySwap from './components/CurrencySwap';
|
|
|
|
import CurrentRates from './components/CurrentRates';
|
|
|
|
import PartThree from './components/PartThree';
|
2018-01-02 18:04:50 +00:00
|
|
|
import SupportFooter from './components/SupportFooter';
|
2017-09-25 02:06:28 +00:00
|
|
|
import ReceivingAddress from './components/ReceivingAddress';
|
|
|
|
import SwapInfoHeader from './components/SwapInfoHeader';
|
2017-10-04 04:13:49 +00:00
|
|
|
import TabSection from 'containers/TabSection';
|
2018-01-02 18:04:50 +00:00
|
|
|
import { merge } from 'lodash';
|
2018-01-22 12:24:05 +00:00
|
|
|
import { RouteNotFound } from 'components/RouteNotFound';
|
|
|
|
import { Switch, Route, RouteComponentProps } from 'react-router';
|
2018-02-12 20:43:07 +00:00
|
|
|
import { getOffline } from 'selectors/config';
|
2017-09-25 02:06:28 +00:00
|
|
|
|
|
|
|
interface ReduxStateProps {
|
|
|
|
step: number;
|
2017-12-11 17:44:53 +00:00
|
|
|
origin: SwapInput;
|
|
|
|
destination: SwapInput;
|
|
|
|
bityRates: NormalizedBityRates;
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftRates: NormalizedShapeshiftRates;
|
2017-12-11 17:44:53 +00:00
|
|
|
options: NormalizedOptions;
|
2018-01-02 18:04:50 +00:00
|
|
|
provider: ProviderName;
|
2017-09-25 02:06:28 +00:00
|
|
|
bityOrder: any;
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrder: any;
|
2017-09-25 02:06:28 +00:00
|
|
|
destinationAddress: string;
|
|
|
|
isFetchingRates: boolean | null;
|
|
|
|
secondsRemaining: number | null;
|
|
|
|
outputTx: string | null;
|
|
|
|
isPostingOrder: boolean;
|
2018-01-02 18:04:50 +00:00
|
|
|
bityOrderStatus: string | null;
|
|
|
|
shapeshiftOrderStatus: string | null;
|
2017-09-25 02:06:28 +00:00
|
|
|
paymentAddress: string | null;
|
2018-01-11 18:04:11 +00:00
|
|
|
isOffline: boolean;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface ReduxActionProps {
|
|
|
|
changeStepSwap: TChangeStepSwap;
|
|
|
|
destinationAddressSwap: TDestinationAddressSwap;
|
|
|
|
restartSwap: TRestartSwap;
|
|
|
|
stopLoadBityRatesSwap: TStopLoadBityRatesSwap;
|
2018-01-02 18:04:50 +00:00
|
|
|
stopLoadShapeshiftRatesSwap: TStopLoadShapeshiftRatesSwap;
|
|
|
|
shapeshiftOrderCreateRequestedSwap: TShapeshiftOrderCreateRequestedSwap;
|
2017-09-25 02:06:28 +00:00
|
|
|
bityOrderCreateRequestedSwap: TBityOrderCreateRequestedSwap;
|
2018-01-02 18:04:50 +00:00
|
|
|
startPollShapeshiftOrderStatus: TStartPollShapeshiftOrderStatus;
|
2017-09-25 02:06:28 +00:00
|
|
|
startPollBityOrderStatus: TStartPollBityOrderStatus;
|
2018-01-02 18:04:50 +00:00
|
|
|
startOrderTimerSwap: TStartOrderTimerSwap;
|
2017-09-25 02:06:28 +00:00
|
|
|
stopOrderTimerSwap: TStopOrderTimerSwap;
|
|
|
|
stopPollBityOrderStatus: TStopPollBityOrderStatus;
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollShapeshiftOrderStatus: TStopPollShapeshiftOrderStatus;
|
2017-09-25 02:06:28 +00:00
|
|
|
showNotification: TShowNotification;
|
2017-12-11 17:44:53 +00:00
|
|
|
initSwap: TInitSwap;
|
2018-01-02 18:04:50 +00:00
|
|
|
swapProvider: TChangeSwapProvider;
|
2017-09-25 02:06:28 +00:00
|
|
|
}
|
|
|
|
|
2018-01-22 12:24:05 +00:00
|
|
|
class Swap extends Component<ReduxActionProps & ReduxStateProps & RouteComponentProps<{}>, {}> {
|
2017-09-25 02:06:28 +00:00
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
// STATE
|
|
|
|
bityRates,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftRates,
|
|
|
|
provider,
|
2017-12-11 17:44:53 +00:00
|
|
|
options,
|
|
|
|
origin,
|
|
|
|
destination,
|
2017-09-25 02:06:28 +00:00
|
|
|
destinationAddress,
|
|
|
|
step,
|
|
|
|
bityOrder,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrder,
|
2017-09-25 02:06:28 +00:00
|
|
|
secondsRemaining,
|
|
|
|
paymentAddress,
|
2018-01-02 18:04:50 +00:00
|
|
|
bityOrderStatus,
|
|
|
|
shapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
isPostingOrder,
|
|
|
|
outputTx,
|
|
|
|
// ACTIONS
|
2017-12-11 17:44:53 +00:00
|
|
|
initSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
restartSwap,
|
|
|
|
stopLoadBityRatesSwap,
|
|
|
|
changeStepSwap,
|
|
|
|
destinationAddressSwap,
|
|
|
|
bityOrderCreateRequestedSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrderCreateRequestedSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
showNotification,
|
|
|
|
startOrderTimerSwap,
|
|
|
|
startPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollShapeshiftOrderStatus,
|
|
|
|
startPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopOrderTimerSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollBityOrderStatus,
|
|
|
|
swapProvider
|
2017-09-25 02:06:28 +00:00
|
|
|
} = this.props;
|
|
|
|
|
2018-01-22 12:24:05 +00:00
|
|
|
const currentPath = this.props.match.url;
|
|
|
|
|
2018-01-02 18:04:50 +00:00
|
|
|
const reference = provider === 'shapeshift' ? shapeshiftOrder.orderId : bityOrder.reference;
|
2017-09-25 02:06:28 +00:00
|
|
|
|
|
|
|
const ReceivingAddressProps = {
|
|
|
|
isPostingOrder,
|
2017-12-11 17:44:53 +00:00
|
|
|
origin,
|
2018-03-01 17:53:29 +00:00
|
|
|
destinationId: destination.label,
|
2018-01-02 18:04:50 +00:00
|
|
|
destinationKind: destination.amount as number,
|
2017-09-25 02:06:28 +00:00
|
|
|
destinationAddressSwap,
|
|
|
|
destinationAddress,
|
|
|
|
stopLoadBityRatesSwap,
|
|
|
|
changeStepSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
provider,
|
|
|
|
bityOrderCreateRequestedSwap,
|
|
|
|
shapeshiftOrderCreateRequestedSwap
|
2017-09-25 02:06:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const SwapInfoHeaderProps = {
|
2017-12-11 17:44:53 +00:00
|
|
|
origin,
|
|
|
|
destination,
|
2017-09-25 02:06:28 +00:00
|
|
|
reference,
|
|
|
|
secondsRemaining,
|
|
|
|
restartSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
bityOrderStatus,
|
|
|
|
shapeshiftOrderStatus,
|
|
|
|
provider
|
2017-09-25 02:06:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const CurrencySwapProps = {
|
|
|
|
showNotification,
|
|
|
|
bityRates,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftRates,
|
|
|
|
provider,
|
2017-12-11 17:44:53 +00:00
|
|
|
options,
|
|
|
|
initSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
swapProvider,
|
2017-09-25 02:06:28 +00:00
|
|
|
changeStepSwap
|
|
|
|
};
|
|
|
|
|
2018-01-02 18:04:50 +00:00
|
|
|
const paymentInfo =
|
|
|
|
provider === 'shapeshift'
|
|
|
|
? merge(origin, { amount: shapeshiftOrder.depositAmount })
|
|
|
|
: merge(origin, { amount: bityOrder.amount });
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
const PaymentInfoProps = {
|
2018-01-02 18:04:50 +00:00
|
|
|
origin: paymentInfo,
|
2017-09-25 02:06:28 +00:00
|
|
|
paymentAddress
|
|
|
|
};
|
|
|
|
|
|
|
|
const PartThreeProps = {
|
|
|
|
...SwapInfoHeaderProps,
|
|
|
|
...PaymentInfoProps,
|
|
|
|
reference,
|
2018-01-02 18:04:50 +00:00
|
|
|
provider,
|
2017-09-25 02:06:28 +00:00
|
|
|
startOrderTimerSwap,
|
|
|
|
stopOrderTimerSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
startPollBityOrderStatus,
|
|
|
|
startPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
showNotification,
|
|
|
|
destinationAddress,
|
|
|
|
outputTx
|
|
|
|
};
|
|
|
|
|
2018-01-02 18:04:50 +00:00
|
|
|
const SupportProps = {
|
|
|
|
origin,
|
|
|
|
destination,
|
|
|
|
destinationAddress,
|
|
|
|
paymentAddress,
|
|
|
|
reference,
|
|
|
|
provider,
|
|
|
|
shapeshiftRates,
|
|
|
|
bityRates
|
|
|
|
};
|
|
|
|
|
2017-09-25 02:06:28 +00:00
|
|
|
return (
|
2018-01-11 18:04:11 +00:00
|
|
|
<TabSection isUnavailableOffline={true}>
|
2017-09-29 02:09:01 +00:00
|
|
|
<section className="Tab-content swap-tab">
|
2018-01-22 12:24:05 +00:00
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
exact={true}
|
|
|
|
path={`${currentPath}`}
|
|
|
|
render={() => (
|
|
|
|
<React.Fragment>
|
2018-02-25 01:29:34 +00:00
|
|
|
{step === 1 && <CurrentRates />}
|
2018-01-22 12:24:05 +00:00
|
|
|
{(step === 2 || step === 3) && <SwapInfoHeader {...SwapInfoHeaderProps} />}
|
|
|
|
<main className="Tab-content-pane">
|
|
|
|
{step === 1 && <CurrencySwap {...CurrencySwapProps} />}
|
|
|
|
{step === 2 && <ReceivingAddress {...ReceivingAddressProps} />}
|
|
|
|
{step === 3 && <PartThree {...PartThreeProps} />}
|
|
|
|
</main>
|
|
|
|
</React.Fragment>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<RouteNotFound />
|
|
|
|
</Switch>
|
2017-09-29 02:09:01 +00:00
|
|
|
</section>
|
2018-01-02 18:04:50 +00:00
|
|
|
<SupportFooter {...SupportProps} />
|
2017-10-04 04:13:49 +00:00
|
|
|
</TabSection>
|
2017-09-25 02:06:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function mapStateToProps(state: AppState) {
|
|
|
|
return {
|
|
|
|
step: state.swap.step,
|
2017-12-11 17:44:53 +00:00
|
|
|
origin: state.swap.origin,
|
|
|
|
destination: state.swap.destination,
|
2017-09-25 02:06:28 +00:00
|
|
|
bityRates: state.swap.bityRates,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftRates: state.swap.shapeshiftRates,
|
|
|
|
provider: state.swap.provider,
|
2017-12-11 17:44:53 +00:00
|
|
|
options: state.swap.options,
|
2017-09-25 02:06:28 +00:00
|
|
|
bityOrder: state.swap.bityOrder,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrder: state.swap.shapeshiftOrder,
|
2017-09-25 02:06:28 +00:00
|
|
|
destinationAddress: state.swap.destinationAddress,
|
|
|
|
isFetchingRates: state.swap.isFetchingRates,
|
|
|
|
secondsRemaining: state.swap.secondsRemaining,
|
|
|
|
outputTx: state.swap.outputTx,
|
|
|
|
isPostingOrder: state.swap.isPostingOrder,
|
2018-01-02 18:04:50 +00:00
|
|
|
bityOrderStatus: state.swap.bityOrderStatus,
|
|
|
|
shapeshiftOrderStatus: state.swap.shapeshiftOrderStatus,
|
2018-01-11 18:04:11 +00:00
|
|
|
paymentAddress: state.swap.paymentAddress,
|
2018-02-12 20:43:07 +00:00
|
|
|
isOffline: getOffline(state)
|
2017-09-25 02:06:28 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, {
|
|
|
|
changeStepSwap: dChangeStepSwap,
|
2017-12-11 17:44:53 +00:00
|
|
|
initSwap: dInitSwap,
|
|
|
|
bityOrderCreateRequestedSwap: dBityOrderCreateRequestedSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
shapeshiftOrderCreateRequestedSwap: dShapeshiftOrderCreateRequestedSwap,
|
2017-12-11 17:44:53 +00:00
|
|
|
destinationAddressSwap: dDestinationAddressSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
restartSwap: dRestartSwap,
|
|
|
|
startOrderTimerSwap: dStartOrderTimerSwap,
|
|
|
|
startPollBityOrderStatus: dStartPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
startPollShapeshiftOrderStatus: dStartPollShapeshiftOrderStatus,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopLoadBityRatesSwap: dStopLoadBityRatesSwap,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopLoadShapeshiftRatesSwap: dStopLoadShapeshiftRatesSwap,
|
2017-09-25 02:06:28 +00:00
|
|
|
stopOrderTimerSwap: dStopOrderTimerSwap,
|
|
|
|
stopPollBityOrderStatus: dStopPollBityOrderStatus,
|
2018-01-02 18:04:50 +00:00
|
|
|
stopPollShapeshiftOrderStatus: dStopPollShapeshiftOrderStatus,
|
|
|
|
showNotification: dShowNotification,
|
|
|
|
swapProvider: dChangeSwapProvider
|
2017-09-25 02:06:28 +00:00
|
|
|
})(Swap);
|