From ae266e397b1f1f13fdec218b8df8ec7468b4c731 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 20 Sep 2016 12:02:45 -0300 Subject: [PATCH 1/7] wip --- public/views/includes/walletActivity.html | 50 +++++++++---------- public/views/modals/tx-details.html | 6 +-- public/views/tab-home.html | 4 +- src/js/controllers/modals/txDetails.js | 59 ++++++++++++++++------- src/js/controllers/tab-home.js | 18 ++++++- src/js/services/profileService.js | 10 ++-- 6 files changed, 93 insertions(+), 54 deletions(-) diff --git a/public/views/includes/walletActivity.html b/public/views/includes/walletActivity.html index ed0f57e07..0e9fceb76 100644 --- a/public/views/includes/walletActivity.html +++ b/public/views/includes/walletActivity.html @@ -1,65 +1,65 @@ -
- Copayer joined +
+ Copayer joined
-
+
Wallet created
-
+
Payment Sent
- {{x.amountStr}} + {{notification.amountStr}}
-
+
Payment Received
- {{x.amountStr}} + {{notification.amountStr}}
-
- Proposal Deleted: - {{x.message}} +
+ Proposal Deleted: + {{notification.message}}
- {{x.amountStr}}: + {{notification.amountStr}}:
-
+
Proposal Rejected: - {{x.message}} + {{notification.message}}
- {{x.amountStr}}: + {{notification.amountStr}}:
- + New Proposal: - {{x.message}} + {{notification.message}}
- {{x.amountStr}} + {{notification.amountStr}}
- + Proposal Accepted: - {{x.message}} + {{notification.message}}
- {{x.amountStr}} + {{notification.amountStr}}

- - - {{ x.creatorName}}@ - {{x.wallet.name}} - + + + {{ notification.creatorName}}@ + {{notification.wallet.name}} +

diff --git a/public/views/modals/tx-details.html b/public/views/modals/tx-details.html index d7145f679..a0f3571c8 100644 --- a/public/views/modals/tx-details.html +++ b/public/views/modals/tx-details.html @@ -9,11 +9,11 @@ -
+
- - + +
diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 60849ecf8..7be004eab 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -35,7 +35,7 @@
-
+ diff --git a/src/js/controllers/modals/txDetails.js b/src/js/controllers/modals/txDetails.js index 2324ac4b9..b6c2f3f32 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -1,28 +1,54 @@ 'use strict'; -angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { +angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { var self = $scope.self; - var wallet = profileService.getWallet($stateParams.walletId); + var wallet = profileService.getWallet($stateParams.walletId || $scope.walletId); var config = configService.getSync(); var configWallet = config.wallet; var walletSettings = configWallet.settings; $scope.init = function() { - $scope.alternativeIsoCode = walletSettings.alternativeIsoCode; - $scope.color = wallet.color; - $scope.copayerId = wallet.credentials.copayerId; - $scope.isShared = wallet.credentials.n > 1; + findTx($scope.txid, function(err, tx) { + if (err) { + $log.error(err); + return; + } + console.log('TX FOUND', tx); + $scope.btx = lodash.cloneDeep(tx); + $scope.alternativeIsoCode = walletSettings.alternativeIsoCode; + $scope.color = wallet.color; + $scope.copayerId = wallet.credentials.copayerId; + $scope.isShared = wallet.credentials.n > 1; + // $scope.btx.amountStr = txFormatService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName; + // $scope.btx.feeStr = txFormatService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName; + $scope.btx.feeLevel = walletSettings.feeLevel; - $scope.btx.amountStr = txFormatService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName; - $scope.btx.feeStr = txFormatService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName; - $scope.btx.feeLevel = walletSettings.feeLevel; + if ($scope.btx.action != 'invalid') { + if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); + if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); + if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); + } - if ($scope.btx.action != 'invalid') { - if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); - if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); - if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); - } - initActionList(); + initActionList(); + getAlternativeAmount(); + + $timeout(function() { + $scope.$apply(); + }, 10); + }); + }; + + function findTx(txid, cb) { + walletService.getTxHistory(wallet, {}, function(err, txHistory) { + if (err) return cb(err); + + var tx = lodash.find(txHistory, { + txid: txid + }); + + if (tx) return cb(null, tx); + else return cb(); + }); }; function initActionList() { @@ -90,7 +116,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio }); }; - $scope.getAlternativeAmount = function() { + var getAlternativeAmount = function() { var satToBtc = 1 / 100000000; wallet.getFiatRate({ @@ -123,5 +149,4 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.cancel = function() { $scope.txDetailsModal.hide(); }; - }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 2ed46ed6d..0efcbaddf 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicScrollDelegate, lodash, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, lodash, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { $scope.externalServices = {}; $scope.bitpayCardEnabled = true; // TODO $scope.openTxpModal = txpModalService.open; @@ -16,6 +16,18 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.coinbaseEnabled = config.coinbase.enabled && !isWindowsPhoneApp; }); + $scope.openTxModal = function(n) { + console.log(n); + $scope.txid = n.txid; + $scope.walletId = n.walletId; + $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { + scope: $scope + }).then(function(modal) { + $scope.txDetailsModal = modal; + $scope.txDetailsModal.show(); + }); + }; + $scope.openWallet = function(wallet) { if (!wallet.isComplete()) { return $state.go('tabs.copayers', { @@ -112,7 +124,9 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.hideHomeTip = function() { $scope.homeTip = null; $state.transitionTo($state.current, null, { - reload: false, inherit: false, notify: false + reload: false, + inherit: false, + notify: false }); }; diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index d3a81e915..c6bc0d3d0 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -822,11 +822,11 @@ angular.module('copayApp.services') x.action = function() { // TODO? - $state.go('tabs.details', { - walletId: x.walletId, - txpId: x.txpId, - txid: x.txid, - }); + // $state.go('tabs.details', { + // walletId: x.walletId, + // txpId: x.txpId, + // txid: x.txid, + // }); }; }); From 64b879fcd3fa4801cc291f650495dd006c9f1c14 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 20 Sep 2016 13:56:54 -0300 Subject: [PATCH 2/7] open tx modal from home --- public/views/modals/tx-details.html | 54 +++++++++++++++----------- src/js/controllers/modals/txDetails.js | 27 +++++++++---- src/js/controllers/tab-home.js | 1 - src/js/services/onGoingProcess.js | 1 + 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/public/views/modals/tx-details.html b/public/views/modals/tx-details.html index a0f3571c8..79e7f5be9 100644 --- a/public/views/modals/tx-details.html +++ b/public/views/modals/tx-details.html @@ -1,5 +1,5 @@ - + @@ -9,10 +9,10 @@ -
+
- + @@ -30,30 +30,30 @@
-
- Sent from {{wallet.credentials.walletName}} -
- -
+
+ Sent from {{wallet.credentials.walletName}} +
+
+
-
-
- -
- Received Funds +
+
+
+ Received Funds +
-
- Moved Funds -
+
+ Moved Funds +
-
-
+
@@ -75,14 +75,22 @@
-
Created by
- {{btx.creatorName}} - - - +
+ Date + + + +
+
+
Created by
+ {{btx.creatorName}} + + + +
-
+
Fee
{{btx.feeLevel}} ({{btx.feeStr}}) diff --git a/src/js/controllers/modals/txDetails.js b/src/js/controllers/modals/txDetails.js index b6c2f3f32..b7c142edb 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -1,26 +1,37 @@ 'use strict'; -angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { +angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, ongoingProcess, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { var self = $scope.self; var wallet = profileService.getWallet($stateParams.walletId || $scope.walletId); var config = configService.getSync(); var configWallet = config.wallet; var walletSettings = configWallet.settings; + $scope.title = gettextCatalog.getString('Transaction'); + $scope.loadingTxInfo = false; $scope.init = function() { + $scope.loadingTxInfo = true; + ongoingProcess.set('loadingTxInfo', true); findTx($scope.txid, function(err, tx) { + ongoingProcess.set('loadingTxInfo', false); + $scope.loadingTxInfo = false; if (err) { $log.error(err); - return; + popupService.showAlert(gettextCatalog.getString('Error'), err); + return $scope.cancel(); } - console.log('TX FOUND', tx); + + if (!tx) { + $log.warn('No tx found'); + popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); + return $scope.cancel(); + } + $scope.btx = lodash.cloneDeep(tx); $scope.alternativeIsoCode = walletSettings.alternativeIsoCode; $scope.color = wallet.color; $scope.copayerId = wallet.credentials.copayerId; $scope.isShared = wallet.credentials.n > 1; - // $scope.btx.amountStr = txFormatService.formatAmount($scope.btx.amount, true) + ' ' + walletSettings.unitName; - // $scope.btx.feeStr = txFormatService.formatAmount($scope.btx.fees, true) + ' ' + walletSettings.unitName; $scope.btx.feeLevel = walletSettings.feeLevel; if ($scope.btx.action != 'invalid') { @@ -46,8 +57,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio txid: txid }); - if (tx) return cb(null, tx); - else return cb(); + return cb(null, tx); }); }; @@ -148,5 +158,8 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.cancel = function() { $scope.txDetailsModal.hide(); + $timeout(function() { + $scope.txDetailsModal.remove(); + }, 10); }; }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 0efcbaddf..605c67ee3 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -17,7 +17,6 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); $scope.openTxModal = function(n) { - console.log(n); $scope.txid = n.txid; $scope.walletId = n.walletId; $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { diff --git a/src/js/services/onGoingProcess.js b/src/js/services/onGoingProcess.js index be1d5ee70..642051951 100644 --- a/src/js/services/onGoingProcess.js +++ b/src/js/services/onGoingProcess.js @@ -32,6 +32,7 @@ angular.module('copayApp.services').factory('ongoingProcess', function($log, $ti 'sweepingWallet': gettext('Sweeping Wallet...'), 'validatingWallet': gettext('Validating wallet integrity...'), 'validatingWords': gettext('Validating recovery phrase...'), + 'loadingTxInfo': gettext('Loading transaction info...'), }; root.clear = function() { From 1cfd4c733f87213751ca40380079693d84d74ea0 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 20 Sep 2016 16:21:05 -0300 Subject: [PATCH 3/7] refactor call tx modal --- public/views/activity.html | 2 +- public/views/modals/tx-details.html | 4 +- public/views/tab-home.html | 2 +- src/js/controllers/activity.js | 33 ++++++++++-- src/js/controllers/modals/txDetails.js | 69 +++++++------------------- src/js/controllers/tab-home.js | 33 +++++++++--- src/js/controllers/walletDetails.js | 9 +--- src/js/services/walletService.js | 11 ++++ 8 files changed, 88 insertions(+), 75 deletions(-) diff --git a/public/views/activity.html b/public/views/activity.html index 8a1738373..c020fa25f 100644 --- a/public/views/activity.html +++ b/public/views/activity.html @@ -19,7 +19,7 @@
-
+
diff --git a/public/views/modals/tx-details.html b/public/views/modals/tx-details.html index 79e7f5be9..e1e2c3640 100644 --- a/public/views/modals/tx-details.html +++ b/public/views/modals/tx-details.html @@ -9,7 +9,7 @@ -
+
@@ -53,7 +53,7 @@
-
+
diff --git a/public/views/tab-home.html b/public/views/tab-home.html index 7be004eab..c870f2088 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -30,7 +30,7 @@ {{txpsN}} - +
diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 6205357c5..a55eb40f0 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -1,10 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('activityController', - function($rootScope, $timeout, $scope, $state, lodash, profileService, walletService, configService, txFormatService, $ionicModal, $log, platformInfo) { - var self = this; - - + function($timeout, $scope, $log, $ionicModal, lodash, profileService, walletService, ongoingProcess, popupService, gettextCatalog) { $scope.init = function() { $scope.fetchingNotifications = true; profileService.getNotifications(50, function(err, n) { @@ -19,4 +16,32 @@ angular.module('copayApp.controllers').controller('activityController', }, 1); }); } + + $scope.openTxModal = function(n) { + var wallet = profileService.getWallet(n.walletId); + + ongoingProcess.set('loadingTxInfo', true); + walletService.getTx(wallet, n.txid, function(err, tx) { + ongoingProcess.set('loadingTxInfo', false); + + if (err) { + $log.error(err); + return popupService.showAlert(gettextCatalog.getString('Error'), err); + } + + if (!tx) { + $log.warn('No tx found'); + return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); + } + + $scope.wallet = wallet; + $scope.btx = lodash.cloneDeep(tx); + $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { + scope: $scope + }).then(function(modal) { + $scope.txDetailsModal = modal; + $scope.txDetailsModal.show(); + }); + }); + }; }); diff --git a/src/js/controllers/modals/txDetails.js b/src/js/controllers/modals/txDetails.js index b7c142edb..dcd14c962 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -1,64 +1,32 @@ 'use strict'; angular.module('copayApp.controllers').controller('txDetailsController', function($log, $timeout, $scope, $filter, $stateParams, ongoingProcess, walletService, lodash, gettextCatalog, profileService, configService, txFormatService, externalLinkService, popupService) { - var self = $scope.self; - var wallet = profileService.getWallet($stateParams.walletId || $scope.walletId); var config = configService.getSync(); var configWallet = config.wallet; var walletSettings = configWallet.settings; + var wallet; $scope.title = gettextCatalog.getString('Transaction'); - $scope.loadingTxInfo = false; $scope.init = function() { - $scope.loadingTxInfo = true; - ongoingProcess.set('loadingTxInfo', true); - findTx($scope.txid, function(err, tx) { - ongoingProcess.set('loadingTxInfo', false); - $scope.loadingTxInfo = false; - if (err) { - $log.error(err); - popupService.showAlert(gettextCatalog.getString('Error'), err); - return $scope.cancel(); - } + wallet = $scope.wallet; + $scope.alternativeIsoCode = walletSettings.alternativeIsoCode; + $scope.color = wallet.color; + $scope.copayerId = wallet.credentials.copayerId; + $scope.isShared = wallet.credentials.n > 1; + $scope.btx.feeLevel = walletSettings.feeLevel; - if (!tx) { - $log.warn('No tx found'); - popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); - return $scope.cancel(); - } + if ($scope.btx.action != 'invalid') { + if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); + if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); + if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); + } - $scope.btx = lodash.cloneDeep(tx); - $scope.alternativeIsoCode = walletSettings.alternativeIsoCode; - $scope.color = wallet.color; - $scope.copayerId = wallet.credentials.copayerId; - $scope.isShared = wallet.credentials.n > 1; - $scope.btx.feeLevel = walletSettings.feeLevel; + initActionList(); + getAlternativeAmount(); - if ($scope.btx.action != 'invalid') { - if ($scope.btx.action == 'sent') $scope.title = gettextCatalog.getString('Sent Funds'); - if ($scope.btx.action == 'received') $scope.title = gettextCatalog.getString('Received Funds'); - if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); - } - - initActionList(); - getAlternativeAmount(); - - $timeout(function() { - $scope.$apply(); - }, 10); - }); - }; - - function findTx(txid, cb) { - walletService.getTxHistory(wallet, {}, function(err, txHistory) { - if (err) return cb(err); - - var tx = lodash.find(txHistory, { - txid: txid - }); - - return cb(null, tx); - }); + $timeout(function() { + $scope.$apply(); + }, 100); }; function initActionList() { @@ -158,8 +126,5 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.cancel = function() { $scope.txDetailsModal.hide(); - $timeout(function() { - $scope.txDetailsModal.remove(); - }, 10); }; }); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 605c67ee3..2acf9428c 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('tabHomeController', - function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, lodash, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { + function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { $scope.externalServices = {}; $scope.bitpayCardEnabled = true; // TODO $scope.openTxpModal = txpModalService.open; @@ -17,13 +17,30 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); $scope.openTxModal = function(n) { - $scope.txid = n.txid; - $scope.walletId = n.walletId; - $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { - scope: $scope - }).then(function(modal) { - $scope.txDetailsModal = modal; - $scope.txDetailsModal.show(); + var wallet = profileService.getWallet(n.walletId); + + ongoingProcess.set('loadingTxInfo', true); + walletService.getTx(wallet, n.txid, function(err, tx) { + ongoingProcess.set('loadingTxInfo', false); + + if (err) { + $log.error(err); + return popupService.showAlert(gettextCatalog.getString('Error'), err); + } + + if (!tx) { + $log.warn('No tx found'); + return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); + } + + $scope.wallet = wallet; + $scope.btx = lodash.cloneDeep(tx); + $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { + scope: $scope + }).then(function(modal) { + $scope.txDetailsModal = modal; + $scope.txDetailsModal.show(); + }); }); }; diff --git a/src/js/controllers/walletDetails.js b/src/js/controllers/walletDetails.js index f9a23f91c..9b1b63c41 100644 --- a/src/js/controllers/walletDetails.js +++ b/src/js/controllers/walletDetails.js @@ -131,18 +131,13 @@ angular.module('copayApp.controllers').controller('walletDetailsController', fun $scope.close = function() { $scope.searchModal.hide(); } - }; $scope.openTxModal = function(btx) { - var self = this; - $scope.btx = lodash.cloneDeep(btx); - $scope.self = self; - + $scope.walletId = wallet.id; $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { - scope: $scope, - hideDelay: 500 + scope: $scope }).then(function(modal) { $scope.txDetailsModal = modal; $scope.txDetailsModal.show(); diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index d23c8b906..0af28637b 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -502,6 +502,17 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; + root.getTx = function(wallet, txid, cb) { + root.getTxHistory(wallet, {}, function(err, txHistory) { + if (err) return cb(err); + + var tx = lodash.find(txHistory, { + txid: txid + }); + + return cb(null, tx); + }); + }; root.getTxHistory = function(wallet, opts, cb) { opts = opts || {}; From 9ce67ed68a5f1445427e97fd0a3040a2e3d52692 Mon Sep 17 00:00:00 2001 From: Javier Date: Tue, 20 Sep 2016 16:45:43 -0300 Subject: [PATCH 4/7] use cached history first --- src/js/services/walletService.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 0af28637b..7f2f76e20 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -503,15 +503,23 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }; root.getTx = function(wallet, txid, cb) { - root.getTxHistory(wallet, {}, function(err, txHistory) { - if (err) return cb(err); - - var tx = lodash.find(txHistory, { + if (wallet.completeHistory && wallet.completeHistory.isValid) { + var tx = lodash.find(wallet.completeHistory, { txid: txid }); return cb(null, tx); - }); + } else { + root.getTxHistory(wallet, {}, function(err, txHistory) { + if (err) return cb(err); + + var tx = lodash.find(txHistory, { + txid: txid + }); + + return cb(null, tx); + }); + } }; root.getTxHistory = function(wallet, opts, cb) { From ceb97796c77ea9dee090bdb0b7ed2977629f86d6 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 10:49:56 -0300 Subject: [PATCH 5/7] refactor --- src/js/controllers/modals/txDetails.js | 27 +++++++++++++++++++++----- src/js/services/walletService.js | 15 ++++++++++---- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/src/js/controllers/modals/txDetails.js b/src/js/controllers/modals/txDetails.js index dcd14c962..dd2ed813c 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -21,12 +21,29 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio if ($scope.btx.action == 'moved') $scope.title = gettextCatalog.getString('Moved Funds'); } + updateMemo(); initActionList(); getAlternativeAmount(); $timeout(function() { $scope.$apply(); - }, 100); + }); + }; + + function updateMemo() { + wallet.getTxNote({ + txid: $scope.btx.txid + }, function(err, note) { + if (err || !note) { + $log.debug(gettextCatalog.getString('Could not fetch transaction note')); + return; + } + + $scope.note = note; + $timeout(function() { + $scope.$apply(); + }); + }); }; function initActionList() { @@ -64,12 +81,12 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio }; $scope.showCommentPopup = function() { - popupService.showPrompt(gettextCatalog.getString('Memo'), ' ', {}, function(res) { + popupService.showPrompt(gettextCatalog.getString('Memo'), ' ', {}, function(text) { $log.debug('Saving memo'); var args = { txid: $scope.btx.txid, - body: res + body: text }; wallet.editTxNote(args, function(err) { @@ -81,7 +98,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.btx.note = null; if (args.body) { $scope.btx.note = {}; - $scope.btx.note.body = res; + $scope.btx.note.body = text; $scope.btx.note.editedByName = wallet.credentials.copayerName; $scope.btx.note.editedOn = Math.floor(Date.now() / 1000); } @@ -89,7 +106,7 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $timeout(function() { $scope.$apply(); - }, 200); + }); }); }); }; diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index 7f2f76e20..abeff92ee 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -503,23 +503,30 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }; root.getTx = function(wallet, txid, cb) { + var tx; + if (wallet.completeHistory && wallet.completeHistory.isValid) { - var tx = lodash.find(wallet.completeHistory, { + tx = lodash.find(wallet.completeHistory, { txid: txid }); - return cb(null, tx); + finish(); } else { root.getTxHistory(wallet, {}, function(err, txHistory) { if (err) return cb(err); - var tx = lodash.find(txHistory, { + tx = lodash.find(txHistory, { txid: txid }); - return cb(null, tx); + finish(); }); } + + function finish() { + if (tx) return cb(null, tx); + else return cb(); + }; }; root.getTxHistory = function(wallet, opts, cb) { From b146d405391a23deff57821cf0f5346ba67811d4 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 11:38:38 -0300 Subject: [PATCH 6/7] open txp modal from recent activity --- public/views/activity.html | 2 +- public/views/tab-home.html | 2 +- src/js/controllers/activity.js | 32 +++++++++++++++++++++++++------- src/js/controllers/tab-home.js | 13 ++++++++++++- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/public/views/activity.html b/public/views/activity.html index c020fa25f..ea976412a 100644 --- a/public/views/activity.html +++ b/public/views/activity.html @@ -19,7 +19,7 @@
-
+
diff --git a/public/views/tab-home.html b/public/views/tab-home.html index c870f2088..a60921131 100644 --- a/public/views/tab-home.html +++ b/public/views/tab-home.html @@ -44,7 +44,7 @@
Updating activity. Please stand by
- +
diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index a55eb40f0..c1b7a8a2c 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -1,7 +1,9 @@ 'use strict'; angular.module('copayApp.controllers').controller('activityController', - function($timeout, $scope, $log, $ionicModal, lodash, profileService, walletService, ongoingProcess, popupService, gettextCatalog) { + function($timeout, $scope, $log, $ionicModal, lodash, txpModalService, profileService, walletService, ongoingProcess, popupService, gettextCatalog) { + $scope.openTxpModal = txpModalService.open; + $scope.init = function() { $scope.fetchingNotifications = true; profileService.getNotifications(50, function(err, n) { @@ -11,13 +13,29 @@ angular.module('copayApp.controllers').controller('activityController', } $scope.fetchingNotifications = false; $scope.notifications = n; - $timeout(function() { - $scope.$apply(); - }, 1); - }); - } - $scope.openTxModal = function(n) { + profileService.getTxps({}, function(err, txps, n) { + if (err) $log.error(err); + $scope.txps = txps; + $timeout(function() { + $scope.$apply(); + }); + }); + }); + }; + + $scope.openNotificationModal = function(n) { + if (!n.txpId && n.txid) { + openTxModal(n); + } else { + var txp = lodash.find($scope.txps, { + id: n.txpId + }); + if (txp) txpModalService.open(txp); + } + }; + + var openTxModal = function(n) { var wallet = profileService.getWallet(n.walletId); ongoingProcess.set('loadingTxInfo', true); diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 2acf9428c..4a6965e31 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -16,7 +16,18 @@ angular.module('copayApp.controllers').controller('tabHomeController', $scope.coinbaseEnabled = config.coinbase.enabled && !isWindowsPhoneApp; }); - $scope.openTxModal = function(n) { + $scope.openNotificationModal = function(n) { + if (!n.txpId && n.txid) { + openTxModal(n); + } else { + var txp = lodash.find($scope.txps, { + id: n.txpId + }); + if (txp) txpModalService.open(txp); + } + }; + + var openTxModal = function(n) { var wallet = profileService.getWallet(n.walletId); ongoingProcess.set('loadingTxInfo', true); From e71b7ae963d9ebbe0c462b691075d1179d425b27 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 11:43:40 -0300 Subject: [PATCH 7/7] not found message --- src/js/controllers/activity.js | 4 ++++ src/js/controllers/tab-home.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index c1b7a8a2c..025a4b062 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -32,6 +32,10 @@ angular.module('copayApp.controllers').controller('activityController', id: n.txpId }); if (txp) txpModalService.open(txp); + else { + $log.warn('No txp found'); + return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); + } } }; diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 4a6965e31..12d7547c5 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -24,6 +24,10 @@ angular.module('copayApp.controllers').controller('tabHomeController', id: n.txpId }); if (txp) txpModalService.open(txp); + else { + $log.warn('No txp found'); + return popupService.showAlert(gettextCatalog.getString('Transaction not found'), null); + } } };