diff --git a/index.html b/index.html index 06859b9fc..48d2a689b 100644 --- a/index.html +++ b/index.html @@ -91,15 +91,6 @@ -
-
-
- {{$root.$flashMessage.message}} - × -
-
-
-
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() { diff --git a/js/controllers/import.js b/js/controllers/import.js index 4ba9d0d0d..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...'; @@ -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; } diff --git a/js/controllers/send.js b/js/controllers/send.js index 9d4e96cb3..5d94e90fd 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; @@ -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..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; @@ -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/controllers/signin.js b/js/controllers/signin.js index 3b76fa09e..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(); @@ -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); diff --git a/js/controllers/transactions.js b/js/controllers/transactions.js index e4bffcc90..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; @@ -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; }; diff --git a/js/directives.js b/js/directives.js index fac694ddb..6ee8e901b 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; 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: { diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index a47c013e9..fc6da0350 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; @@ -73,6 +76,11 @@ describe("Unit: Controllers", function() { expect(array.length).equal(n); }); }); + describe('#create', function() { + it('should work with invalid form', function() { + scope.create(invalidForm); + }); + }); }); @@ -321,4 +329,42 @@ 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); + }); + }); + + 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); + }); + }); + }); + });