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

[FIX] Option to edit the send_max (RT-3205) #2464

Merged
merged 2 commits into from
May 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions src/js/tabs/advanced.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand Down Expand Up @@ -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];
}
};
Expand Down
10 changes: 7 additions & 3 deletions src/js/tabs/exchange.controller.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -78,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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 5 additions & 1 deletion src/js/tabs/send.controller.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
44 changes: 44 additions & 0 deletions src/templates/tabs/advanced.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/exchange.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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} }}  
Expand Down
2 changes: 1 addition & 1 deletion src/templates/tabs/send.jade
Original file line number Diff line number Diff line change
Expand Up @@ -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} }}  
Expand Down