2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-04-25 14:42:17 -03:00
|
|
|
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log) {
|
2015-03-06 12:00:10 -03:00
|
|
|
var root = {};
|
|
|
|
|
|
|
|
|
|
var defaultConfig = {
|
|
|
|
|
// wallet limits
|
|
|
|
|
limits: {
|
|
|
|
|
totalCopayers: 6,
|
|
|
|
|
mPlusN: 100,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Bitcore wallet service URL
|
|
|
|
|
bws: {
|
2015-04-17 18:10:22 -03:00
|
|
|
url: 'https://bws.bitpay.com/bws/api',
|
2015-03-06 12:00:10 -03:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// wallet default config
|
|
|
|
|
wallet: {
|
|
|
|
|
requiredCopayers: 2,
|
|
|
|
|
totalCopayers: 3,
|
|
|
|
|
spendUnconfirmed: true,
|
|
|
|
|
reconnectDelay: 5000,
|
|
|
|
|
idleDurationMin: 4,
|
|
|
|
|
settings: {
|
|
|
|
|
unitName: 'bits',
|
|
|
|
|
unitToSatoshi: 100,
|
|
|
|
|
unitDecimals: 2,
|
|
|
|
|
unitCode: 'bit',
|
|
|
|
|
alternativeName: 'US Dollar',
|
|
|
|
|
alternativeIsoCode: 'USD',
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2015-09-11 13:11:41 -03:00
|
|
|
// External services
|
|
|
|
|
glidera: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
testnet: false
|
|
|
|
|
},
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
rates: {
|
|
|
|
|
url: 'https://insight.bitpay.com:443/api/rates',
|
|
|
|
|
},
|
2015-12-23 14:17:24 -03:00
|
|
|
|
2016-01-13 10:12:10 -03:00
|
|
|
pushNotifications: {
|
|
|
|
|
enabled: true,
|
|
|
|
|
config: {
|
|
|
|
|
android: {
|
2016-01-19 19:02:25 -03:00
|
|
|
senderID: '1036948132229',
|
2016-01-13 10:12:10 -03:00
|
|
|
},
|
|
|
|
|
ios: {
|
|
|
|
|
alert: 'true',
|
|
|
|
|
badge: 'true',
|
|
|
|
|
sound: 'true',
|
|
|
|
|
},
|
|
|
|
|
windows: {},
|
|
|
|
|
}
|
2015-12-23 14:17:24 -03:00
|
|
|
},
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var configCache = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
root.getSync = function() {
|
|
|
|
|
if (!configCache)
|
|
|
|
|
throw new Error('configService#getSync called when cache is not initialized');
|
|
|
|
|
|
|
|
|
|
return configCache;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.get = function(cb) {
|
2015-04-25 14:42:17 -03:00
|
|
|
|
2015-04-25 12:37:04 -03:00
|
|
|
storageService.getConfig(function(err, localConfig) {
|
2015-03-06 12:00:10 -03:00
|
|
|
if (localConfig) {
|
|
|
|
|
configCache = JSON.parse(localConfig);
|
|
|
|
|
|
|
|
|
|
//these ifs are to avoid migration problems
|
|
|
|
|
if (!configCache.bws) {
|
|
|
|
|
configCache.bws = defaultConfig.bws;
|
|
|
|
|
}
|
2015-06-17 07:32:50 -07:00
|
|
|
if (!configCache.wallet) {
|
|
|
|
|
configCache.wallet = defaultConfig.wallet;
|
|
|
|
|
}
|
2015-03-06 12:00:10 -03:00
|
|
|
if (!configCache.wallet.settings.unitCode) {
|
|
|
|
|
configCache.wallet.settings.unitCode = defaultConfig.wallet.settings.unitCode;
|
|
|
|
|
}
|
2015-09-11 13:11:41 -03:00
|
|
|
if (!configCache.glidera) {
|
2015-12-23 14:17:24 -03:00
|
|
|
configCache.glidera = defaultConfig.glidera;
|
2015-09-11 13:11:41 -03:00
|
|
|
}
|
2015-03-06 12:00:10 -03:00
|
|
|
|
|
|
|
|
} else {
|
2015-04-25 14:42:17 -03:00
|
|
|
configCache = lodash.clone(defaultConfig);
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
2015-11-05 18:57:59 -03:00
|
|
|
|
|
|
|
|
// Glidera
|
|
|
|
|
// Disabled for testnet
|
|
|
|
|
configCache.glidera.testnet = false;
|
|
|
|
|
|
2015-04-25 14:42:17 -03:00
|
|
|
$log.debug('Preferences read:', configCache)
|
2015-03-06 12:00:10 -03:00
|
|
|
return cb(err, configCache);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.set = function(newOpts, cb) {
|
2015-12-17 16:26:04 +03:00
|
|
|
var config = lodash.clone(defaultConfig);
|
2015-04-25 12:37:04 -03:00
|
|
|
storageService.getConfig(function(err, oldOpts) {
|
2015-03-06 12:00:10 -03:00
|
|
|
if (lodash.isString(oldOpts)) {
|
|
|
|
|
oldOpts = JSON.parse(oldOpts);
|
|
|
|
|
}
|
|
|
|
|
if (lodash.isString(config)) {
|
|
|
|
|
config = JSON.parse(config);
|
|
|
|
|
}
|
|
|
|
|
if (lodash.isString(newOpts)) {
|
|
|
|
|
newOpts = JSON.parse(newOpts);
|
|
|
|
|
}
|
|
|
|
|
lodash.merge(config, oldOpts, newOpts);
|
|
|
|
|
configCache = config;
|
|
|
|
|
|
2015-04-26 20:13:02 -03:00
|
|
|
storageService.storeConfig(JSON.stringify(config), cb);
|
2015-03-06 12:00:10 -03:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.reset = function(cb) {
|
2015-04-25 12:37:04 -03:00
|
|
|
configCache = lodash.clone(defaultConfig);
|
|
|
|
|
storageService.removeConfig(cb);
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.getDefaults = function() {
|
2015-04-25 12:37:04 -03:00
|
|
|
return lodash.clone(defaultConfig);
|
2015-03-06 12:00:10 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return root;
|
|
|
|
|
});
|