Merge pull request #42 from bitpay/feat/txp-at-home

Feat/txp at home
This commit is contained in:
Matias Alejo Garcia 2016-09-02 10:31:46 -03:00 committed by GitHub
commit e286e7ea56
12 changed files with 220 additions and 77 deletions

View file

@ -123,6 +123,12 @@ angular.module('copayApp.services')
if (wallet.cachedActivity)
wallet.cachedActivity.isValid = false;
if (wallet.cachedTxps)
wallet.cachedTxps.isValid = false;
$rootScope.$emit('bwsEvent', wallet.id, n.type, n);
});
@ -780,7 +786,7 @@ angular.module('copayApp.services')
};
function getNotifications(wallet, cb2) {
function updateNotifications(wallet, cb2) {
if (isActivityCached(wallet) && !opts.force) return cb2();
wallet.getNotifications({
@ -858,7 +864,7 @@ angular.module('copayApp.services')
};
lodash.each(w, function(wallet) {
getNotifications(wallet, function(err) {
updateNotifications(wallet, function(err) {
j++;
if (err) {
$log.warn('Error updating notifications:' + err);
@ -892,5 +898,33 @@ angular.module('copayApp.services')
});
};
root.getTxps = function(opts, cb) {
var MAX = 100;
opts = opts || {};
var w = root.getWallets();
if (lodash.isEmpty(w)) return cb();
var txps = [];
function process(notifications) {
if (!notifications) return [];
var shown = lodash.sortBy(notifications, 'createdOn').reverse();
shown = shown.splice(0, opts.limit || MAX);
return shown;
};
lodash.each(w, function(x) {
if (x.pendingTxps)
txps = txps.concat(x.pendingTxps);
});
txps = lodash.sortBy(txps, 'createdOn');
txps = lodash.compact(lodash.flatten(txps)).slice(0,MAX);
var n = txps.length;
return cb(null, process(txps), n);
};
return root;
});

View file

@ -0,0 +1,31 @@
'use strict';
angular.module('copayApp.services').factory('txpModalService', function(configService, $rootScope, $ionicModal) {
var root = {};
var glideraActive = true; // TODO TODO TODO
// isGlidera flag is a security measure so glidera status is not
// only determined by the tx.message
root.open = function(tx) {
var config = configService.getSync().wallet;
var scope = $rootScope.$new(true);
scope.tx = tx;
scope.wallet = tx.wallet;
scope.copayers = tx.wallet.copayers;
scope.isGlidera = glideraActive;
scope.currentSpendUnconfirmed = config.spendUnconfirmed;
$ionicModal.fromTemplateUrl('views/modals/txp-details.html', {
scope: scope
}).then(function(modal) {
scope.txpDetailsModal = modal;
scope.txpDetailsModal.show();
});
};
return root;
});