aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2017-11-09 23:09:20 +0800
committerFabio Berger <me@fabioberger.com>2017-11-09 23:09:20 +0800
commitc96c681758a9bb62b4444ce21747c3781e9dc742 (patch)
tree545cf0c2adea7777d7e2c9bff6015e7b33cc0843 /src/utils
parent6007609f7132d5f919c8e9de04ae6c652ce38980 (diff)
downloaddexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar.gz
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar.bz2
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar.lz
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar.xz
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.tar.zst
dexon-sol-tools-c96c681758a9bb62b4444ce21747c3781e9dc742.zip
Add assert.isValidBaseUnitAmount that checks for decimals in amounts that should be in baseUnits. This can sometimes alert developers whenever they accidentally pass in unitAmounts.
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/assert.ts6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/utils/assert.ts b/src/utils/assert.ts
index 286105345..48aed6ad3 100644
--- a/src/utils/assert.ts
+++ b/src/utils/assert.ts
@@ -11,6 +11,12 @@ export const assert = {
const isBigNumber = _.isObject(value) && (value as any).isBigNumber;
this.assert(isBigNumber, this.typeAssertionMessage(variableName, 'BigNumber', value));
},
+ isValidBaseUnitAmount(variableName: string, value: BigNumber) {
+ const hasDecimals = value.decimalPlaces() !== 0;
+ this.assert(
+ !hasDecimals, `${variableName} should be in baseUnits (no decimals), found value: ${value.toNumber()}`,
+ );
+ },
isUndefined(value: any, variableName?: string): void {
this.assert(_.isUndefined(value), this.typeAssertionMessage(variableName, 'undefined', value));
},