From cf8fdd3a701f21bfc3b2ec8397fa65948f5cdc78 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Wed, 6 Jun 2018 16:26:04 +0200 Subject: Move spawnSwitchErr to @0xproject/utils --- packages/contract-wrappers/src/utils/utils.ts | 3 --- packages/order-watcher/src/order_watcher/order_watcher.ts | 4 ++-- packages/order-watcher/src/utils/utils.ts | 3 --- packages/react-docs/src/components/custom_enum.tsx | 1 - packages/react-docs/src/components/documentation.tsx | 1 - packages/react-docs/src/components/type.tsx | 4 ++-- packages/react-docs/src/components/type_definition.tsx | 4 ++-- packages/react-docs/src/utils/typedoc_utils.ts | 4 ++-- packages/react-docs/src/utils/utils.ts | 5 ----- packages/utils/CHANGELOG.json | 8 ++++++++ packages/utils/src/error_utils.ts | 5 +++++ packages/utils/src/index.ts | 1 + packages/website/ts/components/token_balances.tsx | 4 ++-- packages/website/ts/components/ui/lifecycle_raised_button.tsx | 3 ++- packages/website/ts/components/wallet/wallet.tsx | 4 ++-- packages/website/ts/utils/utils.ts | 3 --- 16 files changed, 28 insertions(+), 29 deletions(-) delete mode 100644 packages/react-docs/src/utils/utils.ts create mode 100644 packages/utils/src/error_utils.ts (limited to 'packages') diff --git a/packages/contract-wrappers/src/utils/utils.ts b/packages/contract-wrappers/src/utils/utils.ts index 7cf9450a0..689a7ee0a 100644 --- a/packages/contract-wrappers/src/utils/utils.ts +++ b/packages/contract-wrappers/src/utils/utils.ts @@ -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(); diff --git a/packages/order-watcher/src/order_watcher/order_watcher.ts b/packages/order-watcher/src/order_watcher/order_watcher.ts index 29936a066..498ec5357 100644 --- a/packages/order-watcher/src/order_watcher/order_watcher.ts +++ b/packages/order-watcher/src/order_watcher/order_watcher.ts @@ -14,7 +14,7 @@ import { Provider, SignedOrder, } from '@0xproject/types'; -import { AbiDecoder, intervalUtils } from '@0xproject/utils'; +import { AbiDecoder, errorUtils, intervalUtils } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import * as _ from 'lodash'; @@ -344,7 +344,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 { diff --git a/packages/order-watcher/src/utils/utils.ts b/packages/order-watcher/src/utils/utils.ts index d34f6b99f..087fc635e 100644 --- a/packages/order-watcher/src/utils/utils.ts +++ b/packages/order-watcher/src/utils/utils.ts @@ -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(); diff --git a/packages/react-docs/src/components/custom_enum.tsx b/packages/react-docs/src/components/custom_enum.tsx index 797372f35..c4252d9e2 100644 --- a/packages/react-docs/src/components/custom_enum.tsx +++ b/packages/react-docs/src/components/custom_enum.tsx @@ -3,7 +3,6 @@ import * as _ from 'lodash'; import * as React from 'react'; import { CustomType } from '../types'; -import { utils } from '../utils/utils'; const STRING_ENUM_CODE_PREFIX = ' strEnum('; diff --git a/packages/react-docs/src/components/documentation.tsx b/packages/react-docs/src/components/documentation.tsx index 25687db67..f34d9f1fb 100644 --- a/packages/react-docs/src/components/documentation.tsx +++ b/packages/react-docs/src/components/documentation.tsx @@ -29,7 +29,6 @@ import { TypescriptMethod, } from '../types'; import { constants } from '../utils/constants'; -import { utils } from '../utils/utils'; import { Badge } from './badge'; import { Comment } from './comment'; diff --git a/packages/react-docs/src/components/type.tsx b/packages/react-docs/src/components/type.tsx index 2b7b49672..007d7da3e 100644 --- a/packages/react-docs/src/components/type.tsx +++ b/packages/react-docs/src/components/type.tsx @@ -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'; @@ -7,7 +8,6 @@ import * as ReactTooltip from 'react-tooltip'; import { DocsInfo } from '../docs_info'; import { Type as TypeDef, TypeDefinitionByName, TypeDocTypes } from '../types'; import { constants } from '../utils/constants'; -import { utils } from '../utils/utils'; import { Signature } from './signature'; import { TypeDefinition } from './type_definition'; @@ -140,7 +140,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. diff --git a/packages/react-docs/src/components/type_definition.tsx b/packages/react-docs/src/components/type_definition.tsx index a8e601ac2..f11b8f973 100644 --- a/packages/react-docs/src/components/type_definition.tsx +++ b/packages/react-docs/src/components/type_definition.tsx @@ -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, EnumValue, 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 { buttonIconName = 'zmdi-long-arrow-up'; break; default: - throw utils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection); + throw errorUtils.spawnSwitchErr('wrappedEtherDirection', wrappedEtherDirection); } } const onClick = isWrappedEtherDirectionOpen diff --git a/packages/website/ts/utils/utils.ts b/packages/website/ts/utils/utils.ts index b9d962b75..a802e16d7 100644 --- a/packages/website/ts/utils/utils.ts +++ b/packages/website/ts/utils/utils.ts @@ -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)); }, -- cgit v1.2.3