use property instead of flying data around
This commit is contained in:
parent
5d21258634
commit
7fbfe5d9fd
1 changed files with 17 additions and 15 deletions
|
|
@ -36,6 +36,8 @@ class AmountInput {
|
|||
this.element = null;
|
||||
this.parentElement = parentElement;
|
||||
this.id = id;
|
||||
|
||||
this.eurInput = null;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
@ -46,12 +48,12 @@ class AmountInput {
|
|||
eurAmount.id = 'eur-amount';
|
||||
eurAmount.className = 'money-amount-input-area';
|
||||
|
||||
const eurInput = document.createElement('input');
|
||||
eurInput.id = 'input-eur-amount';
|
||||
eurInput.type = 'text';
|
||||
eurInput.className = 'money-input input-money-amount';
|
||||
eurInput.value = '100';
|
||||
eurInput.required = true;
|
||||
this.eurInput = document.createElement('input');
|
||||
this.eurInput.id = 'input-eur-amount';
|
||||
this.eurInput.type = 'text';
|
||||
this.eurInput.className = 'money-input input-money-amount';
|
||||
this.eurInput.value = '100';
|
||||
this.eurInput.required = true;
|
||||
|
||||
const eurSymbol = document.createElement('div');
|
||||
eurSymbol.id = 'eur-symbol';
|
||||
|
|
@ -63,7 +65,7 @@ class AmountInput {
|
|||
eurCharacter.textContent = '€';
|
||||
|
||||
eurSymbol.appendChild(eurCharacter);
|
||||
eurAmount.appendChild(eurInput);
|
||||
eurAmount.appendChild(this.eurInput);
|
||||
eurAmount.appendChild(eurSymbol);
|
||||
|
||||
const btcAmount = document.createElement('div');
|
||||
|
|
@ -92,23 +94,23 @@ class AmountInput {
|
|||
amountArea.appendChild(eurAmount);
|
||||
amountArea.appendChild(btcAmount);
|
||||
|
||||
eurInput.addEventListener('blur', () => {
|
||||
validateAndFormatEurAmountInput(eurInput);
|
||||
this.updateBtcInput(eurInput, btcInput);
|
||||
this.eurInput.addEventListener('blur', () => {
|
||||
validateAndFormatEurAmountInput(this.eurInput);
|
||||
this.updateBtcInput(btcInput);
|
||||
});
|
||||
|
||||
eurInput.addEventListener('input', () => {
|
||||
eurInput.value = eurInput.value.replace(/[^0-9]/g, '');
|
||||
this.updateBtcInput(eurInput, btcInput);
|
||||
this.eurInput.addEventListener('input', () => {
|
||||
this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, '');
|
||||
this.updateBtcInput(btcInput);
|
||||
});
|
||||
|
||||
this.element = amountArea;
|
||||
this.parentElement.appendChild(this.element);
|
||||
}
|
||||
|
||||
updateBtcInput(eurInput, btcAmountInput) {
|
||||
updateBtcInput(btcAmountInput) {
|
||||
const eurToSatRate = 1021;
|
||||
const cleanEurAmount = readIntFromEurAmountInput(eurInput);
|
||||
const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
|
||||
|
||||
const satsAmount = cleanEurAmount * eurToSatRate;
|
||||
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue