From 7fbfe5d9fd95dbd8722ca9c33e2958214ff50fb0 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 22 Mar 2025 12:20:45 +0100 Subject: [PATCH] use property instead of flying data around --- src/front/pages/offers.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/front/pages/offers.js b/src/front/pages/offers.js index bd6c0fe..eaf3169 100644 --- a/src/front/pages/offers.js +++ b/src/front/pages/offers.js @@ -36,6 +36,8 @@ class AmountInput { this.element = null; this.parentElement = parentElement; this.id = id; + + this.eurInput = null; } render() { @@ -46,12 +48,12 @@ class AmountInput { eurAmount.id = 'eur-amount'; eurAmount.className = 'money-amount-input-area'; - const eurInput = document.createElement('input'); - eurInput.id = 'input-eur-amount'; - eurInput.type = 'text'; - eurInput.className = 'money-input input-money-amount'; - eurInput.value = '100'; - eurInput.required = true; + this.eurInput = document.createElement('input'); + this.eurInput.id = 'input-eur-amount'; + this.eurInput.type = 'text'; + this.eurInput.className = 'money-input input-money-amount'; + this.eurInput.value = '100'; + this.eurInput.required = true; const eurSymbol = document.createElement('div'); eurSymbol.id = 'eur-symbol'; @@ -63,7 +65,7 @@ class AmountInput { eurCharacter.textContent = '€'; eurSymbol.appendChild(eurCharacter); - eurAmount.appendChild(eurInput); + eurAmount.appendChild(this.eurInput); eurAmount.appendChild(eurSymbol); const btcAmount = document.createElement('div'); @@ -92,23 +94,23 @@ class AmountInput { amountArea.appendChild(eurAmount); amountArea.appendChild(btcAmount); - eurInput.addEventListener('blur', () => { - validateAndFormatEurAmountInput(eurInput); - this.updateBtcInput(eurInput, btcInput); + this.eurInput.addEventListener('blur', () => { + validateAndFormatEurAmountInput(this.eurInput); + this.updateBtcInput(btcInput); }); - eurInput.addEventListener('input', () => { - eurInput.value = eurInput.value.replace(/[^0-9]/g, ''); - this.updateBtcInput(eurInput, btcInput); + this.eurInput.addEventListener('input', () => { + this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, ''); + this.updateBtcInput(btcInput); }); this.element = amountArea; this.parentElement.appendChild(this.element); } - updateBtcInput(eurInput, btcAmountInput) { + updateBtcInput(btcAmountInput) { const eurToSatRate = 1021; - const cleanEurAmount = readIntFromEurAmountInput(eurInput); + const cleanEurAmount = readIntFromEurAmountInput(this.eurInput); const satsAmount = cleanEurAmount * eurToSatRate; const formattedSatsAmount = formatNumberWithSpaces(satsAmount);