diff options
author | Fabio Berger <me@fabioberger.com> | 2017-11-09 23:09:20 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2017-11-10 03:11:46 +0800 |
commit | ae74965774e8b0f12165d02135097f25f8fa927b (patch) | |
tree | 64da64ad47476fbba035a56a5d45438309b1e228 /src/utils/assert.ts | |
parent | e952c98ca835627063cb675931d8de11aee84e78 (diff) | |
download | dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar.gz dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar.bz2 dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar.lz dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar.xz dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.tar.zst dexon-sol-tools-ae74965774e8b0f12165d02135097f25f8fa927b.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/assert.ts')
-rw-r--r-- | src/utils/assert.ts | 6 |
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)); }, |