From 0656c8d7e041807fd9793113279db86712dcf13d Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 27 Oct 2014 10:49:25 -0300 Subject: [PATCH 1/3] fixed delete wallet --- config.js | 2 +- js/models/Identity.js | 16 +++++++++++----- js/plugins/EncryptedInsightStorage.js | 19 +++++++++++++------ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/config.js b/config.js index 72e9c6d30..da19b8a87 100644 --- a/config.js +++ b/config.js @@ -61,7 +61,7 @@ var defaultConfig = { }, EncryptedInsightStorage: { - url: 'https://test-insight.bitpay.com:443/api/email' + url: 'http://localhost:3001/api/email' }, GoogleDrive: { diff --git a/js/models/Identity.js b/js/models/Identity.js index 843726495..a87cdcfce 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -224,13 +224,19 @@ Identity.prototype.storeWallet = function(wallet, cb) { }; Identity.prototype.toObj = function() { - return _.extend({walletIds: _.keys(this.wallets)}, - _.pick(this, 'version', 'fullName', 'password', 'email')); + return _.extend({ + walletIds: _.keys(this.wallets) + }, + _.pick(this, 'version', 'fullName', 'password', 'email')); }; Identity.prototype.exportWithWalletInfo = function() { - return _.extend({wallets: _.map(this.wallets, function(wallet) { return wallet.toObj(); })}, - _.pick(this, 'version', 'fullName', 'password', 'email')); + return _.extend({ + wallets: _.map(this.wallets, function(wallet) { + return wallet.toObj(); + }) + }, + _.pick(this, 'version', 'fullName', 'password', 'email')); }; /** @@ -493,7 +499,7 @@ Identity.prototype.deleteWallet = function(walletId, cb) { var self = this; delete this.wallets[walletId]; - this.storage.deleteItem(walletId, function(err) { + this.storage.removeItem(Wallet.getStorageKey(walletId), function(err) { if (err) { return cb(err); } diff --git a/js/plugins/EncryptedInsightStorage.js b/js/plugins/EncryptedInsightStorage.js index c1c3d998a..bd0d86e28 100644 --- a/js/plugins/EncryptedInsightStorage.js +++ b/js/plugins/EncryptedInsightStorage.js @@ -9,13 +9,15 @@ inherits(EncryptedInsightStorage, InsightStorage); EncryptedInsightStorage.prototype.getItem = function(name, callback) { var key = cryptoUtil.kdf(this.password, this.email); - InsightStorage.prototype.getItem.apply(this, [name, function(err, body) { - var decryptedJson = cryptoUtil.decrypt(key, body); - if (!decryptedJson) { - return callback('Internal Error'); + InsightStorage.prototype.getItem.apply(this, [name, + function(err, body) { + var decryptedJson = cryptoUtil.decrypt(key, body); + if (!decryptedJson) { + return callback('Internal Error'); + } + return callback(null, decryptedJson); } - return callback(null, decryptedJson); - }]); + ]); }; EncryptedInsightStorage.prototype.setItem = function(name, value, callback) { @@ -24,4 +26,9 @@ EncryptedInsightStorage.prototype.setItem = function(name, value, callback) { InsightStorage.prototype.setItem.apply(this, [name, record, callback]); }; +EncryptedInsightStorage.prototype.removeItem = function(name, callback) { + var key = cryptoUtil.kdf(this.password, this.email); + InsightStorage.prototype.removeItem.apply(this, [name, callback]); +}; + module.exports = EncryptedInsightStorage; From fc0535a69fc27cc7f3ee497903c495b675868043 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 27 Oct 2014 11:10:32 -0300 Subject: [PATCH 2/3] handling profile with no wallets --- js/models/Identity.js | 1 + js/services/identityService.js | 79 +++++++++++++++++----------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/js/models/Identity.js b/js/models/Identity.js index a87cdcfce..1c6191899 100644 --- a/js/models/Identity.js +++ b/js/models/Identity.js @@ -519,6 +519,7 @@ Identity.prototype.decodeSecret = function(secret) { }; Identity.prototype.getLastFocusedWallet = function() { + if (_.keys(this.wallets).length == 0) return; return _.max(this.wallets, function(wallet) { return wallet.lastTimestamp || 0; }); diff --git a/js/services/identityService.js b/js/services/identityService.js index dd94448c0..117a3d078 100644 --- a/js/services/identityService.js +++ b/js/services/identityService.js @@ -1,48 +1,47 @@ 'use strict'; angular.module('copayApp.services') -.factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) { - var root = {}; + .factory('identityService', function($rootScope, $location, pluginManager, controllerUtils) { + var root = {}; - root.create = function (scope, form) { - copay.Identity.create({ - email: form.email.$modelValue, - password: form.password.$modelValue, - pluginManager: pluginManager, - network: config.network, - networkName: config.networkName, - walletDefaults: config.wallet, - passphraseConfig: config.passphraseConfig, - }, function(err, iden) { - var firstWallet = iden.getLastFocusedWallet(); - controllerUtils.bindProfile(scope, iden, firstWallet); - scope.loading = false; - }); - }; - - - root.open = function (scope, form) { - copay.Identity.open({ - email: form.email.$modelValue, - password: form.password.$modelValue, - pluginManager: pluginManager, - network: config.network, - networkName: config.networkName, - walletDefaults: config.wallet, - passphraseConfig: config.passphraseConfig, - }, function(err, iden) { - if (err && !iden) { - console.log('Error:' + err) - controllerUtils.onErrorDigest( - scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error'); - } else { + root.create = function(scope, form) { + copay.Identity.create({ + email: form.email.$modelValue, + password: form.password.$modelValue, + pluginManager: pluginManager, + network: config.network, + networkName: config.networkName, + walletDefaults: config.wallet, + passphraseConfig: config.passphraseConfig, + }, function(err, iden) { var firstWallet = iden.getLastFocusedWallet(); controllerUtils.bindProfile(scope, iden, firstWallet); - } - scope.loading = false; - }); - } + scope.loading = false; + }); + }; - return root; -}); + root.open = function(scope, form) { + copay.Identity.open({ + email: form.email.$modelValue, + password: form.password.$modelValue, + pluginManager: pluginManager, + network: config.network, + networkName: config.networkName, + walletDefaults: config.wallet, + passphraseConfig: config.passphraseConfig, + }, function(err, iden) { + if (err && !iden) { + console.log('Error:' + err) + controllerUtils.onErrorDigest( + scope, (err.toString() || '').match('PNOTFOUND') ? 'Profile not found' : 'Unknown error'); + } else { + var firstWallet = iden.getLastFocusedWallet(); + controllerUtils.bindProfile(scope, iden, firstWallet); + } + scope.loading = false; + }); + } + + return root; + }); From fd021fc56bb0616da43d98231d8389087b7c2e83 Mon Sep 17 00:00:00 2001 From: Ivan Socolsky Date: Mon, 27 Oct 2014 11:13:35 -0300 Subject: [PATCH 3/3] restored config.js --- config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/config.js b/config.js index da19b8a87..65807a47d 100644 --- a/config.js +++ b/config.js @@ -61,7 +61,8 @@ var defaultConfig = { }, EncryptedInsightStorage: { - url: 'http://localhost:3001/api/email' + url: 'https://test-insight.bitpay.com:443/api/email' + // url: 'http://localhost:3001/api/email' }, GoogleDrive: {