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

247 lines
7.2 KiB
TypeScript
Raw Normal View History

Migrate to Typescript (#224) * Refactor babel/types * Refactor entry point * Refactor actions * Refactor api * Full project refactor -- Broad type fixing sweep * - completely fix merge conflicts - handle various type errors * Add tslint to package.json * Dependency cleanup * Fix module resolution * Work on type definitions for untyped libs * progress commit * Add more definition typing * various type additions * Add unit types * Fix sagaiterator + unit types * various types added * additional type additions * Fix typing on Sagas * remove flowfixmes; swap translate for translateRaw * Get rid of contracts - awaiting Henry's contract PR * Remove contracts from routing * Fix most of actions/reducers * refactor actions directory structure * fix reducer action type imports * Fix most of type errors pre-actions refactor * fix action creator imports in containers * Refactor more * Refactor index of actions * fix action imports; use module level index export * package-lock.json updated * Use action types in props * Type up action creators * Fix most of connect errors * Typefixing progress * More types * Fix run-time errors * Caching improvements for webpack * Remove path resolve from webpack * Update non-breaking packages to latest version * Fix token typing * Remove unused color code * Fix wallet decrypt dispatch * Set redux-form related props/functions to ANY, since we're stripping it out later on * Revert BigNumber.js package changes * Extend window to custom object for Perf * Format Navigation * Typecase keystore errors as any (since we shouldnt touch this) * Push wallet context fix * - find/replace value->payload in swap - properly type swap state properties - extract inline reducer into reducer function * - type local storage retrieved items as generic * - bind all RPCClient methods with fat arrow * - reformat * Change to enums for constants * Change state into any * Fix swap errors * ensure that seconds are passed into state as integers * Fix rest of errors * use parseInt explicitly instead of type coercion * Fix derivation-checker, remove flow command, add tslint command, add tslint-react, tell travis to use tslint instead of flow. * Whoops, remove those tests. * Remove unsupported (yet) config option. * Fix precommit to target ts and tsx files. * Fix some errors, ignore some silly rules. * Revert jest to v19, use ts-jest and make all tests typescript. Fixes all but one. * Get rid of saga tests * Fix tslint errors
2017-09-24 19:06:28 -07:00
import {
showNotification as dShowNotification,
TShowNotification
} from 'actions/notifications';
import {
bityOrderCreateRequestedSwap as dBityOrderCreateRequestedSwap,
changeStepSwap as dChangeStepSwap,
destinationAddressSwap as dDestinationAddressSwap,
destinationAmountSwap as dDestinationAmountSwap,
destinationKindSwap as dDestinationKindSwap,
loadBityRatesRequestedSwap as dLoadBityRatesRequestedSwap,
originAmountSwap as dOriginAmountSwap,
originKindSwap as dOriginKindSwap,
restartSwap as dRestartSwap,
startOrderTimerSwap as dStartOrderTimerSwap,
startPollBityOrderStatus as dStartPollBityOrderStatus,
stopLoadBityRatesSwap as dStopLoadBityRatesSwap,
stopOrderTimerSwap as dStopOrderTimerSwap,
stopPollBityOrderStatus as dStopPollBityOrderStatus,
TBityOrderCreateRequestedSwap,
TChangeStepSwap,
TDestinationAddressSwap,
TDestinationAmountSwap,
TDestinationKindSwap,
TLoadBityRatesRequestedSwap,
TOriginAmountSwap,
TOriginKindSwap,
TRestartSwap,
TStartOrderTimerSwap,
TStartPollBityOrderStatus,
TStopLoadBityRatesSwap,
TStopOrderTimerSwap,
TStopPollBityOrderStatus
} from 'actions/swap';
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';
import ReceivingAddress from './components/ReceivingAddress';
import SwapInfoHeader from './components/SwapInfoHeader';
import App from 'containers/App';
Migrate to Typescript (#224) * Refactor babel/types * Refactor entry point * Refactor actions * Refactor api * Full project refactor -- Broad type fixing sweep * - completely fix merge conflicts - handle various type errors * Add tslint to package.json * Dependency cleanup * Fix module resolution * Work on type definitions for untyped libs * progress commit * Add more definition typing * various type additions * Add unit types * Fix sagaiterator + unit types * various types added * additional type additions * Fix typing on Sagas * remove flowfixmes; swap translate for translateRaw * Get rid of contracts - awaiting Henry's contract PR * Remove contracts from routing * Fix most of actions/reducers * refactor actions directory structure * fix reducer action type imports * Fix most of type errors pre-actions refactor * fix action creator imports in containers * Refactor more * Refactor index of actions * fix action imports; use module level index export * package-lock.json updated * Use action types in props * Type up action creators * Fix most of connect errors * Typefixing progress * More types * Fix run-time errors * Caching improvements for webpack * Remove path resolve from webpack * Update non-breaking packages to latest version * Fix token typing * Remove unused color code * Fix wallet decrypt dispatch * Set redux-form related props/functions to ANY, since we're stripping it out later on * Revert BigNumber.js package changes * Extend window to custom object for Perf * Format Navigation * Typecase keystore errors as any (since we shouldnt touch this) * Push wallet context fix * - find/replace value->payload in swap - properly type swap state properties - extract inline reducer into reducer function * - type local storage retrieved items as generic * - bind all RPCClient methods with fat arrow * - reformat * Change to enums for constants * Change state into any * Fix swap errors * ensure that seconds are passed into state as integers * Fix rest of errors * use parseInt explicitly instead of type coercion * Fix derivation-checker, remove flow command, add tslint command, add tslint-react, tell travis to use tslint instead of flow. * Whoops, remove those tests. * Remove unsupported (yet) config option. * Fix precommit to target ts and tsx files. * Fix some errors, ignore some silly rules. * Revert jest to v19, use ts-jest and make all tests typescript. Fixes all but one. * Get rid of saga tests * Fix tslint errors
2017-09-24 19:06:28 -07:00
interface ReduxStateProps {
originAmount: number | null;
destinationAmount: number | null;
originKind: string;
destinationKind: string;
destinationKindOptions: string[];
originKindOptions: string[];
step: number;
bityRates: any;
bityOrder: any;
destinationAddress: string;
isFetchingRates: boolean | null;
secondsRemaining: number | null;
outputTx: string | null;
isPostingOrder: boolean;
orderStatus: string | null;
paymentAddress: string | null;
}
interface ReduxActionProps {
changeStepSwap: TChangeStepSwap;
originKindSwap: TOriginKindSwap;
destinationKindSwap: TDestinationKindSwap;
originAmountSwap: TOriginAmountSwap;
destinationAmountSwap: TDestinationAmountSwap;
loadBityRatesRequestedSwap: TLoadBityRatesRequestedSwap;
destinationAddressSwap: TDestinationAddressSwap;
restartSwap: TRestartSwap;
stopLoadBityRatesSwap: TStopLoadBityRatesSwap;
bityOrderCreateRequestedSwap: TBityOrderCreateRequestedSwap;
startPollBityOrderStatus: TStartPollBityOrderStatus;
stopOrderTimerSwap: TStopOrderTimerSwap;
stopPollBityOrderStatus: TStopPollBityOrderStatus;
showNotification: TShowNotification;
startOrderTimerSwap: TStartOrderTimerSwap;
}
class Swap extends Component<ReduxActionProps & ReduxStateProps, {}> {
public componentDidMount() {
// TODO: Use `isFetchingRates` to show a loader
this.props.loadBityRatesRequestedSwap();
}
public componentWillUnmount() {
this.props.stopLoadBityRatesSwap();
}
public render() {
const {
// STATE
bityRates,
originAmount,
destinationAmount,
originKind,
destinationKind,
destinationKindOptions,
originKindOptions,
destinationAddress,
step,
bityOrder,
secondsRemaining,
paymentAddress,
orderStatus,
isPostingOrder,
outputTx,
// ACTIONS
restartSwap,
stopLoadBityRatesSwap,
changeStepSwap,
originKindSwap,
destinationKindSwap,
originAmountSwap,
destinationAmountSwap,
destinationAddressSwap,
bityOrderCreateRequestedSwap,
showNotification,
startOrderTimerSwap,
startPollBityOrderStatus,
stopOrderTimerSwap,
stopPollBityOrderStatus
} = this.props;
const { reference } = bityOrder;
const ReceivingAddressProps = {
isPostingOrder,
originAmount,
originKind,
destinationKind,
destinationAddressSwap,
destinationAddress,
stopLoadBityRatesSwap,
changeStepSwap,
bityOrderCreateRequestedSwap
};
const SwapInfoHeaderProps = {
reference,
secondsRemaining,
originAmount,
originKind,
destinationKind,
destinationAmount,
restartSwap,
orderStatus
};
const { ETHBTC, ETHREP, BTCETH, BTCREP } = bityRates;
const CurrentRatesProps = { ETHBTC, ETHREP, BTCETH, BTCREP };
const CurrencySwapProps = {
showNotification,
bityRates,
originAmount,
destinationAmount,
originKind,
destinationKind,
destinationKindOptions,
originKindOptions,
originKindSwap,
destinationKindSwap,
originAmountSwap,
destinationAmountSwap,
changeStepSwap
};
const PaymentInfoProps = {
originKind,
originAmount,
paymentAddress
};
const PartThreeProps = {
...SwapInfoHeaderProps,
...PaymentInfoProps,
reference,
startOrderTimerSwap,
startPollBityOrderStatus,
stopOrderTimerSwap,
stopPollBityOrderStatus,
showNotification,
destinationAddress,
outputTx
};
return (
<App>
<section className="Tab-content swap-tab">
{step === 1 && <CurrentRates {...CurrentRatesProps} />}
{(step === 2 || step === 3) && (
<SwapInfoHeader {...SwapInfoHeaderProps} />
)}
Migrate to Typescript (#224) * Refactor babel/types * Refactor entry point * Refactor actions * Refactor api * Full project refactor -- Broad type fixing sweep * - completely fix merge conflicts - handle various type errors * Add tslint to package.json * Dependency cleanup * Fix module resolution * Work on type definitions for untyped libs * progress commit * Add more definition typing * various type additions * Add unit types * Fix sagaiterator + unit types * various types added * additional type additions * Fix typing on Sagas * remove flowfixmes; swap translate for translateRaw * Get rid of contracts - awaiting Henry's contract PR * Remove contracts from routing * Fix most of actions/reducers * refactor actions directory structure * fix reducer action type imports * Fix most of type errors pre-actions refactor * fix action creator imports in containers * Refactor more * Refactor index of actions * fix action imports; use module level index export * package-lock.json updated * Use action types in props * Type up action creators * Fix most of connect errors * Typefixing progress * More types * Fix run-time errors * Caching improvements for webpack * Remove path resolve from webpack * Update non-breaking packages to latest version * Fix token typing * Remove unused color code * Fix wallet decrypt dispatch * Set redux-form related props/functions to ANY, since we're stripping it out later on * Revert BigNumber.js package changes * Extend window to custom object for Perf * Format Navigation * Typecase keystore errors as any (since we shouldnt touch this) * Push wallet context fix * - find/replace value->payload in swap - properly type swap state properties - extract inline reducer into reducer function * - type local storage retrieved items as generic * - bind all RPCClient methods with fat arrow * - reformat * Change to enums for constants * Change state into any * Fix swap errors * ensure that seconds are passed into state as integers * Fix rest of errors * use parseInt explicitly instead of type coercion * Fix derivation-checker, remove flow command, add tslint command, add tslint-react, tell travis to use tslint instead of flow. * Whoops, remove those tests. * Remove unsupported (yet) config option. * Fix precommit to target ts and tsx files. * Fix some errors, ignore some silly rules. * Revert jest to v19, use ts-jest and make all tests typescript. Fixes all but one. * Get rid of saga tests * Fix tslint errors
2017-09-24 19:06:28 -07:00
<main className="Tab-content-pane">
{step === 1 && <CurrencySwap {...CurrencySwapProps} />}
{step === 2 && <ReceivingAddress {...ReceivingAddressProps} />}
{step === 3 && <PartThree {...PartThreeProps} />}
</main>
</section>
</App>
Migrate to Typescript (#224) * Refactor babel/types * Refactor entry point * Refactor actions * Refactor api * Full project refactor -- Broad type fixing sweep * - completely fix merge conflicts - handle various type errors * Add tslint to package.json * Dependency cleanup * Fix module resolution * Work on type definitions for untyped libs * progress commit * Add more definition typing * various type additions * Add unit types * Fix sagaiterator + unit types * various types added * additional type additions * Fix typing on Sagas * remove flowfixmes; swap translate for translateRaw * Get rid of contracts - awaiting Henry's contract PR * Remove contracts from routing * Fix most of actions/reducers * refactor actions directory structure * fix reducer action type imports * Fix most of type errors pre-actions refactor * fix action creator imports in containers * Refactor more * Refactor index of actions * fix action imports; use module level index export * package-lock.json updated * Use action types in props * Type up action creators * Fix most of connect errors * Typefixing progress * More types * Fix run-time errors * Caching improvements for webpack * Remove path resolve from webpack * Update non-breaking packages to latest version * Fix token typing * Remove unused color code * Fix wallet decrypt dispatch * Set redux-form related props/functions to ANY, since we're stripping it out later on * Revert BigNumber.js package changes * Extend window to custom object for Perf * Format Navigation * Typecase keystore errors as any (since we shouldnt touch this) * Push wallet context fix * - find/replace value->payload in swap - properly type swap state properties - extract inline reducer into reducer function * - type local storage retrieved items as generic * - bind all RPCClient methods with fat arrow * - reformat * Change to enums for constants * Change state into any * Fix swap errors * ensure that seconds are passed into state as integers * Fix rest of errors * use parseInt explicitly instead of type coercion * Fix derivation-checker, remove flow command, add tslint command, add tslint-react, tell travis to use tslint instead of flow. * Whoops, remove those tests. * Remove unsupported (yet) config option. * Fix precommit to target ts and tsx files. * Fix some errors, ignore some silly rules. * Revert jest to v19, use ts-jest and make all tests typescript. Fixes all but one. * Get rid of saga tests * Fix tslint errors
2017-09-24 19:06:28 -07:00
);
}
}
function mapStateToProps(state: AppState) {
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,
step: state.swap.step,
bityRates: state.swap.bityRates,
bityOrder: state.swap.bityOrder,
destinationAddress: state.swap.destinationAddress,
isFetchingRates: state.swap.isFetchingRates,
secondsRemaining: state.swap.secondsRemaining,
outputTx: state.swap.outputTx,
isPostingOrder: state.swap.isPostingOrder,
orderStatus: state.swap.orderStatus,
paymentAddress: state.swap.paymentAddress
};
}
export default connect(mapStateToProps, {
bityOrderCreateRequestedSwap: dBityOrderCreateRequestedSwap,
changeStepSwap: dChangeStepSwap,
destinationAddressSwap: dDestinationAddressSwap,
destinationAmountSwap: dDestinationAmountSwap,
destinationKindSwap: dDestinationKindSwap,
loadBityRatesRequestedSwap: dLoadBityRatesRequestedSwap,
originAmountSwap: dOriginAmountSwap,
originKindSwap: dOriginKindSwap,
restartSwap: dRestartSwap,
startOrderTimerSwap: dStartOrderTimerSwap,
startPollBityOrderStatus: dStartPollBityOrderStatus,
stopLoadBityRatesSwap: dStopLoadBityRatesSwap,
stopOrderTimerSwap: dStopOrderTimerSwap,
stopPollBityOrderStatus: dStopPollBityOrderStatus,
showNotification: dShowNotification
})(Swap);