From b94d13b413c9eef7b4afd7244cbc48167239f629 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 21 Dec 2017 09:34:50 +0100 Subject: Refactor toBaseUnitAmount so that it throws if user supplies unitAmount with too many decimals --- packages/0x.js/src/0x.ts | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'packages/0x.js/src') diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts index 596d6ffba..a18f1fc55 100644 --- a/packages/0x.js/src/0x.ts +++ b/packages/0x.js/src/0x.ts @@ -149,6 +149,10 @@ export class ZeroEx { const unit = new BigNumber(10).pow(decimals); const baseUnitAmount = amount.times(unit); + const hasDecimals = baseUnitAmount.decimalPlaces() !== 0; + if (hasDecimals) { + throw new Error(`Invalid unit amount: ${amount.toString()} - Too many decimal places`); + } return baseUnitAmount; } /** -- cgit v1.2.3