">
+
≈ "> /
+
">
ℹ️
From 5bd4bcc603358f903cd3008ca9d3e0e7f9c4f6b0 Mon Sep 17 00:00:00 2001
From: daf <59562656+dafdafdafdaf@users.noreply.github.com>
Date: Tue, 23 Jun 2026 18:58:56 +0200
Subject: [PATCH 2/3] collateral increments on UI + past fiat rates for
one-year-old simulations + other stuff
---
JS/scripts.js | 93 +++++++++++++++++++++++++++++++++++++----------
compute.php | 77 ++++++++++++++++++++++++---------------
index.php | 2 +-
languages/en.json | 16 ++++----
languages/es.json | 16 ++++----
languages/fr.json | 16 ++++----
languages/it.json | 16 ++++----
style.css | 10 +++--
8 files changed, 164 insertions(+), 82 deletions(-)
diff --git a/JS/scripts.js b/JS/scripts.js
index b1327f2..94d76ae 100644
--- a/JS/scripts.js
+++ b/JS/scripts.js
@@ -34,39 +34,92 @@ function partial(fieldId) {
const rawValue = input.value;
const value = Number(rawValue);
const min = Number(input.min); // 1
- const max = Number(input.max); // 1000 or 4000
+ const fullcollateral = Number(input.placeholder); // 1000 or 4000
if (refusalCount[fieldId] === undefined)
refusalCount[fieldId] = 0;
- const isValid = rawValue !== '' && Number.isInteger(value) && value >= min && value <= max;
+ const isValid = rawValue !== '' && Number.isInteger(value) && value >= min;
if (!isValid) {
refusalCount[fieldId]++;
const lastValid = input.dataset.lastValid ?? input.placeholder;
input.value = lastValid;
if (refusalCount[fieldId] >= 5)
- alert(JSalert + min + " & " + max + ".");
+ alert(JSalert);
} else { // valid partial collateral entered by the visitor
refusalCount[fieldId] = 0;
input.dataset.lastValid = rawValue;
+ const thenumber = document.getElementById(fieldId + "-number");
const yearlydash = document.getElementById(fieldId + "-earning");
const yearlyfiat = document.getElementById(fieldId + "-fiat-earning");
- // updated earnings
- yearlydash.textContent = ((value / max) * yearlydash.dataset.placeholder).toFixed(1);
- yearlyfiat.textContent = ((value / max) * yearlyfiat.dataset.placeholder).toFixed(1);
- // bounces to show it
- yearlydash.classList.remove('earning-update');
- yearlyfiat.classList.remove('earning-update');
- void yearlydash.offsetWidth;
- void yearlyfiat.offsetWidth;
- yearlydash.classList.add('earning-update');
- yearlyfiat.classList.add('earning-update');
- yearlydash.addEventListener('animationend', () => {
- yearlydash.classList.remove('earning-update');
- }, { once: true });
- yearlyfiat.addEventListener('animationend', () => {
- yearlyfiat.classList.remove('earning-update');
- }, { once: true });
+ // updated number of MNs/eMNs
+ var newnumber = Number((value / fullcollateral).toFixed(1));
+ var times = "";
+ if (newnumber != 1)
+ times = " × ";
+ if (newnumber < 0.1)
+ newnumber = "≈ 0.05";
+ else if (!Number.isInteger(newnumber))
+ newnumber = "≈ " + newnumber;
+ thenumber.textContent = newnumber + times;
+ // updated number and earnings
+ yearlydash.textContent = ((value / fullcollateral) * yearlydash.dataset.placeholder).toFixed(1);
+ yearlyfiat.textContent = ((value / fullcollateral) * yearlyfiat.dataset.placeholder).toFixed(0);
+ // funky bounces to show it
+ [thenumber, yearlydash, yearlyfiat].forEach(element => {
+ element.classList.remove('earning-update');
+ void element.offsetWidth;
+ element.classList.add('earning-update');
+ element.addEventListener('animationend', () => {
+ element.classList.remove('earning-update');
+ }, { once: true });
+ });
+
+
+
}
-}
\ No newline at end of file
+}
+
+// 1000 or 4000 increments management (using up/down arrow keys)
+document.addEventListener("DOMContentLoaded", () => {
+ ['coll-MN', 'coll-Evo'].forEach(id => {
+ const input = document.getElementById(id);
+ if (!input)
+ return;
+ const stepValue = Number(input.placeholder); // 1000 for MN, 4000 for Evo
+ let lastValue = Number(input.value);
+ // 1 : up/down arrow on keyboard
+ input.addEventListener('keydown', (e) => {
+ let currentValue = Number(input.value) || 0;
+ if (e.key === 'ArrowUp') {
+ e.preventDefault();
+ let newValue = Math.ceil((currentValue + 0.1) / stepValue) * stepValue;
+ input.value = newValue;
+ input.dispatchEvent(new Event('input'));
+ } else if (e.key === 'ArrowDown') {
+ e.preventDefault();
+ let newValue = Math.floor((currentValue - 0.1) / stepValue) * stepValue;
+ input.value = Math.max(Number(input.min) || 1, newValue);
+
+ input.dispatchEvent(new Event('input'));
+ }
+ });
+ // 2 : browser arrows clicked
+ input.addEventListener('input', (e) => {
+ if (e.inputType !== 'insertText' && e.inputType !== 'deleteContentBackward') {
+ let currentValue = Number(input.value) || 0;
+ if (currentValue > lastValue) {
+ let newValue = Math.ceil((lastValue + 0.1) / stepValue) * stepValue;
+ input.value = newValue;
+ }
+ else if (currentValue < lastValue) {
+ let newValue = Math.floor((lastValue - 0.1) / stepValue) * stepValue;
+ input.value = Math.max(Number(input.min) || 1, newValue);
+ }
+ partial(id.replace('coll-', ''));
+ }
+ lastValue = Number(input.value);
+ });
+ });
+});
\ No newline at end of file
diff --git a/compute.php b/compute.php
index 023e861..f599abb 100644
--- a/compute.php
+++ b/compute.php
@@ -1,6 +1,6 @@
$now, "readable" => date("Y-m-d H:i:s", $now)];
$JSON["lastPrices"]["USD"]["365d"] = round($prices[0][1], 2);
$JSON["lastPrices"]["USD"]["current"] = round($prices[count($prices) - 1][1], 2);
- $JSON["lastPrices"]["USD"]["status"] = "Dash/USD price refreshed";
+ $JSON["lastPrices"]["USD"]["status"][] = "Dash/USD price refreshed";
}
} catch (Exception $e) {
- $JSON["lastPrices"]["USD"]["status"] = "Fetch failed: " . $e->getMessage();
+ $JSON["lastPrices"]["USD"]["status"][] = "Fetch failed: " . $e->getMessage();
}
}
-// Exchange rates update (ExchangeRate-API) if missing or outdated
+// Exchange rates update (Frankfurter.dev) if missing or outdated
$needs_exchange_update = false;
if (!isset($JSON["lastPrices"]["conversion_rates"]) || !isset($JSON["lastPrices"]["conversion_rates"]["time"]["timestamp"]) || ($now - $JSON["lastPrices"]["conversion_rates"]["time"]["timestamp"]) > ($hoursExchangeRate * 60 * 60)) {
$needs_exchange_update = true;
}
if ($needs_exchange_update) {
- try {
- $url_exchange = "https://v6.exchangerate-api.com/v6/" . $ExchangeRateAPIKey . "/latest/USD";
- $data_exch = http_get_json($url_exchange);
- if (isset($data_exch["conversion_rates"])) {
- $JSON["lastPrices"]["conversion_rates"] = [
- "source" => "ExchangeRate-API",
- "time" => [
- "timestamp" => $now,
- "readable" => date("Y-m-d H:i:s", $now)
- ]
- ];
- foreach (array_keys($fiatcurrencies) as $f) {
- if (!isset($data_exch["conversion_rates"][$f])) {
- $JSON["lastPrices"]["conversion_rates"]["status"] = "Warning: missing rate for " . $f;
+ $JSON["lastPrices"]["conversion_rates"] = [
+ "source" => "Frankfurter.dev",
+ "time" => [
+ "timestamp" => $now,
+ "readable" => date("Y-m-d H:i:s", $now)
+ ]
+ ];
+ $exch_rate_dates = array("now" => $now, "one-year-ago" => ($now - (365 * 24 * 60 * 60)));
+ foreach ($exch_rate_dates as $datename => $datestamp) {
+ try {
+ if ($datename == "one-year-ago")
+ $data_exch_get = "&date=" . date("Y-m-d", $datestamp);
+ else
+ $data_exch_get = "";
+ $data_exch = http_get_json("https://api.frankfurter.dev/v2/rates?base=USD" . $data_exch_get);
+ if (is_array($data_exch) and !empty($data_exch)) {
+ $JSON["lastPrices"]["conversion_rates"][$datename] = [
+ "time" => [
+ "timestamp" => $datestamp,
+ "readable" => date("Y-m-d H:i:s", $datestamp)
+ ]
+ ];
+ $JSON["lastPrices"]["conversion_rates"][$datename]["USD"] = 1;
+ foreach ($data_exch as $row) { // Harvest exchange rates for followed fiat currencies
+ if (in_array($row["quote"], array_keys($fiatcurrencies)))
+ $JSON["lastPrices"]["conversion_rates"][$datename][$row["quote"]] = (float)$row["rate"];
+ }
+ foreach (array_keys($fiatcurrencies) as $f) { // Check if some followed fiat are missing
+ if (!isset($JSON["lastPrices"]["conversion_rates"][$datename][$f])) {
+ $JSON["lastPrices"]["conversion_rates"][$datename]["status"][] = "Warning: missing rate for " . $f;
+ }
}
- $JSON["lastPrices"]["conversion_rates"][$f] = $data_exch["conversion_rates"][$f] ?? 1.0;
+ $JSON["lastPrices"]["conversion_rates"][$datename]["status"][] = "Conversion rates refreshed";
}
- $JSON["lastPrices"]["conversion_rates"]["status"] = "Conversion rates refreshed";
+ } catch (Exception $e) {
+ $JSON["lastPrices"]["conversion_rates"][$datename]["status"][] = "Exchange update failed: " . $e->getMessage();
}
- } catch (Exception $e) {
- $JSON["lastPrices"]["conversion_rates"]["status"] = "Exchange update failed: " . $e->getMessage();
}
}
// Saving lastPrices.json
if ($needs_price_update || $needs_exchange_update) {
- file_put_contents("cache/lastPrices.json", json_encode($JSON["lastPrices"], JSON_PRETTY_PRINT), LOCK_EX); // maybe we should prevent saving failures
- $JSON["lastPrices"]["status"] = "JSON saved";
+ if (!file_put_contents("cache/lastPrices.json", json_encode($JSON["lastPrices"], JSON_PRETTY_PRINT), LOCK_EX))
+ $JSON["lastPrices"]["status"][] = "failed to save JSON";
+ else
+ $JSON["lastPrices"]["status"][] = "JSON saved";
}
@@ -191,7 +208,7 @@ function dash_rpc(string $method, array $params = []):array|int|bool {
$JSON["rewards"]["yearly"][$type]["DASH"] = round(($JSON["APY"][$now][$type] / 100) * $collateral[$type], 8);
foreach (array_keys($fiatcurrencies) as $fiatcurrency) {
$currentfiat = strtoupper($fiatcurrency);
- $rate = $JSON["lastPrices"]["conversion_rates"][$currentfiat] ?? 1.0;
+ $rate = $JSON["lastPrices"]["conversion_rates"]["now"][$currentfiat] ?? 1.0;
$JSON["rewards"]["yearly"][$type][$currentfiat] = round($JSON["rewards"]["yearly"][$type]["DASH"] * $dashPriceUSD * $rate, 0);
}
@@ -199,7 +216,7 @@ function dash_rpc(string $method, array $params = []):array|int|bool {
$dashPrice365d = $JSON["lastPrices"]["USD"]["365d"];
foreach (array_keys($fiatcurrencies) as $fiatcurrency) {
$currentfiat = strtoupper($fiatcurrency);
- $rate = $JSON["lastPrices"]["conversion_rates"][$currentfiat] ?? 1.0;
+ $rate = $JSON["lastPrices"]["conversion_rates"]["now"][$currentfiat] ?? 1.0;
$historiqueAPY = json_decode(file_get_contents("cache/APYhistory.json"), true);
$rewardspast365d = calculateInterestAndAPY($historiqueAPY, ($now - (365 * 24 * 60 * 60)), $now, $type, $collateral[$type]);
diff --git a/index.php b/index.php
index 34c919f..318f5b5 100644
--- a/index.php
+++ b/index.php
@@ -323,7 +323,7 @@ function boldify(string $sometext, string $font):string { // fix bold problems i
ℹ️