Changed around line 1
+ document.addEventListener('DOMContentLoaded', () => {
+ const amount = document.getElementById('amount');
+ const fromSelect = document.getElementById('from');
+ const toSelect = document.getElementById('to');
+ const result = document.getElementById('result');
+ const resultCurrency = document.getElementById('result-currency');
+ const swapBtn = document.getElementById('swap-btn');
+ const rateFrom = document.getElementById('rate-from');
+ const rateTo = document.getElementById('rate-to');
+ const rateValue = document.getElementById('rate-value');
+
+ // Mock exchange rates (in real app, these would come from an API)
+ const rates = {
+ BTC: 30000,
+ ETH: 2000,
+ USDT: 1,
+ BNB: 300,
+ USDC: 1
+ };
+
+ function calculateRate(from, to, amount) {
+ const fromRate = rates[from];
+ const toRate = rates[to];
+ return (amount * fromRate / toRate).toFixed(8);
+ }
+
+ function updateResult() {
+ const fromCurrency = fromSelect.value;
+ const toCurrency = toSelect.value;
+ const inputAmount = parseFloat(amount.value) || 0;
+
+ const convertedAmount = calculateRate(fromCurrency, toCurrency, inputAmount);
+ result.textContent = convertedAmount;
+ resultCurrency.textContent = toCurrency;
+
+ // Update rate info
+ rateFrom.textContent = fromCurrency;
+ rateTo.textContent = toCurrency;
+ rateValue.textContent = calculateRate(fromCurrency, toCurrency, 1);
+ }
+
+ function swapCurrencies() {
+ const temp = fromSelect.value;
+ fromSelect.value = toSelect.value;
+ toSelect.value = temp;
+ updateResult();
+ }
+
+ // Event listeners
+ amount.addEventListener('input', updateResult);
+ fromSelect.addEventListener('change', updateResult);
+ toSelect.addEventListener('change', updateResult);
+ swapBtn.addEventListener('click', swapCurrencies);
+
+ // Initialize
+ updateResult();
+ });