aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/src/util
diff options
context:
space:
mode:
authorSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-03 04:22:10 +0800
committerSteve Klebanoff <steve.klebanoff@gmail.com>2018-11-03 04:22:10 +0800
commit620f439816b8c62edb5f0e2e140647176b8702c8 (patch)
treee4d0fdf5505d64eca40dd0bda61fedef6da1a015 /packages/instant/src/util
parentf5623632d86504b4081ff6d102c2f9468e2dfa0d (diff)
downloaddexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar.gz
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar.bz2
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar.lz
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar.xz
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.tar.zst
dexon-0x-contracts-620f439816b8c62edb5f0e2e140647176b8702c8.zip
Move MaybeBigNumber functions into helper
Diffstat (limited to 'packages/instant/src/util')
-rw-r--r--packages/instant/src/util/maybe_big_number.ts25
1 files changed, 25 insertions, 0 deletions
diff --git a/packages/instant/src/util/maybe_big_number.ts b/packages/instant/src/util/maybe_big_number.ts
new file mode 100644
index 000000000..113ba552f
--- /dev/null
+++ b/packages/instant/src/util/maybe_big_number.ts
@@ -0,0 +1,25 @@
+import { BigNumber } from '@0x/utils';
+import * as _ from 'lodash';
+
+import { MaybeBigNumber } from '../types';
+
+export const maybeBigNumberUtil = {
+ // converts a string to a MaybeBigNumber
+ // if string is a NaN, considered undefined
+ stringToMaybeBigNumber: (stringValue: string): MaybeBigNumber => {
+ let validBigNumber: BigNumber;
+ try {
+ validBigNumber = new BigNumber(stringValue);
+ } catch {
+ return undefined;
+ }
+
+ return validBigNumber.isNaN() ? undefined : validBigNumber;
+ },
+ areMaybeBigNumbersEqual: (val1: MaybeBigNumber, val2: MaybeBigNumber): boolean => {
+ if (!_.isUndefined(val1) && !_.isUndefined(val2)) {
+ return val1.equals(val2);
+ }
+ return _.isUndefined(val1) && _.isUndefined(val2);
+ },
+};