diff --git a/config.js b/config.js index 7b67351bd..d4772c096 100644 --- a/config.js +++ b/config.js @@ -53,8 +53,8 @@ var defaultConfig = { verbose: 1, plugins: { - LocalStorage: true, - // GoogleDrive: true, + //LocalStorage: true, + GoogleDrive: true, }, GoogleDrive: { diff --git a/js/controllers/home.js b/js/controllers/home.js index b0d325448..23119ded1 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -5,8 +5,7 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc controllerUtils.redirIfLogged(); $scope.retreiving = true; - - walletFactory.getWallets(function(ret) { + walletFactory.getWallets(function(err,ret) { $scope.retreiving = false; $scope.hasWallets = (ret && ret.length > 0) ? true : false; }); diff --git a/js/controllers/open.js b/js/controllers/open.js index 8fb5df483..a98ff6a5e 100644 --- a/js/controllers/open.js +++ b/js/controllers/open.js @@ -16,16 +16,23 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc $scope.loading = false; $scope.retreiving = true; - walletFactory.getWallets(function(wallets) { + walletFactory.getWallets(function(err, wallets) { - if (!wallets || !wallets.length) { + if (err || !wallets || !wallets.length) { $location.path('/'); } else { + $scope.retreiving = false; $scope.wallets = wallets.sort(cmp); walletFactory.storage.getLastOpened(function(ret) { + if (ret && _.indexOf(_.pluck($scope.wallets, 'id')) == -1) + ret = null; + $scope.selectedWalletId = ret || ($scope.wallets[0] && $scope.wallets[0].id); - $scope.retreiving = false; + + setTimeout(function() { + $rootScope.$digest(); + }, 0); }); } }); @@ -49,9 +56,10 @@ angular.module('copayApp.controllers').controller('OpenController', function($sc $scope.loading = false; notification.error('Error', err.errMsg || 'Wrong password'); $rootScope.$digest(); + } else { + $rootScope.updatingBalance = true; + controllerUtils.startNetwork(w, $scope); } - $rootScope.updatingBalance = true; - controllerUtils.startNetwork(w, $scope); }); }); }; diff --git a/js/models/Storage.js b/js/models/Storage.js index 4c8c658cb..36d5f5fda 100644 --- a/js/models/Storage.js +++ b/js/models/Storage.js @@ -4,12 +4,13 @@ var CryptoJS = require('node-cryptojs-aes').CryptoJS; var bitcore = require('bitcore'); var preconditions = require('preconditions').instance(); var _ = require('underscore'); - +var CACHE_DURATION = 1000 * 60 * 5; var id = 0; function Storage(opts) { opts = opts || {}; + this.wListCache = {}; this.__uniqueid = ++id; if (opts.password) this.setPassphrase(opts.password); @@ -211,6 +212,9 @@ Storage.prototype.getWalletIds = function(cb) { Storage.prototype.getWallets = function(cb) { preconditions.checkArgument(cb); + if (this.wListCache.ts > Date.now()) + return cb(this.wListCache.data) + var wallets = []; var self = this; @@ -228,6 +232,8 @@ Storage.prototype.getWallets = function(cb) { name: name, }); if (++i == l) { + self.wListCache.data = wallets; + self.wListCache.ts = Date.now() + CACHE_DURATION; return cb(wallets); } }) diff --git a/js/models/core/TxProposals.js b/js/models/core/TxProposals.js index 44f1f9bb7..80e3648c5 100644 --- a/js/models/core/TxProposals.js +++ b/js/models/core/TxProposals.js @@ -50,7 +50,6 @@ TxProposals.prototype.getNtxidsSince = function(sinceTs) { if (txp.createdTs >= sinceTs) ret.push(ii); } -console.log('[TxProposals.js.52:ret:]',ret); //TODO return ret; }; diff --git a/plugins/GoogleDrive.js b/plugins/GoogleDrive.js index 8cf41d72e..ee4260ea5 100644 --- a/plugins/GoogleDrive.js +++ b/plugins/GoogleDrive.js @@ -3,6 +3,7 @@ var preconditions = require('preconditions').singleton(); var loaded = 0; var SCOPES = 'https://www.googleapis.com/auth/drive'; +var log = require('../js/log'); function GoogleDrive(config) { preconditions.checkArgument(config && config.clientId, 'No clientId at GoogleDrive config'); @@ -24,8 +25,7 @@ function GoogleDrive(config) { }; window.InitGoogleDrive = function() { - - // console.log('[googleDrive.js.18] setting loaded'); //TODO + log.debug('googleDrive loadeded'); //TODO loaded = 1; }; @@ -47,7 +47,7 @@ GoogleDrive.prototype.initLoaded = function() { */ GoogleDrive.prototype.checkAuth = function() { - console.log('\tChecking google Auth'); + log.debug('Google Drive: Checking Auth'); gapi.auth.authorize({ 'client_id': this.clientId, 'scope': SCOPES, @@ -61,7 +61,7 @@ GoogleDrive.prototype.checkAuth = function() { */ GoogleDrive.prototype.handleAuthResult = function(authResult) { var self = this; - // console.log('[googleDrive.js.39:authResult:]', authResult); //TODO + log.debug('Google Drive: authResult', authResult); //TODO if (authResult.error) { if (authResult.error) { @@ -93,7 +93,7 @@ GoogleDrive.prototype._httpGet = function(theUrl) { } GoogleDrive.prototype.getItem = function(k, cb) { - console.log('[googleDrive.js.95:getItem:]', k); //TODO + //console.log('[googleDrive.js.95:getItem:]', k); //TODO var self = this; self.checkReady(); @@ -208,7 +208,7 @@ GoogleDrive.prototype._mkdir = function(cb) { preconditions.checkArgument(cb); var self = this; - console.log('Creating drive folder ' + this.home); + log.debug('Creating drive folder ' + this.home); var request = gapi.client.request({ 'path': '/drive/v2/files', @@ -231,18 +231,17 @@ GoogleDrive.prototype._idForName = function(name, cb) { var self = this; if (!self.isReady) { - console.log('\tWaiting for Drive'); + log.debug('Waiting for Google Drive'); self.ts = self.ts * 1.5; return setTimeout(self._idForName.bind(self, name, cb), self.ts); } - // console.log('[googleDrive.js.178:name:]', name); //TODO if (self.idCache[name]) { // console.log('[googleDrive.js.212:] FROM CACHE', name, self.idCache[name]); //TODO return cb(self.idCache[name]); } - console.log('Querying for: ', name); //TODO + log.debug('GoogleDrive Querying for: ', name); //TODO var args; var idParent = name == this.home ? 'root' : self.idCache[this.home]; diff --git a/views/home.html b/views/home.html index 7018435e9..7c1c71e11 100644 --- a/views/home.html +++ b/views/home.html @@ -3,7 +3,7 @@ Retreiving information from storage... -
+
Copay