From d2f09291cfacf4113fe9bf68a09598dc30c8414d Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Thu, 30 Oct 2014 16:20:25 -0300 Subject: [PATCH] add change storage to settings --- config.js | 4 ++-- js/controllers/history.js | 23 +++++++------------- js/controllers/settings.js | 22 ++++++++++++++++++- js/services/controllerUtils.js | 27 ++++++++++++------------ test/unit/controllers/controllersSpec.js | 13 +++++++----- views/history.html | 9 +------- views/settings.html | 10 +++++++++ 7 files changed, 64 insertions(+), 44 deletions(-) diff --git a/config.js b/config.js index cbf991b12..f948ea2ac 100644 --- a/config.js +++ b/config.js @@ -55,10 +55,10 @@ var defaultConfig = { plugins: { //LocalStorage: true, - EncryptedLocalStorage: true, +// EncryptedLocalStorage: true, //GoogleDrive: true, //InsightStorage: true - //EncryptedInsightStorage: true + EncryptedInsightStorage: true, }, EncryptedInsightStorage: { diff --git a/js/controllers/history.js b/js/controllers/history.js index 961f494fa..f5f0e465b 100644 --- a/js/controllers/history.js +++ b/js/controllers/history.js @@ -5,7 +5,6 @@ angular.module('copayApp.controllers').controller('HistoryController', function($scope, $rootScope, $timeout, controllerUtils, notification, rateService) { controllerUtils.redirIfNotComplete(); - var w = $rootScope.wallet; $scope.loading = false; @@ -18,6 +17,7 @@ angular.module('copayApp.controllers').controller('HistoryController', var satToUnit = 1 / w.settings.unitToSatoshi; + $scope.update = function() { $scope.loading = true; var from = ($scope.txpCurrentPage - 1) * $scope.txpItemsPerPage; @@ -31,6 +31,8 @@ angular.module('copayApp.controllers').controller('HistoryController', }, 0); }; + + $scope.show = function() { $scope.loading = true; setTimeout(function() { @@ -38,20 +40,15 @@ angular.module('copayApp.controllers').controller('HistoryController', }, 10); }; - $scope.toogleLast = function() { - $scope.lastShowed = !$scope.lastShowed; - if ($scope.lastShowed) { - $scope.getTransactions(); - } - }; $scope.getTransactions = function() { - var self = this; + var w = $rootScope.wallet; if (!w) return; $scope.blockchain_txs = w.cached_txs || []; $scope.loading = true; + w.getTransactionHistory(function(err, res) { if (err) throw err; @@ -77,13 +74,6 @@ angular.module('copayApp.controllers').controller('HistoryController', $scope.getShortNetworkName = function() { return w.getNetworkName().substring(0, 4); }; - - // Autoload transactions on 1-of-1 - if ($rootScope.wallet && $rootScope.wallet.totalCopayers == 1) { - $scope.lastShowed = true; - $scope.getTransactions(); - } - $scope.amountAlternative = function(amount, txIndex, cb) { var w = $rootScope.wallet; rateService.whenAvailable(function() { @@ -92,4 +82,7 @@ angular.module('copayApp.controllers').controller('HistoryController', return cb ? cb() : null; }); }; + + // Autoload transactions + $scope.getTransactions(); }); diff --git a/js/controllers/settings.js b/js/controllers/settings.js index c9fdede6f..9671c5598 100644 --- a/js/controllers/settings.js +++ b/js/controllers/settings.js @@ -8,6 +8,23 @@ angular.module('copayApp.controllers').controller('SettingsController', function $scope.insightLivenet = config.network.livenet.url; $scope.insightTestnet = config.network.testnet.url; + $scope.availableStorages = [{ + name: 'Insight', + pluginName: 'EncryptedInsightStorage', + }, { + name: 'Localstorage', + pluginName: 'EncryptedLocalStorage', + }, + // { + // name: 'GoogleDrive', + // pluginName: 'GoogleDrive', + // } + ]; + + _.each($scope.availableStorages, function(v){ + if (config.plugins[v.pluginName]) + $scope.selectedStorage = v; + }); $scope.availableLanguages = [{ name: 'English', @@ -39,11 +56,14 @@ angular.module('copayApp.controllers').controller('SettingsController', function }, } + var plugins = {}; + plugins[$scope.selectedStorage.pluginName] = true; localStorage.setItem('config', JSON.stringify({ network: insightSettings, version: copay.version, - defaultLanguage: $scope.selectedLanguage.isoCode + defaultLanguage: $scope.selectedLanguage.isoCode, + plugins: plugins, })); // Go home reloading the application diff --git a/js/services/controllerUtils.js b/js/services/controllerUtils.js index 0d42459ce..9c581e897 100644 --- a/js/services/controllerUtils.js +++ b/js/services/controllerUtils.js @@ -32,22 +32,23 @@ angular.module('copayApp.services') root.logout = function() { if ($rootScope.iden) { - $rootScope.iden.store(null, function(){ + $rootScope.iden.store(null, function() { $rootScope.iden.close(); + + delete $rootScope['wallet']; + delete $rootScope['iden']; + + // Clear rootScope + for (var i in $rootScope) { + if (i.charAt(0) != '$') { + delete $rootScope[i]; + } + } + + $location.path('/'); + }); } - - delete $rootScope['wallet']; - delete $rootScope['iden']; - - // Clear rootScope - for (var i in $rootScope) { - if (i.charAt(0) != '$') { - delete $rootScope[i]; - } - } - - $location.path('/'); }; root.onError = function(scope) { diff --git a/test/unit/controllers/controllersSpec.js b/test/unit/controllers/controllersSpec.js index 5e8df93a5..654484485 100644 --- a/test/unit/controllers/controllersSpec.js +++ b/test/unit/controllers/controllersSpec.js @@ -64,7 +64,7 @@ describe("Unit: Controllers", function() { w.getSecret = sinon.stub().returns('secret'); w.getName = sinon.stub().returns('fakeWallet'); w.exportEncrypted = sinon.stub().returns('1234567'); - w.getTransactionHistory = sinon.stub().yields({}); + w.getTransactionHistory = sinon.stub().yields(null); w.getNetworkName = sinon.stub().returns('testnet'); w.createTx = sinon.stub().yields(null); @@ -147,19 +147,22 @@ describe("Unit: Controllers", function() { }); describe('History Controller', function() { - var transactionsCtrl; + var ctrl; beforeEach(inject(function($controller, $rootScope) { + scope = $rootScope.$new(); - transactionsCtrl = $controller('HistoryController', { + scope.wallet = null; + scope.getTransactions = sinon.stub(); + ctrl = $controller('HistoryController', { $scope: scope, }); })); it('should exist', function() { - should.exist(transactionsCtrl); + should.exist(ctrl); }); - it('should have a TransactionController controller', function() { + it('should have a HistoryController controller', function() { expect(scope.loading).equal(false); }); diff --git a/views/history.html b/views/history.html index c476da1b2..18102d26b 100644 --- a/views/history.html +++ b/views/history.html @@ -20,14 +20,7 @@ - -
- - -
+
No transactions yet.
diff --git a/views/settings.html b/views/settings.html index 5c3169805..da62e5ca9 100644 --- a/views/settings.html +++ b/views/settings.html @@ -26,6 +26,16 @@ Insight API server is open-source software. You can run your own instances, check Insight API Homepage
+
+ Wallet and profile storage + + +
+ Wallets and profiles are stored encrypted using your password as a key. You can store the encrypted data locally, on your platform, or remotely on the Insight Server. More pluggins are welcomed! +
+
+