2014-11-29 19:31:17 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
angular.module('copayApp.services')
|
2014-12-10 13:18:28 -08:00
|
|
|
.factory('pendingTxsService', function($rootScope, $filter, rateService) {
|
2014-11-29 19:31:17 -08:00
|
|
|
var root = {};
|
2014-12-10 13:18:28 -08:00
|
|
|
|
|
|
|
root.setAlternativeAmount = function(w, tx, cb) {
|
|
|
|
var alternativeIsoCode = w.settings.alternativeIsoCode;
|
|
|
|
rateService.whenAvailable(function() {
|
|
|
|
_.each(tx.outs, function(out) {
|
|
|
|
var valueSat = out.valueSat * w.settings.unitToSatoshi;
|
|
|
|
out.alternativeAmount = $filter('noFractionNumber')(
|
|
|
|
rateService.toFiat(valueSat, alternativeIsoCode), 2);
|
|
|
|
out.alternativeIsoCode = alternativeIsoCode;
|
|
|
|
});
|
|
|
|
if (cb) return cb(tx);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
root.getDecoratedTxProposals = function(w) {
|
|
|
|
var txps = w.getPendingTxProposals();
|
|
|
|
|
|
|
|
_.each(txps, function(tx) {
|
|
|
|
root.setAlternativeAmount(w, tx);
|
|
|
|
if (tx.outs) {
|
|
|
|
_.each(tx.outs, function(out) {
|
|
|
|
out.valueSat = out.value;
|
|
|
|
out.value = $filter('noFractionNumber')(out.value);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return txps;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @desc adds 2 fields to wallet: pendingTxProposalsCountForUs, pendingTxProposals.
|
|
|
|
*
|
|
|
|
* @param w wallet
|
|
|
|
*/
|
2014-11-29 19:31:17 -08:00
|
|
|
root.update = function(w) {
|
2014-11-30 06:08:51 -08:00
|
|
|
var w = $rootScope.wallet;
|
|
|
|
if (!w) return;
|
|
|
|
|
2014-12-10 13:18:28 -08:00
|
|
|
//pendingTxCount
|
2014-11-30 06:18:25 -08:00
|
|
|
var ret = w.getPendingTxProposalsCount();
|
2014-12-10 13:18:28 -08:00
|
|
|
w.pendingTxProposalsCountForUs = ret.pendingForUs;
|
|
|
|
w.pendingTxProposals = root.getDecoratedTxProposals(w);
|
2014-11-29 19:31:17 -08:00
|
|
|
};
|
2014-12-10 13:18:28 -08:00
|
|
|
|
2014-11-29 19:31:17 -08:00
|
|
|
return root;
|
|
|
|
});
|