Merge pull request #2933 from matiu/feat/save-remote-pref
save lang and unit in BWS (for notifications)
This commit is contained in:
commit
02943bb9c4
7 changed files with 161 additions and 81 deletions
|
|
@ -1,7 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment) {
|
angular.module('copayApp.controllers').controller('indexController', function($rootScope, $scope, $log, $filter, $timeout, lodash, go, profileService, configService, isCordova, rateService, storageService, addressService, gettextCatalog, gettext, amMoment) {
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
self.isCordova = isCordova;
|
self.isCordova = isCordova;
|
||||||
self.onGoingProcess = {};
|
self.onGoingProcess = {};
|
||||||
|
|
@ -154,15 +153,55 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
self.updatePreferences = function(cb) {
|
self._updateRemotePreferencesFor = function(clients, prefs, cb) {
|
||||||
|
var client = clients.shift();
|
||||||
|
|
||||||
|
if (!client)
|
||||||
|
return cb();
|
||||||
|
|
||||||
|
$log.debug('Saving remote preferences', client.credentials.walletName, prefs);
|
||||||
|
client.savePreferences(prefs, function(err) {
|
||||||
|
if (err) return cb(err);
|
||||||
|
|
||||||
|
self._updateRemotePreferencesFor(clients, prefs, cb);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
self.updateRemotePreferences = function(opts, cb) {
|
||||||
|
var prefs = opts.preferences || {};
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
fc.getPreferences(function(err, preferences) {
|
|
||||||
|
// Update this JIC.
|
||||||
|
var config = configService.getSync().wallet.settings;
|
||||||
|
self.unitName = config.unitName;
|
||||||
|
|
||||||
|
//prefs.email (may come from arguments)
|
||||||
|
prefs.language = self.defaultLanguageIsoCode;
|
||||||
|
prefs.unit = self.unitName;
|
||||||
|
|
||||||
|
var clients = [];
|
||||||
|
if (opts.saveAll) {
|
||||||
|
clients = lodash.values(profileService.walletClients);
|
||||||
|
} else {
|
||||||
|
clients = [fc];
|
||||||
|
};
|
||||||
|
|
||||||
|
self._updateRemotePreferencesFor(clients, prefs, function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
self.handleError(err);
|
self.handleError(err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
}
|
}
|
||||||
self.preferences = preferences;
|
if (!fc) return cb();
|
||||||
return cb(err, preferences);
|
|
||||||
|
fc.getPreferences(function(err, preferences) {
|
||||||
|
if (err) {
|
||||||
|
self.handleError(err);
|
||||||
|
return cb(err);
|
||||||
|
}
|
||||||
|
self.preferences = preferences;
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -212,11 +251,14 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
$log.debug('Updating Status:', fc, tries);
|
$log.debug('Updating Status:', fc, tries);
|
||||||
get(function(err, walletStatus) {
|
get(function(err, walletStatus) {
|
||||||
var currentStatusHash = _walletStatusHash(walletStatus);
|
var currentStatusHash = _walletStatusHash(walletStatus);
|
||||||
$log.debug('Status update. hash:' + currentStatusHash + ' Try:'+ tries);
|
$log.debug('Status update. hash:' + currentStatusHash + ' Try:' + tries);
|
||||||
if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7) {
|
if (!err && opts.untilItChanges && initStatusHash == currentStatusHash && tries < 7) {
|
||||||
return $timeout(function() {
|
return $timeout(function() {
|
||||||
$log.debug('Retrying update... Try:' + tries)
|
$log.debug('Retrying update... Try:' + tries)
|
||||||
return self.updateAll({walletStatus: null, untilItChanges: true}, initStatusHash, ++tries);
|
return self.updateAll({
|
||||||
|
walletStatus: null,
|
||||||
|
untilItChanges: true
|
||||||
|
}, initStatusHash, ++tries);
|
||||||
}, 1400 * tries);
|
}, 1400 * tries);
|
||||||
}
|
}
|
||||||
if (!opts.quiet)
|
if (!opts.quiet)
|
||||||
|
|
@ -340,7 +382,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$log.debug('Wallet Opened');
|
$log.debug('Wallet Opened');
|
||||||
self.updateAll(lodash.isObject(walletStatus) ? {walletStatus: walletStatus} : null);
|
self.updateAll(lodash.isObject(walletStatus) ? {
|
||||||
|
walletStatus: walletStatus
|
||||||
|
} : null);
|
||||||
$rootScope.$apply();
|
$rootScope.$apply();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -466,8 +510,8 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
self.alternativeIsoCode = config.alternativeIsoCode;
|
self.alternativeIsoCode = config.alternativeIsoCode;
|
||||||
|
|
||||||
// Check address
|
// Check address
|
||||||
addressService.isUsed(self.walletId, balance.byAddress, function(err, used){
|
addressService.isUsed(self.walletId, balance.byAddress, function(err, used) {
|
||||||
if (used) {
|
if (used) {
|
||||||
$log.debug('Address used. Creating new');
|
$log.debug('Address used. Creating new');
|
||||||
$rootScope.$emit('Local/NeedNewAddress');
|
$rootScope.$emit('Local/NeedNewAddress');
|
||||||
}
|
}
|
||||||
|
|
@ -571,40 +615,27 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
self.setDefaultLanguage = function(setLang) {
|
self.setUxLanguage = function() {
|
||||||
var userLang;
|
var userLang = configService.getSync().wallet.settings.defaultLanguage;
|
||||||
if (!setLang) {
|
if (!userLang) {
|
||||||
userLang = configService.getSync().wallet.settings.defaultLanguage;
|
// Auto-detect browser language
|
||||||
if (!userLang) {
|
var androidLang;
|
||||||
// Auto-detect browser language
|
|
||||||
var androidLang;
|
|
||||||
|
|
||||||
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
if (navigator && navigator.userAgent && (androidLang = navigator.userAgent.match(/android.*\W(\w\w)-(\w\w)\W/i))) {
|
||||||
userLang = androidLang[1];
|
userLang = androidLang[1];
|
||||||
} else {
|
} else {
|
||||||
// works for iOS and Android 4.x
|
// works for iOS and Android 4.x
|
||||||
userLang = navigator.userLanguage || navigator.language;
|
userLang = navigator.userLanguage || navigator.language;
|
||||||
}
|
|
||||||
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
|
||||||
}
|
}
|
||||||
if (userLang != gettextCatalog.getCurrentLanguage()) {
|
userLang = userLang ? (userLang.split('-', 1)[0] || 'en') : 'en';
|
||||||
$log.debug('Setting default language: ' + userLang);
|
|
||||||
gettextCatalog.setCurrentLanguage(userLang);
|
|
||||||
amMoment.changeLocale(userLang);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
configService.set({
|
|
||||||
wallet: {
|
|
||||||
settings: {
|
|
||||||
defaultLanguage: setLang
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, function() {
|
|
||||||
gettextCatalog.setCurrentLanguage(setLang);
|
|
||||||
amMoment.changeLocale(setLang);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
self.defaultLanguageIsoCode = setLang || userLang;
|
if (userLang != gettextCatalog.getCurrentLanguage()) {
|
||||||
|
$log.debug('Setting default language: ' + userLang);
|
||||||
|
gettextCatalog.setCurrentLanguage(userLang);
|
||||||
|
amMoment.changeLocale(userLang);
|
||||||
|
}
|
||||||
|
|
||||||
|
self.defaultLanguageIsoCode = userLang;
|
||||||
self.defaultLanguageName = lodash.result(lodash.find(self.availableLanguages, {
|
self.defaultLanguageName = lodash.result(lodash.find(self.availableLanguages, {
|
||||||
'isoCode': self.defaultLanguageIsoCode
|
'isoCode': self.defaultLanguageIsoCode
|
||||||
}), 'name');
|
}), 'name');
|
||||||
|
|
@ -625,14 +656,47 @@ 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() {
|
||||||
|
$log.debug('Remote preferences saved')
|
||||||
|
storageService.setRemotePrefsStoredFlag(function() {});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/NewFocusedWallet', function() {
|
||||||
|
self.setUxLanguage();
|
||||||
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/LanguageSettingUpdated', function() {
|
||||||
|
self.setUxLanguage();
|
||||||
|
self.updateRemotePreferences({
|
||||||
|
saveAll: true
|
||||||
|
}, function() {
|
||||||
|
$log.debug('Remote preferences saved')
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
|
$rootScope.$on('Local/UnitSettingUpdated', function(event) {
|
||||||
self.updateAll();
|
self.updateAll();
|
||||||
self.updateTxHistory();
|
self.updateTxHistory();
|
||||||
|
self.updateRemotePreferences({
|
||||||
|
saveAll: true
|
||||||
|
}, function() {
|
||||||
|
$log.debug('Remote preferences saved')
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$rootScope.$on('Local/EmailSettingUpdated', function(event, email, cb) {
|
||||||
$rootScope.$on('Local/EmailUpdated', function(event, cb) {
|
self.updateRemotePreferences({
|
||||||
self.updatePreferences(cb);
|
preferences: {
|
||||||
|
email: email
|
||||||
|
},
|
||||||
|
}, cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/BWSUpdated', function(event) {
|
$rootScope.$on('Local/BWSUpdated', function(event) {
|
||||||
|
|
@ -646,7 +710,9 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
|
|
||||||
self.debouncedUpdate = lodash.throttle(function() {
|
self.debouncedUpdate = lodash.throttle(function() {
|
||||||
self.updateAll({quiet: true});
|
self.updateAll({
|
||||||
|
quiet: true
|
||||||
|
});
|
||||||
self.updateTxHistory();
|
self.updateTxHistory();
|
||||||
}, 4000, {
|
}, 4000, {
|
||||||
leading: false,
|
leading: false,
|
||||||
|
|
@ -708,10 +774,6 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('Local/DefaultLanguage', function(event, setLang) {
|
|
||||||
self.setDefaultLanguage(setLang);
|
|
||||||
});
|
|
||||||
|
|
||||||
$rootScope.$on('NewIncomingTx', function() {
|
$rootScope.$on('NewIncomingTx', function() {
|
||||||
self.updateBalance();
|
self.updateBalance();
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
|
|
@ -720,14 +782,20 @@ angular.module('copayApp.controllers').controller('indexController', function($r
|
||||||
});
|
});
|
||||||
|
|
||||||
$rootScope.$on('NewOutgoingTx', function() {
|
$rootScope.$on('NewOutgoingTx', function() {
|
||||||
self.updateAll({walletStatus: null, untilItChanges: true});
|
self.updateAll({
|
||||||
|
walletStatus: null,
|
||||||
|
untilItChanges: true
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved',
|
lodash.each(['NewTxProposal', 'TxProposalFinallyRejected', 'TxProposalRemoved',
|
||||||
'Local/NewTxProposal', 'Local/TxProposalAction', 'ScanFinished'
|
'Local/NewTxProposal', 'Local/TxProposalAction', 'ScanFinished'
|
||||||
], function(eventName) {
|
], function(eventName) {
|
||||||
$rootScope.$on(eventName, function(event, untilItChanges) {
|
$rootScope.$on(eventName, function(event, untilItChanges) {
|
||||||
self.updateAll({walletStatus: null, untilItChanges: untilItChanges});
|
self.updateAll({
|
||||||
|
walletStatus: null,
|
||||||
|
untilItChanges: untilItChanges
|
||||||
|
});
|
||||||
$timeout(function() {
|
$timeout(function() {
|
||||||
self.updateTxHistory();
|
self.updateTxHistory();
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
|
||||||
|
|
@ -8,20 +8,9 @@ angular.module('copayApp.controllers').controller('preferencesEmailController',
|
||||||
|
|
||||||
var fc = profileService.focusedClient;
|
var fc = profileService.focusedClient;
|
||||||
this.saving = true;
|
this.saving = true;
|
||||||
fc.savePreferences({
|
$scope.$emit('Local/EmailSettingUpdated', self.email, function() {
|
||||||
email: this.email
|
|
||||||
}, function(err) {
|
|
||||||
self.saving = false;
|
self.saving = false;
|
||||||
if (err) {
|
go.path('preferences');
|
||||||
$log.warn(err);
|
|
||||||
$scope.$emit('Local/ClientError', err);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$scope.$emit('Local/EmailUpdated', function(err){
|
|
||||||
go.path('preferences');
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,24 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesLanguageController',
|
angular.module('copayApp.controllers').controller('preferencesLanguageController',
|
||||||
function($scope, $timeout, go) {
|
function($scope, $log, $timeout, configService, go) {
|
||||||
|
|
||||||
this.save = function(newLang) {
|
this.save = function(newLang) {
|
||||||
$scope.$emit('Local/DefaultLanguage', newLang);
|
|
||||||
$timeout(function() {
|
var opts = {
|
||||||
go.preferences();
|
wallet: {
|
||||||
}, 100);
|
settings: {
|
||||||
|
defaultLanguage: newLang
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
configService.set(opts, function(err) {
|
||||||
|
if (err) $log.warn(err);
|
||||||
|
$scope.$emit('Local/LanguageSettingUpdated');
|
||||||
|
$timeout(function() {
|
||||||
|
go.preferences();
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('preferencesUnitController',
|
angular.module('copayApp.controllers').controller('preferencesUnitController',
|
||||||
function($rootScope, $scope, configService, go) {
|
function($rootScope, $scope, $log, configService, go) {
|
||||||
var config = configService.getSync();
|
var config = configService.getSync();
|
||||||
this.unitName = config.wallet.settings.unitName;
|
this.unitName = config.wallet.settings.unitName;
|
||||||
this.unitOpts = [
|
this.unitOpts = [
|
||||||
|
|
@ -51,8 +51,9 @@ angular.module('copayApp.controllers').controller('preferencesUnitController',
|
||||||
this.unitName = newUnit.shortName;
|
this.unitName = newUnit.shortName;
|
||||||
|
|
||||||
configService.set(opts, function(err) {
|
configService.set(opts, function(err) {
|
||||||
if (err) console.log(err);
|
if (err) $log.warn(err);
|
||||||
$scope.$emit('Local/UnitSettingUpdated');
|
$scope.$emit('Local/UnitSettingUpdated');
|
||||||
|
go.preferences();
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ angular
|
||||||
'main': {
|
'main': {
|
||||||
templateUrl: 'views/splash.html',
|
templateUrl: 'views/splash.html',
|
||||||
controller: function($scope, $timeout, $log, profileService, storageService, go) {
|
controller: function($scope, $timeout, $log, profileService, storageService, go) {
|
||||||
storageService.getCopayDisclaimer(function(err, val) {
|
storageService.getCopayDisclaimerFlag(function(err, val) {
|
||||||
if (!val) go.path('disclaimer');
|
if (!val) go.path('disclaimer');
|
||||||
|
|
||||||
if (profileService.profile) {
|
if (profileService.profile) {
|
||||||
|
|
@ -109,7 +109,7 @@ angular
|
||||||
'main': {
|
'main': {
|
||||||
templateUrl: 'views/disclaimer.html',
|
templateUrl: 'views/disclaimer.html',
|
||||||
controller: function($scope, $timeout, storageService, applicationService, go) {
|
controller: function($scope, $timeout, storageService, applicationService, go) {
|
||||||
storageService.getCopayDisclaimer(function(err, val) {
|
storageService.getCopayDisclaimerFlag(function(err, val) {
|
||||||
$scope.agreed = val;
|
$scope.agreed = val;
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
$scope.$digest();
|
$scope.$digest();
|
||||||
|
|
@ -117,7 +117,7 @@ angular
|
||||||
});
|
});
|
||||||
|
|
||||||
$scope.agree = function() {
|
$scope.agree = function() {
|
||||||
storageService.setCopayDisclaimer(function(err) {
|
storageService.setCopayDisclaimerFlag(function(err) {
|
||||||
$timeout(function(){
|
$timeout(function(){
|
||||||
applicationService.restart();
|
applicationService.restart();
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
|
||||||
|
|
@ -125,17 +125,19 @@ angular.module('copayApp.services')
|
||||||
$log.debug('Preferences read');
|
$log.debug('Preferences read');
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
root.applyConfig();
|
root.applyConfig();
|
||||||
$rootScope.$emit('Local/DefaultLanguage');
|
|
||||||
root.setWalletClients();
|
root.setWalletClients();
|
||||||
storageService.getFocusedWalletId(function(err, focusedWalletId) {
|
storageService.getFocusedWalletId(function(err, focusedWalletId) {
|
||||||
if (err) return cb(err);
|
if (err) return cb(err);
|
||||||
root._setFocus(focusedWalletId, cb);
|
root._setFocus(focusedWalletId, function() {
|
||||||
|
$rootScope.$emit('Local/ProfileBound');
|
||||||
|
return cb();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
root.loadAndBindProfile = function(cb) {
|
root.loadAndBindProfile = function(cb) {
|
||||||
storageService.getCopayDisclaimer(function(err, val) {
|
storageService.getCopayDisclaimerFlag(function(err, val) {
|
||||||
if (!val) {
|
if (!val) {
|
||||||
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
return cb(new Error('NONAGREEDDISCLAIMER: Non agreed disclaimer'));
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -176,13 +176,21 @@ angular.module('copayApp.services')
|
||||||
storage.remove('config', cb);
|
storage.remove('config', cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.setCopayDisclaimer = function(cb) {
|
root.setCopayDisclaimerFlag = function(cb) {
|
||||||
storage.set('agreeDisclaimer', true, cb);
|
storage.set('agreeDisclaimer', true, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
root.getCopayDisclaimer = function(cb) {
|
root.getCopayDisclaimerFlag = function(cb) {
|
||||||
storage.get('agreeDisclaimer', cb);
|
storage.get('agreeDisclaimer', cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
root.setRemotePrefsStoredFlag = function(cb) {
|
||||||
|
storage.set('remotePrefStored', true, cb);
|
||||||
|
};
|
||||||
|
|
||||||
|
root.getRemotePrefsStoredFlag = function(cb) {
|
||||||
|
storage.get('remotePrefStored', cb);
|
||||||
|
};
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue