ref process txps

This commit is contained in:
Matias Alejo Garcia 2016-08-23 16:53:26 -03:00
commit bb0eec5097
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
4 changed files with 128 additions and 67 deletions

View file

@ -1,7 +1,7 @@
'use strict';
angular.module('copayApp.controllers').controller('preferencesDeleteWalletController',
function($scope, $ionicPopup, $stateParams, lodash, notification, profileService, $state, gettextCatalog, ongoingProcess) {
function($scope, $ionicPopup, $stateParams, lodash, profileService, $state, gettextCatalog, ongoingProcess) {
var wallet = profileService.getWallet($stateParams.walletId);
$scope.alias = lodash.isEqual(wallet.name, wallet.credentials.walletName) ? null : wallet.name + ' ';
$scope.walletName = '[' + wallet.credentials.walletName + ']';
@ -39,9 +39,6 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
$scope.error = err.message || err;
} else {
$state.go('tabs.home');
notification.success(gettextCatalog.getString('Success'), gettextCatalog.getString('The wallet "{{walletName}}" was deleted', {
walletName: walletName
}));
}
});
};

View file

@ -3,6 +3,7 @@
angular.module('copayApp.controllers').controller('tabHomeController',
function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) {
var self = this;
$scope.txps = [];
self.setWallets = function() {
$scope.wallets = profileService.getWallets();
@ -15,69 +16,11 @@ angular.module('copayApp.controllers').controller('tabHomeController',
return;
}
$scope.txps = lodash.sortBy(txps, 'createdOn').reverse();
};
var formatPendingTxps = function(txps) {
$scope.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = profileService.getWallet(tx.walletId);
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
});
return txps;
console.log('[tab-home.js.18]', $scope.txps); //TODO
};
self.updateAllWallets = function() {
$scope.wallets = profileService.getWallets();
var txps = [];
@ -87,12 +30,12 @@ angular.module('copayApp.controllers').controller('tabHomeController',
if (err) {
console.log('[tab-home.js.35:err:]', $log.error(err)); //TODO
return;
} // TODO
}
if (status.pendingTxps && status.pendingTxps[0]) {
txps = txps.concat(status.pendingTxps);
}
if (--i == 0) {
txps = formatPendingTxps(txps);
setPendingTxps(txps);
}
wallet.status = status;
@ -116,7 +59,6 @@ angular.module('copayApp.controllers').controller('tabHomeController',
if ( (status.pendingTxps && status.pendingTxps[0]) || wasAny ) {
txps = txps.concat(status.pendingTxps);
txps = formatPendingTxps(txps);
setPendingTxps(txps);
}
wallet.status = status;

View file

@ -75,5 +75,64 @@ angular.module('copayApp.services').factory('txFormatService', function(bwcServi
return tx;
};
root.formatPendingTxps = function(txps) {
$scope.pendingTxProposalsCountForUs = 0;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = profileService.getWallet(tx.walletId);
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
});
return txps;
};
return root;
});

View file

@ -126,6 +126,68 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
root.getStatus = function(wallet, opts, cb) {
opts = opts || {};
function processPendingTxps(status) {
var txps = status.pendingTxps;
var now = Math.floor(Date.now() / 1000);
/* To test multiple outputs...
var txp = {
message: 'test multi-output',
fee: 1000,
createdOn: new Date() / 1000,
outputs: []
};
function addOutput(n) {
txp.outputs.push({
amount: 600,
toAddress: '2N8bhEwbKtMvR2jqMRcTCQqzHP6zXGToXcK',
message: 'output #' + (Number(n) + 1)
});
};
lodash.times(150, addOutput);
txps.push(txp);
*/
lodash.each(txps, function(tx) {
tx = txFormatService.processTx(tx);
// no future transactions...
if (tx.createdOn > now)
tx.createdOn = now;
tx.wallet = wallet;
if (!tx.wallet) {
$log.error("no wallet at txp?");
return;
}
var action = lodash.find(tx.actions, {
copayerId: tx.wallet.copayerId
});
if (!action && tx.status == 'pending') {
tx.pendingForUs = true;
}
if (action && action.type == 'accept') {
tx.statusForUs = 'accepted';
} else if (action && action.type == 'reject') {
tx.statusForUs = 'rejected';
} else {
tx.statusForUs = 'pending';
}
if (!tx.deleteLockTime)
tx.canBeRemoved = true;
});
wallet.pendingTxps = txps;
};
function get(cb) {
wallet.getStatus({
twoStep: true
@ -238,11 +300,12 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim
}, root.WALLET_STATUS_DELAY_BETWEEN_TRIES * tries);
}
processPendingTxps(status);
$log.debug('Got Wallet Status for:' + wallet.credentials.walletName);
cacheStatus(status);
// wallet.setPendingTxps(status.pendingTxps);
return cb(null, status);
});
};