function into method

This commit is contained in:
counterweight 2025-03-22 12:19:14 +01:00
parent 4bd7dfc7ff
commit 5d21258634
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -31,15 +31,6 @@ function validateAndFormatEurAmountInput(eurAmountInput) {
eurAmountInput.classList.add('input-is-invalid'); 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 { class AmountInput {
constructor({ parentElement, id }) { constructor({ parentElement, id }) {
this.element = null; this.element = null;
@ -103,17 +94,26 @@ class AmountInput {
eurInput.addEventListener('blur', () => { eurInput.addEventListener('blur', () => {
validateAndFormatEurAmountInput(eurInput); validateAndFormatEurAmountInput(eurInput);
updateBtcInput(eurInput, btcInput); this.updateBtcInput(eurInput, btcInput);
}); });
eurInput.addEventListener('input', () => { eurInput.addEventListener('input', () => {
eurInput.value = eurInput.value.replace(/[^0-9]/g, ''); eurInput.value = eurInput.value.replace(/[^0-9]/g, '');
updateBtcInput(eurInput, btcInput); this.updateBtcInput(eurInput, btcInput);
}); });
this.element = amountArea; this.element = amountArea;
this.parentElement.appendChild(this.element); 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() { function offersPage() {