diff --git a/js/directives.js b/js/directives.js index 6859c5fa0..3cc79625d 100644 --- a/js/directives.js +++ b/js/directives.js @@ -17,6 +17,12 @@ angular.module('copayApp.directives') // Is this a payment protocol URI (BIP-72)? if (uri && uri.merchant) { scope.wallet.fetchPaymentTx(uri.merchant, function(err, merchantData) { + if ((err && err.message === 'No unspent outputs.') + || scope.availableBalance < +merchantData.total) { + ctrl.$setValidity('validAddress', false); + return; + } + if (err) { if (scope._resetPayPro) scope._resetPayPro(); ctrl.$setValidity('validAddress', false); diff --git a/js/models/core/Wallet.js b/js/models/core/Wallet.js index db8d63159..122192f0f 100644 --- a/js/models/core/Wallet.js +++ b/js/models/core/Wallet.js @@ -937,6 +937,9 @@ Wallet.prototype.receivePaymentRequest = function(options, pr, cb) { return this.getUnspent(function(err, unspent) { if (options.fetch) { + if (!unspent || !unspent.length) { + return cb(new Error('No unspent outputs.')); + } self.createPaymentTxSync(options, merchantData, unspent); return cb(null, merchantData, pr); }