From 2849f773e2df1c098b2de36355bf36e7220ef60a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Mon, 1 Sep 2014 15:40:31 -0300 Subject: [PATCH] change name to Encrypted --- Gruntfile.js | 5 +- bower.json | 3 +- copay.js | 2 +- js/app.js | 10 +++- js/models/core/WalletFactory.js | 4 +- .../{LocalEncrypted.js => Encrypted.js} | 27 +++++---- ...st.LocalEncrypted.js => test.Encrypted.js} | 60 +++++++++---------- util/build.js | 4 ++ 8 files changed, 66 insertions(+), 49 deletions(-) rename js/models/storage/{LocalEncrypted.js => Encrypted.js} (89%) rename test/{test.LocalEncrypted.js => test.Encrypted.js} (84%) diff --git a/Gruntfile.js b/Gruntfile.js index e4d0a51ef..fc4b77dee 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -42,7 +42,8 @@ module.exports = function(grunt) { }, scripts: { files: [ - 'js/models/**/*.js' + 'js/models/**/*.js', + 'plugins/*.js', ], tasks: ['shell:dev'] }, @@ -129,7 +130,7 @@ module.exports = function(grunt) { 'js/controllers/*.js', 'js/translations.js', 'js/mobile.js', // PLACEHOLDER: CORDOVA SRIPT - 'js/init.js' + 'js/init.js', ], dest: 'js/copayMain.js' } diff --git a/bower.json b/bower.json index 9300e2b27..cccd15f07 100644 --- a/bower.json +++ b/bower.json @@ -24,7 +24,8 @@ "zeroclipboard": "~1.3.5", "ng-idle": "*", "underscore": "~1.7.0", - "inherits": "~0.0.1" + "inherits": "~0.0.1", + "angular-load": "0.2.0" }, "resolutions": { "angular": "=1.2.19" diff --git a/copay.js b/copay.js index 5f058d6ab..e821f7918 100644 --- a/copay.js +++ b/copay.js @@ -11,7 +11,7 @@ module.exports.HDParams = require('./js/models/core/HDParams'); // components var Async = module.exports.Async = require('./js/models/network/Async'); var Insight = module.exports.Insight = require('./js/models/blockchain/Insight'); -var StorageLocalEncrypted = module.exports.StorageLocalEncrypted = require('./js/models/storage/LocalEncrypted'); +var StorageEncrypted = module.exports.StorageEncrypted = require('./js/models/storage/Encrypted'); module.exports.WalletFactory = require('./js/models/core/WalletFactory'); module.exports.Wallet = require('./js/models/core/Wallet'); diff --git a/js/app.js b/js/app.js index a5c169307..e7b038516 100644 --- a/js/app.js +++ b/js/app.js @@ -37,9 +37,17 @@ var modules = [ 'copayApp.directives', ]; -if (config.plugins.googleDrive) +if (config.plugins.length) modules.push('angularLoad'); +if (config.plugins.googleDrive) { + var googleDrive = require('../plugins/googleDrive'); + var a = new googleDrive(); + a.init(); +console.log('[app.js.41:new:]',a); //TODO +} + + var copayApp = window.copayApp = angular.module('copayApp', modules); copayApp.config(function($sceDelegateProvider) { diff --git a/js/models/core/WalletFactory.js b/js/models/core/WalletFactory.js index b91853657..adf542ae1 100644 --- a/js/models/core/WalletFactory.js +++ b/js/models/core/WalletFactory.js @@ -8,7 +8,7 @@ var _ = require('underscore'); var log = require('../../log'); var Async = module.exports.Async = require('../network/Async'); var Insight = module.exports.Insight = require('../blockchain/Insight'); -var StorageLocalEncrypted = module.exports.StorageLocalEncrypted = require('../storage/LocalEncrypted'); +var StorageEncrypted = module.exports.StorageEncrypted = require('../storage/Encrypted'); var preconditions = require('preconditions').singleton(); /** @@ -36,7 +36,7 @@ function WalletFactory(config, version) { var self = this; config = config || {}; - this.Storage = config.Storage || StorageLocalEncrypted; + this.Storage = config.Storage || StorageEncrypted; this.Network = config.Network || Async; this.Blockchain = config.Blockchain || Insight; diff --git a/js/models/storage/LocalEncrypted.js b/js/models/storage/Encrypted.js similarity index 89% rename from js/models/storage/LocalEncrypted.js rename to js/models/storage/Encrypted.js index b093eaaa4..1997f7841 100644 --- a/js/models/storage/LocalEncrypted.js +++ b/js/models/storage/Encrypted.js @@ -13,9 +13,12 @@ function Storage(opts) { this._setPassphrase(opts.password); try { - this.localStorage = opts.localStorage || localStorage; + this.storage = opts.storage || localStorage; this.sessionStorage = opts.sessionStorage || sessionStorage; - } catch (e) {} + } catch (e) { + console.log('Error in storage:', e); //TODO + }; + preconditions.checkState(this.localStorage, 'No localstorage found'); preconditions.checkState(this.sessionStorage, 'No sessionStorage found'); } @@ -54,7 +57,7 @@ Storage.prototype._decrypt = function(base64) { Storage.prototype._read = function(k) { var ret; - ret = this.localStorage.getItem(k); + ret = this.storage.getItem(k); if (!ret) return null; ret = this._decrypt(ret); if (!ret) return null; @@ -67,23 +70,23 @@ Storage.prototype._write = function(k, v) { v = JSON.stringify(v); v = this._encrypt(v); - this.localStorage.setItem(k, v); + this.storage.setItem(k, v); }; // get value by key Storage.prototype.getGlobal = function(k) { - var item = this.localStorage.getItem(k); + var item = this.storage.getItem(k); return item == 'undefined' ? undefined : item; }; // set value for key Storage.prototype.setGlobal = function(k, v) { - this.localStorage.setItem(k, typeof v === 'object' ? JSON.stringify(v) : v); + this.storage.setItem(k, typeof v === 'object' ? JSON.stringify(v) : v); }; // remove value for key Storage.prototype.removeGlobal = function(k) { - this.localStorage.removeItem(k); + this.storage.removeItem(k); }; Storage.prototype.getSessionId = function() { @@ -127,8 +130,8 @@ Storage.prototype.getWalletIds = function() { var walletIds = []; var uniq = {}; - for (var i = 0; i < this.localStorage.length; i++) { - var key = this.localStorage.key(i); + for (var i = 0; i < this.storage.length; i++) { + var key = this.storage.key(i); var split = key.split('::'); if (split.length == 2) { var walletId = split[0]; @@ -162,8 +165,8 @@ Storage.prototype.deleteWallet = function(walletId) { var toDelete = {}; toDelete['nameFor::' + walletId] = 1; - for (var i = 0; i < this.localStorage.length; i++) { - var key = this.localStorage.key(i); + for (var i = 0; i < this.storage.length; i++) { + var key = this.storage.key(i); var split = key.split('::'); if (split.length == 2 && split[0] === walletId) { toDelete[key] = 1; @@ -192,7 +195,7 @@ Storage.prototype.setFromObj = function(walletId, obj) { // remove all values Storage.prototype.clearAll = function() { - this.localStorage.clear(); + this.storage.clear(); }; Storage.prototype.import = function(base64) { diff --git a/test/test.LocalEncrypted.js b/test/test.Encrypted.js similarity index 84% rename from test/test.LocalEncrypted.js rename to test/test.Encrypted.js index 32149e58f..bfe2fcd18 100644 --- a/test/test.LocalEncrypted.js +++ b/test/test.Encrypted.js @@ -3,7 +3,7 @@ var chai = chai || require('chai'); var should = chai.should(); var is_browser = typeof process == 'undefined' || typeof process.versions === 'undefined'; var copay = copay || require('../copay'); -var LocalEncrypted = copay.StorageLocalEncrypted; +var Encrypted = copay.StorageEncrypted; var fakeWallet = 'fake-wallet-id'; var timeStamp = Date.now(); @@ -11,23 +11,23 @@ var localMock = require('./mocks/FakeLocalStorage'); var sessionMock = require('./mocks/FakeLocalStorage'); -describe('Storage/LocalEncrypted model', function() { - var s = new LocalEncrypted({ - localStorage: localMock, +describe('Storage/Encrypted model', function() { + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, }); s._setPassphrase('mysupercoolpassword'); it('should create an instance', function() { - var s2 = new LocalEncrypted({ - localStorage: localMock, + var s2 = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, }); should.exist(s2); }); it('should fail when encrypting without a password', function() { - var s2 = new LocalEncrypted({ - localStorage: localMock, + var s2 = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, }); (function() { @@ -71,8 +71,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#export', function() { it('should export the encrypted wallet', function() { - var storage = new LocalEncrypted({ - localStorage: localMock, + var storage = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password', }); @@ -89,8 +89,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#remove', function() { it('should remove an item', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -105,8 +105,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#getWalletIds', function() { it('should get wallet ids', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -118,8 +118,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#getName #setName', function() { it('should get/set names', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -130,8 +130,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#getLastOpened #setLastOpened', function() { it('should get/set names', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -143,8 +143,8 @@ describe('Storage/LocalEncrypted model', function() { if (is_browser) { describe('#getSessionId', function() { it('should get SessionId', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -158,8 +158,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#getWallets', function() { it('should retreive wallets from storage', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -178,8 +178,8 @@ describe('Storage/LocalEncrypted model', function() { }); describe('#deleteWallet', function() { it('should delete a wallet', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -198,8 +198,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#setFromObj', function() { it('set localstorage from an object', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -218,8 +218,8 @@ describe('Storage/LocalEncrypted model', function() { describe('#globals', function() { it('should set, get and remove keys', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); @@ -237,8 +237,8 @@ describe('Storage/LocalEncrypted model', function() { describe('session storage', function() { it('should get a session ID', function() { - var s = new LocalEncrypted({ - localStorage: localMock, + var s = new Encrypted({ + storage: localMock, sessionStorage: sessionMock, password: 'password' }); diff --git a/util/build.js b/util/build.js index b60af799b..21e2afda8 100644 --- a/util/build.js +++ b/util/build.js @@ -83,6 +83,10 @@ var createBundle = function(opts) { b.require('./js/models/core/HDPath', { expose: '../js/models/core/HDPath' }); + b.require('./plugins/googleDrive', { + expose: '../plugins/googleDrive' + }); + b.require('./config', { expose: '../config' });