Cubex

document.addEventListener("DOMContentLoaded", () => { class CurrencyConverter { constructor() { this.exchangeRate = 1470.67; this.usdAmount = 1; this.usdtAmount = 0.9996109; this.ngnAmount = 1437.0; this.initializeElements(); this.bindEvents(); this.checkUrlParameters(); this.updateDisplay(); } initializeElements() { this.usdInput = document.querySelector(".amount-input"); this.usdtDisplay = document.querySelector(".crypto-field .amount"); this.ngnDisplay = document.querySelector(".receive-field .amount"); this.rateDisplay = document.querySelector(".rate-display span"); this.swapButton = document.querySelector(".swap-button"); this.ctaButton = document.querySelector(".cta-button"); } getUrlParameter(name) { const urlParams = new URLSearchParams(window.location.search); return urlParams.get(name); } checkUrlParameters() { const amountParam = this.getUrlParameter("amount"); if (amountParam) { const amount = parseFloat(amountParam); if (!isNaN(amount) && amount > 0) { this.usdAmount = amount; this.usdInput.value = amount; this.calculateConversion(); } } } bindEvents() { this.usdInput.addEventListener("input", (e) => { this.usdAmount = parseFloat(e.target.value) || 0; this.calculateConversion(); }); this.swapButton.addEventListener("click", () => { this.swapCurrencies(); }); this.ctaButton.addEventListener("click", () => { this.handleSellUSDT(); }); document.querySelectorAll(".currency-selector").forEach((selector) => { selector.addEventListener("click", (e) => { this.handleCurrencySelectorClick(e); }); }); } calculateConversion() { this.usdtAmount = this.usdAmount * 0.9996109; this.ngnAmount = this.usdAmount * this.exchangeRate; this.updateDisplay(); } updateDisplay() { this.usdtDisplay.textContent = this.usdtAmount.toFixed(7); this.ngnDisplay.textContent = `N${this.ngnAmount.toLocaleString("en-NG", { minimumFractionDigits: 2, maximumFractionDigits: 2, })}`; this.rateDisplay.textContent = `1 USDT = NGN ${this.exchangeRate.toLocaleString("en-NG")}/$`; } swapCurrencies() { this.swapButton.style.transform = "rotate(180deg)"; setTimeout(() => { this.swapButton.style.transform = "rotate(0deg)"; }, 300); this.calculateConversion(); } handleSellUSDT() { if (this.usdAmount <= 0) { alert("Please enter a valid USD amount"); return; } const confirmMessage = `Sell ${this.usdtAmount.toFixed(7)} USDT for N${this.ngnAmount.toLocaleString("en-NG")}?`; if (confirm(confirmMessage)) { alert( "Transaction initiated! You will receive N" + this.ngnAmount.toLocaleString("en-NG") + " in your account." ); this.usdAmount = 1; this.usdInput.value = 1; this.calculateConversion(); } } handleCurrencySelectorClick(e) { e.currentTarget.style.backgroundColor = "#f3f4f6"; setTimeout(() => { e.currentTarget.style.backgroundColor = ""; }, 200); } } new CurrencyConverter(); // Hover effects and button animations document.querySelectorAll(".input-field").forEach((field) => { field.addEventListener("mouseenter", () => { field.style.boxShadow = "0 0 0 3px rgba(120, 40, 137, 0.1)"; }); field.addEventListener("mouseleave", () => { field.style.boxShadow = ""; }); }); document.querySelectorAll("button").forEach((button) => { button.addEventListener("click", () => { button.style.transform = "scale(0.98)"; setTimeout(() => (button.style.transform = ""), 150); }); }); });