From aa9cdf8a8a8730b95861cf167baca1b68e92cf53 Mon Sep 17 00:00:00 2001 From: Kumi Date: Fri, 30 Aug 2024 09:38:34 +0200 Subject: [PATCH] feat(ui): add custom behavior to fiat buttons Enhanced the fiat currency buttons to include event listeners. When a button is clicked, it now updates the select box value and triggers the appropriate conversion function (XMR to Fiat or Fiat to XMR). The browser's address bar is also updated to reflect the selected currency. This improves the user experience by making currency selection more intuitive and dynamic. --- index.php | 2 +- src/js/main.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/index.php b/index.php index 09ea316..3f52fc9 100644 --- a/index.php +++ b/index.php @@ -166,7 +166,7 @@ foreach (array_reverse($preferred_currencies) as $currency) { echo ""; foreach ($chunk as $currency) { $currencyName = isset(${"l_" . strtolower($currency)}) ? ${"l_" . strtolower($currency)} : $currency; - echo "{$currency}"; + echo "{$currency}"; } echo ""; echo ""; diff --git a/src/js/main.js b/src/js/main.js index 29a33db..7390237 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -24,6 +24,21 @@ document.addEventListener('DOMContentLoaded', function () { const selectBox = document.getElementById('selectBox'); const convertXMRToFiatBtn = document.getElementById('convertXMRToFiat'); const convertFiatToXMRBtn = document.getElementById('convertFiatToXMR'); + const fiatButtons = document.querySelectorAll('.fiat-btn'); + + // Add event listeners for the currency buttons + fiatButtons.forEach(button => { + button.addEventListener('click', (e) => { + e.preventDefault(); + selectBox.value = button.textContent; + if (lastModifiedField === 'xmr') { + xmrConvert(); + } else { + fiatConvert(); + } + history.pushState(null, '', `?in=${button.textContent}`); + }); + }); // Add event listeners for the copy buttons copyXMRBtn.addEventListener('click', copyToClipBoardXMR);