Skip to content

Commit d18500e

Browse files
authored
refactor validating... will still behave weirdly if somehow manages to get bad data set (sets localStorage without checking if it's valid)
1 parent 851c30e commit d18500e

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

www/lendingbot.js

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,27 +378,21 @@ function doSave() {
378378

379379
// Bitcoin Display Unit
380380
localStorage.displayUnitText = $('input[name="btcDisplayUnit"]:checked').val();
381-
btcDisplayUnitsModes.forEach(function(unit) {
382-
if(unit.name == localStorage.displayUnitText) {
383-
displayUnit = unit;
384-
}
385-
})
381+
if(btcDisplayUnitsModes.indexOf(localStorage.displayUnitText) !== -1) {
382+
displayUnit = localStorage.displayUnitText;
383+
}
386384

387385
// OutputCurrencyDisplayMode
388386
localStorage.outputCurrencyDisplayModeText = $('input[name="outputCurrencyDisplayMode"]:checked').val();
389-
validOutputCurrencyDisplayModes.forEach(function(mode) {
390-
if(mode == localStorage.outputCurrencyDisplayModeText) {
391-
outputCurrencyDisplayMode = mode;
392-
}
393-
})
394-
387+
if(validOutputCurrencyDisplayModes.indexOf(localStorage.outputCurrencyDisplayModeText) !== -1) {
388+
outputCurrencyDisplayMode = localStorage.outputCurrencyDisplayModeText;
389+
}
390+
395391
//Effective rate calculation
396392
localStorage.effRateMode = $('input[name="effRateMode"]:checked').val();
397-
validEffRateModes.forEach(function(mode) {
398-
if(mode == localStorage.effRateMode) {
399-
effRateMode = mode;
400-
}
401-
})
393+
if(validEffRateModes.indexOf(localStorage.effRateMode) !== -1) {
394+
effRateMode = localStorage.effRateMode;
395+
}
402396

403397
toastr.success("Settings saved!");
404398
$('#settings_modal').modal('hide');

0 commit comments

Comments
 (0)