Skip to content

Commit

Permalink
Merge pull request bitpay#75 from matiu/bug/non-uri-sending
Browse files Browse the repository at this point in the history
Bug/non uri sending
  • Loading branch information
matiu committed Jan 21, 2019
1 parent 08c808d commit 245f8d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 9 additions & 3 deletions packages/bitcore-wallet-cli/bin/cli-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,17 +231,23 @@ Utils.parseAmount = function(text) {
var regex = '^(\\d*(\\.\\d{0,8})?)\\s*(' + _.keys(Utils.UNITS2).join('|') + ')?$';
var match = new RegExp(regex, 'i').exec(text.trim());

if (!match || match.length === 0) throw new Error('Invalid amount');
if (!match || match.length === 0) {
Utils.die('Invalid amount: ' + text);
}

var amount = parseFloat(match[1]);
if (!_.isNumber(amount) || _.isNaN(amount)) throw new Error('Invalid amount');

var unit = (match[3] || 'sat').toLowerCase();
var rate = Utils.UNITS2[unit];
if (!rate) throw new Error('Invalid unit')
if (!rate) {
Utils.die('Invalid unit: ' + unit);
}

var amountSat = parseFloat((amount * rate).toPrecision(12));
if (amountSat != Math.round(amountSat)) throw new Error('Invalid amount');
if (amountSat != Math.round(amountSat)) {
Utils.die('Invalid amount: ' + amount + ' ' + unit);
}

return amountSat;
};
Expand Down
5 changes: 2 additions & 3 deletions packages/bitcore-wallet-cli/bin/wallet-send
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ utils.getClient(program, {
var coin = client.credentials.coin;
var bitcore = Bitcore_[coin];


var uri, addr, amount, note;

// no backwards compat uri
Expand All @@ -101,8 +100,8 @@ utils.getClient(program, {

// BIP21
try {
var parsed = new bitcore.URI(arg1);

var parsed = new bitcore.URI(arg1);
if (!parsed.r) {

addr = parsed.address ? parsed.address.toString() : '';
Expand All @@ -113,7 +112,7 @@ utils.getClient(program, {
uri = parsed.r;
}
} catch (e) {
utils.die(e);
uri = null;
}
}

Expand Down

0 comments on commit 245f8d3

Please sign in to comment.