Wallet/src/js/services/configService.js

285 lines
6 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
2016-08-22 14:42:43 -03:00
angular.module('copayApp.services').factory('configService', function(storageService, lodash, $log, $timeout, $rootScope) {
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
},
2016-11-02 10:18:10 -03:00
download: {
url: 'https://bitpay.com/wallet',
},
rateApp: {
ios: 'https://itunes.apple.com/app/bitpay-secure-bitcoin-wallet/id1149581638',
android: 'https://play.google.com/store/apps/details?id=com.bitpay.wallet',
wp: ''
},
2015-03-06 12:00:10 -03:00
// wallet default config
wallet: {
requiredCopayers: 2,
totalCopayers: 3,
spendUnconfirmed: false,
2015-03-06 12:00:10 -03:00
reconnectDelay: 5000,
idleDurationMin: 4,
settings: {
unitName: 'BTC',
2016-10-21 11:47:32 -03:00
unitToSatoshi: 100000000,
unitDecimals: 8,
unitCode: 'btc',
2015-03-06 12:00:10 -03:00
alternativeName: 'US Dollar',
alternativeIsoCode: 'USD',
}
},
2015-09-11 13:11:41 -03:00
// External services
glidera: {
enabled: true,
testnet: false
},
Feat/coinbase integration (#4012) * Oauth2 and first view * Connect with Coinbase using mobile * Buy and Sell through Coinbase * Fix buy * Receive and send bitcoin to Coinbase account * Receive bitcoin from Coinbase to Copay * Complete user and account information. Connection errors * Improves error handler * Removes console.log * Coinbase background color. Send to Coinbase form validation * Fix send from different wallet * Send and receive using Coinbase * Pagination activity * Fix Buy and Sell * One option in the sidebar to Buy and Sell * Native balance on Coinbase homepage * Rename receive and send * Auto-close window after authenticate * Reorder * Get payment methods * Fix when token expired * Fix token expired * Integration: sell and send to Coinbase * Store pending transaction before sell * Sell flow completed * Removing files * Fix sell * Fix sell * Fix sell * Sell completed * Buy bitcoin through coinbase * Buy auto * Currency set to USD * Select payment methods. Limits * Removes payment methods from preferences * Fix signs. Tx ordered by updated. Minor fixes * Removes console.log * Improving ux-language things * Fix selectedpaymentmethod if not verified * Set error if tx not found * Price sensitivity. Minor fixes * Adds coinbase api key to gitignore * Coinbase production ready * Fix sell in usd * Bug fixes * New Sensitivity step * Refresh token with a simple click * Refresh token * Refactor * Fix auto reconnect if token expired Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com> * Fix calls if token expired
2016-04-13 14:08:03 -03:00
coinbase: {
2016-09-27 15:57:39 -03:00
enabled: false, //disable coinbase for this release
Feat/coinbase integration (#4012) * Oauth2 and first view * Connect with Coinbase using mobile * Buy and Sell through Coinbase * Fix buy * Receive and send bitcoin to Coinbase account * Receive bitcoin from Coinbase to Copay * Complete user and account information. Connection errors * Improves error handler * Removes console.log * Coinbase background color. Send to Coinbase form validation * Fix send from different wallet * Send and receive using Coinbase * Pagination activity * Fix Buy and Sell * One option in the sidebar to Buy and Sell * Native balance on Coinbase homepage * Rename receive and send * Auto-close window after authenticate * Reorder * Get payment methods * Fix when token expired * Fix token expired * Integration: sell and send to Coinbase * Store pending transaction before sell * Sell flow completed * Removing files * Fix sell * Fix sell * Fix sell * Sell completed * Buy bitcoin through coinbase * Buy auto * Currency set to USD * Select payment methods. Limits * Removes payment methods from preferences * Fix signs. Tx ordered by updated. Minor fixes * Removes console.log * Improving ux-language things * Fix selectedpaymentmethod if not verified * Set error if tx not found * Price sensitivity. Minor fixes * Adds coinbase api key to gitignore * Coinbase production ready * Fix sell in usd * Bug fixes * New Sensitivity step * Refresh token with a simple click * Refresh token * Refactor * Fix auto reconnect if token expired Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com> * Fix calls if token expired
2016-04-13 14:08:03 -03:00
testnet: false
},
2016-09-27 15:57:39 -03:00
bitpayCard: {
enabled: true
},
amazon: {
enabled: true
},
//Experimental Features
recentTransactions: {
enabled: false //disabled by default
2016-09-27 15:57:39 -03:00
},
frequentlyUsed: {
enabled: true
},
2015-03-06 12:00:10 -03:00
rates: {
url: 'https://insight.bitpay.com:443/api/rates',
},
2016-04-11 12:56:18 -03:00
release: {
url: 'https://api.github.com/repos/bitpay/copay/releases/latest'
},
pushNotifications: {
enabled: true,
config: {
android: {
2016-01-19 19:02:25 -03:00
senderID: '1036948132229',
2016-02-24 19:04:29 -03:00
icon: 'push',
iconColor: '#2F4053'
},
ios: {
alert: 'true',
badge: 'true',
sound: 'true',
},
windows: {},
}
},
2016-10-31 14:08:52 -03:00
emailNotifications: {
enabled: false,
},
2015-03-06 12:00:10 -03:00
};
var configCache = null;
2016-09-22 17:38:33 -03:00
var colorList = [
{
color: "#DD4B39",
name: "Cinnabar"
},
{
color: "#F38F12",
name: "Carrot Orange"
},
{
color: "#FAA77F",
name: "Light Salmon"
},
{
color: "#D0B136",
name: "Metallic Gold"
},
{
color: "#9EDD72",
name: "Feijoa"
},
{
color: "#29BB9C",
name: "Shamrock"
},
{
color: "#019477",
name: "Observatory"
},
{
color: "#77DADA",
name: "Turquoise Blue"
},
{
color: "#4A90E2",
name: "Cornflower Blue"
},
{
color: "#484ED3",
name: "Free Speech Blue"
},
{
color: "#9B59B6",
name: "Deep Lilac"
},
{
color: "#E856EF",
name: "Free Speech Magenta"
},
{
color: "#FF599E",
name: "Brilliant Rose"
},
{
color: "#7A8C9E",
name: "Light Slate Grey"
}
];
root.getColorList = function() {
return colorList;
};
2015-03-06 12:00:10 -03:00
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;
}
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) {
configCache.glidera = defaultConfig.glidera;
2015-09-11 13:11:41 -03:00
}
Feat/coinbase integration (#4012) * Oauth2 and first view * Connect with Coinbase using mobile * Buy and Sell through Coinbase * Fix buy * Receive and send bitcoin to Coinbase account * Receive bitcoin from Coinbase to Copay * Complete user and account information. Connection errors * Improves error handler * Removes console.log * Coinbase background color. Send to Coinbase form validation * Fix send from different wallet * Send and receive using Coinbase * Pagination activity * Fix Buy and Sell * One option in the sidebar to Buy and Sell * Native balance on Coinbase homepage * Rename receive and send * Auto-close window after authenticate * Reorder * Get payment methods * Fix when token expired * Fix token expired * Integration: sell and send to Coinbase * Store pending transaction before sell * Sell flow completed * Removing files * Fix sell * Fix sell * Fix sell * Sell completed * Buy bitcoin through coinbase * Buy auto * Currency set to USD * Select payment methods. Limits * Removes payment methods from preferences * Fix signs. Tx ordered by updated. Minor fixes * Removes console.log * Improving ux-language things * Fix selectedpaymentmethod if not verified * Set error if tx not found * Price sensitivity. Minor fixes * Adds coinbase api key to gitignore * Coinbase production ready * Fix sell in usd * Bug fixes * New Sensitivity step * Refresh token with a simple click * Refresh token * Refactor * Fix auto reconnect if token expired Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com> * Fix calls if token expired
2016-04-13 14:08:03 -03:00
if (!configCache.coinbase) {
configCache.coinbase = defaultConfig.coinbase;
}
2016-09-27 15:57:39 -03:00
if (!configCache.amazon) {
configCache.amazon = defaultConfig.amazon;
}
if (!configCache.bitpayCard) {
configCache.bitpayCard = defaultConfig.bitpayCard;
}
if (!configCache.recentTransactions) {
configCache.recentTransactions = defaultConfig.recentTransactions;
}
if (!configCache.frequentlyUsed) {
configCache.frequentlyUsed = defaultConfig.frequentlyUsed;
}
2016-01-22 00:35:11 -03:00
if (!configCache.pushNotifications) {
configCache.pushNotifications = defaultConfig.pushNotifications;
}
2015-03-06 12:00:10 -03:00
} else {
configCache = lodash.clone(defaultConfig);
2015-03-06 12:00:10 -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
Feat/coinbase integration (#4012) * Oauth2 and first view * Connect with Coinbase using mobile * Buy and Sell through Coinbase * Fix buy * Receive and send bitcoin to Coinbase account * Receive bitcoin from Coinbase to Copay * Complete user and account information. Connection errors * Improves error handler * Removes console.log * Coinbase background color. Send to Coinbase form validation * Fix send from different wallet * Send and receive using Coinbase * Pagination activity * Fix Buy and Sell * One option in the sidebar to Buy and Sell * Native balance on Coinbase homepage * Rename receive and send * Auto-close window after authenticate * Reorder * Get payment methods * Fix when token expired * Fix token expired * Integration: sell and send to Coinbase * Store pending transaction before sell * Sell flow completed * Removing files * Fix sell * Fix sell * Fix sell * Sell completed * Buy bitcoin through coinbase * Buy auto * Currency set to USD * Select payment methods. Limits * Removes payment methods from preferences * Fix signs. Tx ordered by updated. Minor fixes * Removes console.log * Improving ux-language things * Fix selectedpaymentmethod if not verified * Set error if tx not found * Price sensitivity. Minor fixes * Adds coinbase api key to gitignore * Coinbase production ready * Fix sell in usd * Bug fixes * New Sensitivity step * Refresh token with a simple click * Refresh token * Refactor * Fix auto reconnect if token expired Signed-off-by: Gustavo Maximiliano Cortez <cmgustavo83@gmail.com> * Fix calls if token expired
2016-04-13 14:08:03 -03:00
// Coinbase
// Disabled for testnet
configCache.coinbase.testnet = false;
$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) {
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;
});