diff --git a/src/js/controllers/topup.js b/src/js/controllers/topup.js index 3b72623c6..a6261fd35 100644 --- a/src/js/controllers/topup.js +++ b/src/js/controllers/topup.js @@ -21,12 +21,13 @@ angular.module('copayApp.controllers').controller('topUpController', function($s }); }; - var showError = function(title, msg) { + var showError = function(title, msg, cb) { + cb = cb || function() {}; title = title || gettextCatalog.getString('Error'); $scope.sendStatus = ''; $log.error(msg); msg = msg.errors ? msg.errors[0].message : msg; - popupService.showAlert(title, msg); + popupService.showAlert(title, msg, cb); }; var satToFiat = function(sat, cb) { @@ -153,6 +154,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s message: err }) } + + if (maxValues.amount == 0) { + return cb({message: gettextCatalog.getString('Insufficient funds for fee')}); + } + var maxAmountBtc = Number((maxValues.amount / 100000000).toFixed(8)); createInvoice({amount: maxAmountBtc, currency: 'BTC'}, function(err, inv) { @@ -161,6 +167,10 @@ angular.module('copayApp.controllers').controller('topUpController', function($s var invoiceFeeSat = parseInt((inv.buyerPaidBtcMinerFee * 100000000).toFixed()); var newAmountSat = maxValues.amount - invoiceFeeSat; + if (newAmountSat <= 0) { + return cb({message: gettextCatalog.getString('Insufficient funds for fee')}); + } + return cb(null, newAmountSat, 'sat'); }); }); @@ -256,6 +266,12 @@ angular.module('copayApp.controllers').controller('topUpController', function($s }); $scope.topUpConfirm = function() { + + if (!createdTx) { + showError(null, gettextCatalog.getString('Transaction has not been created')); + return; + } + var title = gettextCatalog.getString('Confirm'); var okText = gettextCatalog.getString('OK'); var cancelText = gettextCatalog.getString('Cancel'); @@ -289,7 +305,10 @@ angular.module('copayApp.controllers').controller('topUpController', function($s calculateAmount(wallet, function(err, a, c) { ongoingProcess.set('retrievingInputs', false); if (err) { - showErrorAndBack(err.title, err.message); + createdTx = message = $scope.totalAmountStr = $scope.amountUnitStr = $scope.wallet = null; + showError(err.title, err.message, function() { + $scope.showWalletSelector(); + }); return; } var parsedAmount = txFormatService.parseAmount(a, c); diff --git a/www/views/topup.html b/www/views/topup.html index 145a22f67..76d43082d 100644 --- a/www/views/topup.html +++ b/www/views/topup.html @@ -20,7 +20,7 @@
{{amountUnitStr}}
-
+
@ {{rate | currency:currencySymbol:2}} {{currencyIsoCode}} per BTC ... @@ -41,36 +41,38 @@
-
- Details -
-
- Funds to be added - - {{amount | currency:currencySymbol:2}} {{currencyIsoCode}} - ... - -
-
- Invoice Fee - - {{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}} - ... - -
-
- Network Fee - - {{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}} - ... - -
-
- Total - - {{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}} - ({{totalAmountStr}}) - +
+
+ Details +
+
+ Funds to be added + + {{amount | currency:currencySymbol:2}} {{currencyIsoCode}} + ... + +
+
+ Invoice Fee + + {{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}} + ... + +
+
+ Network Fee + + {{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}} + ... + +
+
+ Total + + {{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}} + ({{totalAmountStr}}) + +
@@ -81,14 +83,14 @@ ng-click="topUpConfirm()" ng-if="!isCordova" click-send-status="sendStatus" - is-disabled="!wallet"> + is-disabled="!wallet || !totalAmountStr"> Add funds + is-disabled="!wallet || !totalAmountStr"> Slide to confirm