From 4bd7dfc7ffb52bfca1fc157739f53c3b13a71aa0 Mon Sep 17 00:00:00 2001 From: counterweight Date: Sat, 22 Mar 2025 12:17:48 +0100 Subject: [PATCH] working --- src/front/pages/offers.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/front/pages/offers.js b/src/front/pages/offers.js index d0cec08..2c27ad3 100644 --- a/src/front/pages/offers.js +++ b/src/front/pages/offers.js @@ -4,7 +4,7 @@ const BuyOrSellButtonGroup = require('../components/BuyOrSellButtonGroup'); const PremiumSelector = require('../components/PremiumSelector'); const PriceDisplay = require('../components/PriceDisplay'); -function readIntFromEurAmountInput() { +function readIntFromEurAmountInput(eurAmountInput) { const eurAmountFieldValue = eurAmountInput.value; const regularExpression = /([\d\s]+)/; const matchResult = eurAmountFieldValue.match(regularExpression); @@ -19,8 +19,8 @@ function readIntFromEurAmountInput() { return cleanInputNumber; } -function validateAndFormatEurAmountInput() { - const cleanInputNumber = readIntFromEurAmountInput(); +function validateAndFormatEurAmountInput(eurAmountInput) { + const cleanInputNumber = readIntFromEurAmountInput(eurAmountInput); eurAmountInput.classList.remove('input-is-valid', 'input-is-invalid'); if (cleanInputNumber) { eurAmountInput.value = formatNumberWithSpaces(cleanInputNumber); @@ -31,9 +31,9 @@ function validateAndFormatEurAmountInput() { eurAmountInput.classList.add('input-is-invalid'); } -function updateBtcInput() { +function updateBtcInput(eurInput, btcAmountInput) { const eurToSatRate = 1021; - const cleanEurAmount = readIntFromEurAmountInput(); + const cleanEurAmount = readIntFromEurAmountInput(eurInput); const satsAmount = cleanEurAmount * eurToSatRate; const formattedSatsAmount = formatNumberWithSpaces(satsAmount); @@ -102,13 +102,13 @@ class AmountInput { amountArea.appendChild(btcAmount); eurInput.addEventListener('blur', () => { - validateAndFormatEurAmountInput(); - updateBtcInput(); + validateAndFormatEurAmountInput(eurInput); + updateBtcInput(eurInput, btcInput); }); eurInput.addEventListener('input', () => { - eurAmountInput.value = eurAmountInput.value.replace(/[^0-9]/g, ''); - updateBtcInput(); + eurInput.value = eurInput.value.replace(/[^0-9]/g, ''); + updateBtcInput(eurInput, btcInput); }); this.element = amountArea; @@ -760,8 +760,6 @@ function offersPage() { applyTrustCheckboxConstraints(allMembersCheckbox); }); - updateBtcInput(); - const myOffers = new MyOffers(ownOffersContainer); }