mirror of https://github.com/BTCPrivate/copay.git
Set default ports automatically on Insight URLs
This commit is contained in:
parent
bdbaee561e
commit
28d888b75f
|
@ -1,6 +1,6 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location, controllerUtils, notification) {
|
||||||
|
|
||||||
angular.module('copayApp.controllers').controller('SettingsController', function($scope, $rootScope, $window, $location, controllerUtils) {
|
|
||||||
|
|
||||||
controllerUtils.redirIfLogged();
|
controllerUtils.redirIfLogged();
|
||||||
$scope.title = 'Settings';
|
$scope.title = 'Settings';
|
||||||
|
@ -8,6 +8,7 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
$scope.insightLivenet = config.network.livenet.url;
|
$scope.insightLivenet = config.network.livenet.url;
|
||||||
$scope.insightTestnet = config.network.testnet.url;
|
$scope.insightTestnet = config.network.testnet.url;
|
||||||
|
|
||||||
|
|
||||||
$scope.availableLanguages = [{
|
$scope.availableLanguages = [{
|
||||||
name: 'English',
|
name: 'English',
|
||||||
isoCode: 'en',
|
isoCode: 'en',
|
||||||
|
@ -23,7 +24,12 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$scope.save = function() {
|
$scope.save = function() {
|
||||||
|
$scope.insightLivenet = copay.Insight.setCompleteUrl($scope.insightLivenet);
|
||||||
|
$scope.insightTestnet = copay.Insight.setCompleteUrl($scope.insightTestnet);
|
||||||
|
|
||||||
|
|
||||||
var insightSettings = {
|
var insightSettings = {
|
||||||
livenet: {
|
livenet: {
|
||||||
url: $scope.insightLivenet,
|
url: $scope.insightLivenet,
|
||||||
|
@ -33,6 +39,7 @@ angular.module('copayApp.controllers').controller('SettingsController', function
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
localStorage.setItem('config', JSON.stringify({
|
localStorage.setItem('config', JSON.stringify({
|
||||||
network: insightSettings,
|
network: insightSettings,
|
||||||
version: copay.version,
|
version: copay.version,
|
||||||
|
|
|
@ -48,7 +48,30 @@ angular.module('copayApp.directives')
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
.directive('validAmount', ['$rootScope', '$locale',
|
.directive('validUrl', [
|
||||||
|
|
||||||
|
function() {
|
||||||
|
return {
|
||||||
|
require: 'ngModel',
|
||||||
|
link: function(scope, elem, attrs, ctrl) {
|
||||||
|
var validator = function(value) {
|
||||||
|
// Regular url
|
||||||
|
if (/^https?:\/\//.test(value)) {
|
||||||
|
ctrl.$setValidity('validUrl', true);
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
ctrl.$setValidity('validUrl', false);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ctrl.$parsers.unshift(validator);
|
||||||
|
ctrl.$formatters.unshift(validator);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
])
|
||||||
|
.directive('validAmount', ['$rootScope', '$locale',
|
||||||
function($rootScope, locale) {
|
function($rootScope, locale) {
|
||||||
var w = $rootScope.wallet;
|
var w = $rootScope.wallet;
|
||||||
preconditions.checkState(w);
|
preconditions.checkState(w);
|
||||||
|
@ -68,7 +91,7 @@ angular.module('copayApp.directives')
|
||||||
if (typeof vNum == "number" && vNum > 0) {
|
if (typeof vNum == "number" && vNum > 0) {
|
||||||
var decimals = Number(w.settings.unitDecimals);
|
var decimals = Number(w.settings.unitDecimals);
|
||||||
var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP);
|
var sep_index = ('' + value).indexOf(formats.DECIMAL_SEP);
|
||||||
var str_value = ('' + value).substring(sep_index+1);
|
var str_value = ('' + value).substring(sep_index + 1);
|
||||||
if (sep_index > 0 && str_value.length > decimals) {
|
if (sep_index > 0 && str_value.length > decimals) {
|
||||||
ctrl.$setValidity('validAmount', false);
|
ctrl.$setValidity('validAmount', false);
|
||||||
scope.notValidAmount = true;
|
scope.notValidAmount = true;
|
||||||
|
|
|
@ -45,6 +45,58 @@ var Insight = function(opts) {
|
||||||
this.socket = this.getSocket();
|
this.socket = this.getSocket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Insight.setCompleteUrl = function(uri) {
|
||||||
|
|
||||||
|
if (!uri) return uri;
|
||||||
|
|
||||||
|
var re = /^(?:(?![^:@]+:[^:@\/]*@)(http|https|ws|wss):\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?((?:[a-f0-9]{0,4}:){2,7}[a-f0-9]{0,4}|[^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
||||||
|
|
||||||
|
var parts = [
|
||||||
|
'source', 'protocol', 'authority', 'userInfo', 'user', 'password', 'host', 'port', 'relative', 'path', 'directory', 'file', 'query', 'anchor'
|
||||||
|
];
|
||||||
|
|
||||||
|
function parseuri(str) {
|
||||||
|
var m = re.exec(str || ''),
|
||||||
|
uri = {},
|
||||||
|
i = 14;
|
||||||
|
|
||||||
|
while (i--) {
|
||||||
|
uri[parts[i]] = m[i] || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return uri;
|
||||||
|
};
|
||||||
|
|
||||||
|
var opts_host;
|
||||||
|
var opts_secure;
|
||||||
|
var opts_port;
|
||||||
|
var opts_protocol;
|
||||||
|
if (uri) {
|
||||||
|
uri = parseuri(uri);
|
||||||
|
opts_host = uri.host;
|
||||||
|
opts_protocol = uri.protocol;
|
||||||
|
opts_secure = uri.protocol == 'https' || uri.protocol == 'wss';
|
||||||
|
opts_port = uri.port;
|
||||||
|
}
|
||||||
|
|
||||||
|
var this_secure = null != opts_secure ? opts_secure :
|
||||||
|
('https:' == location.protocol);
|
||||||
|
|
||||||
|
var opts_hostname;
|
||||||
|
if (opts_host) {
|
||||||
|
var pieces = opts_host.split(':');
|
||||||
|
opts_hostname = pieces.shift();
|
||||||
|
if (pieces.length) opts_port = pieces.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
var this_port = opts_port ||
|
||||||
|
(this_secure ? 443 : 80);
|
||||||
|
|
||||||
|
var newUri = opts_protocol + '://' + opts_host + ':' + this_port;
|
||||||
|
|
||||||
|
return newUri;
|
||||||
|
}
|
||||||
|
|
||||||
util.inherits(Insight, EventEmitter);
|
util.inherits(Insight, EventEmitter);
|
||||||
|
|
||||||
Insight.prototype.STATUS = {
|
Insight.prototype.STATUS = {
|
||||||
|
|
|
@ -15,10 +15,13 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend translate>Insight API server</legend>
|
<legend translate>Insight API server</legend>
|
||||||
<label for="insight-livenet">Livenet</label>
|
<label for="insightLivenet">Livenet</label>
|
||||||
<input type="text" ng-model="insightLivenet" class="form-control" name="insight-livenet">
|
<small translate class="has-error" ng-show="settingsForm.insightLivenet.$invalid">not valid</small>
|
||||||
<label for="insight-testnet">Testnet</label>
|
<input type="text" ng-model="insightLivenet" class="form-control" name="insightLivenet" valid-url required>
|
||||||
<input type="text" ng-model="insightTestnet" class="form-control" name="insight-testnet">
|
|
||||||
|
<label for="insightTestnet">Testnet</label>
|
||||||
|
<small translate class="has-error" ng-show="settingsForm.insightTestnet.$invalid">not valid</small>
|
||||||
|
<input type="text" ng-model="insightTestnet" class="form-control" name="insightTestnet" valid-url required>
|
||||||
|
|
||||||
<p translate class="small">
|
<p translate class="small">
|
||||||
Insight API server is open-source software. You can run your own instances, check <a href="http://insight.is" target="_blank">Insight API Homepage</a>
|
Insight API server is open-source software. You can run your own instances, check <a href="http://insight.is" target="_blank">Insight API Homepage</a>
|
||||||
|
@ -26,7 +29,7 @@
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<div class="text-right m20t">
|
<div class="text-right m20t">
|
||||||
<a class="back-button text-white m20r" href="#!/">« <span translate>Back</span></a>
|
<a class="back-button text-white m20r" href="#!/">« <span translate>Back</span></a>
|
||||||
<button translate type="submit" class="button primary m0 ng-binding" ng-disabled="setupForm.$invalid || loading" disabled="disabled" ng-click="save()">
|
<button translate type="submit" class="button primary m0 ng-binding" ng-disabled="settingsForm.$invalid || loading" ng-click="save()">
|
||||||
Save
|
Save
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue