mirror of https://github.com/BTCPrivate/copay.git
add LocalStorage plugin
This commit is contained in:
parent
c0360e7beb
commit
b9881c1147
|
@ -44,7 +44,8 @@ module.exports = function(grunt) {
|
|||
files: [
|
||||
'js/models/**/*.js',
|
||||
'plugins/*.js',
|
||||
'copay.js'
|
||||
'copay.js',
|
||||
'utils/*.js'
|
||||
],
|
||||
tasks: ['shell:dev']
|
||||
},
|
||||
|
|
|
@ -53,7 +53,8 @@ var defaultConfig = {
|
|||
verbose: 1,
|
||||
|
||||
plugins: {
|
||||
GoogleDrive: true,
|
||||
LocalStorage: true,
|
||||
// GoogleDrive: true,
|
||||
},
|
||||
|
||||
GoogleDrive: {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('HomeController',
|
||||
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils, pluginManager) {
|
||||
function($scope, $rootScope, $location, walletFactory, notification, controllerUtils) {
|
||||
|
||||
controllerUtils.redirIfLogged();
|
||||
|
||||
|
|
|
@ -10,11 +10,11 @@ function PluginManager(config) {
|
|||
if (!config.plugins[pluginName])
|
||||
continue;
|
||||
|
||||
console.log('Loading ' + pluginName);
|
||||
console.log('Loading plugin: ' + pluginName);
|
||||
var pluginClass = require('../plugins/' + pluginName);
|
||||
var pluginObj = new pluginClass();
|
||||
pluginObj.init();
|
||||
this._register(pluginObj);
|
||||
this._register(pluginObj, pluginName);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -24,14 +24,12 @@ var KIND_MULTIPLE = PluginManager.KIND_MULTIPLE = 2;
|
|||
PluginManager.TYPE = {};
|
||||
PluginManager.TYPE['STORAGE'] = KIND_UNIQUE;
|
||||
|
||||
PluginManager.prototype._register = function(obj) {
|
||||
preconditions.checkArgument(obj.type,'Plugin has not type');
|
||||
PluginManager.prototype._register = function(obj, name) {
|
||||
preconditions.checkArgument(obj.type,'Plugin has not type:' + name);
|
||||
var type = obj.type;
|
||||
console.log('[PluginManager.js.29:type:]',type); //TODO
|
||||
|
||||
var kind = PluginManager.TYPE[type];
|
||||
preconditions.checkArgument(kind, 'Plugin has unkown type');
|
||||
preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered');
|
||||
preconditions.checkArgument(kind, 'Plugin has unkown type' + name);
|
||||
preconditions.checkState(kind !== PluginManager.KIND_UNIQUE || !this.registered[type], 'Plugin kind already registered: ' + name);
|
||||
|
||||
if (kind === PluginManager.KIND_UNIQUE) {
|
||||
this.registered[type] = obj;
|
||||
|
@ -41,6 +39,8 @@ console.log('[PluginManager.js.29:type:]',type); //TODO
|
|||
}
|
||||
};
|
||||
|
||||
PluginManager.prototype.getOne = function(type) {};
|
||||
PluginManager.prototype.get = function(type) {
|
||||
return this.registered[type];
|
||||
};
|
||||
|
||||
module.exports = PluginManager;
|
||||
|
|
|
@ -36,11 +36,13 @@ function WalletFactory(config, version) {
|
|||
var self = this;
|
||||
config = config || {};
|
||||
|
||||
this.Storage = config.Storage || StorageEncrypted;
|
||||
this.pluginManager = new copay.PluginManager(config);
|
||||
|
||||
this.Storage = config.Storage || StorageEncrypted;
|
||||
this.Network = config.Network || Async;
|
||||
this.Blockchain = config.Blockchain || Insight;
|
||||
this.storage = new this.Storage({storage: this.pluginManager.get('STORAGE')});
|
||||
|
||||
this.storage = new this.Storage(config.storage);
|
||||
this.networks = {
|
||||
'livenet': new this.Network(config.network.livenet),
|
||||
'testnet': new this.Network(config.network.testnet),
|
||||
|
|
|
@ -130,6 +130,8 @@ Storage.prototype.getWalletIds = function() {
|
|||
var walletIds = [];
|
||||
var uniq = {};
|
||||
|
||||
console.log('[Encrypted.js.144]', this.storage); //TODO
|
||||
console.log('[Encrypted.js.144]', this.storage.length); //TODO
|
||||
for (var i = 0; i < this.storage.length; i++) {
|
||||
var key = this.storage.key(i);
|
||||
var split = key.split('::');
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').value('pluginManager', new copay.PluginManager(config));
|
||||
angular.module('copayApp.services').factory('pluginManager', function(angularLoad){
|
||||
return new copay.PluginManager(config);
|
||||
});
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
'use strict';
|
||||
|
||||
function LocalStorage() {
|
||||
this.type = 'STORAGE';
|
||||
};
|
||||
|
||||
LocalStorage.prototype.init = function() {
|
||||
console.log(' init LocalStorage'); //TODO
|
||||
};
|
||||
|
||||
|
||||
LocalStorage.prototype.getItem = function(k) {
|
||||
return localStorage.getItem(k);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.setItem = function(k,v) {
|
||||
localStorage.setItem(k,v);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.removeItem = function(k) {
|
||||
localStorage.removeItem(k);
|
||||
};
|
||||
|
||||
LocalStorage.prototype.clear = function() {
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
delete LocalStorage.prototype.length;
|
||||
|
||||
Object.defineProperty(LocalStorage.prototype, 'length', {
|
||||
get: function() {
|
||||
return localStorage.length;
|
||||
}
|
||||
});
|
||||
|
||||
LocalStorage.prototype.key = function(k) {
|
||||
var v = localStorage.key(k);
|
||||
return v;
|
||||
};
|
||||
|
||||
|
||||
module.exports = LocalStorage;
|
|
@ -5,7 +5,38 @@ function GoogleDrive() {
|
|||
};
|
||||
|
||||
GoogleDrive.prototype.init = function() {
|
||||
console.log('[googleDrive.js.3] init'); //TODO
|
||||
console.log('[googleDrive.js.3] init GoogleDrive'); //TODO
|
||||
};
|
||||
|
||||
|
||||
GoogleDrive.prototype.getItem = function(k) {
|
||||
return localStorage.getItem(k);
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.setItem = function(k,v) {
|
||||
localStorage.setItem(k,v);
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.removeItem = function(k) {
|
||||
localStorage.removeItem(k);
|
||||
};
|
||||
|
||||
GoogleDrive.prototype.clear = function() {
|
||||
localStorage.clear();
|
||||
};
|
||||
|
||||
delete GoogleDrive.prototype.length;
|
||||
|
||||
Object.defineProperty(GoogleDrive.prototype, 'length', {
|
||||
get: function() {
|
||||
return localStorage.length;
|
||||
}
|
||||
});
|
||||
|
||||
GoogleDrive.prototype.key = function(k) {
|
||||
var v = localStorage.key(k);
|
||||
return v;
|
||||
};
|
||||
|
||||
|
||||
module.exports = GoogleDrive;
|
||||
|
|
|
@ -91,6 +91,10 @@ var createBundle = function(opts) {
|
|||
b.require('./plugins/GoogleDrive', {
|
||||
expose: '../plugins/GoogleDrive'
|
||||
});
|
||||
b.require('./plugins/LocalStorage', {
|
||||
expose: '../plugins/LocalStorage'
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
b.require('./config', {
|
||||
|
|
Loading…
Reference in New Issue