aboutsummaryrefslogtreecommitdiffstats
path: root/packages/order-utils/src
diff options
context:
space:
mode:
authorFrancesco Agosti <francesco.agosti93@gmail.com>2018-09-05 03:37:53 +0800
committerGitHub <noreply@github.com>2018-09-05 03:37:53 +0800
commit01210c291c23aae19d201557118f39a8bd970ca0 (patch)
treea93ff78321eda2b98a15669a458622ec79deba1a /packages/order-utils/src
parenta5859c6cee0729cf493afa4ff192469cd781fa2b (diff)
parent6eb980abe2900d179f796bfdae4d79544f447952 (diff)
downloaddexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar.gz
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar.bz2
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar.lz
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar.xz
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.tar.zst
dexon-sol-tools-01210c291c23aae19d201557118f39a8bd970ca0.zip
Merge pull request #1044 from 0xProject/feature/website/update-portal-v2
[website] Update portal for v2
Diffstat (limited to 'packages/order-utils/src')
-rw-r--r--packages/order-utils/src/index.ts1
-rw-r--r--packages/order-utils/src/parsing_utils.ts27
2 files changed, 28 insertions, 0 deletions
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',
+ ]);
+ },
+};