From 5d212586342fe81c190c28bb99367f1cf79d2b50 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 22 Mar 2025 12:19:14 +0100 Subject: [PATCH] function into method --- src/front/pages/offers.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/front/pages/offers.js b/src/front/pages/offers.js index 2c27ad3..bd6c0fe 100644 --- a/src/front/pages/offers.js +++ b/src/front/pages/offers.js @@ -31,15 +31,6 @@ function validateAndFormatEurAmountInput(eurAmountInput) { eurAmountInput.classList.add('input-is-invalid'); } -function updateBtcInput(eurInput, btcAmountInput) { - const eurToSatRate = 1021; - const cleanEurAmount = readIntFromEurAmountInput(eurInput); - - const satsAmount = cleanEurAmount * eurToSatRate; - const formattedSatsAmount = formatNumberWithSpaces(satsAmount); - btcAmountInput.value = formattedSatsAmount; -} - class AmountInput { constructor({ parentElement, id }) { this.element = null; @@ -103,17 +94,26 @@ class AmountInput { eurInput.addEventListener('blur', () => { validateAndFormatEurAmountInput(eurInput); - updateBtcInput(eurInput, btcInput); + this.updateBtcInput(eurInput, btcInput); }); eurInput.addEventListener('input', () => { eurInput.value = eurInput.value.replace(/[^0-9]/g, ''); - updateBtcInput(eurInput, btcInput); + this.updateBtcInput(eurInput, btcInput); }); this.element = amountArea; this.parentElement.appendChild(this.element); } + + updateBtcInput(eurInput, btcAmountInput) { + const eurToSatRate = 1021; + const cleanEurAmount = readIntFromEurAmountInput(eurInput); + + const satsAmount = cleanEurAmount * eurToSatRate; + const formattedSatsAmount = formatNumberWithSpaces(satsAmount); + btcAmountInput.value = formattedSatsAmount; + } } function offersPage() {