refactor profileService

This commit is contained in:
Matias Alejo Garcia 2016-06-06 12:21:15 -03:00
commit 4865ea8ad8
No known key found for this signature in database
GPG key ID: 02470DB551277AB3
9 changed files with 241 additions and 204 deletions

View file

@ -54,15 +54,15 @@ angular.module('copayApp.controllers').controller('copayersController',
modalInstance.result.then(function(ok) {
if (ok) {
_deleteWallet();
doDeleteWallet();
}
});
};
var _deleteWallet = function() {
var doDeleteWallet = function() {
var fc = profileService.focusedClient;
var walletName = fc.credentials.walletName;
profileService.deleteWalletFC({}, function(err) {
profileService.deleteWalletClient(fc, function(err) {
if (err) {
self.error = err.message || err;
$timeout(function() {

View file

@ -169,7 +169,7 @@ angular.module('copayApp.controllers').controller('createController',
self.loading = true;
$timeout(function() {
profileService.createWallet(opts, function(err, walletId) {
profileService.createWallet(opts, function(err) {
self.loading = false;
if (err) {
$log.warn(err);

View file

@ -10,8 +10,6 @@ angular.module('copayApp.controllers').controller('disclaimerController',
opts = opts || {};
$log.debug('Creating profile');
profileService.create(opts, function(err) {
console.log('[disclaimer.js.13]', err); //TODO
if (err) {
$log.warn(err);
$scope.error = err;
@ -33,8 +31,6 @@ angular.module('copayApp.controllers').controller('disclaimerController',
$scope.error = "";
self.creatingProfile = false;
console.log('[disclaimer.js.33]'); //TODO
});
};
@ -44,10 +40,7 @@ angular.module('copayApp.controllers').controller('disclaimerController',
profileService.getProfile(function(err, profile) {
if (!profile) {
console.log('[disclaimer.js.43]'); //TODO
create(opts);
console.log('[disclaimer.js.46]'); //TODO
} else {
$log.info('There is already a profile');
self.creatingProfile = false;

View file

@ -284,9 +284,10 @@ angular.module('copayApp.controllers').controller('indexController', function($r
};
// TODO: should not be in index.js
self.updateRemotePreferences = function(opts, cb) {
var clients;
var prefs = opts.preferences || {};
var fc = profileService.focusedClient;
// Update this JIC.
var config = configService.getSync().wallet.settings;
@ -295,24 +296,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
prefs.language = self.defaultLanguageIsoCode;
prefs.unit = config.unitCode;
var clients = [];
if (opts.saveAll) {
clients = lodash.values(profileService.walletClients);
if (opts.client) {
clients = [opts.client];
} else {
clients = [fc];
clients = lodash.values(profileService.walletClients);
};
self._updateRemotePreferencesFor(clients, prefs, function(err) {
if (err) return cb(err);
if (!fc) return cb();
fc.getPreferences(function(err, preferences) {
if (err) {
return cb(err);
}
self.preferences = preferences;
return cb();
lodash.each(clients, function(c) {
c.preferences = lodash.assign(prefs, c.preferences);
});
return cb();
});
};
@ -1055,7 +1052,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
return;
}
profileService.setWalletClients();
profileService.addWalletClient(fc, {
force: true
});
self.startScan(self.walletId);
});
};
@ -1513,9 +1512,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/ProfileBound', function() {
storageService.getRemotePrefsStoredFlag(function(err, val) {
if (err || val) return;
self.updateRemotePreferences({
saveAll: true
}, function() {
self.updateRemotePreferences({}, function() {
$log.debug('Remote preferences saved');
storageService.setRemotePrefsStoredFlag(function() {});
});
@ -1524,9 +1521,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
$rootScope.$on('Local/LanguageSettingUpdated', function() {
self.setUxLanguage(function() {
self.updateRemotePreferences({
saveAll: true
}, function() {
self.updateRemotePreferences({}, function() {
$log.debug('Remote preferences saved')
});
});
@ -1558,15 +1553,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
self.updateAll({
triggerTxUpdate: true,
});
self.updateRemotePreferences({
saveAll: true
}, function() {
self.updateRemotePreferences({}, function() {
$log.debug('Remote preferences saved')
});
});
$rootScope.$on('Local/EmailSettingUpdated', function(event, email, cb) {
$rootScope.$on('Local/EmailSettingUpdated', function(event, client, email, cb) {
self.updateRemotePreferences({
client: client,
preferences: {
email: email || null
},
@ -1582,11 +1576,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
}
});
$rootScope.$on('Local/ProfileCreated', function(event) {
self.updateRemotePreferences({
saveAll: true
}, function() {
$log.debug('Remote preferences saved');
lodash.each(['Local/ProfileCreated', 'Local/WalletListUpdated'], function(eventName) {
$rootScope.$on(eventName, function(event, client) {
self.updateRemotePreferences({
client: client
}, function() {
$log.debug('Remote preferences saved');
});
});
});
@ -1743,6 +1740,7 @@ angular.module('copayApp.controllers').controller('indexController', function($r
});
$rootScope.$on('Local/NoWallets', function(event) {
$log.debug('Event: NoWallets');
$timeout(function() {
self.hasProfile = true;

View file

@ -40,19 +40,19 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
modalInstance.result.then(function(ok) {
if (ok) {
_deleteWallet();
doDeleteWallet();
}
});
};
var _deleteWallet = function() {
var doDeleteWallet = function() {
$scope.isDeletingWallet = true;
var fc = profileService.focusedClient;
var name = fc.credentials.walletName;
var walletName = (fc.alias || '') + ' [' + name + ']';
var self = this;
profileService.deleteWalletFC({}, function(err) {
profileService.deleteWalletClient(fc, function(err) {
$scope.isDeletingWallet = false;
if (err) {
self.error = err.message || err;
@ -72,7 +72,7 @@ angular.module('copayApp.controllers').controller('preferencesDeleteWalletContro
delete_msg,
function(buttonIndex) {
if (buttonIndex == 1) {
_deleteWallet();
doDeleteWallet();
}
},
confirm_msg, [accept_msg, cancel_msg]

View file

@ -8,7 +8,7 @@ angular.module('copayApp.controllers').controller('preferencesEmailController',
var fc = profileService.focusedClient;
this.saving = true;
$scope.$emit('Local/EmailSettingUpdated', self.email, function() {
$scope.$emit('Local/EmailSettingUpdated', fc,self.email, function() {
self.saving = false;
go.path('preferences');
});