This commit is contained in:
counterweight 2025-03-22 12:17:48 +01:00
parent 37b9722643
commit 4bd7dfc7ff
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -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);
}