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() {