diff options
Diffstat (limited to 'packages')
-rw-r--r-- | packages/connect/package.json | 1 | ||||
-rw-r--r-- | packages/connect/src/utils/relayer_response_json_parsers.ts | 5 | ||||
-rw-r--r-- | packages/connect/src/utils/type_converters.ts | 26 | ||||
-rw-r--r-- | packages/order-utils/src/index.ts | 1 | ||||
-rw-r--r-- | packages/order-utils/src/parsing_utils.ts | 27 | ||||
-rw-r--r-- | packages/website/package.json | 2 | ||||
-rw-r--r-- | packages/website/ts/blockchain.ts | 3 | ||||
-rw-r--r-- | packages/website/ts/components/generate_order/generate_order_form.tsx | 2 | ||||
-rw-r--r-- | packages/website/ts/components/order_json.tsx | 1 | ||||
-rw-r--r-- | packages/website/ts/containers/generate_order_form.ts | 1 | ||||
-rw-r--r-- | packages/website/ts/redux/dispatcher.ts | 1 | ||||
-rw-r--r-- | packages/website/ts/redux/reducer.ts | 1 | ||||
-rw-r--r-- | packages/website/ts/types.ts | 2 | ||||
-rw-r--r-- | packages/website/ts/utils/order_parser.ts | 33 |
14 files changed, 42 insertions, 64 deletions
diff --git a/packages/connect/package.json b/packages/connect/package.json index 543852350..04daaea97 100644 --- a/packages/connect/package.json +++ b/packages/connect/package.json @@ -45,6 +45,7 @@ "dependencies": { "@0xproject/assert": "^1.0.7", "@0xproject/json-schemas": "^1.0.1-rc.6", + "@0xproject/order-utils": "^1.0.1-rc.6", "@0xproject/types": "^1.0.1-rc.6", "@0xproject/typescript-typings": "^1.0.5", "@0xproject/utils": "^1.0.7", diff --git a/packages/connect/src/utils/relayer_response_json_parsers.ts b/packages/connect/src/utils/relayer_response_json_parsers.ts index ebd877b70..bc31f231d 100644 --- a/packages/connect/src/utils/relayer_response_json_parsers.ts +++ b/packages/connect/src/utils/relayer_response_json_parsers.ts @@ -1,5 +1,6 @@ import { assert } from '@0xproject/assert'; import { schemas } from '@0xproject/json-schemas'; +import { orderParsingUtils } from '@0xproject/order-utils'; import { APIOrder, @@ -19,7 +20,7 @@ export const relayerResponseJsonParsers = { }, parseAssetPairsItemsJson(json: any): AssetPairsItem[] { return json.map((assetDataPair: any) => { - return typeConverters.convertStringsFieldsToBigNumbers(assetDataPair, [ + return orderParsingUtils.convertStringsFieldsToBigNumbers(assetDataPair, [ 'assetDataA.minAmount', 'assetDataA.maxAmount', 'assetDataB.minAmount', @@ -44,6 +45,6 @@ export const relayerResponseJsonParsers = { }, parseOrderConfigResponseJson(json: any): OrderConfigResponse { assert.doesConformToSchema('orderConfigResponse', json, schemas.relayerApiOrderConfigResponseSchema); - return typeConverters.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']); + return orderParsingUtils.convertStringsFieldsToBigNumbers(json, ['makerFee', 'takerFee']); }, }; diff --git a/packages/connect/src/utils/type_converters.ts b/packages/connect/src/utils/type_converters.ts index 4b211a0b2..d57ea00e5 100644 --- a/packages/connect/src/utils/type_converters.ts +++ b/packages/connect/src/utils/type_converters.ts @@ -1,4 +1,4 @@ -import { BigNumber } from '@0xproject/utils'; +import { orderParsingUtils } from '@0xproject/order-utils'; import * as _ from 'lodash'; import { APIOrder } from '../types'; @@ -21,28 +21,6 @@ export const typeConverters = { }; }, convertAPIOrderStringFieldsToBigNumber(apiOrder: any): APIOrder { - return { ...apiOrder, order: typeConverters.convertOrderStringFieldsToBigNumber(apiOrder.order) }; - }, - convertOrderStringFieldsToBigNumber(order: any): any { - return typeConverters.convertStringsFieldsToBigNumbers(order, [ - 'makerAssetAmount', - 'takerAssetAmount', - 'makerFee', - 'takerFee', - 'expirationTimeSeconds', - 'salt', - ]); - }, - convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { - const result = _.assign({}, obj); - _.each(fields, field => { - _.update(result, field, (value: string) => { - if (_.isUndefined(value)) { - throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); - } - return new BigNumber(value); - }); - }); - return result; + return { ...apiOrder, order: orderParsingUtils.convertOrderStringFieldsToBigNumber(apiOrder.order) }; }, }; diff --git a/packages/order-utils/src/index.ts b/packages/order-utils/src/index.ts index 354299304..1553647c6 100644 --- a/packages/order-utils/src/index.ts +++ b/packages/order-utils/src/index.ts @@ -6,6 +6,7 @@ export { eip712Utils } from './eip712_utils'; export { marketUtils } from './market_utils'; export { rateUtils } from './rate_utils'; export { sortingUtils } from './sorting_utils'; +export { orderParsingUtils } from './parsing_utils'; export { OrderStateUtils } from './order_state_utils'; export { AbstractBalanceAndProxyAllowanceFetcher } from './abstract/abstract_balance_and_proxy_allowance_fetcher'; diff --git a/packages/order-utils/src/parsing_utils.ts b/packages/order-utils/src/parsing_utils.ts new file mode 100644 index 000000000..232c54b7b --- /dev/null +++ b/packages/order-utils/src/parsing_utils.ts @@ -0,0 +1,27 @@ +import { BigNumber } from '@0xproject/utils'; +import * as _ from 'lodash'; + +export const orderParsingUtils = { + convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { + const result = _.assign({}, obj); + _.each(fields, field => { + _.update(result, field, (value: string) => { + if (_.isUndefined(value)) { + throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); + } + return new BigNumber(value); + }); + }); + return result; + }, + convertOrderStringFieldsToBigNumber(order: any): any { + return orderParsingUtils.convertStringsFieldsToBigNumbers(order, [ + 'makerAssetAmount', + 'takerAssetAmount', + 'makerFee', + 'takerFee', + 'expirationTimeSeconds', + 'salt', + ]); + }, +}; diff --git a/packages/website/package.json b/packages/website/package.json index 4c6299a4f..f8177cafd 100644 --- a/packages/website/package.json +++ b/packages/website/package.json @@ -68,7 +68,6 @@ "@types/accounting": "^0.4.1", "@types/blockies": "^0.0.0", "@types/deep-equal": "^1.0.0", - "@types/web3-provider-engine": "^14.0.0", "@types/find-versions": "^2.0.0", "@types/jsonschema": "^1.1.1", "@types/lodash": "4.14.104", @@ -85,6 +84,7 @@ "@types/react-scroll": "1.5.3", "@types/react-tap-event-plugin": "0.0.30", "@types/redux": "^3.6.0", + "@types/web3-provider-engine": "^14.0.0", "awesome-typescript-loader": "^3.1.3", "copy-webpack-plugin": "^4.0.1", "copyfiles": "^2.0.0", diff --git a/packages/website/ts/blockchain.ts b/packages/website/ts/blockchain.ts index 36c449573..a976f915f 100644 --- a/packages/website/ts/blockchain.ts +++ b/packages/website/ts/blockchain.ts @@ -19,7 +19,7 @@ import { SignerSubprovider, Web3ProviderEngine, } from '@0xproject/subproviders'; -import { ECSignature, Order, SignedOrder, Token as ZeroExToken } from '@0xproject/types'; +import { SignedOrder, Token as ZeroExToken } from '@0xproject/types'; import { BigNumber, intervalUtils, logUtils, promisify } from '@0xproject/utils'; import { Web3Wrapper } from '@0xproject/web3-wrapper'; import { BlockParam, LogWithDecodedArgs, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types'; @@ -42,7 +42,6 @@ import { InjectedProviderObservable, InjectedProviderUpdate, InjectedWeb3, - PortalOrder, Providers, ProviderType, Side, diff --git a/packages/website/ts/components/generate_order/generate_order_form.tsx b/packages/website/ts/components/generate_order/generate_order_form.tsx index 054b9524f..ec153c005 100644 --- a/packages/website/ts/components/generate_order/generate_order_form.tsx +++ b/packages/website/ts/components/generate_order/generate_order_form.tsx @@ -1,6 +1,6 @@ import { assetDataUtils, generatePseudoRandomSalt, orderHashUtils } from '@0xproject/order-utils'; import { colors } from '@0xproject/react-shared'; -import { ECSignature, Order as ZeroExOrder } from '@0xproject/types'; +import { Order as ZeroExOrder } from '@0xproject/types'; import { BigNumber, logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import Dialog from 'material-ui/Dialog'; diff --git a/packages/website/ts/components/order_json.tsx b/packages/website/ts/components/order_json.tsx index 2a4d992a0..a2a53a523 100644 --- a/packages/website/ts/components/order_json.tsx +++ b/packages/website/ts/components/order_json.tsx @@ -1,4 +1,3 @@ -import { ECSignature } from '@0xproject/types'; import { BigNumber, fetchAsync, logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import Paper from 'material-ui/Paper'; diff --git a/packages/website/ts/containers/generate_order_form.ts b/packages/website/ts/containers/generate_order_form.ts index b2f74f0f8..bc9d6f524 100644 --- a/packages/website/ts/containers/generate_order_form.ts +++ b/packages/website/ts/containers/generate_order_form.ts @@ -1,4 +1,3 @@ -import { ECSignature } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as React from 'react'; import { connect } from 'react-redux'; diff --git a/packages/website/ts/redux/dispatcher.ts b/packages/website/ts/redux/dispatcher.ts index 5e79b6518..c418cab3f 100644 --- a/packages/website/ts/redux/dispatcher.ts +++ b/packages/website/ts/redux/dispatcher.ts @@ -1,4 +1,3 @@ -import { ECSignature } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Dispatch } from 'redux'; import { State } from 'ts/redux/reducer'; diff --git a/packages/website/ts/redux/reducer.ts b/packages/website/ts/redux/reducer.ts index 99907e93e..f54801639 100644 --- a/packages/website/ts/redux/reducer.ts +++ b/packages/website/ts/redux/reducer.ts @@ -1,5 +1,4 @@ import { generatePseudoRandomSalt } from '@0xproject/order-utils'; -import { ECSignature } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import * as _ from 'lodash'; import * as moment from 'moment'; diff --git a/packages/website/ts/types.ts b/packages/website/ts/types.ts index 19cc8f858..5fe9eef99 100644 --- a/packages/website/ts/types.ts +++ b/packages/website/ts/types.ts @@ -1,4 +1,4 @@ -import { ECSignature, SignedOrder } from '@0xproject/types'; +import { SignedOrder } from '@0xproject/types'; import { BigNumber } from '@0xproject/utils'; import { Provider } from 'ethereum-types'; import * as React from 'react'; diff --git a/packages/website/ts/utils/order_parser.ts b/packages/website/ts/utils/order_parser.ts index 2e1d4d2f2..816200e3b 100644 --- a/packages/website/ts/utils/order_parser.ts +++ b/packages/website/ts/utils/order_parser.ts @@ -1,4 +1,5 @@ -import { BigNumber, logUtils } from '@0xproject/utils'; +import { orderParsingUtils } from '@0xproject/order-utils'; +import { logUtils } from '@0xproject/utils'; import * as _ from 'lodash'; import { portalOrderSchema } from 'ts/schemas/portal_order_schema'; @@ -29,7 +30,7 @@ export const orderParser = { return undefined; } const signedOrder = _.get(order, 'signedOrder'); - const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder); + const convertedSignedOrder = orderParsingUtils.convertOrderStringFieldsToBigNumber(signedOrder); const result = { ...order, signedOrder: convertedSignedOrder, @@ -39,7 +40,7 @@ export const orderParser = { parseJsonString(orderJson: string): PortalOrder { const order = JSON.parse(orderJson); const signedOrder = _.get(order, 'signedOrder'); - const convertedSignedOrder = convertOrderStringFieldsToBigNumber(signedOrder); + const convertedSignedOrder = orderParsingUtils.convertOrderStringFieldsToBigNumber(signedOrder); const result = { ...order, signedOrder: convertedSignedOrder, @@ -47,29 +48,3 @@ export const orderParser = { return result; }, }; - -// TODO: consolidate this function with that in typeConverters in @0xproject/connect -function convertOrderStringFieldsToBigNumber(order: any): any { - return convertStringsFieldsToBigNumbers(order, [ - 'makerAssetAmount', - 'takerAssetAmount', - 'makerFee', - 'takerFee', - 'expirationTimeSeconds', - 'salt', - ]); -} - -// TODO: consolidate this function with that in typeConverters in @0xproject/connect -function convertStringsFieldsToBigNumbers(obj: any, fields: string[]): any { - const result = _.assign({}, obj); - _.each(fields, field => { - _.update(result, field, (value: string) => { - if (_.isUndefined(value)) { - throw new Error(`Could not find field '${field}' while converting string fields to BigNumber.`); - } - return new BigNumber(value); - }); - }); - return result; -} |