Merge pull request #27 from peter50216/upstream_master

Add support to remember prices in query string.
master
Mike Bryant 4 years ago committed by GitHub
commit 60c1f160d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -71,14 +71,39 @@ const getFirstBuyState = function () {
return JSON.parse(localStorage.getItem('first_buy'))
}
const getPrices = function () {
let prices = JSON.parse(localStorage.getItem("sell_prices"))
if (!prices || isEmpty(prices) || prices.length !== 14) {
return null
} else {
return prices
const getPricesFromLocalstorage = function () {
try {
const sell_prices = JSON.parse(localStorage.getItem("sell_prices"));
if (!Array.isArray(sell_prices) || sell_prices.length !== 14) {
return null;
}
return sell_prices;
} catch (e) {
return null;
}
}
};
const getPricesFromQuery = function () {
try {
const params = new URLSearchParams(window.location.search.substr(1));
const sell_prices = params.get("prices").split(".").map((x) => parseInt(x, 10));
if (!Array.isArray(sell_prices) || sell_prices.length !== 14) {
return null;
}
window.price_from_query = true;
return sell_prices;
} catch (e) {
return null;
}
};
const getPrices = function () {
return getPricesFromQuery() || getPricesFromLocalstorage();
};
const getSellPrices = function () {
//Checks all sell inputs and returns an array with their values
@ -117,7 +142,9 @@ const update = function () {
buy_input.prop('disabled', first_buy);
const prices = [buy_price, buy_price, ...sell_prices];
updateLocalStorage(prices, first_buy);
if (!window.price_from_query) {
updateLocalStorage(prices, first_buy);
}
calculateOutput(prices, first_buy);
}

Loading…
Cancel
Save