use property instead of flying data around

This commit is contained in:
counterweight 2025-03-22 12:20:45 +01:00
parent 5d21258634
commit 7fbfe5d9fd
Signed by: counterweight
GPG key ID: 883EDBAA726BD96C

View file

@ -36,6 +36,8 @@ class AmountInput {
this.element = null; this.element = null;
this.parentElement = parentElement; this.parentElement = parentElement;
this.id = id; this.id = id;
this.eurInput = null;
} }
render() { render() {
@ -46,12 +48,12 @@ class AmountInput {
eurAmount.id = 'eur-amount'; eurAmount.id = 'eur-amount';
eurAmount.className = 'money-amount-input-area'; eurAmount.className = 'money-amount-input-area';
const eurInput = document.createElement('input'); this.eurInput = document.createElement('input');
eurInput.id = 'input-eur-amount'; this.eurInput.id = 'input-eur-amount';
eurInput.type = 'text'; this.eurInput.type = 'text';
eurInput.className = 'money-input input-money-amount'; this.eurInput.className = 'money-input input-money-amount';
eurInput.value = '100'; this.eurInput.value = '100';
eurInput.required = true; this.eurInput.required = true;
const eurSymbol = document.createElement('div'); const eurSymbol = document.createElement('div');
eurSymbol.id = 'eur-symbol'; eurSymbol.id = 'eur-symbol';
@ -63,7 +65,7 @@ class AmountInput {
eurCharacter.textContent = '€'; eurCharacter.textContent = '€';
eurSymbol.appendChild(eurCharacter); eurSymbol.appendChild(eurCharacter);
eurAmount.appendChild(eurInput); eurAmount.appendChild(this.eurInput);
eurAmount.appendChild(eurSymbol); eurAmount.appendChild(eurSymbol);
const btcAmount = document.createElement('div'); const btcAmount = document.createElement('div');
@ -92,23 +94,23 @@ class AmountInput {
amountArea.appendChild(eurAmount); amountArea.appendChild(eurAmount);
amountArea.appendChild(btcAmount); amountArea.appendChild(btcAmount);
eurInput.addEventListener('blur', () => { this.eurInput.addEventListener('blur', () => {
validateAndFormatEurAmountInput(eurInput); validateAndFormatEurAmountInput(this.eurInput);
this.updateBtcInput(eurInput, btcInput); this.updateBtcInput(btcInput);
}); });
eurInput.addEventListener('input', () => { this.eurInput.addEventListener('input', () => {
eurInput.value = eurInput.value.replace(/[^0-9]/g, ''); this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, '');
this.updateBtcInput(eurInput, btcInput); this.updateBtcInput(btcInput);
}); });
this.element = amountArea; this.element = amountArea;
this.parentElement.appendChild(this.element); this.parentElement.appendChild(this.element);
} }
updateBtcInput(eurInput, btcAmountInput) { updateBtcInput(btcAmountInput) {
const eurToSatRate = 1021; const eurToSatRate = 1021;
const cleanEurAmount = readIntFromEurAmountInput(eurInput); const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
const satsAmount = cleanEurAmount * eurToSatRate; const satsAmount = cleanEurAmount * eurToSatRate;
const formattedSatsAmount = formatNumberWithSpaces(satsAmount); const formattedSatsAmount = formatNumberWithSpaces(satsAmount);