Wallet/src/js/controllers/preferencesBwsUrl.js

53 lines
1.4 KiB
JavaScript
Raw Normal View History

2015-03-06 12:00:10 -03:00
'use strict';
angular.module('copayApp.controllers').controller('preferencesBwsUrlController',
2015-10-19 11:19:28 -03:00
function($scope, $log, configService, go, applicationService, profileService, storageService) {
2015-03-06 12:00:10 -03:00
this.error = null;
this.success = null;
2015-10-15 17:47:22 -03:00
var fc = profileService.focusedClient;
var walletId = fc.credentials.walletId;
var defaults = configService.getDefaults();
2015-03-06 12:00:10 -03:00
var config = configService.getSync();
this.bwsurl = (config.bwsFor && config.bwsFor[walletId]) || defaults.bws.url;
2015-03-06 12:00:10 -03:00
2015-11-03 09:59:30 -03:00
this.resetDefaultUrl = function() {
2015-11-10 20:05:05 -03:00
this.bwsurl = defaults.bws.url;
2015-11-03 09:59:30 -03:00
};
2015-03-06 12:00:10 -03:00
this.save = function() {
2015-09-08 09:01:49 -03:00
var bws;
switch (this.bwsurl) {
case 'prod':
case 'production':
bws = 'https://bws.bitpay.com/bws/api'
break;
case 'sta':
case 'staging':
bws = 'https://bws-staging.b-pay.net/bws/api'
break;
case 'loc':
case 'local':
bws = 'http://localhost:3232/bws/api'
break;
};
if (bws) {
$log.info('Using BWS URL Alias to ' + bws);
this.bwsurl = bws;
}
2015-10-19 17:26:15 -03:00
var opts = {
bwsFor: {}
2015-10-19 17:26:15 -03:00
};
opts.bwsFor[walletId] = this.bwsurl;
2015-03-06 12:00:10 -03:00
2015-10-19 17:26:15 -03:00
configService.set(opts, function(err) {
if (err) console.log(err);
storageService.setCleanAndScanAddresses(walletId, function() {
applicationService.restart();
});
2015-03-06 12:00:10 -03:00
});
};
2015-11-10 20:05:05 -03:00
});