aboutsummaryrefslogtreecommitdiffstats
path: root/packages/0x.js/src
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-12-22 01:22:28 +0800
committerGitHub <noreply@github.com>2017-12-22 01:22:28 +0800
commit734d220d6050ad7b9fa66e5e0695b848501eeff6 (patch)
treea66808f2d37e852894be4160098566552d3d4f3d /packages/0x.js/src
parentdc1d2a33a5e9396a57777c992f6c7b49e75480a0 (diff)
parentfffe8c355e9c8d9e9ad4e0d7cdf9822f4df5f399 (diff)
downloaddexon-0x-contracts-734d220d6050ad7b9fa66e5e0695b848501eeff6.tar.gz
dexon-0x-contracts-734d220d6050ad7b9fa66e5e0695b848501eeff6.tar.zst
dexon-0x-contracts-734d220d6050ad7b9fa66e5e0695b848501eeff6.zip
Merge pull request #287 from 0xProject/fix/toBaseUnitAmount
Fix toBaseUnitAmount Issue
Diffstat (limited to 'packages/0x.js/src')
-rw-r--r--packages/0x.js/src/0x.ts6
1 files changed, 5 insertions, 1 deletions
diff --git a/packages/0x.js/src/0x.ts b/packages/0x.js/src/0x.ts
index 7393cc814..a18f1fc55 100644
--- a/packages/0x.js/src/0x.ts
+++ b/packages/0x.js/src/0x.ts
@@ -128,7 +128,7 @@ export class ZeroEx {
* @return The amount in units.
*/
public static toUnitAmount(amount: BigNumber, decimals: number): BigNumber {
- assert.isBigNumber('amount', amount);
+ assert.isValidBaseUnitAmount('amount', amount);
assert.isNumber('decimals', decimals);
const aUnit = new BigNumber(10).pow(decimals);
@@ -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;
}
/**