Skip to content
This repository was archived by the owner on Sep 2, 2023. It is now read-only.

Commit

Permalink
[FIX] fix WebSocket server editing
Browse files Browse the repository at this point in the history
check data to be valid
fallback to default server settings
if user entered invalid data
(some data lead to exception in websocket constructor)
  • Loading branch information
darkdarkdragon committed Aug 25, 2015
1 parent 521c020 commit 15b741f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 41 deletions.
6 changes: 5 additions & 1 deletion config-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,16 @@ var Options = {
persistent_auth: false
};

Options.defaultServers = Options.server.servers;

// Load client-side overrides
if (store.enabled) {
var settings = JSON.parse(store.get('ripple_settings') || '{}');

if (settings.server && settings.server.servers) {
Options.server.servers = settings.server.servers;
Options.server.servers = _.filter(settings.server.servers, function(s) {
return !s.isEmptyServer && _.isNumber(s.port) && !_.isNaN(s.port);
});
}

if (settings.advanced_feature_switch) {
Expand Down
44 changes: 29 additions & 15 deletions src/js/controllers/navbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,43 @@ module.controller('NavbarCtrl', ['$scope', '$element', '$compile', 'rpId',
$scope.show_secondary = !$scope.show_secondary;
};

// Username
$scope.$watch('userCredentials', function(){
var username = $scope.userCredentials.username;
$scope.shortUsername = null;
if(username && username.length > 25) {
$scope.shortUsername = username.substring(0,24)+"...";
function serverStatusUpdate() {
$scope.fee = network.remote.createTransaction()._computeFee();

if (!$scope.connected && $scope.userCredentials.username) {
$scope.serverStatus = 'disconnected';
}
else if ($scope.connected && $scope.fee) {
if ((parseFloat(ripple.Amount.from_json($scope.fee).to_human()) > parseFloat(Options.low_load_threshold)) && (parseFloat($scope.fee) < parseFloat(Options.max_tx_network_fee))) {
$scope.serverLoad = 'mediumLoad';
$scope.serverStatus = 'mediumLoad';
} else if (parseFloat($scope.fee) >= parseFloat(Options.max_tx_network_fee)) {
$scope.serverLoad = 'highLoad';
$scope.serverStatus = 'highLoad';
} else {
$scope.serverLoad = '';
$scope.serverStatus = 'lowLoad';
}
}
}, true);
else {
$scope.serverStatus = 'connected';
}
}

$scope.$on('$netConnected', function (e) {
$scope.$watch('connected', serverStatusUpdate, true);

// Username
$scope.$watch('userCredentials', serverStatusUpdate, true);

$scope.$on('$netConnected', function(e) {
setConnectionStatus(true);
});

$scope.$on('$netDisconnected', function (e) {
$scope.$on('$netDisconnected', function(e) {
setConnectionStatus(false);
});

var updateNotifications = function () {
var updateNotifications = function() {
if ($scope.events) {
$scope.notifications = $scope.events.slice(0,10);
}
Expand Down Expand Up @@ -102,11 +121,6 @@ module.controller('NavbarCtrl', ['$scope', '$element', '$compile', 'rpId',

function setConnectionStatus(connected) {
$scope.connected = !!connected;
if (connected) {
notifyEl.find('.type-offline').remove();
} else {
notifyEl.append('<div class="notification active type-offline">OFFLINE</div>');
}
}

// A notification might have been queued already before the app was fully
Expand Down
18 changes: 13 additions & 5 deletions src/js/services/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ module.factory('rpNetwork', ['$rootScope', function($scope)
* library directly. This is not to be intended to be an abstraction
* layer on top of an abstraction layer.
*/
var Network = function ()
{
var Network = function() {
this.remote = new ripple.Remote(Options.server, true);
this.remote.on('connected', this.handleConnect.bind(this));
this.remote.on('disconnected', this.handleDisconnect.bind(this));
Expand All @@ -32,9 +31,18 @@ module.factory('rpNetwork', ['$rootScope', function($scope)
this.connected = false;
};

Network.prototype.init = function ()
{
this.remote.connect();
Network.prototype.init = function() {
try {
this.remote.connect();
} catch (e) {
console.warn(e);
// fallback to default servers
Options.server.servers = Options.defaultServers;
this.remote = new ripple.Remote(Options.server, true);
this.remote.on('connected', this.handleConnect.bind(this));
this.remote.on('disconnected', this.handleDisconnect.bind(this));
this.remote.connect();
}
};

/**
Expand Down
39 changes: 23 additions & 16 deletions src/js/tabs/advanced.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,20 @@ AdvancedTab.prototype.angular = function(module)
$scope.editAcctOptions = false;
$scope.max_tx_network_fee_human = ripple.Amount.from_json($scope.options.max_tx_network_fee).to_human();

$scope.saveBlob = function () {
$scope.saveSetings = function() {
// force serve ports to be number
_.each($scope.options.server.servers, function(s) {
s.port = +s.port;
});
// Save in local storage
if (!store.disabled) {
store.set('ripple_settings', JSON.stringify($scope.options));
store.set('ripple_settings', angular.toJson($scope.options));
}
}

$scope.saveBlob = function() {

$scope.saveSetings();

$scope.editBlob = false;

Expand All @@ -59,7 +68,7 @@ AdvancedTab.prototype.angular = function(module)
// Save in local storage
if (!store.disabled) {
$scope.options.max_tx_network_fee = ripple.Amount.from_human($scope.max_tx_network_fee_human).to_json();
store.set('ripple_settings', JSON.stringify($scope.options));
store.set('ripple_settings', angular.toJson($scope.options));
}

$scope.editMaxNetworkFee = false;
Expand All @@ -71,7 +80,7 @@ AdvancedTab.prototype.angular = function(module)
$scope.saveAcctOptions = function () {
if (!store.disabled) {
// Save in local storage
store.set('ripple_settings', JSON.stringify($scope.options));
store.set('ripple_settings', angular.toJson($scope.options));
}

$scope.editAcctOptions = false;
Expand Down Expand Up @@ -123,10 +132,7 @@ AdvancedTab.prototype.angular = function(module)
$scope.remove = function () {
$scope.options.server.servers.splice($scope.index,1);

// Save in local storage
if (!store.disabled) {
store.set('ripple_settings', JSON.stringify($scope.options));
}
$scope.saveSetings();
}

$scope.hasRemove = function () {
Expand All @@ -140,8 +146,12 @@ AdvancedTab.prototype.angular = function(module)
}

$scope.editing = false;
$scope.server = $.extend({}, $scope.optionsBackup.server.servers[$scope.index]);

console.log('---- ServerRowCtrl::cancel index: ' + $scope.index);
console.log(JSON.stringify($scope.server));
$scope.server = $.extend({ '$$hashKey' : $scope.server.$$hashKey }, $scope.optionsBackup.server.servers[$scope.index]);
Options.server.servers[$scope.index] = $.extend({}, $scope.optionsBackup.server.servers[$scope.index]);
console.log(JSON.stringify($scope.server));
console.log(JSON.stringify(Options.server.servers));
}

$scope.noCancel = function () {
Expand All @@ -152,13 +162,10 @@ AdvancedTab.prototype.angular = function(module)
$scope.server.isEmptyServer = false;
$scope.editing = false;

// Save in local storage
if (!store.disabled) {
store.set('ripple_settings', JSON.stringify($scope.options));
}
$scope.saveSetings();

// Reload
location.reload();
// Reload
location.reload();
};
}
]);
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/advanced.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
section.col-xs-12.content(ng-controller="AdvancedCtrl")
.row(ng-show='connected')
.row
.col-sm-3
include settings/navbar
.col-sm-9.list
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/security.jade
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
section.col-xs-12.content(ng-controller="SecurityCtrl")
.row(ng-show='connected')
.row
.col-sm-4.col-md-3.col-xs-12(ng-show="isUnlocked")
include settings/navbar
.col-sm-8.col-md-9.col-xs-12.list(ng-show="isUnlocked")
Expand Down
6 changes: 4 additions & 2 deletions src/templates/tabs/settingsgateway.jade
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
section.col-xs-12.content(ng-controller="SettingsGatewayCtrl")
.row(ng-show='connected')
.row
.col-sm-12.notification-wrapper
.alert.alert-success(ng-show="success.bridge", l10n) Your bitcoin bridge has been changed successfully.
.alert.alert-success(ng-show="success.advanced_feature_switch", l10n) Trustline advanced settings have been changed successfully.
.alert.alert-info(ng-show="edit.defaultRippleFlagSaving", l10n) Updating DefaultRipple flag...
.alert.alert-success(ng-show="notif == 'defaultRippleUpdated'", l10n) DefaultRipple flag updated
.col-sm-3
include settings/navbar
.col-sm-9.list
group.disconnected(ng-hide="connected")
p.literal(l10n) You have to be online to see this screen
.col-sm-9.list(ng-show='connected')
section.content#gateways
h4(l10n) Settings
form.trust-line-form(name="accountsAdvForm", ng-submit='save("advanced_feature_switch")')
Expand Down

0 comments on commit 15b741f

Please sign in to comment.