Fix names. Fix sendMax
This commit is contained in:
parent
db33b6f685
commit
7e86153272
2 changed files with 28 additions and 13 deletions
|
|
@ -29,8 +29,8 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
popupService.showAlert(title, msg);
|
||||
};
|
||||
|
||||
var satToAlternative = function(sat, cb) {
|
||||
txFormatService.formatToCode(sat, $scope.currencyIsoCode, function(value) {
|
||||
var satToFiat = function(sat, cb) {
|
||||
txFormatService.toFiat(sat, $scope.currencyIsoCode, function(value) {
|
||||
return cb(value);
|
||||
});
|
||||
};
|
||||
|
|
@ -61,13 +61,13 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
};
|
||||
|
||||
var setTotalAmount = function(amountSat, invoiceFeeSat, networkFeeSat) {
|
||||
satToAlternative(amountSat, function(a) {
|
||||
satToFiat(amountSat, function(a) {
|
||||
$scope.amount = Number(a);
|
||||
|
||||
satToAlternative(invoiceFeeSat, function(i) {
|
||||
satToFiat(invoiceFeeSat, function(i) {
|
||||
$scope.invoiceFee = Number(i);
|
||||
|
||||
satToAlternative(networkFeeSat, function(n) {
|
||||
satToFiat(networkFeeSat, function(n) {
|
||||
$scope.networkFee = Number(n);
|
||||
$scope.totalAmount = $scope.amount + $scope.invoiceFee + $scope.networkFee;
|
||||
$timeout(function() {
|
||||
|
|
@ -140,25 +140,32 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
});
|
||||
};
|
||||
|
||||
var parseAmount = function(wallet, cb) {
|
||||
var calculateAmount = function(wallet, cb) {
|
||||
// Global variables defined beforeEnter
|
||||
var a = amount;
|
||||
var c = currency;
|
||||
|
||||
if (useSendMax) {
|
||||
sendMaxService.getInfo(wallet, function(err, values) {
|
||||
sendMaxService.getInfo(wallet, function(err, maxValues) {
|
||||
if (err) {
|
||||
return cb({
|
||||
title: null,
|
||||
message: err
|
||||
})
|
||||
}
|
||||
var maxAmountBtc = Number((values.amount / 100000000).toFixed(8));
|
||||
var maxAmountBtc = Number((maxValues.amount / 100000000).toFixed(8));
|
||||
|
||||
createInvoice({amount: maxAmountBtc, currency: 'BTC'}, function(err, inv) {
|
||||
if (err) return cb(err);
|
||||
|
||||
return cb(null, txFormatService.parseAmount(maxAmountBtc - inv.buyerPaidBtcMinerFee, 'BTC'));
|
||||
var invoiceFeeSat = parseInt((inv.buyerPaidBtcMinerFee * 100000000).toFixed());
|
||||
var newAmountSat = maxValues.amount - invoiceFeeSat;
|
||||
|
||||
return cb(null, newAmountSat, 'sat');
|
||||
});
|
||||
});
|
||||
} else {
|
||||
return cb(null, txFormatService.parseAmount(amount, currency));
|
||||
return cb(null, a, c);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -190,6 +197,7 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
return;
|
||||
}
|
||||
|
||||
// Save TX in memory
|
||||
createdTx = ctxp;
|
||||
|
||||
$scope.totalAmountStr = txFormatService.formatAmountStr(ctxp.amount);
|
||||
|
|
@ -278,12 +286,13 @@ angular.module('copayApp.controllers').controller('topUpController', function($s
|
|||
$scope.onWalletSelect = function(wallet) {
|
||||
$scope.wallet = wallet;
|
||||
ongoingProcess.set('retrievingInputs', true);
|
||||
parseAmount(wallet, function(err, parsedAmount) {
|
||||
calculateAmount(wallet, function(err, a, c) {
|
||||
ongoingProcess.set('retrievingInputs', false);
|
||||
if (err) {
|
||||
showErrorAndBack(err.title, err.message);
|
||||
return;
|
||||
}
|
||||
var parsedAmount = txFormatService.parseAmount(a, c);
|
||||
initializeTopUp(wallet, parsedAmount);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
|
|||
return root.formatAmount(satoshis) + ' ' + config.unitName;
|
||||
};
|
||||
|
||||
root.formatToCode = function(satoshis, code, cb) {
|
||||
root.toFiat = function(satoshis, code, cb) {
|
||||
if (isNaN(satoshis)) return;
|
||||
var val = function() {
|
||||
var v1 = rateService.toFiat(satoshis, code);
|
||||
|
|
@ -189,9 +189,15 @@ angular.module('copayApp.services').factory('txFormatService', function($filter,
|
|||
var alternativeIsoCode = config.alternativeIsoCode;
|
||||
|
||||
// If fiat currency
|
||||
if (currency != 'bits' && currency != 'BTC') {
|
||||
if (currency != 'bits' && currency != 'BTC' && currency != 'sat') {
|
||||
amountUnitStr = $filter('formatFiatAmount')(amount) + ' ' + currency;
|
||||
amountSat = rateService.fromFiat(amount, currency).toFixed(0);
|
||||
} else if (currency == 'sat') {
|
||||
amountSat = amount;
|
||||
amountUnitStr = root.formatAmountStr(amountSat);
|
||||
// convert sat to BTC
|
||||
amount = (amountSat * satToBtc).toFixed(8);
|
||||
currency = 'BTC';
|
||||
} else {
|
||||
amountSat = parseInt((amount * unitToSatoshi).toFixed(0));
|
||||
amountUnitStr = root.formatAmountStr(amountSat);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue