2015-03-06 12:00:10 -03:00
|
|
|
'use strict';
|
|
|
|
|
|
2018-03-27 11:44:43 +09:00
|
|
|
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout, $rootScope, platformInfo) {
|
2015-03-06 12:00:10 -03:00
|
|
|
var root = {};
|
|
|
|
|
|
2017-06-08 15:09:39 -03:00
|
|
|
var isWindowsPhoneApp = platformInfo.isCordova && platformInfo.isWP;
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
var defaultConfig = {
|
|
|
|
|
// wallet limits
|
|
|
|
|
limits: {
|
|
|
|
|
totalCopayers: 6,
|
|
|
|
|
mPlusN: 100,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// Bitcore wallet service URL
|
|
|
|
|
bws: {
|
2017-10-26 16:03:15 +09:00
|
|
|
url: 'https://bws.bitcoin.com/bws/api'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
bwscash: {
|
|
|
|
|
url: 'https://bwscash.bitcoin.com/bws/api'
|
2015-03-06 12:00:10 -03:00
|
|
|
},
|
|
|
|
|
|
2016-11-02 10:18:10 -03:00
|
|
|
download: {
|
2017-03-09 16:48:38 -03:00
|
|
|
bitpay: {
|
2017-06-18 18:52:13 +09:00
|
|
|
url: 'https://wallet.bitcoin.com'
|
2017-03-09 16:48:38 -03:00
|
|
|
},
|
|
|
|
|
copay: {
|
2017-06-18 18:52:13 +09:00
|
|
|
url: 'https://wallet.bitcoin.com'
|
2017-06-12 19:21:47 +09:00
|
|
|
},
|
|
|
|
|
bitcoincom: {
|
|
|
|
|
url: 'https://wallet.bitcoin.com'
|
2017-03-09 16:48:38 -03:00
|
|
|
}
|
2016-11-02 10:18:10 -03:00
|
|
|
},
|
|
|
|
|
|
2017-11-20 16:02:54 +09:00
|
|
|
blockExplorer: {
|
|
|
|
|
btc: 'explorer.bitcoin.com/btc',
|
|
|
|
|
bch: 'explorer.bitcoin.com/bch'
|
|
|
|
|
},
|
|
|
|
|
|
2017-03-09 14:46:07 -03:00
|
|
|
rateApp: {
|
|
|
|
|
bitpay: {
|
|
|
|
|
ios: 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1149581638&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8',
|
|
|
|
|
android: 'https://play.google.com/store/apps/details?id=com.bitpay.wallet',
|
|
|
|
|
wp: ''
|
|
|
|
|
},
|
|
|
|
|
copay: {
|
|
|
|
|
ios: 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=951330296&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8',
|
|
|
|
|
android: 'https://play.google.com/store/apps/details?id=com.bitpay.copay',
|
|
|
|
|
wp: ''
|
2017-06-12 19:21:47 +09:00
|
|
|
},
|
|
|
|
|
bitcoincom: {
|
2017-11-16 13:39:45 +09:00
|
|
|
ios: 'http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=1252903728&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8',
|
2017-06-18 18:52:13 +09:00
|
|
|
android: 'https://play.google.com/store/apps/details?id=com.bitcoin.mwallet',
|
2017-06-12 19:21:47 +09:00
|
|
|
wp: ''
|
2017-03-09 14:46:07 -03:00
|
|
|
}
|
2017-03-09 10:20:28 -03:00
|
|
|
},
|
2015-03-06 12:00:10 -03:00
|
|
|
// wallet default config
|
|
|
|
|
wallet: {
|
|
|
|
|
requiredCopayers: 2,
|
|
|
|
|
totalCopayers: 3,
|
2017-10-27 17:30:15 +09:00
|
|
|
spendUnconfirmed: true,
|
2015-03-06 12:00:10 -03:00
|
|
|
reconnectDelay: 5000,
|
|
|
|
|
idleDurationMin: 4,
|
|
|
|
|
settings: {
|
2016-10-18 18:47:12 -04:00
|
|
|
unitName: 'BTC',
|
2016-10-21 11:47:32 -03:00
|
|
|
unitToSatoshi: 100000000,
|
|
|
|
|
unitDecimals: 8,
|
2016-10-18 18:47:12 -04:00
|
|
|
unitCode: 'btc',
|
2015-03-06 12:00:10 -03:00
|
|
|
alternativeName: 'US Dollar',
|
|
|
|
|
alternativeIsoCode: 'USD',
|
2018-04-25 13:59:25 +09:00
|
|
|
priceDisplay: 'fiat', // 'fiat' || 'crypto'
|
2015-03-06 12:00:10 -03:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2017-03-29 11:30:16 -03:00
|
|
|
lock: {
|
2017-04-18 13:19:16 -03:00
|
|
|
method: null,
|
|
|
|
|
value: null,
|
2017-03-30 11:31:23 -03:00
|
|
|
bannedUntil: null,
|
2017-02-24 14:46:54 -05:00
|
|
|
},
|
|
|
|
|
|
2017-10-26 16:03:15 +09:00
|
|
|
cashSupport: true,
|
2017-08-29 10:52:26 -03:00
|
|
|
|
2017-01-31 16:32:45 -03:00
|
|
|
recentTransactions: {
|
2015-09-11 13:11:41 -03:00
|
|
|
enabled: true,
|
|
|
|
|
},
|
|
|
|
|
|
2017-01-31 16:32:45 -03:00
|
|
|
hideNextSteps: {
|
2017-06-08 15:09:39 -03:00
|
|
|
enabled: isWindowsPhoneApp ? true : false,
|
2016-09-27 15:57:39 -03:00
|
|
|
},
|
|
|
|
|
|
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-04-11 12:56:18 -03:00
|
|
|
release: {
|
2017-06-18 18:52:13 +09:00
|
|
|
url: 'https://api.github.com/repos/Bitcoin-com/Wallet/releases/latest'
|
2016-04-11 12:56:18 -03:00
|
|
|
},
|
|
|
|
|
|
2017-02-03 18:03:29 -03:00
|
|
|
pushNotificationsEnabled: true,
|
2016-10-31 14:08:52 -03:00
|
|
|
|
2017-07-14 15:45:18 -03:00
|
|
|
confirmedTxsNotifications: {
|
2017-07-13 11:12:15 -03:00
|
|
|
enabled: true,
|
|
|
|
|
},
|
|
|
|
|
|
2016-10-31 14:08:52 -03:00
|
|
|
emailNotifications: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
2017-07-19 16:42:15 -04:00
|
|
|
|
2018-06-13 16:33:06 +02:00
|
|
|
soundsEnabled: true,
|
2018-02-26 11:47:11 +05:00
|
|
|
|
2017-07-19 16:42:15 -04:00
|
|
|
log: {
|
|
|
|
|
filter: 'debug',
|
|
|
|
|
},
|
2017-11-01 16:26:42 +09:00
|
|
|
|
|
|
|
|
bitcoinAlias: 'btc',
|
2017-11-17 15:43:04 +09:00
|
|
|
bitcoinCashAlias: 'bch',
|
2018-06-08 12:06:12 +05:30
|
|
|
bitcoinWalletColor: '#535353', // Dark Grey
|
|
|
|
|
bitcoinCashWalletColor: '#eeb640', // Observatory
|
2018-05-08 10:28:13 +02:00
|
|
|
|
2018-05-09 10:39:11 +09:00
|
|
|
homeSectionIsHidden: {
|
|
|
|
|
services: false
|
|
|
|
|
}
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2016-08-19 23:40:28 -03:00
|
|
|
root._queue = [];
|
|
|
|
|
root.whenAvailable = function(cb) {
|
|
|
|
|
if (!configCache) {
|
|
|
|
|
root._queue.push(cb);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
return cb(configCache);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
root.get = function(cb) {
|
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;
|
|
|
|
|
}
|
2017-01-31 17:32:11 -03:00
|
|
|
|
|
|
|
|
if (!configCache.hideNextSteps) {
|
|
|
|
|
configCache.hideNextSteps = defaultConfig.hideNextSteps;
|
2016-09-27 15:57:39 -03:00
|
|
|
}
|
2017-01-31 17:32:11 -03:00
|
|
|
|
2017-10-26 16:03:15 +09:00
|
|
|
// Always support Bitcoin Cash
|
|
|
|
|
configCache.cashSupport = true;
|
2017-08-29 10:52:26 -03:00
|
|
|
|
2016-09-27 15:57:39 -03:00
|
|
|
if (!configCache.recentTransactions) {
|
|
|
|
|
configCache.recentTransactions = defaultConfig.recentTransactions;
|
|
|
|
|
}
|
2016-01-22 00:35:11 -03:00
|
|
|
if (!configCache.pushNotifications) {
|
|
|
|
|
configCache.pushNotifications = defaultConfig.pushNotifications;
|
|
|
|
|
}
|
2017-01-06 12:11:47 -05:00
|
|
|
if (!configCache.bitpayAccount) {
|
|
|
|
|
configCache.bitpayAccount = defaultConfig.bitpayAccount;
|
|
|
|
|
}
|
2015-03-06 12:00:10 -03:00
|
|
|
|
2017-08-24 17:02:49 -03:00
|
|
|
if (configCache.wallet.settings.unitCode == 'bit') {
|
|
|
|
|
// Convert to BTC. Bits will be disabled
|
|
|
|
|
configCache.wallet.settings.unitName = defaultConfig.wallet.settings.unitName;
|
|
|
|
|
configCache.wallet.settings.unitToSatoshi = defaultConfig.wallet.settings.unitToSatoshi;
|
|
|
|
|
configCache.wallet.settings.unitDecimals = defaultConfig.wallet.settings.unitDecimals;
|
|
|
|
|
configCache.wallet.settings.unitCode = defaultConfig.wallet.settings.unitCode;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-25 13:59:25 +09:00
|
|
|
// If display is not configure, take the default value
|
|
|
|
|
if (!configCache.wallet.settings.priceDisplay) {
|
2018-04-27 15:35:36 +09:00
|
|
|
configCache.wallet.settings.priceDisplay = defaultConfig.wallet.settings.priceDisplay;
|
2018-04-25 13:59:25 +09:00
|
|
|
}
|
|
|
|
|
|
2017-10-26 16:03:15 +09:00
|
|
|
// Convert tarascash wallet to new style cash wallet
|
|
|
|
|
if (configCache.bwsbcc && configCache.bwsbcc.url && configCache.bwsbcc.url.indexOf('bwsbcc') >= 0) {
|
|
|
|
|
configCache.bwsbcc = defaultConfig.bwscash.url;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (configCache.bwsFor) {
|
|
|
|
|
for (var key in configCache.bwsFor) {
|
|
|
|
|
if (configCache.bwsFor[key].indexOf('bwsbcc') >= 0) {
|
|
|
|
|
configCache.bwsFor[key] = defaultConfig.bwscash.url;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-09 10:39:11 +09:00
|
|
|
|
|
|
|
|
if (!configCache.homeSectionIsHidden) {
|
|
|
|
|
configCache.homeSectionIsHidden = defaultConfig.homeSectionIsHidden;
|
|
|
|
|
}
|
2017-10-26 16:03:15 +09: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
|
|
|
|
2016-08-22 19:17:31 -03:00
|
|
|
configCache.bwsFor = configCache.bwsFor || {};
|
|
|
|
|
configCache.colorFor = configCache.colorFor || {};
|
|
|
|
|
configCache.aliasFor = configCache.aliasFor || {};
|
2016-09-01 17:46:56 -03:00
|
|
|
configCache.emailFor = configCache.emailFor || {};
|
2016-08-22 19:17:31 -03:00
|
|
|
|
2015-04-25 14:42:17 -03:00
|
|
|
$log.debug('Preferences read:', configCache)
|
2016-08-19 23:40:28 -03:00
|
|
|
|
|
|
|
|
lodash.each(root._queue, function(x) {
|
|
|
|
|
$timeout(function() {
|
|
|
|
|
return x(configCache);
|
|
|
|
|
}, 1);
|
|
|
|
|
});
|
|
|
|
|
root._queue = [];
|
|
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
return cb(err, configCache);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
root.set = function(newOpts, cb) {
|
2016-02-16 16:56:14 -05:00
|
|
|
var config = lodash.cloneDeep(defaultConfig);
|
2015-04-25 12:37:04 -03:00
|
|
|
storageService.getConfig(function(err, oldOpts) {
|
2016-06-09 19:00:09 -03:00
|
|
|
oldOpts = 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);
|
|
|
|
|
}
|
2016-06-09 19:00:09 -03:00
|
|
|
|
2015-03-06 12:00:10 -03:00
|
|
|
lodash.merge(config, oldOpts, newOpts);
|
|
|
|
|
configCache = config;
|
|
|
|
|
|
2016-08-22 14:42:43 -03:00
|
|
|
$rootScope.$emit('Local/SettingsUpdated');
|
|
|
|
|
|
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;
|
|
|
|
|
});
|