From bb0eec50971399eb54f9e1ea0e05e21c584f38c1 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 23 Aug 2016 16:53:26 -0300 Subject: [PATCH] ref process txps --- src/js/controllers/preferencesDelete.js | 5 +- src/js/controllers/tab-home.js | 66 ++----------------------- src/js/services/txFormatService.js | 59 ++++++++++++++++++++++ src/js/services/walletService.js | 65 +++++++++++++++++++++++- 4 files changed, 128 insertions(+), 67 deletions(-) diff --git a/src/js/controllers/preferencesDelete.js b/src/js/controllers/preferencesDelete.js index 9963f6f92..98ab2d080 100644 --- a/src/js/controllers/preferencesDelete.js +++ b/src/js/controllers/preferencesDelete.js @@ -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 - })); } }); }; diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index e866fd80b..df2f3b83c 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -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; diff --git a/src/js/services/txFormatService.js b/src/js/services/txFormatService.js index bfcaeb1c8..19b969238 100644 --- a/src/js/services/txFormatService.js +++ b/src/js/services/txFormatService.js @@ -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; }); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index ddd26e82e..284b3eaca 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -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); }); };