From 8f619786ddfa7347f41553b190379ba8bf8e2d0a Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 25 Oct 2015 23:25:44 -0300 Subject: [PATCH] refactor store data --- src/js/services/profileService.js | 43 ++++++++++++++----------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index b574e2a93..d78f1f889 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -247,30 +247,11 @@ angular.module('copayApp.services') }, function(err, secret) { if (err) return bwsError.cb(err, gettext('Error creating wallet'), cb); - root.storeData(walletClient, opts.bwsurl, cb); + root._addWalletClient(walletClient, opts, cb); }) }); }; - root.storeData = function(walletClient, bwsurl, cb) { - var walletId = walletClient.credentials.walletId; - var defaults = configService.getDefaults(); - var opts_ = { - bwsFor: {} - }; - opts_.bwsFor[walletId] = bwsurl || defaults.bws.url; - configService.set(opts_, function(err) { - if (err) console.log(err); - - root.profile.credentials.push(JSON.parse(walletClient.export())); - root.setWalletClients(); - - root.setAndStoreFocus(walletId, function() { - storageService.storeProfile(root.profile, cb); - }); - }); - } - root.joinWallet = function(opts, cb) { var walletClient = bwcService.getClient(); $log.debug('Joining Wallet:', opts); @@ -296,7 +277,7 @@ angular.module('copayApp.services') walletClient.joinWallet(opts.secret, opts.myName || 'me', {}, function(err) { if (err) return bwsError.cb(err, gettext('Could not join wallet'), cb); - root.storeData(walletClient, opts.bwsurl, cb); + root._addWalletClient(walletClient, opts, cb); }); }); }; @@ -338,8 +319,24 @@ angular.module('copayApp.services') if (w) { return cb(gettext('Wallet already in Copay' + ": ") + w.walletName); } - root.storeData(walletClient, opts.bwsurl, function(err){ - return cb(err, walletId); + + var defaults = configService.getDefaults(); + var bwsFor = {}; + bwsFor[walletId] = opts.bwsurl || defaults.bws.url; + + configService.set({ + bwsFor: bwsFor, + }, function(err) { + if (err) console.log(err); + + root.profile.credentials.push(JSON.parse(walletClient.export())); + root.setWalletClients(); + + root.setAndStoreFocus(walletId, function() { + storageService.storeProfile(root.profile, function(err){ + return cb(err, walletId); + }); + }); }); };