check precision is consistent with unit
This commit is contained in:
parent
a5a672b473
commit
c23f962030
|
@ -121,7 +121,10 @@ WalletUtils.parseAmount = function(text) {
|
|||
var rate = WalletUtils.UNITS[unit];
|
||||
if (!rate) throw new Error('Invalid unit')
|
||||
|
||||
return Utils.strip(amount * rate);
|
||||
var amountSat = Utils.strip(amount * rate);
|
||||
if (amountSat != Math.round(amountSat)) throw new Error('Invalid amount');
|
||||
|
||||
return amountSat;
|
||||
};
|
||||
|
||||
module.exports = WalletUtils;
|
||||
|
|
|
@ -80,6 +80,7 @@ describe('WalletUtils', function() {
|
|||
var texts = {
|
||||
'1': 1,
|
||||
'0': 0,
|
||||
'1.': 1,
|
||||
'000000.0000': 0,
|
||||
'123': 123,
|
||||
'123sat': 123,
|
||||
|
@ -113,8 +114,12 @@ describe('WalletUtils', function() {
|
|||
'-3',
|
||||
'1 b t c',
|
||||
'btc1',
|
||||
'btc 1',
|
||||
'1,234',
|
||||
'0.000000001btc',
|
||||
'0.1sat',
|
||||
'0.123bit',
|
||||
'2.000000009btc',
|
||||
];
|
||||
_.each(texts, function(text) {
|
||||
var valid = true;
|
||||
|
|
Loading…
Reference in New Issue