diff options
author | Fabio Berger <me@fabioberger.com> | 2017-12-21 16:34:50 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-12-21 16:34:50 +0800 |
commit | b94d13b413c9eef7b4afd7244cbc48167239f629 (patch) | |
tree | ff9583f69f38e225ee69d7521fd6d82745129770 /packages/0x.js/src | |
parent | 85e16c1233fc2c7020c2556cd79ac7d53cee4c98 (diff) | |
download | dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar.gz dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar.bz2 dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar.lz dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar.xz dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.tar.zst dexon-sol-tools-b94d13b413c9eef7b4afd7244cbc48167239f629.zip |
Refactor toBaseUnitAmount so that it throws if user supplies unitAmount with too many decimals
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r-- | packages/0x.js/src/0x.ts | 4 |
1 files changed, 4 insertions, 0 deletions
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; } /** |