copay/js/controllers/settings.js

103 lines
3.0 KiB
JavaScript
Raw Normal View History

2014-05-13 10:19:37 -07:00
'use strict';
2014-08-27 13:15:05 -07:00
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location, controllerUtils, rateService) {
2014-08-04 07:27:46 -07:00
2014-08-11 13:26:48 -07:00
controllerUtils.redirIfLogged();
$scope.title = 'Settings';
$scope.networkName = config.networkName;
$scope.insightHost = config.blockchain.host;
$scope.insightPort = config.blockchain.port;
$scope.insightSecure = config.blockchain.schema === 'https';
$scope.disableVideo = typeof config.disableVideo === undefined ? true : config.disableVideo;
$scope.forceNetwork = config.forceNetwork;
2014-08-11 13:26:48 -07:00
$scope.unitOpts = [{
name: 'Satoshis (100,000,000 satoshis = 1BTC)',
shortName: 'SAT',
2014-08-27 13:15:05 -07:00
value: 1,
decimals: 0
2014-08-11 13:26:48 -07:00
}, {
name: 'bits (1,000,000 bits = 1BTC)',
shortName: 'bits',
2014-08-27 13:15:05 -07:00
value: 100,
decimals: 2
2014-08-11 13:26:48 -07:00
}, {
name: 'mBTC (1,000 mBTC = 1BTC)',
shortName: 'mBTC',
2014-08-27 13:15:05 -07:00
value: 100000,
decimals: 5
2014-08-11 13:26:48 -07:00
}, {
name: 'BTC',
shortName: 'BTC',
2014-08-27 13:15:05 -07:00
value: 100000000,
decimals: 8
2014-08-11 13:26:48 -07:00
}];
2014-08-27 13:15:05 -07:00
$scope.selectedAlternative = {
2014-09-01 07:04:57 -07:00
name: config.alternativeName,
isoCode: config.alternativeIsoCode
2014-08-27 13:15:05 -07:00
};
2014-09-01 07:04:57 -07:00
$scope.alternativeOpts = rateService.isAvailable ?
rateService.listAlternatives() : [$scope.selectedAlternative];
2014-08-27 13:15:05 -07:00
rateService.whenAvailable(function() {
$scope.alternativeOpts = rateService.listAlternatives();
for (var ii in $scope.alternativeOpts) {
if (config.alternativeIsoCode === $scope.alternativeOpts[ii].isoCode) {
$scope.selectedAlternative = $scope.alternativeOpts[ii];
}
}
});
2014-08-11 13:26:48 -07:00
for (var ii in $scope.unitOpts) {
if (config.unitName === $scope.unitOpts[ii].shortName) {
$scope.selectedUnit = $scope.unitOpts[ii];
break;
}
2014-08-11 13:26:48 -07:00
}
2014-06-09 12:58:17 -07:00
2014-08-11 13:26:48 -07:00
$scope.changeNetwork = function() {
$scope.insightHost = $scope.networkName !== 'testnet' ? 'test-insight.bitpay.com' : 'insight.bitpay.com';
};
2014-06-09 12:58:17 -07:00
2014-06-26 14:47:27 -07:00
2014-08-11 13:26:48 -07:00
$scope.changeInsightSSL = function() {
$scope.insightPort = $scope.insightSecure ? 80 : 443;
};
2014-06-26 14:47:27 -07:00
2014-08-11 13:26:48 -07:00
$scope.save = function() {
var network = config.network;
2014-08-25 14:26:26 -07:00
network.host = $scope.insightHost;
network.port = $scope.insightPort;
network.schema = $scope.insightSecure ? 'https' : 'http';
2014-05-15 11:25:58 -07:00
2014-08-11 13:26:48 -07:00
localStorage.setItem('config', JSON.stringify({
networkName: $scope.networkName,
blockchain: {
host: $scope.insightHost,
port: $scope.insightPort,
schema: $scope.insightSecure ? 'https' : 'http',
},
socket: {
host: $scope.insightHost,
port: $scope.insightPort,
schema: $scope.insightSecure ? 'https' : 'http',
},
network: network,
disableVideo: $scope.disableVideo,
unitName: $scope.selectedUnit.shortName,
unitToSatoshi: $scope.selectedUnit.value,
2014-08-27 13:15:05 -07:00
unitDecimals: $scope.selectedUnit.decimals,
alternativeName: $scope.selectedAlternative.name,
alternativeIsoCode: $scope.selectedAlternative.isoCode,
version: copay.version
2014-08-11 13:26:48 -07:00
}));
2014-08-11 13:26:48 -07:00
// Go home reloading the application
var hashIndex = window.location.href.indexOf('#!/');
window.location = window.location.href.substr(0, hashIndex);
};
});