ref/functions-names-01
This commit is contained in:
parent
3dd7f7a607
commit
39b6aa149c
3 changed files with 6 additions and 6 deletions
46
src/js/services/txFormatService.js
Normal file
46
src/js/services/txFormatService.js
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('txFormatService', function(profileService, rateService, configService, lodash) {
|
||||
var root = {};
|
||||
|
||||
var formatAmountStr = function(amount) {
|
||||
if (!amount) return;
|
||||
var config = configService.getSync().wallet.settings;
|
||||
return profileService.formatAmount(amount) + ' ' + config.unitName;
|
||||
};
|
||||
|
||||
var formatAlternativeStr = function(amount) {
|
||||
if (!amount) return;
|
||||
var config = configService.getSync().wallet.settings;
|
||||
return (rateService.toFiat(amount, config.alternativeIsoCode) ? rateService.toFiat(amount, config.alternativeIsoCode).toFixed(2) : 'N/A') + ' ' + config.alternativeIsoCode;
|
||||
};
|
||||
|
||||
var formatFeeStr = function(fee) {
|
||||
if (!fee) return;
|
||||
var config = configService.getSync().wallet.settings;
|
||||
return profileService.formatAmount(fee) + ' ' + config.unitName;
|
||||
};
|
||||
|
||||
root.processTx = function(tx) {
|
||||
if (!tx) return;
|
||||
|
||||
var outputs = tx.outputs ? tx.outputs.length : 0;
|
||||
if (outputs > 1 && tx.action != 'received') {
|
||||
tx.hasMultiplesOutputs = true;
|
||||
tx.recipientCount = outputs;
|
||||
tx.amount = lodash.reduce(tx.outputs, function(total, o) {
|
||||
o.amountStr = formatAmountStr(o.amount);
|
||||
o.alternativeAmountStr = formatAlternativeStr(o.amount);
|
||||
return total + o.amount;
|
||||
}, 0);
|
||||
}
|
||||
|
||||
tx.amountStr = formatAmountStr(tx.amount);
|
||||
tx.alternativeAmountStr = formatAlternativeStr(tx.amount);
|
||||
tx.feeStr = formatFeeStr(tx.fee || tx.fees);
|
||||
|
||||
return tx;
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue