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.
This commit is contained in:
Kumi 2024-08-30 09:38:34 +02:00
parent 0f891ba6ea
commit aa9cdf8a8a
No known key found for this signature in database
GPG Key ID: ECBCC9082395383F
2 changed files with 16 additions and 1 deletions

View File

@ -166,7 +166,7 @@ foreach (array_reverse($preferred_currencies) as $currency) {
echo "<tr>";
foreach ($chunk as $currency) {
$currencyName = isset(${"l_" . strtolower($currency)}) ? ${"l_" . strtolower($currency)} : $currency;
echo "<td><a href=\"/?in={$currency}\" class=\"btn btn-light\" title=\"{$currencyName}\" data-toggle=\"tooltip\" data-bs-html=\"true\" data-placement=\"top\">{$currency}</a></td>";
echo "<td><a href=\"/?in={$currency}\" class=\"btn btn-light fiat-btn\" title=\"{$currencyName}\" data-toggle=\"tooltip\" data-bs-html=\"true\" data-placement=\"top\">{$currency}</a></td>";
}
echo "</tr>";
echo "<tr style=\"display:none;\">";

View File

@ -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);