mirror of https://github.com/BTCPrivate/copay.git
Fix when insufficient funds
This commit is contained in:
parent
55f0021444
commit
0b514c0b44
|
@ -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);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
</div>
|
||||
<div class="amount-label">
|
||||
<div class="amount-final">{{amountUnitStr}}</div>
|
||||
<div class="alternative">
|
||||
<div class="alternative" ng-show="amountUnitStr">
|
||||
<span ng-if="rate">@
|
||||
{{rate | currency:currencySymbol:2}} {{currencyIsoCode}} per BTC</span>
|
||||
<span ng-if="!rate">...</span>
|
||||
|
@ -41,36 +41,38 @@
|
|||
<i class="icon bp-arrow-right"></i>
|
||||
</div>
|
||||
|
||||
<div class="item item-divider" translate>
|
||||
Details
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Funds to be added</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="amount">{{amount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!amount">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Invoice Fee</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="invoiceFee">{{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!invoiceFee">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Network Fee</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="networkFee">{{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!networkFee">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Total</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="totalAmount">{{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="totalAmountStr">({{totalAmountStr}})</span>
|
||||
</span>
|
||||
<div ng-show="totalAmountStr">
|
||||
<div class="item item-divider" translate>
|
||||
Details
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Funds to be added</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="amount">{{amount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!amount">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Invoice Fee</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="invoiceFee">{{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!invoiceFee">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Network Fee</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="networkFee">{{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="!networkFee">...</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="item">
|
||||
<span translate>Total</span>
|
||||
<span class="item-note">
|
||||
<span ng-if="totalAmount">{{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||
<span ng-if="totalAmountStr">({{totalAmountStr}})</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -81,14 +83,14 @@
|
|||
ng-click="topUpConfirm()"
|
||||
ng-if="!isCordova"
|
||||
click-send-status="sendStatus"
|
||||
is-disabled="!wallet">
|
||||
is-disabled="!wallet || !totalAmountStr">
|
||||
Add funds
|
||||
</click-to-accept>
|
||||
<slide-to-accept
|
||||
ng-if="isCordova"
|
||||
slide-on-confirm="topUpConfirm()"
|
||||
slide-send-status="sendStatus"
|
||||
is-disabled="!wallet">
|
||||
is-disabled="!wallet || !totalAmountStr">
|
||||
Slide to confirm
|
||||
</slide-to-accept>
|
||||
<slide-to-accept-success
|
||||
|
|
Loading…
Reference in New Issue