copay/js/filters.js

71 lines
2.0 KiB
JavaScript
Raw Normal View History

2014-03-14 13:38:27 -07:00
'use strict';
2014-05-16 13:18:25 -07:00
angular.module('copayApp.filters', [])
.filter('amTimeAgo', ['amMoment',
function(amMoment) {
return function(input) {
return amMoment.preprocessDate(input).fromNow();
};
}
])
.filter('paged', function() {
return function(elements) {
2014-05-26 06:46:05 -07:00
if (elements) {
return elements.filter(Boolean);
}
return false;
};
2014-05-22 13:42:56 -07:00
})
.filter('removeEmpty', function() {
return function(elements) {
elements = elements || [];
2014-07-22 12:08:57 -07:00
// Hide empty change addresses from other copayers
return elements.filter(function(e) {
2014-07-22 12:08:57 -07:00
return !e.isChange || e.balance > 0;
});
}
})
2014-07-22 12:08:57 -07:00
.filter('noFractionNumber', ['$filter', '$locale', '$rootScope',
function(filter, locale, $rootScope) {
var numberFilter = filter('number');
var formats = locale.NUMBER_FORMATS;
return function(amount, n) {
if (typeof(n) === 'undefined' && !$rootScope.wallet) return amount;
2014-06-23 09:26:13 -07:00
var fractionSize = (typeof(n) !== 'undefined') ?
n : $rootScope.wallet.settings.unitToSatoshi.toString().length - 1;
var value = numberFilter(amount, fractionSize);
var sep = value.indexOf(formats.DECIMAL_SEP);
var group = value.indexOf(formats.GROUP_SEP);
if (amount >= 0) {
if (group > 0) {
if (sep < 0) {
return value;
}
var intValue = value.substring(0, sep);
var floatValue = parseFloat(value.substring(sep));
if (floatValue === 0) {
floatValue = '';
2014-09-03 12:24:25 -07:00
} else {
if (floatValue % 1 === 0) {
floatValue = floatValue.toFixed(0);
2014-09-03 12:24:25 -07:00
}
floatValue = floatValue.toString().substring(1);
}
var finalValue = intValue + floatValue;
return finalValue;
} else {
value = parseFloat(value);
if (value % 1 === 0) {
value = value.toFixed(0);
}
return value;
}
}
return 0;
};
}
]);