add configService
This commit is contained in:
parent
526bc53a7b
commit
e4f5862576
7 changed files with 73 additions and 43 deletions
|
|
@ -21,7 +21,7 @@
|
|||
"socket.io-client": ">=1.0.0",
|
||||
"ng-idle": "*",
|
||||
"inherits": "~0.0.1",
|
||||
lodash": "~2.4.1",
|
||||
"lodash": "~2.4.1",
|
||||
"angular-gravatar": "*",
|
||||
"angular-touch": "~1.3.0"
|
||||
},
|
||||
|
|
|
|||
23
copay.js
23
copay.js
|
|
@ -5,19 +5,22 @@ module.exports.TxProposals = require('./js/models/TxProposals');
|
|||
module.exports.PrivateKey = require('./js/models/PrivateKey');
|
||||
module.exports.HDPath = require('./js/models/HDPath');
|
||||
module.exports.HDParams = require('./js/models/HDParams');
|
||||
module.exports.crypto = require('./js/util/crypto');
|
||||
module.exports.logger = require('./js/util/log');
|
||||
module.exports.csv = require('./js/util/csv');
|
||||
|
||||
|
||||
// components
|
||||
var Async = module.exports.Async = require('./js/models/Async');
|
||||
var Insight = module.exports.Insight = require('./js/models/Insight');
|
||||
var RateService = module.exports.RateService = require('./js/models/RateService');
|
||||
|
||||
module.exports.Async = require('./js/models/Async');
|
||||
module.exports.Insight = require('./js/models/Insight');
|
||||
module.exports.RateService = require('./js/models/RateService');
|
||||
module.exports.Identity = require('./js/models/Identity');
|
||||
module.exports.Wallet = require('./js/models/Wallet');
|
||||
module.exports.Compatibility = require('./js/models/Compatibility');
|
||||
module.exports.PluginManager = require('./js/models/PluginManager');
|
||||
|
||||
|
||||
module.exports.crypto = require('./js/util/crypto');
|
||||
module.exports.logger = require('./js/util/log');
|
||||
module.exports.csv = require('./js/util/csv');
|
||||
|
||||
module.exports.version = require('./version').version;
|
||||
module.exports.commitHash = require('./version').commitHash;
|
||||
|
||||
|
||||
module.exports.defaultConfig = require('./config');
|
||||
|
||||
|
|
|
|||
|
|
@ -140,7 +140,6 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
if ((err.toString() || '').match('PNOTFOUND')) {
|
||||
$scope.error = 'Invalid email or password';
|
||||
pinService.clear(function() {
|
||||
copay.logger.debug('PIN erased');
|
||||
});
|
||||
} else if ((err.toString() || '').match('Connection')) {
|
||||
$scope.error = 'Could not connect to Insight Server';
|
||||
|
|
@ -150,7 +149,9 @@ angular.module('copayApp.controllers').controller('HomeController', function($sc
|
|||
$scope.error = 'Unknown error';
|
||||
}
|
||||
$rootScope.starting = false;
|
||||
$rootScope.$digest();
|
||||
$timeout(function(){
|
||||
$rootScope.$digest();
|
||||
},1)
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, $anchorScroll, notification, applicationService, localstorageService) {
|
||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $route, $location, notification, configService) {
|
||||
$scope.title = 'Settings';
|
||||
$scope.defaultLanguage = config.defaultLanguage || 'en';
|
||||
$scope.insightLivenet = config.network.livenet.url;
|
||||
|
|
@ -57,7 +57,6 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
$scope.save = function() {
|
||||
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
|
||||
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
|
||||
|
|
@ -73,33 +72,32 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
|||
},
|
||||
}
|
||||
|
||||
|
||||
var plugins = {};
|
||||
plugins[$scope.selectedStorage.pluginName] = true;
|
||||
copay.logger.setLevel($scope.selectedLogLevel.name);
|
||||
|
||||
localstorageService.setItem('config', JSON.stringify({
|
||||
network: insightSettings,
|
||||
version: copay.version,
|
||||
defaultLanguage: $scope.selectedLanguage.isoCode,
|
||||
plugins: plugins,
|
||||
logLevel: $scope.selectedLogLevel.name,
|
||||
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
||||
url: insightSettings.livenet.url + '/api/email'
|
||||
}),
|
||||
rates: _.extend(config.rates, {
|
||||
url: insightSettings.livenet.url + '/api/rates'
|
||||
}),
|
||||
}), function() {
|
||||
applicationService.restart();
|
||||
});
|
||||
|
||||
configService.set({
|
||||
network: insightSettings,
|
||||
version: copay.version,
|
||||
defaultLanguage: $scope.selectedLanguage.isoCode,
|
||||
plugins: plugins,
|
||||
logLevel: $scope.selectedLogLevel.name,
|
||||
EncryptedInsightStorage: _.extend(config.EncryptedInsightStorage, {
|
||||
url: insightSettings.livenet.url + '/api/email'
|
||||
}),
|
||||
rates: _.extend(config.rates, {
|
||||
url: insightSettings.livenet.url + '/api/rates'
|
||||
}),
|
||||
},
|
||||
function() {
|
||||
notification.success('Settings saved');
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
$scope.reset = function() {
|
||||
localstorageService.removeItem('config', function() {
|
||||
applicationService.reload();
|
||||
configService.reset(function() {
|
||||
notification.success('Settings reseted');
|
||||
$location.path('/');
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
24
js/services/configService.js
Normal file
24
js/services/configService.js
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('configService', function(localstorageService) {
|
||||
var root = {};
|
||||
|
||||
root.set = function(opts, cb) {
|
||||
copay.logger.setLevel(opts.logLevel);
|
||||
localstorageService.getItem('config', function(err, oldOps) {
|
||||
|
||||
_.defaults(opts, JSON.parse(oldOps));
|
||||
|
||||
// TODO remove this gloval variable.
|
||||
config = opts;
|
||||
localstorageService.setItem('config', JSON.stringify(opts), cb);
|
||||
});
|
||||
};
|
||||
|
||||
root.reset = function(cb) {
|
||||
config = copay.defaultConfig;
|
||||
localstorageService.removeItem('config',cb);
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
@ -11,10 +11,10 @@ angular.module('copayApp.services')
|
|||
var root = {};
|
||||
root.check = function(scope) {
|
||||
copay.Identity.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
}, function(anyProfile) {
|
||||
copay.Wallet.checkIfExistsAny({
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
}, function(anyWallet) {
|
||||
scope.loading = false;
|
||||
scope.anyProfile = anyProfile ? true : false;
|
||||
|
|
@ -47,7 +47,7 @@ angular.module('copayApp.services')
|
|||
copay.Identity.create({
|
||||
email: email,
|
||||
password: password,
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
@ -99,7 +99,7 @@ angular.module('copayApp.services')
|
|||
var opts = {
|
||||
email: email,
|
||||
password: password,
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
@ -344,7 +344,7 @@ angular.module('copayApp.services')
|
|||
|
||||
root.importProfile = function(str, password, cb) {
|
||||
copay.Identity.importFromEncryptedFullJson(str, password, {
|
||||
pluginManager: pluginManager,
|
||||
pluginManager: pluginManager.getInstance(config),
|
||||
network: config.network,
|
||||
networkName: config.networkName,
|
||||
walletDefaults: config.wallet,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,10 @@
|
|||
'use strict';
|
||||
|
||||
angular.module('copayApp.services').factory('pluginManager', function() {
|
||||
var pm = new copay.PluginManager(config);
|
||||
return pm;
|
||||
var root = {};
|
||||
root.getInstance = function(config){
|
||||
return new copay.PluginManager(config);
|
||||
};
|
||||
|
||||
return root;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue