From 36cbfd27123d1dc67a90934623788f9f9086c295 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 22 Mar 2025 12:34:36 +0100 Subject: [PATCH] make btcinput property --- src/front/pages/offers.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/front/pages/offers.js b/src/front/pages/offers.js index eaf3169..580b263 100644 --- a/src/front/pages/offers.js +++ b/src/front/pages/offers.js @@ -38,6 +38,7 @@ class AmountInput { this.id = id; this.eurInput = null; + this.btcInput = null; } render() { @@ -72,11 +73,11 @@ class AmountInput { btcAmount.id = 'btc-amount'; btcAmount.className = 'money-amount-input-area'; - const btcInput = document.createElement('input'); - btcInput.id = 'input-btc-amount'; - btcInput.type = 'text'; - btcInput.className = 'money-input input-money-amount'; - btcInput.disabled = true; + this.btcInput = document.createElement('input'); + this.btcInput.id = 'input-btc-amount'; + this.btcInput.type = 'text'; + this.btcInput.className = 'money-input input-money-amount'; + this.btcInput.disabled = true; const satsSymbol = document.createElement('div'); satsSymbol.id = 'sats-symbol'; @@ -88,7 +89,7 @@ class AmountInput { satsCharacter.textContent = 'SAT'; satsSymbol.appendChild(satsCharacter); - btcAmount.appendChild(btcInput); + btcAmount.appendChild(this.btcInput); btcAmount.appendChild(satsSymbol); amountArea.appendChild(eurAmount); @@ -96,25 +97,27 @@ class AmountInput { this.eurInput.addEventListener('blur', () => { validateAndFormatEurAmountInput(this.eurInput); - this.updateBtcInput(btcInput); + this.updateBtcInput(); }); this.eurInput.addEventListener('input', () => { this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, ''); - this.updateBtcInput(btcInput); + this.updateBtcInput(); }); + this.updateBtcInput(); + this.element = amountArea; this.parentElement.appendChild(this.element); } - updateBtcInput(btcAmountInput) { + updateBtcInput() { const eurToSatRate = 1021; const cleanEurAmount = readIntFromEurAmountInput(this.eurInput); const satsAmount = cleanEurAmount * eurToSatRate; const formattedSatsAmount = formatNumberWithSpaces(satsAmount); - btcAmountInput.value = formattedSatsAmount; + this.btcInput.value = formattedSatsAmount; } }