Merge pull request #671 from 0xProject/refactor/move-spawn-switch-to-utils
Move spawnSwitchErr to @0xproject/utils
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
export const utils = {
|
||||
spawnSwitchErr(name: string, value: any): Error {
|
||||
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
|
||||
},
|
||||
getCurrentUnixTimestampSec(): BigNumber {
|
||||
const milisecondsInSecond = 1000;
|
||||
return new BigNumber(Date.now() / milisecondsInSecond).round();
|
||||
|
||||
@@ -14,7 +14,7 @@ import {
|
||||
Provider,
|
||||
SignedOrder,
|
||||
} from '@0xproject/types';
|
||||
import { intervalUtils } from '@0xproject/utils';
|
||||
import { errorUtils, intervalUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@@ -39,7 +39,6 @@ import {
|
||||
} from '../generated_contract_wrappers/token';
|
||||
import { OnOrderStateChangeCallback, OrderWatcherConfig, OrderWatcherError } from '../types';
|
||||
import { assert } from '../utils/assert';
|
||||
import { utils } from '../utils/utils';
|
||||
|
||||
import { EventWatcher } from './event_watcher';
|
||||
import { ExpirationWatcher } from './expiration_watcher';
|
||||
@@ -344,7 +343,7 @@ export class OrderWatcher {
|
||||
return; // noop
|
||||
|
||||
default:
|
||||
throw utils.spawnSwitchErr('decodedLog.event', decodedLog.event);
|
||||
throw errorUtils.spawnSwitchErr('decodedLog.event', decodedLog.event);
|
||||
}
|
||||
}
|
||||
private async _emitRevalidateOrdersAsync(orderHashes: string[]): Promise<void> {
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
|
||||
export const utils = {
|
||||
spawnSwitchErr(name: string, value: any): Error {
|
||||
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
|
||||
},
|
||||
getCurrentUnixTimestampSec(): BigNumber {
|
||||
const milisecondsInASecond = 1000;
|
||||
return new BigNumber(Date.now() / milisecondsInASecond).round();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { colors, constants as sharedConstants, utils as sharedUtils } from '@0xproject/react-shared';
|
||||
import { errorUtils } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
import { Link as ScrollLink } from 'react-scroll';
|
||||
@@ -6,7 +7,6 @@ import * as ReactTooltip from 'react-tooltip';
|
||||
|
||||
import { DocsInfo } from '../docs_info';
|
||||
import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types';
|
||||
import { utils } from '../utils/utils';
|
||||
|
||||
import { Signature } from './signature';
|
||||
import { TypeDefinition } from './type_definition';
|
||||
@@ -129,7 +129,7 @@ export function Type(props: TypeProps): any {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw utils.spawnSwitchErr('type.typeDocType', type.typeDocType);
|
||||
throw errorUtils.spawnSwitchErr('type.typeDocType', type.typeDocType);
|
||||
}
|
||||
// HACK: Normalize BigNumber to simply BigNumber. For some reason the type
|
||||
// name is unpredictably one or the other.
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { AnchorTitle, colors, HeaderSizes } from '@0xproject/react-shared';
|
||||
import { errorUtils } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
import * as React from 'react';
|
||||
|
||||
import { DocsInfo } from '../docs_info';
|
||||
import { CustomType, CustomTypeChild, KindString, TypeDocTypes } from '../types';
|
||||
import { constants } from '../utils/constants';
|
||||
import { utils } from '../utils/utils';
|
||||
|
||||
import { Comment } from './comment';
|
||||
import { CustomEnum } from './custom_enum';
|
||||
@@ -96,7 +96,7 @@ export class TypeDefinition extends React.Component<TypeDefinitionProps, TypeDef
|
||||
break;
|
||||
|
||||
default:
|
||||
throw utils.spawnSwitchErr('type.kindString', customType.kindString);
|
||||
throw errorUtils.spawnSwitchErr('type.kindString', customType.kindString);
|
||||
}
|
||||
|
||||
const typeDefinitionAnchorId = `${this.props.sectionName}-${customType.name}`;
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { errorUtils } from '@0xproject/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { DocsInfo } from '../docs_info';
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
TypescriptFunction,
|
||||
TypescriptMethod,
|
||||
} from '../types';
|
||||
import { utils } from '../utils/utils';
|
||||
|
||||
export const typeDocUtils = {
|
||||
isType(entity: TypeDocNode): boolean {
|
||||
@@ -197,7 +197,7 @@ export const typeDocUtils = {
|
||||
break;
|
||||
|
||||
default:
|
||||
throw utils.spawnSwitchErr('kindString', entity.kindString);
|
||||
throw errorUtils.spawnSwitchErr('kindString', entity.kindString);
|
||||
}
|
||||
});
|
||||
return docSection;
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
[
|
||||
{
|
||||
"version": "0.6.3",
|
||||
"changes": [
|
||||
{
|
||||
"note": "Added errorUtils.spawnSwitchErr"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"timestamp": 1527009133,
|
||||
"version": "0.6.2",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export const utils = {
|
||||
export const errorUtils = {
|
||||
spawnSwitchErr(name: string, value: any): Error {
|
||||
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
|
||||
},
|
||||
@@ -7,3 +7,4 @@ export { AbiDecoder } from './abi_decoder';
|
||||
export { logUtils } from './log_utils';
|
||||
export { abiUtils } from './abi_utils';
|
||||
export { NULL_BYTES } from './constants';
|
||||
export { errorUtils } from './error_utils';
|
||||
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
Styles,
|
||||
utils as sharedUtils,
|
||||
} from '@0xproject/react-shared';
|
||||
import { BigNumber, logUtils } from '@0xproject/utils';
|
||||
import { BigNumber, errorUtils, logUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import Dialog from 'material-ui/Dialog';
|
||||
@@ -500,7 +500,7 @@ export class TokenBalances extends React.Component<TokenBalancesProps, TokenBala
|
||||
return null; // No error to show
|
||||
|
||||
default:
|
||||
throw utils.spawnSwitchErr('errorType', this.state.errorType);
|
||||
throw errorUtils.spawnSwitchErr('errorType', this.state.errorType);
|
||||
}
|
||||
}
|
||||
private _onErrorOccurred(errorType: BalanceErrs): void {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { colors } from '@0xproject/react-shared';
|
||||
import { errorUtils } from '@0xproject/utils';
|
||||
import RaisedButton from 'material-ui/RaisedButton';
|
||||
import * as React from 'react';
|
||||
import { utils } from 'ts/utils/utils';
|
||||
|
||||
const COMPLETE_STATE_SHOW_LENGTH_MS = 2000;
|
||||
|
||||
@@ -62,7 +62,7 @@ export class LifeCycleRaisedButton extends React.Component<LifeCycleRaisedButton
|
||||
label = this.props.labelComplete;
|
||||
break;
|
||||
default:
|
||||
throw utils.spawnSwitchErr('ButtonState', this.state.buttonState);
|
||||
throw errorUtils.spawnSwitchErr('ButtonState', this.state.buttonState);
|
||||
}
|
||||
return (
|
||||
<RaisedButton
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EtherscanLinkSuffixes, Styles, utils as sharedUtils } from '@0xproject/react-shared';
|
||||
import { BigNumber } from '@0xproject/utils';
|
||||
import { BigNumber, errorUtils } from '@0xproject/utils';
|
||||
import { Web3Wrapper } from '@0xproject/web3-wrapper';
|
||||
import * as _ from 'lodash';
|
||||
import CircularProgress from 'material-ui/CircularProgress';
|
||||
@@ -491,7 +491,7 @@ export class Wallet extends React.Component<WalletProps, WalletState> {
|
||||
buttonIconName = 'zmdi-long-arrow-up';
|
||||
break;
|
||||
default:
|
||||
throw utils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection);
|
||||
throw errorUtils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection);
|
||||
}
|
||||
}
|
||||
const onClick = isWrappedEtherDirectionOpen
|
||||
|
||||
@@ -33,9 +33,6 @@ export const utils = {
|
||||
throw new Error(message);
|
||||
}
|
||||
},
|
||||
spawnSwitchErr(name: string, value: any): Error {
|
||||
return new Error(`Unexpected switch value: ${value} encountered for ${name}`);
|
||||
},
|
||||
isNumeric(n: string): boolean {
|
||||
return !isNaN(parseFloat(n)) && isFinite(Number(n));
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user