diff options
author | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-03 04:22:10 +0800 |
---|---|---|
committer | Steve Klebanoff <steve.klebanoff@gmail.com> | 2018-11-03 04:22:10 +0800 |
commit | 620f439816b8c62edb5f0e2e140647176b8702c8 (patch) | |
tree | e4d0fdf5505d64eca40dd0bda61fedef6da1a015 /packages/instant/src/util | |
parent | f5623632d86504b4081ff6d102c2f9468e2dfa0d (diff) | |
download | dexon-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.ts | 25 |
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); + }, +}; |