From 60a7f0c287b36bd897a559666e807e8eeafda510 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 14:55:56 -0300 Subject: [PATCH 1/5] save memo correctly --- public/views/modals/tx-details.html | 1 - src/js/controllers/modals/txDetails.js | 7 ++++++- src/js/services/popupService.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/public/views/modals/tx-details.html b/public/views/modals/tx-details.html index e1e2c3640..3365cbee9 100644 --- a/public/views/modals/tx-details.html +++ b/public/views/modals/tx-details.html @@ -141,7 +141,6 @@
Add Memo Memo -
{{btx.note.body}}
diff --git a/src/js/controllers/modals/txDetails.js b/src/js/controllers/modals/txDetails.js index dd2ed813c..d5b6f79d3 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -81,7 +81,12 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio }; $scope.showCommentPopup = function() { - popupService.showPrompt(gettextCatalog.getString('Memo'), ' ', {}, function(text) { + var opts = {}; + if ($scope.btx.note && $scope.btx.note.body) opts.defaultText = $scope.btx.note.body; + + popupService.showPrompt(null, gettextCatalog.getString('Memo'), opts, function(text) { + if (typeof text == "undefined") return; + $log.debug('Saving memo'); var args = { diff --git a/src/js/services/popupService.js b/src/js/services/popupService.js index 1e1c93a22..c50903d46 100644 --- a/src/js/services/popupService.js +++ b/src/js/services/popupService.js @@ -37,7 +37,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni inputPlaceholder: opts.inputPlaceholder, defaultText: opts.defaultText }).then(function(res) { - return cb(res) + return cb(res); }); }; From c12f33b1d94e9a56f735a1d6c83709c67b934de2 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 16:04:25 -0300 Subject: [PATCH 2/5] open a rejected txp --- src/js/controllers/tab-home.js | 22 +++++++++++++++++----- src/js/services/txpModalService.js | 7 ++++--- src/js/services/walletService.js | 7 +++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index 95c0908f3..a9718c5ba 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -2,6 +2,7 @@ angular.module('copayApp.controllers').controller('tabHomeController', function($rootScope, $timeout, $scope, $state, $stateParams, $ionicModal, $ionicScrollDelegate, gettextCatalog, lodash, popupService, ongoingProcess, profileService, walletService, configService, $log, platformInfo, storageService, txpModalService, $window) { + var wallet; $scope.externalServices = {}; $scope.bitpayCardEnabled = true; // TODO $scope.openTxpModal = txpModalService.open; @@ -17,22 +18,33 @@ angular.module('copayApp.controllers').controller('tabHomeController', }); $scope.openNotificationModal = function(n) { + wallet = profileService.getWallet(n.walletId); + if (n.txid) { openTxModal(n); } else { var txp = lodash.find($scope.txps, { id: n.txpId }); - if (txp) txpModalService.open(txp); - else { - $log.warn('No txp found'); - return popupService.showAlert(null, gettextCatalog.getString('Transaction not found')); + if (txp) { + txpModalService.open(txp); + } else { + ongoingProcess.set('loadingTxInfo', true); + walletService.getTxp(wallet, n.txpId, function(err, txp) { + var _txp = txp; + ongoingProcess.set('loadingTxInfo', false); + if (err) { + $log.warn('No txp found'); + return popupService.showAlert(null, gettextCatalog.getString('Transaction not found')); + } + txpModalService.open(_txp); + }); } } }; var openTxModal = function(n) { - var wallet = profileService.getWallet(n.walletId); + wallet = profileService.getWallet(n.walletId); ongoingProcess.set('loadingTxInfo', true); walletService.getTx(wallet, n.txid, function(err, tx) { diff --git a/src/js/services/txpModalService.js b/src/js/services/txpModalService.js index b14f5c4fd..bc7d244d4 100644 --- a/src/js/services/txpModalService.js +++ b/src/js/services/txpModalService.js @@ -1,6 +1,6 @@ 'use strict'; -angular.module('copayApp.services').factory('txpModalService', function(configService, $rootScope, $ionicModal) { +angular.module('copayApp.services').factory('txpModalService', function(configService, profileService, $rootScope, $ionicModal) { var root = {}; @@ -11,11 +11,12 @@ angular.module('copayApp.services').factory('txpModalService', function(configSe root.open = function(tx) { + var wallet = tx.wallet ? tx.wallet : profileService.getWallet(tx.walletId); var config = configService.getSync().wallet; var scope = $rootScope.$new(true); scope.tx = tx; - scope.wallet = tx.wallet; - scope.copayers = tx.wallet ? tx.wallet.copayers : null; + scope.wallet = wallet; + scope.copayers = wallet ? wallet.copayers : null; scope.isGlidera = glideraActive; scope.currentSpendUnconfirmed = config.spendUnconfirmed; // scope.tx.hasMultiplesOutputs = true; // Uncomment to test multiple outputs diff --git a/src/js/services/walletService.js b/src/js/services/walletService.js index abeff92ee..c6ec8bac5 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -502,6 +502,13 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; + root.getTxp = function(wallet, txpid, cb) { + wallet.getTx(txpid, function(err, txp) { + if (err) return cb(err); + return cb(null, txp); + }); + }; + root.getTx = function(wallet, txid, cb) { var tx; From fca4a154c3a2395203f1c751aaa322dd87cc3185 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 16:19:00 -0300 Subject: [PATCH 3/5] fix toAddress param --- src/js/services/txpModalService.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/js/services/txpModalService.js b/src/js/services/txpModalService.js index bc7d244d4..a17f1c030 100644 --- a/src/js/services/txpModalService.js +++ b/src/js/services/txpModalService.js @@ -15,6 +15,7 @@ angular.module('copayApp.services').factory('txpModalService', function(configSe var config = configService.getSync().wallet; var scope = $rootScope.$new(true); scope.tx = tx; + if (!scope.tx.toAddress) scope.tx.toAddress = tx.outputs[0].toAddress; scope.wallet = wallet; scope.copayers = wallet ? wallet.copayers : null; scope.isGlidera = glideraActive; From 93d694d04822d3692a5a5bf40343dfda3deb102e Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 17:28:59 -0300 Subject: [PATCH 4/5] sync memo --- public/views/modals/tx-details.html | 6 +++--- src/js/controllers/activity.js | 19 ++++++++++++------- src/js/controllers/modals/txDetails.js | 7 ------- src/js/controllers/tab-home.js | 19 ++++++++++++------- src/js/services/walletService.js | 9 +++++++++ 5 files changed, 36 insertions(+), 24 deletions(-) diff --git a/public/views/modals/tx-details.html b/public/views/modals/tx-details.html index 3365cbee9..797909be6 100644 --- a/public/views/modals/tx-details.html +++ b/public/views/modals/tx-details.html @@ -139,9 +139,9 @@
- Add Memo - Memo -
+ Add Memo + Memo +
{{btx.note.body}}
Edited by {{btx.note.editedByName}}, diff --git a/src/js/controllers/activity.js b/src/js/controllers/activity.js index 696730bff..ee1d50720 100644 --- a/src/js/controllers/activity.js +++ b/src/js/controllers/activity.js @@ -56,13 +56,18 @@ angular.module('copayApp.controllers').controller('activityController', return popupService.showAlert(null, gettextCatalog.getString('Transaction not found')); } - $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(); + walletService.getTxNote(wallet, n.txid, function(err, note) { + if (err) $log.debug(gettextCatalog.getString('Could not fetch transaction note')); + + $scope.wallet = wallet; + $scope.btx = lodash.cloneDeep(tx); + $scope.btx.note = note; + $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 d5b6f79d3..b4e45dae1 100644 --- a/src/js/controllers/modals/txDetails.js +++ b/src/js/controllers/modals/txDetails.js @@ -24,10 +24,6 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio updateMemo(); initActionList(); getAlternativeAmount(); - - $timeout(function() { - $scope.$apply(); - }); }; function updateMemo() { @@ -38,7 +34,6 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $log.debug(gettextCatalog.getString('Could not fetch transaction note')); return; } - $scope.note = note; $timeout(function() { $scope.$apply(); @@ -108,7 +103,6 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.btx.note.editedOn = Math.floor(Date.now() / 1000); } $scope.btx.searcheableString = null; - $timeout(function() { $scope.$apply(); }); @@ -132,7 +126,6 @@ angular.module('copayApp.controllers').controller('txDetailsController', functio $scope.rateDate = res.fetchedOn; $scope.rateStr = res.rate + ' ' + $scope.alternativeIsoCode; $scope.alternativeAmountStr = $filter('formatFiatAmount')(alternativeAmountBtc * res.rate) + ' ' + $scope.alternativeIsoCode; - $scope.$apply(); } }); }; diff --git a/src/js/controllers/tab-home.js b/src/js/controllers/tab-home.js index a9718c5ba..fe9b10423 100644 --- a/src/js/controllers/tab-home.js +++ b/src/js/controllers/tab-home.js @@ -60,13 +60,18 @@ angular.module('copayApp.controllers').controller('tabHomeController', return popupService.showAlert(null, gettextCatalog.getString('Transaction not found')); } - $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(); + walletService.getTxNote(wallet, n.txid, function(err, note) { + if (err) $log.debug(gettextCatalog.getString('Could not fetch transaction note')); + + $scope.wallet = wallet; + $scope.btx = lodash.cloneDeep(tx); + $scope.btx.note = note; + $ionicModal.fromTemplateUrl('views/modals/tx-details.html', { + 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 c6ec8bac5..0c9d00583 100644 --- a/src/js/services/walletService.js +++ b/src/js/services/walletService.js @@ -502,6 +502,15 @@ angular.module('copayApp.services').factory('walletService', function($log, $tim }); }; + root.getTxNote = function(wallet, txid, cb) { + wallet.getTxNote({ + txid: txid + }, function(err, note) { + if (err || !note) return cb(true); + return cb(null, note); + }); + }; + root.getTxp = function(wallet, txpid, cb) { wallet.getTx(txpid, function(err, txp) { if (err) return cb(err); From 44619cb936d901c084f0339f5c117dc194ae8aa7 Mon Sep 17 00:00:00 2001 From: Javier Date: Wed, 21 Sep 2016 17:46:20 -0300 Subject: [PATCH 5/5] fix default text on popupService --- src/js/services/popupService.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/js/services/popupService.js b/src/js/services/popupService.js index c50903d46..2ca1dfa0f 100644 --- a/src/js/services/popupService.js +++ b/src/js/services/popupService.js @@ -58,12 +58,12 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni navigator.notification.confirm(message, onConfirm, title, [okText, cancelText]); }; - var _cordovaPrompt = function(title, message, cb) { + var _cordovaPrompt = function(title, message, opts, cb) { var onPrompt = function(results) { if (results.buttonIndex == 1) return cb(results.input1); else return cb(); } - navigator.notification.prompt(message, onPrompt, title); + navigator.notification.prompt(message, onPrompt, title, null, opts.defaultText); }; /** @@ -118,7 +118,7 @@ angular.module('copayApp.services').service('popupService', function($log, $ioni $log.warn(title + ": " + message); if (isCordova) - _cordovaPrompt(title, message, cb); + _cordovaPrompt(title, message, opts, cb); else _ionicPrompt(title, message, opts, cb); };