format filter
This commit is contained in:
parent
fccd645f54
commit
8dec576a6d
4 changed files with 44 additions and 54 deletions
|
|
@ -634,9 +634,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
var lockedBalanceAlternative = rateService.toFiat(self.lockedBalanceSat, self.alternativeIsoCode);
|
var lockedBalanceAlternative = rateService.toFiat(self.lockedBalanceSat, self.alternativeIsoCode);
|
||||||
var alternativeConversionRate = rateService.toFiat(100000000, self.alternativeIsoCode);
|
var alternativeConversionRate = rateService.toFiat(100000000, self.alternativeIsoCode);
|
||||||
|
|
||||||
self.totalBalanceAlternative = $filter('noFractionNumber')(totalBalanceAlternative, 2);
|
self.totalBalanceAlternative = $filter('formatFiatAmount')(totalBalanceAlternative);
|
||||||
self.lockedBalanceAlternative = $filter('noFractionNumber')(lockedBalanceAlternative, 2);
|
self.lockedBalanceAlternative = $filter('formatFiatAmount')(lockedBalanceAlternative);
|
||||||
self.alternativeConversionRate = $filter('noFractionNumber')(alternativeConversionRate, 2);
|
self.alternativeConversionRate = $filter('formatFiatAmount')(alternativeConversionRate);
|
||||||
|
|
||||||
self.alternativeBalanceAvailable = true;
|
self.alternativeBalanceAvailable = true;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ angular.module('copayApp.controllers').controller('customAmountController', func
|
||||||
var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0));
|
var amountSat = parseInt((amount * $scope.unitToSatoshi).toFixed(0));
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
$scope.customizedAmountUnit = amount + ' ' + $scope.unitName;
|
$scope.customizedAmountUnit = amount + ' ' + $scope.unitName;
|
||||||
$scope.customizedAlternativeUnit = $filter('noFractionNumber')(form.alternative.$modelValue, 2) + ' ' + $scope.alternativeIsoCode;
|
$scope.customizedAlternativeUnit = $filter('formatFiatAmount')(form.alternative.$modelValue) + ' ' + $scope.alternativeIsoCode;
|
||||||
if ($scope.unitName == 'bits') {
|
if ($scope.unitName == 'bits') {
|
||||||
amount = (amountSat * satToBtc).toFixed(8);
|
amount = (amountSat * satToBtc).toFixed(8);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio
|
||||||
var alternativeAmountBtc = ($scope.btx.amount * satToBtc).toFixed(8);
|
var alternativeAmountBtc = ($scope.btx.amount * satToBtc).toFixed(8);
|
||||||
$scope.rateDate = res.fetchedOn;
|
$scope.rateDate = res.fetchedOn;
|
||||||
$scope.rateStr = res.rate + ' ' + $scope.alternativeIsoCode;
|
$scope.rateStr = res.rate + ' ' + $scope.alternativeIsoCode;
|
||||||
$scope.alternativeAmountStr = $filter('noFractionNumber')(alternativeAmountBtc * res.rate, 2) + ' ' + $scope.alternativeIsoCode;
|
$scope.alternativeAmountStr = $filter('formatFiatAmount')(alternativeAmountBtc * res.rate) + ' ' + $scope.alternativeIsoCode;
|
||||||
$scope.$apply();
|
$scope.$apply();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -26,20 +26,19 @@ angular.module('copayApp.filters', [])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
.filter('formatFiatAmount', ['$filter', '$locale', 'configService',
|
||||||
.filter('noFractionNumber', ['$filter', '$locale', 'configService',
|
|
||||||
function(filter, locale, configService) {
|
function(filter, locale, configService) {
|
||||||
var numberFilter = filter('number');
|
var numberFilter = filter('number');
|
||||||
var formats = locale.NUMBER_FORMATS;
|
var formats = locale.NUMBER_FORMATS;
|
||||||
var config = configService.getSync().wallet.settings;
|
var config = configService.getSync().wallet.settings;
|
||||||
return function(amount, n) {
|
return function(amount) {
|
||||||
if (typeof(n) === 'undefined' && !config) return amount;
|
if (!config) return amount;
|
||||||
|
|
||||||
var fractionSize = (typeof(n) !== 'undefined') ?
|
var fractionSize = 2;
|
||||||
n : config.unitToSatoshi.toString().length - 1;
|
|
||||||
var value = numberFilter(amount, fractionSize);
|
var value = numberFilter(amount, fractionSize);
|
||||||
var sep = value.indexOf(formats.DECIMAL_SEP);
|
var sep = value.indexOf(formats.DECIMAL_SEP);
|
||||||
var group = value.indexOf(formats.GROUP_SEP);
|
var group = value.indexOf(formats.GROUP_SEP);
|
||||||
|
|
||||||
if (amount >= 0) {
|
if (amount >= 0) {
|
||||||
if (group > 0) {
|
if (group > 0) {
|
||||||
if (sep < 0) {
|
if (sep < 0) {
|
||||||
|
|
@ -47,22 +46,13 @@ angular.module('copayApp.filters', [])
|
||||||
}
|
}
|
||||||
var intValue = value.substring(0, sep);
|
var intValue = value.substring(0, sep);
|
||||||
var floatValue = parseFloat(value.substring(sep));
|
var floatValue = parseFloat(value.substring(sep));
|
||||||
if (floatValue === 0) {
|
floatValue = floatValue.toFixed(2);
|
||||||
floatValue = '';
|
|
||||||
} else {
|
|
||||||
if (floatValue % 1 === 0) {
|
|
||||||
floatValue = floatValue.toFixed(0);
|
|
||||||
}
|
|
||||||
floatValue = floatValue.toString().substring(1);
|
floatValue = floatValue.toString().substring(1);
|
||||||
}
|
|
||||||
var finalValue = intValue + floatValue;
|
var finalValue = intValue + floatValue;
|
||||||
return finalValue;
|
return finalValue;
|
||||||
} else {
|
} else {
|
||||||
value = parseFloat(value);
|
value = parseFloat(value);
|
||||||
if (value % 1 === 0) {
|
return value.toFixed(2);
|
||||||
value = value.toFixed(0);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue