diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-04 05:26:48 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-07-04 05:26:48 +0800 |
commit | 92c6144b6a7a47402770cd6c1d33db7f4cb847ec (patch) | |
tree | 846bec0c9d7ab14edc93b213d55734a844d4e9f6 /src | |
parent | 8151523d33991a6bb99350f92496719231cc6551 (diff) | |
download | dexon-0x-contracts-92c6144b6a7a47402770cd6c1d33db7f4cb847ec.tar.gz dexon-0x-contracts-92c6144b6a7a47402770cd6c1d33db7f4cb847ec.tar.zst dexon-0x-contracts-92c6144b6a7a47402770cd6c1d33db7f4cb847ec.zip |
Check for a BigNumber instance
Diffstat (limited to 'src')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 106c8774c..7ee7a04ee 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,6 +1,7 @@ import * as _ from 'lodash'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); +import * as Web3 from 'web3'; import {Web3Wrapper} from '../web3_wrapper'; import { ECSignature, @@ -601,7 +602,13 @@ export class ExchangeWrapper extends ContractWrapper { const bignumberWrappingEventCallback = (err: Error, event: ContractEvent) => { if (_.isNull(err)) { const wrapIfBigNumber = (value: ContractEventArg): ContractEventArg => { - return _.isString(value) ? value : new BigNumber(value); + // HACK: The old version of BigNumber used by Web3@0.19.0 does not support the `isBigNumber` + // and checking for a BigNumber instance using `instanceof` does not work either. We therefore + // compare the constructor functions of the possible BigNumber instance and the BigNumber used by + // Web3. + const web3BigNumber = (Web3.prototype as any).BigNumber; + const isWeb3BigNumber = web3BigNumber.toString() === value.constructor.toString(); + return isWeb3BigNumber ? new BigNumber(value) : value; }; event.args = _.mapValues(event.args, wrapIfBigNumber); } |