diff --git a/js/controllers/home.js b/js/controllers/home.js index ae8113843..df4c43ab5 100644 --- a/js/controllers/home.js +++ b/js/controllers/home.js @@ -46,6 +46,8 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc $scope.error = 'Invalid email or password'; } else if ((err.toString() || '').match('Connection')) { $scope.error = 'Could not connect to Insight Server'; + } else if ((err.toString() || '').match('Unable')) { + $scope.error = 'Unable to read data from the Insight Server'; } else { $scope.error = 'Unknown error'; } diff --git a/js/models/PluginManager.js b/js/models/PluginManager.js index d2d8d57fc..c4082ecbd 100644 --- a/js/models/PluginManager.js +++ b/js/models/PluginManager.js @@ -17,7 +17,7 @@ function PluginManager(config) { if(config.pluginsPath){ pluginClass = require(config.pluginsPath + pluginName); } else { - pluginClass = require('../plugins/' + pluginName); + pluginClass = require('../js/plugins/' + pluginName); } var pluginObj = new pluginClass(config[pluginName]); pluginObj.init(); diff --git a/js/plugins/GoogleDrive.js b/js/plugins/GoogleDrive.js index b786fca4b..08634a279 100644 --- a/js/plugins/GoogleDrive.js +++ b/js/plugins/GoogleDrive.js @@ -298,32 +298,4 @@ GoogleDrive.prototype._checkHomeDir = function(cb) { }); }; -GoogleDrive.prototype.allKeys = function(cb) { - var self = this; - - this._checkHomeDir(function(homeId) { - preconditions.checkState(homeId); - - var request = gapi.client.request({ - 'path': '/drive/v2/files', - 'method': 'GET', - 'params': { - 'q': "'" + homeId + "' in parents and trashed = false", - 'fields': 'items(id,title)' - }, - }); - request.execute(function(res) { - // console.log('[googleDrive.js.152:res:]', res); //TODO - if (res.error) - throw new Error(res.error.message); - - var ret = []; - for (var ii in res.items) { - ret.push(res.items[ii].title); - } - return cb(ret); - }); - }); -}; - module.exports = GoogleDrive; diff --git a/js/plugins/InsightStorage.js b/js/plugins/InsightStorage.js index 522444c3e..4b78505bd 100644 --- a/js/plugins/InsightStorage.js +++ b/js/plugins/InsightStorage.js @@ -118,7 +118,7 @@ InsightStorage.prototype._makeGetRequest = function(passphrase, key, callback) { return callback('PNOTFOUND: Profile not found'); } if (response.statusCode !== 200) { - return callback('Connection error'); + return callback('Unable to read item from insight'); } return callback(null, body, InsightStorage.parseResponseHeaders(response.getAllResponseHeaders())); } @@ -217,7 +217,7 @@ InsightStorage.prototype.removeItem = function(key, callback) { 'Authorization': authHeader } }; - log.debug('erase ' + name); + log.debug('Erasing: ' + key); this.request.get(getParams, function(err, response, body) { if (err) { return callback('Connection error'); @@ -236,14 +236,4 @@ InsightStorage.prototype.clear = function(callback) { callback(); }; -InsightStorage.prototype.allKeys = function(callback) { - // TODO: compatibility with localStorage - return callback(null); -}; - -InsightStorage.prototype.getFirst = function(prefix, opts, callback) { - // TODO: compatibility with localStorage - return callback(null, true, true); -}; - module.exports = InsightStorage; diff --git a/js/plugins/LocalStorage.js b/js/plugins/LocalStorage.js index 0692a13ae..8e4ee75e3 100644 --- a/js/plugins/LocalStorage.js +++ b/js/plugins/LocalStorage.js @@ -2,82 +2,57 @@ var _ = require('lodash'); var preconditions = require('preconditions').singleton(); -function LocalStorage() { +function LocalStorage(opts) { this.type = 'DB'; + opts = opts || {}; + - preconditions.checkState(typeof localStorage !== 'undefined', - 'localstorage not available, cannot run plugin'); + this.ls = opts.ls + || ( (typeof localStorage !== 'undefined') ? localStorage : null ); + + preconditions.checkState(this.ls, + 'localstorage not available, cannot run plugin'); }; LocalStorage.prototype.init = function() { }; LocalStorage.prototype.setCredentials = function(email, password, opts) { - this.email = email; - this.password = password; + // NOP }; LocalStorage.prototype.getItem = function(k,cb) { - return cb(null, localStorage.getItem(k)); + preconditions.checkArgument(_.isFunction(cb)); + return cb(null, this.ls.getItem(k)); }; /** * Same as setItem, but fails if an item already exists */ LocalStorage.prototype.createItem = function(name, value, callback) { - if (localStorage.getItem(name)) { + preconditions.checkArgument(_.isFunction(callback)); + if (this.ls.getItem(name)) { return callback('EEXISTS'); } return this.setItem(name, value, callback); }; LocalStorage.prototype.setItem = function(k,v,cb) { - localStorage.setItem(k,v); + preconditions.checkArgument(_.isFunction(cb)); + this.ls.setItem(k,v); return cb(); }; LocalStorage.prototype.removeItem = function(k,cb) { - localStorage.removeItem(k); + preconditions.checkArgument(_.isFunction(cb)); + this.ls.removeItem(k); return cb(); }; LocalStorage.prototype.clear = function(cb) { - localStorage.clear(); + preconditions.checkArgument(_.isFunction(cb)); + this.ls.clear(); return cb(); }; -LocalStorage.prototype.allKeys = function(cb) { - var l = localStorage.length; - var ret = []; - - for(var i=0; i