MyCrypto/common/containers/Tabs/Swap/components/CurrencySwap.tsx

289 lines
9.9 KiB
TypeScript
Raw Normal View History

2017-12-11 09:44:53 -08:00
import { TChangeStepSwap, TInitSwap } from 'actions/swap';
import { NormalizedBityRates, NormalizedOptions, SwapInput } from 'reducers/swap/types';
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 SimpleButton from 'components/ui/SimpleButton';
2017-12-11 09:44:53 -08:00
import bityConfig, { generateKindMax, generateKindMin, WhitelistedCoins } from 'config/bity';
import React, { Component } from 'react';
import translate from 'translations';
2017-12-11 09:44:53 -08:00
import { combineAndUpper } from 'utils/formatters';
import { Dropdown } from 'components/ui';
import Spinner from 'components/ui/Spinner';
2017-12-11 09:44:53 -08:00
import { without, intersection } from 'lodash';
import './CurrencySwap.scss';
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
export interface StateProps {
2017-12-11 09:44:53 -08:00
bityRates: NormalizedBityRates;
options: NormalizedOptions;
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
}
export interface ActionProps {
changeStepSwap: TChangeStepSwap;
2017-12-11 09:44:53 -08:00
initSwap: TInitSwap;
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 State {
disabled: boolean;
2017-12-11 09:44:53 -08:00
origin: SwapInput;
destination: SwapInput;
originKindOptions: WhitelistedCoins[];
destinationKindOptions: WhitelistedCoins[];
originErr: string;
destinationErr: string;
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
}
2017-12-11 09:44:53 -08:00
type Props = StateProps & ActionProps;
export default class CurrencySwap extends Component<Props, State> {
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
public state = {
disabled: true,
2017-12-11 09:44:53 -08:00
origin: { id: 'BTC', amount: NaN } as SwapInput,
destination: { id: 'ETH', amount: NaN } as SwapInput,
originKindOptions: ['BTC', 'ETH'] as WhitelistedCoins[],
destinationKindOptions: ['ETH'] as WhitelistedCoins[],
originErr: '',
destinationErr: ''
};
2017-12-11 09:44:53 -08:00
public componentDidUpdate(prevProps: Props, prevState: State) {
const { origin, destination } = this.state;
const { options } = this.props;
if (origin !== prevState.origin) {
this.setDisabled(origin, destination);
}
if (options.allIds !== prevProps.options.allIds) {
const originKindOptions: WhitelistedCoins[] = intersection<any>(
options.allIds,
this.state.originKindOptions
);
2017-12-11 09:44:53 -08:00
const destinationKindOptions: WhitelistedCoins[] = without<any>(options.allIds, origin.id);
this.setState({
originKindOptions,
destinationKindOptions
});
}
}
2017-12-11 09:44:53 -08:00
public getMinMax = (kind: WhitelistedCoins) => {
let min;
let max;
if (kind !== 'BTC') {
2017-12-11 09:44:53 -08:00
const bityPairRate = this.props.bityRates.byId['BTC' + kind].rate;
min = generateKindMin(bityPairRate, kind);
max = generateKindMax(bityPairRate, kind);
} else {
2017-12-11 09:44:53 -08:00
min = bityConfig.BTCMin;
max = bityConfig.BTCMax;
}
2017-12-11 09:44:53 -08:00
return { min, max };
};
2017-12-11 09:44:53 -08:00
public isMinMaxValid = (amount: number, kind: WhitelistedCoins) => {
const rate = this.getMinMax(kind);
const higherThanMin = amount >= rate.min;
const lowerThanMax = amount <= rate.max;
return higherThanMin && lowerThanMax;
};
2017-12-11 09:44:53 -08:00
public setDisabled(origin: SwapInput, destination: SwapInput) {
const amountsValid = origin.amount && destination.amount;
const minMaxValid = this.isMinMaxValid(origin.amount, origin.id);
2017-12-11 09:44:53 -08:00
const disabled = !(amountsValid && minMaxValid);
2017-12-11 09:44:53 -08:00
const createErrString = (kind: WhitelistedCoins, amount: number) => {
const rate = this.getMinMax(kind);
let errString;
if (amount > rate.max) {
errString = `Maximum ${rate.max} ${kind}`;
} else {
errString = `Minimum ${rate.min} ${kind}`;
}
return errString;
};
2017-12-11 09:44:53 -08:00
const showError = disabled && amountsValid;
const originErr = showError ? createErrString(origin.id, origin.amount) : '';
const destinationErr = showError ? createErrString(destination.id, destination.amount) : '';
2017-12-11 09:44:53 -08:00
this.setState({
disabled,
originErr,
destinationErr
});
}
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
public onClickStartSwap = () => {
2017-12-11 09:44:53 -08:00
const { origin, destination } = this.state;
const { changeStepSwap, initSwap } = this.props;
initSwap({ origin, destination });
changeStepSwap(2);
};
2017-12-11 09:44:53 -08:00
public setOriginAndDestinationToInitialVal = () => {
this.setState({
origin: { ...this.state.origin, amount: NaN },
destination: { ...this.state.destination, amount: NaN }
});
};
2017-12-11 09:44:53 -08:00
public updateOriginAmount = (origin: SwapInput, destination: SwapInput, amount: number) => {
if (amount || amount === 0) {
const pairName = combineAndUpper(origin.id, destination.id);
const bityRate = this.props.bityRates.byId[pairName].rate;
const destinationAmount = amount * bityRate;
this.setState({
origin: { ...this.state.origin, amount },
destination: { ...this.state.destination, amount: destinationAmount }
});
} else {
2017-12-11 09:44:53 -08:00
this.setOriginAndDestinationToInitialVal();
}
};
2017-12-11 09:44:53 -08:00
public updateDestinationAmount = (origin: SwapInput, destination: SwapInput, amount: number) => {
if (amount || amount === 0) {
const pairNameReversed = combineAndUpper(destination.id, origin.id);
const bityRate = this.props.bityRates.byId[pairNameReversed].rate;
const originAmount = amount * bityRate;
this.setState({
origin: { ...this.state.origin, amount: originAmount },
destination: {
...this.state.destination,
amount
}
});
} else {
2017-12-11 09:44:53 -08:00
this.setOriginAndDestinationToInitialVal();
}
};
2017-12-11 09:44:53 -08:00
public onChangeAmount = (event: React.SyntheticEvent<HTMLInputElement>) => {
const type = (event.target as HTMLInputElement).id;
const { origin, destination } = this.state;
const amount = parseFloat((event.target as HTMLInputElement).value);
type === 'origin-swap-input'
? this.updateOriginAmount(origin, destination, amount)
: this.updateDestinationAmount(origin, destination, amount);
};
public onChangeOriginKind = (newOption: WhitelistedCoins) => {
const { origin, destination, destinationKindOptions } = this.state;
const newDestinationAmount = () => {
const pairName = combineAndUpper(destination.id, origin.id);
const bityRate = this.props.bityRates.byId[pairName].rate;
return bityRate * origin.amount;
};
this.setState({
origin: { ...origin, id: newOption },
destination: {
id: newOption === destination.id ? origin.id : destination.id,
amount: newDestinationAmount() ? newDestinationAmount() : destination.amount
},
destinationKindOptions: without([...destinationKindOptions, origin.id], newOption)
});
};
public onChangeDestinationKind = (newOption: WhitelistedCoins) => {
const { origin, destination } = this.state;
const newOriginAmount = () => {
const pairName = combineAndUpper(newOption, origin.id);
const bityRate = this.props.bityRates.byId[pairName].rate;
return bityRate * destination.amount;
};
this.setState({
origin: {
...origin,
amount: newOriginAmount() ? newOriginAmount() : origin.amount
},
destination: { ...destination, id: newOption }
});
};
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
public render() {
2017-12-11 09:44:53 -08:00
const { bityRates } = this.props;
const {
2017-12-11 09:44:53 -08:00
origin,
destination,
originKindOptions,
2017-12-11 09:44:53 -08:00
destinationKindOptions,
originErr,
destinationErr
} = this.state;
2017-12-11 09:44:53 -08:00
const OriginKindDropDown = Dropdown as new () => Dropdown<any>;
const DestinationKindDropDown = Dropdown as new () => Dropdown<typeof destination.id>;
const pairName = combineAndUpper(origin.id, destination.id);
const bityLoaded = bityRates.byId[pairName] ? bityRates.byId[pairName].id : false;
return (
<article className="CurrencySwap">
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
<h1 className="CurrencySwap-title">{translate('SWAP_init_1')}</h1>
{bityLoaded ? (
<div className="form-inline CurrencySwap-inner-wrap">
<div className="CurrencySwap-input-group">
{originErr && <span className="CurrencySwap-error-message">{originErr}</span>}
<input
2017-12-11 09:44:53 -08:00
id="origin-swap-input"
className={`CurrencySwap-input form-control ${
2017-12-11 09:44:53 -08:00
String(origin.amount) !== '' && this.isMinMaxValid(origin.amount, origin.id)
? 'is-valid'
: 'is-invalid'
}`}
type="number"
placeholder="Amount"
2017-12-11 09:44:53 -08:00
value={isNaN(origin.amount) ? '' : origin.amount}
onChange={this.onChangeAmount}
/>
<div className="CurrencySwap-dropdown">
<OriginKindDropDown
2017-12-11 09:44:53 -08:00
ariaLabel={`change origin kind. current origin kind ${origin.id}`}
options={originKindOptions}
2017-12-11 09:44:53 -08:00
value={origin.id}
onChange={this.onChangeOriginKind}
color="default"
/>
</div>
</div>
<h1 className="CurrencySwap-divider">{translate('SWAP_init_2')}</h1>
<div className="CurrencySwap-input-group">
{destinationErr && (
<span className="CurrencySwap-error-message">{destinationErr}</span>
)}
<input
2017-12-11 09:44:53 -08:00
id="destination-swap-input"
className={`CurrencySwap-input form-control ${
2017-12-11 09:44:53 -08:00
String(destination.amount) !== '' && this.isMinMaxValid(origin.amount, origin.id)
? 'is-valid'
: 'is-invalid'
}`}
type="number"
placeholder="Amount"
2017-12-11 09:44:53 -08:00
value={isNaN(destination.amount) ? '' : destination.amount}
onChange={this.onChangeAmount}
/>
<div className="CurrencySwap-dropdown">
<DestinationKindDropDown
2017-12-11 09:44:53 -08:00
ariaLabel={`change destination kind. current destination kind ${destination.id}`}
options={destinationKindOptions}
2017-12-11 09:44:53 -08:00
value={destination.id}
onChange={this.onChangeDestinationKind}
color="default"
/>
</div>
</div>
</div>
) : (
<Spinner />
)}
<div className="CurrencySwap-submit">
<SimpleButton
onClick={this.onClickStartSwap}
text={translate('SWAP_init_CTA')}
disabled={this.state.disabled}
type="primary"
/>
</div>
</article>
);
}
}