From e389a3f82c4d230e3118d27af0daeca61a86a247 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 17:17:24 -0300 Subject: [PATCH 01/11] replace flashmessage for notifications --- js/controllers/send.js | 47 +++++++++++++++------------------- js/controllers/setup.js | 5 +--- js/directives.js | 1 - js/services/controllerUtils.js | 36 ++++++++------------------ 4 files changed, 32 insertions(+), 57 deletions(-) diff --git a/js/controllers/send.js b/js/controllers/send.js index 26c50f6aa..da4bf5610 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -32,10 +32,8 @@ angular.module('copayApp.controllers').controller('SendController', $scope.submitForm = function(form) { if (form.$invalid) { - $rootScope.$flashMessage = { - message: 'Unable to send a transaction proposal. Please, try again', - type: 'error' - }; + var message = 'Unable to send transaction proposal.'; + notification.error('Error', message); return; } @@ -50,20 +48,16 @@ angular.module('copayApp.controllers').controller('SendController', w.createTx(address, amount, commentText, function(ntxid) { if (w.totalCopayers > 1) { $scope.loading = false; - $rootScope.$flashMessage = { - message: 'The transaction proposal has been created', - type: 'success' - }; + var message = 'The transaction proposal has been created'; + notification.success('Success!', message); $rootScope.$digest(); } else { w.sendTx(ntxid, function(txid) { - $rootScope.$flashMessage = txid ? { - type: 'success', - message: 'Transaction broadcasted. txid: ' + txid - } : { - type: 'error', - message: 'There was an error sending the Transaction' - }; + if (txid) { + notification.success('Transaction broadcast', 'Transaction id: ' + txid); + } else { + notification.error('Error', 'There was an error sending the transaction.'); + } $scope.loading = false; }); } @@ -202,10 +196,11 @@ angular.module('copayApp.controllers').controller('SendController', errorMsg = e.message; } - $rootScope.$flashMessage = { - message: errorMsg ? errorMsg : 'Entry removed successful', - type: errorMsg ? 'error' : 'success' - }; + if (errorMsg) { + notification.error('Error', errorMsg); + } else { + notification.success('Success', 'Entry removed successfully'); + } $rootScope.$digest(); }, 500); }; @@ -223,10 +218,7 @@ angular.module('copayApp.controllers').controller('SendController', $scope.submitAddressBook = function(form) { if (form.$invalid) { - $rootScope.$flashMessage = { - message: 'Complete required fields, please', - type: 'error' - }; + notification.error('Form Error', 'Please complete required fields'); return; } var entry = { @@ -255,10 +247,11 @@ angular.module('copayApp.controllers').controller('SendController', errorMsg = e.message; } - $rootScope.$flashMessage = { - message: errorMsg ? errorMsg : 'New entry has been created', - type: errorMsg ? 'error' : 'success' - }; + if (errorMsg) { + notification.error('Error', errorMsg); + } else { + notification.success('Success', 'New entry has been created'); + } $rootScope.$digest(); }, 500); $anchorScroll(); diff --git a/js/controllers/setup.js b/js/controllers/setup.js index dc1cdd834..a2a74f6fc 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -68,10 +68,7 @@ angular.module('copayApp.controllers').controller('SetupController', $scope.create = function(form) { if (form && form.$invalid) { - $rootScope.$flashMessage = { - message: 'Please, enter required fields', - type: 'error' - }; + notification.error('Error', 'Please enter the required fields'); return; } $scope.loading = true; diff --git a/js/directives.js b/js/directives.js index 586a1ac31..f943382a0 100644 --- a/js/directives.js +++ b/js/directives.js @@ -30,7 +30,6 @@ angular.module('copayApp.directives') link: function(scope, element, attrs, ctrl) { setTimeout(function() { scope.$apply(function() { - $rootScope.$flashMessage = {}; }); }, 5000); } diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 065310c54..f8e87d5e9 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -36,35 +36,27 @@ angular.module('copayApp.services') root.onErrorDigest = function(scope, msg) { root.onError(scope); - if (msg) $rootScope.$flashMessage = { - type: 'error', - message: msg - }; + if (msg) { + notification.error('Error', msg); + } $rootScope.$digest(); }; root.installStartupHandlers = function(wallet, $scope) { wallet.on('serverError', function(msg) { - $rootScope.$flashMessage = { - message: 'There was an error connecting to the PeerJS server.' + (msg || 'Check you settings and Internet connection.'), - type: 'error', - }; + notification.error('PeerJS Error', 'There was an error connecting to the PeerJS server.' + + (msg || 'Check you settings and Internet connection.')); root.onErrorDigest($scope); $location.path('addresses'); }); wallet.on('connectionError', function() { - var message = "Looks like you are already connected to this wallet, please logout from it and try importing it again."; - $rootScope.$flashMessage = { - message: message, - type: 'error' - }; + var message = "Looks like you are already connected to this wallet, please logout and try importing it again."; + notification.error('PeerJS Error', message); root.onErrorDigest($scope); }); wallet.on('serverError', function() { - $rootScope.$flashMessage = { - message: 'The PeerJS server is not responding, please try again', - type: 'error' - }; + var message = 'The PeerJS server is not responding, please try again'; + notification.error('PeerJS Error', message); root.onErrorDigest($scope); }); wallet.on('ready', function() { @@ -79,10 +71,7 @@ angular.module('copayApp.services') $rootScope.isCollapsed = true; $rootScope.$watch('insightError', function(status) { if (status === -1) { - $rootScope.$flashMessage = { - type: 'success', - message: 'Networking Restored :)', - }; + notification.success('Networking restored', 'Connection to Insight re-established'); $rootScope.insightError = 0; } }); @@ -117,10 +106,7 @@ angular.module('copayApp.services') notification.enableHtml5Mode(); // for chrome: if support, enable it w.on('badMessage', function(peerId) { - $rootScope.$flashMessage = { - type: 'error', - message: 'Received wrong message from peer id:' + peerId - }; + notification.error('Error', 'Received wrong message from peer ' + peerId); }); w.on('ready', function(myPeerID) { $rootScope.wallet = w; From 40a07e96471ff989d7de5ee677f37717c9fcfca8 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 17:22:41 -0300 Subject: [PATCH 02/11] remove flashmessages from signin --- js/controllers/signin.js | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 3b76fa09e..33f736c9b 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -15,10 +15,7 @@ angular.module('copayApp.controllers').controller('SigninController', $scope.open = function(form) { if (form && form.$invalid) { - $rootScope.$flashMessage = { - message: 'Please, enter required fields', - type: 'error' - }; + notification.error('Error', 'Please enter the required fields'); return; } @@ -36,10 +33,7 @@ angular.module('copayApp.controllers').controller('SigninController', }; if (!w) { $scope.loading = false; - $rootScope.$flashMessage = { - message: errMsg || 'Wrong password', - type: 'error' - }; + notification.error('Error', errMsg || 'Wrong password'); $rootScope.$digest(); return; } @@ -49,10 +43,7 @@ angular.module('copayApp.controllers').controller('SigninController', $scope.join = function(form) { if (form && form.$invalid) { - $rootScope.$flashMessage = { - message: 'Please, enter required fields', - type: 'error' - }; + notification.error('Error', 'Please enter the required fields'); return; } @@ -64,29 +55,15 @@ angular.module('copayApp.controllers').controller('SigninController', $scope.loading = false; if (err || !w) { if (err === 'joinError') - $rootScope.$flashMessage = { - message: 'Can\'t find peer' - }; + notification.error('Can\'t find peer.'); else if (err === 'walletFull') - $rootScope.$flashMessage = { - message: 'The wallet is full', - type: 'error' - }; + notification.error('The wallet is full'); else if (err === 'badNetwork') - $rootScope.$flashMessage = { - message: 'The wallet your are trying to join uses a different Bitcoin Network. Check your settings.', - type: 'error' - }; + notification.error('Network Error', 'The wallet your are trying to join uses a different Bitcoin Network. Check your settings.'); else if (err === 'badSecret') - $rootScope.$flashMessage = { - message: 'Bad secret secret string', - type: 'error' - }; + notification.error('Bad secret', 'The secret string you entered is invalid'); else - $rootScope.$flashMessage = { - message: 'Unknown error', - type: 'error' - }; + notification.error('Unknown error'); controllerUtils.onErrorDigest(); } else { controllerUtils.startNetwork(w, $scope); From 710160ff840bf2cc713c3607ff6f20d93bd8fac7 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 17:27:46 -0300 Subject: [PATCH 03/11] remove flashmessages from import --- js/controllers/import.js | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/js/controllers/import.js b/js/controllers/import.js index 4ba9d0d0d..3756aebf6 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -18,10 +18,7 @@ angular.module('copayApp.controllers').controller('ImportController', var w = walletFactory.import(encryptedObj, passphrase, function(err, w) { if (err) { $scope.loading = false; - $rootScope.$flashMessage = { - message: err.errMsg || 'Wrong password', - type: 'error' - }; + notification.error('Error', err.errMsg || 'Wrong password'); $rootScope.$digest(); return; } @@ -59,10 +56,7 @@ angular.module('copayApp.controllers').controller('ImportController', $scope.import = function(form) { if (form.$invalid) { $scope.loading = false; - $rootScope.$flashMessage = { - message: 'There is an error in the form. Please, try again', - type: 'error' - }; + notification.error('Error', 'There is an error in the form.'); return; } @@ -72,10 +66,7 @@ angular.module('copayApp.controllers').controller('ImportController', if (!backupFile && !backupText) { $scope.loading = false; - $rootScope.$flashMessage = { - message: 'Please, select your backup file or paste the text', - type: 'error' - }; + notification.error('Error', 'Please, select your backup file or paste the file contents'); $scope.loading = false; return; } From c400ba2695e348384aa3a475b0073f1e4b0e3d33 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 17:50:20 -0300 Subject: [PATCH 04/11] remove flashmessages from header --- js/controllers/header.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/js/controllers/header.js b/js/controllers/header.js index d6b2f8924..7d3d3d692 100644 --- a/js/controllers/header.js +++ b/js/controllers/header.js @@ -51,10 +51,7 @@ angular.module('copayApp.controllers').controller('HeaderController', $rootScope.$watch('insightError', function(status) { if (status === -1) { - $rootScope.$flashMessage = { - type: 'success', - message: 'Networking Restored :)', - }; + notification.success('Networking restored', 'Connection to insight restored'); $rootScope.insightError = 0; } }); @@ -98,7 +95,6 @@ angular.module('copayApp.controllers').controller('HeaderController', $scope.signout = function() { logout(); - $scope.clearFlashMessage(); }; $scope.refresh = function() { @@ -111,10 +107,6 @@ angular.module('copayApp.controllers').controller('HeaderController', } }; - $scope.clearFlashMessage = function() { - $rootScope.$flashMessage = {}; - }; - $rootScope.isCollapsed = true; $scope.toggleCollapse = function() { From 1e1ac82a14ccb8c640fab8fbc4e8eb68e25cd9aa Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 17:56:34 -0300 Subject: [PATCH 05/11] remove flashmessages from transactions --- js/controllers/transactions.js | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index e4bffcc90..5efc0eb40 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -107,13 +107,11 @@ angular.module('copayApp.controllers').controller('TransactionsController', $rootScope.txAlertCount = 0; var w = $rootScope.wallet; w.sendTx(ntxid, function(txid) { - $rootScope.$flashMessage = txid ? { - type: 'success', - message: 'Transaction broadcasted. txid: ' + txid - } : { - type: 'error', - message: 'There was an error sending the Transaction' - }; + if (!txid) { + notification.error('Error', 'There was an error sending the transaction'); + } else { + notification.success('Transaction broadcast', 'Transaction id: '+txid); + } if (cb) return cb(); else $scope.update(); }); @@ -124,10 +122,7 @@ angular.module('copayApp.controllers').controller('TransactionsController', var w = $rootScope.wallet; w.sign(ntxid, function(ret) { if (!ret) { - $rootScope.$flashMessage = { - type: 'error', - message: 'There was an error signing the Transaction', - }; + notification.error('Error', 'There was an error signing the transaction'); $scope.update(); } else { var p = w.txProposals.getTxProposal(ntxid); @@ -180,10 +175,7 @@ angular.module('copayApp.controllers').controller('TransactionsController', $rootScope.txAlertCount = 0; var w = $rootScope.wallet; w.reject(ntxid); - $rootScope.$flashMessage = { - type: 'warning', - message: 'Transaction rejected by you' - }; + notification.warning('Transaction rejected', 'You rejected the transaction successfully'); $scope.loading = false; }; From 4c5d3883e1cd8af433e1d88f5241365b462007d5 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 18:15:27 -0300 Subject: [PATCH 06/11] fix import and send, and add test --- js/controllers/import.js | 2 +- js/controllers/send.js | 2 +- test/unit/controllers/controllersSpec.js | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/js/controllers/import.js b/js/controllers/import.js index 3756aebf6..a1991d159 100644 --- a/js/controllers/import.js +++ b/js/controllers/import.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('ImportController', - function($scope, $rootScope, walletFactory, controllerUtils, Passphrase) { + function($scope, $rootScope, walletFactory, controllerUtils, Passphrase, notification) { $scope.title = 'Import a backup'; $scope.importStatus = 'Importing wallet - Reading backup...'; diff --git a/js/controllers/send.js b/js/controllers/send.js index da4bf5610..000f3a71d 100644 --- a/js/controllers/send.js +++ b/js/controllers/send.js @@ -2,7 +2,7 @@ var bitcore = require('bitcore'); angular.module('copayApp.controllers').controller('SendController', - function($scope, $rootScope, $window, $location, $timeout, $anchorScroll, $modal, isMobile) { + function($scope, $rootScope, $window, $location, $timeout, $anchorScroll, $modal, isMobile, notification) { $scope.title = 'Send'; $scope.loading = false; var satToUnit = 1 / config.unitToSatoshi; diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 7dcadc715..2e4448bad 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -301,4 +301,19 @@ describe("Unit: Controllers", function() { }); }); + describe('Import Controller', function() { + var what; + beforeEach(inject(function($controller, $rootScope) { + scope = $rootScope.$new(); + what = $controller('ImportController', { + $scope: scope, + }); + })); + + it('should exist', function() { + should.exist(what); + }); + + }); + }); From 8d3d35ff8346f32932eaccfffa900c74983f9488 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 18:22:32 -0300 Subject: [PATCH 07/11] fix setup, add test --- js/controllers/setup.js | 2 +- test/unit/controllers/controllersSpec.js | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/js/controllers/setup.js b/js/controllers/setup.js index a2a74f6fc..3ac730299 100644 --- a/js/controllers/setup.js +++ b/js/controllers/setup.js @@ -33,7 +33,7 @@ var valid_pairs = { }; angular.module('copayApp.controllers').controller('SetupController', - function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase) { + function($scope, $rootScope, $location, $timeout, walletFactory, controllerUtils, Passphrase, backupService, notification) { $rootScope.videoInfo = {}; $scope.loading = false; diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 2e4448bad..b76b4488c 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -73,6 +73,14 @@ describe("Unit: Controllers", function() { expect(array.length).equal(n); }); }); + describe('#create', function() { + it('should work with invalid form', function() { + var form = { + $invalid: true + }; + scope.create(form); + }); + }); }); From 5e1252333890ff83dc42bb4d7f58cba450fe6648 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 18:37:30 -0300 Subject: [PATCH 08/11] fix signin and add tests --- js/controllers/signin.js | 2 +- test/unit/controllers/controllersSpec.js | 31 +++++++++++++++++++++--- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/js/controllers/signin.js b/js/controllers/signin.js index 33f736c9b..b2e6ef0c8 100644 --- a/js/controllers/signin.js +++ b/js/controllers/signin.js @@ -1,7 +1,7 @@ 'use strict'; angular.module('copayApp.controllers').controller('SigninController', - function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase) { + function($scope, $rootScope, $location, walletFactory, controllerUtils, Passphrase, backupService, notification) { var cmp = function(o1, o2) { var v1 = o1.show.toLowerCase(), v2 = o2.show.toLowerCase(); diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index b76b4488c..bd24badb9 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -12,6 +12,9 @@ saveAs = function(o) { describe("Unit: Controllers", function() { + var invalidForm = { + $invalid: true + }; var scope; @@ -75,10 +78,7 @@ describe("Unit: Controllers", function() { }); describe('#create', function() { it('should work with invalid form', function() { - var form = { - $invalid: true - }; - scope.create(form); + scope.create(invalidForm); }); }); @@ -321,7 +321,30 @@ describe("Unit: Controllers", function() { it('should exist', function() { should.exist(what); }); + }); + describe('Signin Controller', function() { + var what; + beforeEach(inject(function($controller, $rootScope) { + scope = $rootScope.$new(); + what = $controller('SigninController', { + $scope: scope, + }); + })); + + it('should exist', function() { + should.exist(what); + }); + describe('#open', function() { + it('should work with invalid form', function() { + scope.open(invalidForm); + }); + }); + describe('#join', function() { + it('should work with invalid form', function() { + scope.join(invalidForm); + }); + }); }); }); From 507b844eed4d76c991137bbc25dcd9feaaccfcad Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 18:51:25 -0300 Subject: [PATCH 09/11] fix transactions --- js/controllers/transactions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index 5efc0eb40..78fcae464 100644 --- a/js/controllers/transactions.js +++ b/js/controllers/transactions.js @@ -2,7 +2,7 @@ var bitcore = require('bitcore'); angular.module('copayApp.controllers').controller('TransactionsController', - function($scope, $rootScope, $timeout, controllerUtils) { + function($scope, $rootScope, $timeout, controllerUtils, notification) { $scope.title = 'Transactions'; $scope.loading = false; From 5bc573b490440de49a8b385a7e9ca12c8653aeae Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 19:09:48 -0300 Subject: [PATCH 10/11] fix error notif time --- js/services/notifications.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/services/notifications.js b/js/services/notifications.js index 22645ec17..e8f9bda2c 100644 --- a/js/services/notifications.js +++ b/js/services/notifications.js @@ -21,7 +21,7 @@ factory('notification', ['$timeout', enabled: true }, error: { - duration: 1e10, + duration: 5000, enabled: true }, success: { From 938d4b14ef950ca3fd10e72a8a8b95039b258346 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 26 Jun 2014 19:15:39 -0300 Subject: [PATCH 11/11] remove unused html --- index.html | 9 --------- 1 file changed, 9 deletions(-) diff --git a/index.html b/index.html index 0381a52b0..caf12b01b 100644 --- a/index.html +++ b/index.html @@ -91,15 +91,6 @@ -
-
-
- {{$root.$flashMessage.message}} - × -
-
-
-