From b06eec2d5ff1434b4391e38cb801e6541d745848 Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Tue, 28 Apr 2015 02:16:41 +0300 Subject: [PATCH 1/2] [FIX] Option to edit the send_max (RT-3205) Advanced settings: option to edit the send_max of a Send and Simple Trade --- src/js/tabs/advanced.controller.js | 34 ++++++++++++++++++++--- src/js/tabs/exchange.controller.js | 6 +++- src/js/tabs/send.controller.js | 6 +++- src/templates/tabs/advanced.jade | 44 ++++++++++++++++++++++++++++++ src/templates/tabs/exchange.jade | 2 +- src/templates/tabs/send.jade | 2 +- 6 files changed, 86 insertions(+), 8 deletions(-) diff --git a/src/js/tabs/advanced.controller.js b/src/js/tabs/advanced.controller.js index 5f43ba2ca..8d711a937 100644 --- a/src/js/tabs/advanced.controller.js +++ b/src/js/tabs/advanced.controller.js @@ -31,7 +31,6 @@ AdvancedTab.prototype.angular = function(module) $scope.options = Options; $scope.optionsBackup = $.extend(true, {}, Options); - $scope.passwordProtection = !settings.getSetting($scope.userBlob, 'persistUnlock', false); $scope.editConfirmation = { send: false, exchange: false, @@ -40,9 +39,29 @@ AdvancedTab.prototype.angular = function(module) $scope.edit = { blobvault: false, maxNetworkFee: false, - historyApi: false + historyApi: false, + sendMax: false, + exchangeMax: false }; + + function readSettings() { + $scope.passwordProtection = !settings.getSetting($scope.userBlob, 'persistUnlock', false); + $scope.sendMaxDeviation = settings.getSetting($scope.userBlob, 'sendMaxDeviation', 0.1); + $scope.exchangeMaxDeviation = settings.getSetting($scope.userBlob, 'exchangeMaxDeviation', 0.1); + } + + if (settings.blobIsValid($scope.userBlob)) { + readSettings(); + } else { + var removeListener = $scope.$on('$blobUpdate', function() { + if (!settings.blobIsValid($scope.userBlob)) return; + readSettings(); + removeListener(); + }); + } + $scope.max_tx_network_fee_human = ripple.Amount.from_json($scope.options.max_tx_network_fee).to_human(); + $scope.confirmationChanged = { send: false, exchange: false, @@ -54,6 +73,10 @@ AdvancedTab.prototype.angular = function(module) $scope.save = function(type) { switch (type) { + case 'sendMax': + $scope.userBlob.set('/clients/rippletradecom/sendMaxDeviation', $scope.sendMaxDeviation); + case 'exchangeMax': + $scope.userBlob.set('/clients/rippletradecom/exchangeMaxDeviation', $scope.exchangeMaxDeviation); case 'maxNetworkFee': $scope.options.max_tx_network_fee = ripple.Amount.from_human($scope.max_tx_network_fee_human).to_json(); $scope.userBlob.set('/clients/rippletradecom/maxNetworkFee', $scope.options.max_tx_network_fee); @@ -111,8 +134,11 @@ AdvancedTab.prototype.angular = function(module) if (type === 'maxNetworkFee') { $scope.options.max_tx_network_fee = $scope.optionsBackup.max_tx_network_fee; $scope.max_tx_network_fee_human = ripple.Amount.from_json($scope.options.max_tx_network_fee).to_human(); - } - else { + } if (type === 'sendMax') { + $scope.sendMaxDeviation = settings.getSetting($scope.userBlob, 'sendMaxDeviation', 0.1); + } if (type === 'exchangeMax') { + $scope.exchangeMaxDeviation = settings.getSetting($scope.userBlob, 'exchangeMaxDeviation', 0.1); + } else { $scope.options[type] = $scope.optionsBackup[type]; } }; diff --git a/src/js/tabs/exchange.controller.js b/src/js/tabs/exchange.controller.js index cc496afbb..91a2d8658 100644 --- a/src/js/tabs/exchange.controller.js +++ b/src/js/tabs/exchange.controller.js @@ -1,5 +1,6 @@ var util = require('util'), webutil = require('../util/web'), + settings = require('../util/settings'), Tab = require('../client/tab').Tab, Amount = ripple.Amount, Base = ripple.Base, @@ -191,7 +192,9 @@ ExchangeTab.prototype.angular = function (module) var alt = {}; alt.amount = Amount.from_json(raw.source_amount); alt.rate = alt.amount.ratio_human(amount); - alt.send_max = alt.amount.scale('1.001'); + var exchangeMaxDeviation = settings.getSetting($scope.userBlob, 'exchangeMaxDeviation', 0.1); + alt.send_max = alt.amount.scale(1 + exchangeMaxDeviation / 100); + alt.paths = raw.paths_computed ? raw.paths_computed : raw.paths_canonical; @@ -302,6 +305,7 @@ ExchangeTab.prototype.angular = function (module) if (Options.confirmation.exchange) { $scope.mode = 'confirm'; + $scope.exchangeMaxDeviation = settings.getSetting($scope.userBlob, 'exchangeMaxDeviation', 1); } else { $scope.exchange_confirmed(); } diff --git a/src/js/tabs/send.controller.js b/src/js/tabs/send.controller.js index d951d374d..c6c42aea2 100644 --- a/src/js/tabs/send.controller.js +++ b/src/js/tabs/send.controller.js @@ -1,5 +1,6 @@ var util = require('util'), webutil = require('../util/web'), + settings = require('../util/settings'), Tab = require('../client/tab').Tab, Amount = ripple.Amount, Currency = ripple.Currency, @@ -797,7 +798,8 @@ SendTab.prototype.angular = function (module) var slightlyInFuture = new Date(+new Date() + 5 * 60000); alt.rate = alt.amount.ratio_human(amount, {reference_date: slightlyInFuture}); - alt.send_max = alt.amount.scale('1.001'); + var sendMaxDeviation = settings.getSetting($scope.userBlob, 'sendMaxDeviation', 0.1); + alt.send_max = alt.amount.scale(1 + sendMaxDeviation / 100); alt.paths = raw.paths_computed || raw.paths_canonical; // Selected currency should be the first option @@ -964,6 +966,8 @@ SendTab.prototype.angular = function (module) if (Options.confirmation.send) { $scope.mode = 'confirm'; + $scope.sendMaxDeviation = settings.getSetting($scope.userBlob, 'sendMaxDeviation', 0.1); + cleanPasswordUpdater(); // needed for password managers that don't raise change event on input field diff --git a/src/templates/tabs/advanced.jade b/src/templates/tabs/advanced.jade index 062cd4228..09fe4ad46 100644 --- a/src/templates/tabs/advanced.jade +++ b/src/templates/tabs/advanced.jade @@ -98,6 +98,50 @@ section.col-xs-12.content(ng-controller="AdvancedCtrl") button.btn.btn-block.btn-success.btn-xs.submit#saveMaxNetworkFee(type='submit', ng-disabled='maxnetworkfeeForm.$invalid', l10n) Save .col-xs-3.col-sm-3.col-md-1.text-center#cancel a.btn.btn-cancel.btn-block(href="", ng-click='cancelEdit("maxNetworkFee")', l10n) cancel + form(name="sendMaxForm", ng-submit='save("sendMax")') + .descriptor(l10n) Send: max deviation from specified amount + .row.advanced-form-row(ng-hide="edit.sendMax") + .col-xs-9.col-sm-8.col-md-6 + .description {{sendMaxDeviation}} % + .col-xs-1 + .col-xs-3.col-sm-3.col-md-2 + a.btn.btn-block.btn-cancel(href="", ng-click="edit.sendMax = true", l10n) edit + .row.row-padding-small.field-edit-row(ng-show="edit.sendMax") + .col-xs-12.col-sm-9.col-md-6.input-group + input.form-control.maxNetworkFee#sendMaxDeviation( + name='sendMax', type='text' + ng-model='sendMaxDeviation' + required + rp-amount + rp-amount-positive + ) + span.input-group-addon % + .col-xs-6.col-sm-6.col-md-3 + button.btn.btn-block.btn-success.btn-xs.submit#sendMaxDeviationSubmit(type='submit', ng-disabled='sendMaxForm.$invalid', l10n) Save + .col-xs-3.col-sm-3.col-md-1.text-center#sendMaxDeviationCancel + a.btn.btn-cancel.btn-block(href="", ng-click='cancelEdit("sendMax")', l10n) cancel + form(name="exchangeMaxForm", ng-submit='save("exchangeMax")') + .descriptor(l10n) Simple Trade: max deviation from specified amount + .row.advanced-form-row(ng-hide="edit.exchangeMax") + .col-xs-9.col-sm-8.col-md-6 + .description {{exchangeMaxDeviation}} % + .col-xs-1 + .col-xs-3.col-sm-3.col-md-2 + a.btn.btn-block.btn-cancel(href="", ng-click="edit.exchangeMax = true", l10n) edit + .row.row-padding-small.field-edit-row(ng-show="edit.exchangeMax") + .col-xs-12.col-sm-9.col-md-6.input-group + input.form-control.maxNetworkFee#exchangeMaxDeviation( + name='exchangeMax', type='text' + ng-model='exchangeMaxDeviation' + required + rp-amount + rp-amount-positive + ) + span.input-group-addon % + .col-xs-6.col-sm-6.col-md-3 + button.btn.btn-block.btn-success.btn-xs.submit#exchangeMaxDeviationSubmit(type='submit', ng-disabled='exchangeMaxForm.$invalid', l10n) Save + .col-xs-3.col-sm-3.col-md-1.text-center#exchangeMaxDeviationCancel + a.btn.btn-cancel.btn-block(href="", ng-click='cancelEdit("exchangeMax")', l10n) cancel h4#confirmationSettings(l10n) Confirmation Page settings +confirmation('send', 'sendConfirmationForm', 'Send confirmation settings', 'If you hide your send confirmation page, you will not see a confirmation page when sending money. You might pay up to .1% more than you originally specified.', 'sendConfirmationBox') diff --git a/src/templates/tabs/exchange.jade b/src/templates/tabs/exchange.jade index a6e89d433..d0c9295ce 100644 --- a/src/templates/tabs/exchange.jade +++ b/src/templates/tabs/exchange.jade @@ -131,7 +131,7 @@ section.col-xs-12.content(ng-controller="ExchangeCtrl") p.amount_feedback span.value {{exchange.alt.amount | rpamount}} span.currency {{exchange.alt.amount | rpcurrency}} - span + .1% + span + {{exchangeMaxDeviation}}% p span.literal(l10n-inc) Exchange rate: span.value {{exchange.alt.rate | rpamount:{rel_precision: 4} }} diff --git a/src/templates/tabs/send.jade b/src/templates/tabs/send.jade index a1c8605bb..97675a0b3 100644 --- a/src/templates/tabs/send.jade +++ b/src/templates/tabs/send.jade @@ -275,7 +275,7 @@ section.col-xs-12.content(ng-controller='SendCtrl') p.sendmax_feedback span.value {{send.alt.amount | rpamount}} span.currency {{send.alt.amount | rpcurrency}} - span + .1% + span + {{sendMaxDeviation}}% p(ng-hide="!send.alt") span.literal(l10n) Exchange rate: span.value {{send.alt.rate | rpamount:{rel_precision: 4} }} From b7b0a2e2800624ee0710e5c9df11b5d676b46698 Mon Sep 17 00:00:00 2001 From: Ivan Tivonenko Date: Thu, 30 Apr 2015 01:47:04 +0300 Subject: [PATCH 2/2] just trigger travis build --- src/js/tabs/exchange.controller.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/tabs/exchange.controller.js b/src/js/tabs/exchange.controller.js index 91a2d8658..6292882f3 100644 --- a/src/js/tabs/exchange.controller.js +++ b/src/js/tabs/exchange.controller.js @@ -79,13 +79,13 @@ ExchangeTab.prototype.angular = function (module) $location.path('/xrp'); }; - $scope.reset_paths = function () { + $scope.reset_paths = function() { var exchange = $scope.exchange; exchange.alternatives = []; }; - $scope.update_exchange = function () { + $scope.update_exchange = function() { var exchange = $scope.exchange; var currency = ripple.Currency.from_human(exchange.currency_name);