Fix when insufficient funds
This commit is contained in:
parent
55f0021444
commit
0b514c0b44
2 changed files with 57 additions and 36 deletions
|
|
@ -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');
|
title = title || gettextCatalog.getString('Error');
|
||||||
$scope.sendStatus = '';
|
$scope.sendStatus = '';
|
||||||
$log.error(msg);
|
$log.error(msg);
|
||||||
msg = msg.errors ? msg.errors[0].message : msg;
|
msg = msg.errors ? msg.errors[0].message : msg;
|
||||||
popupService.showAlert(title, msg);
|
popupService.showAlert(title, msg, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
var satToFiat = function(sat, cb) {
|
var satToFiat = function(sat, cb) {
|
||||||
|
|
@ -153,6 +154,11 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
message: err
|
message: err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (maxValues.amount == 0) {
|
||||||
|
return cb({message: gettextCatalog.getString('Insufficient funds for fee')});
|
||||||
|
}
|
||||||
|
|
||||||
var maxAmountBtc = Number((maxValues.amount / 100000000).toFixed(8));
|
var maxAmountBtc = Number((maxValues.amount / 100000000).toFixed(8));
|
||||||
|
|
||||||
createInvoice({amount: maxAmountBtc, currency: 'BTC'}, function(err, inv) {
|
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 invoiceFeeSat = parseInt((inv.buyerPaidBtcMinerFee * 100000000).toFixed());
|
||||||
var newAmountSat = maxValues.amount - invoiceFeeSat;
|
var newAmountSat = maxValues.amount - invoiceFeeSat;
|
||||||
|
|
||||||
|
if (newAmountSat <= 0) {
|
||||||
|
return cb({message: gettextCatalog.getString('Insufficient funds for fee')});
|
||||||
|
}
|
||||||
|
|
||||||
return cb(null, newAmountSat, 'sat');
|
return cb(null, newAmountSat, 'sat');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -256,6 +266,12 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.topUpConfirm = function() {
|
$scope.topUpConfirm = function() {
|
||||||
|
|
||||||
|
if (!createdTx) {
|
||||||
|
showError(null, gettextCatalog.getString('Transaction has not been created'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var title = gettextCatalog.getString('Confirm');
|
var title = gettextCatalog.getString('Confirm');
|
||||||
var okText = gettextCatalog.getString('OK');
|
var okText = gettextCatalog.getString('OK');
|
||||||
var cancelText = gettextCatalog.getString('Cancel');
|
var cancelText = gettextCatalog.getString('Cancel');
|
||||||
|
|
@ -289,7 +305,10 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
||||||
calculateAmount(wallet, function(err, a, c) {
|
calculateAmount(wallet, function(err, a, c) {
|
||||||
ongoingProcess.set('retrievingInputs', false);
|
ongoingProcess.set('retrievingInputs', false);
|
||||||
if (err) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
var parsedAmount = txFormatService.parseAmount(a, c);
|
var parsedAmount = txFormatService.parseAmount(a, c);
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="amount-label">
|
<div class="amount-label">
|
||||||
<div class="amount-final">{{amountUnitStr}}</div>
|
<div class="amount-final">{{amountUnitStr}}</div>
|
||||||
<div class="alternative">
|
<div class="alternative" ng-show="amountUnitStr">
|
||||||
<span ng-if="rate">@
|
<span ng-if="rate">@
|
||||||
{{rate | currency:currencySymbol:2}} {{currencyIsoCode}} per BTC</span>
|
{{rate | currency:currencySymbol:2}} {{currencyIsoCode}} per BTC</span>
|
||||||
<span ng-if="!rate">...</span>
|
<span ng-if="!rate">...</span>
|
||||||
|
|
@ -41,36 +41,38 @@
|
||||||
<i class="icon bp-arrow-right"></i>
|
<i class="icon bp-arrow-right"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="item item-divider" translate>
|
<div ng-show="totalAmountStr">
|
||||||
Details
|
<div class="item item-divider" translate>
|
||||||
</div>
|
Details
|
||||||
<div class="item">
|
</div>
|
||||||
<span translate>Funds to be added</span>
|
<div class="item">
|
||||||
<span class="item-note">
|
<span translate>Funds to be added</span>
|
||||||
<span ng-if="amount">{{amount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
<span class="item-note">
|
||||||
<span ng-if="!amount">...</span>
|
<span ng-if="amount">{{amount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||||
</span>
|
<span ng-if="!amount">...</span>
|
||||||
</div>
|
</span>
|
||||||
<div class="item">
|
</div>
|
||||||
<span translate>Invoice Fee</span>
|
<div class="item">
|
||||||
<span class="item-note">
|
<span translate>Invoice Fee</span>
|
||||||
<span ng-if="invoiceFee">{{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
<span class="item-note">
|
||||||
<span ng-if="!invoiceFee">...</span>
|
<span ng-if="invoiceFee">{{invoiceFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||||
</span>
|
<span ng-if="!invoiceFee">...</span>
|
||||||
</div>
|
</span>
|
||||||
<div class="item">
|
</div>
|
||||||
<span translate>Network Fee</span>
|
<div class="item">
|
||||||
<span class="item-note">
|
<span translate>Network Fee</span>
|
||||||
<span ng-if="networkFee">{{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
<span class="item-note">
|
||||||
<span ng-if="!networkFee">...</span>
|
<span ng-if="networkFee">{{networkFee | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||||
</span>
|
<span ng-if="!networkFee">...</span>
|
||||||
</div>
|
</span>
|
||||||
<div class="item">
|
</div>
|
||||||
<span translate>Total</span>
|
<div class="item">
|
||||||
<span class="item-note">
|
<span translate>Total</span>
|
||||||
<span ng-if="totalAmount">{{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
<span class="item-note">
|
||||||
<span ng-if="totalAmountStr">({{totalAmountStr}})</span>
|
<span ng-if="totalAmount">{{totalAmount | currency:currencySymbol:2}} {{currencyIsoCode}}</span>
|
||||||
</span>
|
<span ng-if="totalAmountStr">({{totalAmountStr}})</span>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -81,14 +83,14 @@
|
||||||
ng-click="topUpConfirm()"
|
ng-click="topUpConfirm()"
|
||||||
ng-if="!isCordova"
|
ng-if="!isCordova"
|
||||||
click-send-status="sendStatus"
|
click-send-status="sendStatus"
|
||||||
is-disabled="!wallet">
|
is-disabled="!wallet || !totalAmountStr">
|
||||||
Add funds
|
Add funds
|
||||||
</click-to-accept>
|
</click-to-accept>
|
||||||
<slide-to-accept
|
<slide-to-accept
|
||||||
ng-if="isCordova"
|
ng-if="isCordova"
|
||||||
slide-on-confirm="topUpConfirm()"
|
slide-on-confirm="topUpConfirm()"
|
||||||
slide-send-status="sendStatus"
|
slide-send-status="sendStatus"
|
||||||
is-disabled="!wallet">
|
is-disabled="!wallet || !totalAmountStr">
|
||||||
Slide to confirm
|
Slide to confirm
|
||||||
</slide-to-accept>
|
</slide-to-accept>
|
||||||
<slide-to-accept-success
|
<slide-to-accept-success
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue