From 0c1c09d73148652c17d3b8a295420466f5d042a1 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 25 Oct 2015 23:06:29 -0300 Subject: [PATCH 1/2] fixes callback --- src/js/services/profileService.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/services/profileService.js b/src/js/services/profileService.js index 74049e9f1..b574e2a93 100644 --- a/src/js/services/profileService.js +++ b/src/js/services/profileService.js @@ -338,7 +338,9 @@ angular.module('copayApp.services') if (w) { return cb(gettext('Wallet already in Copay' + ": ") + w.walletName); } - root.storeData(walletClient, opts.bwsurl, cb); + root.storeData(walletClient, opts.bwsurl, function(err){ + return cb(err, walletId); + }); }; root.importWallet = function(str, opts, cb) { From beea420c53de55d61d50ff119252b8472fd3d28e Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Sun, 25 Oct 2015 23:25:44 -0300 Subject: [PATCH 2/2] 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); + }); + }); }); };