diff --git a/packages/web3-wrapper/CHANGELOG.json b/packages/web3-wrapper/CHANGELOG.json index edb4f740b3..3f0339e941 100644 --- a/packages/web3-wrapper/CHANGELOG.json +++ b/packages/web3-wrapper/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "6.0.9", + "changes": [ + { + "note": "Let `toBaseUnitAmount()` accept a `number`", + "pr": 1819 + } + ] + }, { "version": "6.0.8", "changes": [ diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 16b6b7b6c8..6b8c0f363d 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -88,14 +88,13 @@ export class Web3Wrapper { * @param decimals The number of decimal places the unit amount has. * @return The amount in baseUnits. */ - public static toBaseUnitAmount(amount: BigNumber, decimals: number): BigNumber { - assert.isBigNumber('amount', amount); + public static toBaseUnitAmount(amount: BigNumber | number, decimals: number): BigNumber { assert.isNumber('decimals', decimals); const unit = new BigNumber(BASE_TEN).pow(decimals); - const baseUnitAmount = amount.times(unit); + const baseUnitAmount = unit.times(amount); const hasDecimals = baseUnitAmount.decimalPlaces() !== 0; if (hasDecimals) { - throw new Error(`Invalid unit amount: ${amount.toString()} - Too many decimal places`); + throw new Error(`Invalid unit amount: ${amount.toString(BASE_TEN)} - Too many decimal places`); } return baseUnitAmount; }