From 92c6144b6a7a47402770cd6c1d33db7f4cb847ec Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 3 Jul 2017 14:26:48 -0700 Subject: Check for a BigNumber instance --- src/contract_wrappers/exchange_wrapper.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src') 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); } -- cgit