make btcinput property
This commit is contained in:
parent
7fbfe5d9fd
commit
36cbfd2712
1 changed files with 13 additions and 10 deletions
|
|
@ -38,6 +38,7 @@ class AmountInput {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
||||||
this.eurInput = null;
|
this.eurInput = null;
|
||||||
|
this.btcInput = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|
@ -72,11 +73,11 @@ class AmountInput {
|
||||||
btcAmount.id = 'btc-amount';
|
btcAmount.id = 'btc-amount';
|
||||||
btcAmount.className = 'money-amount-input-area';
|
btcAmount.className = 'money-amount-input-area';
|
||||||
|
|
||||||
const btcInput = document.createElement('input');
|
this.btcInput = document.createElement('input');
|
||||||
btcInput.id = 'input-btc-amount';
|
this.btcInput.id = 'input-btc-amount';
|
||||||
btcInput.type = 'text';
|
this.btcInput.type = 'text';
|
||||||
btcInput.className = 'money-input input-money-amount';
|
this.btcInput.className = 'money-input input-money-amount';
|
||||||
btcInput.disabled = true;
|
this.btcInput.disabled = true;
|
||||||
|
|
||||||
const satsSymbol = document.createElement('div');
|
const satsSymbol = document.createElement('div');
|
||||||
satsSymbol.id = 'sats-symbol';
|
satsSymbol.id = 'sats-symbol';
|
||||||
|
|
@ -88,7 +89,7 @@ class AmountInput {
|
||||||
satsCharacter.textContent = 'SAT';
|
satsCharacter.textContent = 'SAT';
|
||||||
|
|
||||||
satsSymbol.appendChild(satsCharacter);
|
satsSymbol.appendChild(satsCharacter);
|
||||||
btcAmount.appendChild(btcInput);
|
btcAmount.appendChild(this.btcInput);
|
||||||
btcAmount.appendChild(satsSymbol);
|
btcAmount.appendChild(satsSymbol);
|
||||||
|
|
||||||
amountArea.appendChild(eurAmount);
|
amountArea.appendChild(eurAmount);
|
||||||
|
|
@ -96,25 +97,27 @@ class AmountInput {
|
||||||
|
|
||||||
this.eurInput.addEventListener('blur', () => {
|
this.eurInput.addEventListener('blur', () => {
|
||||||
validateAndFormatEurAmountInput(this.eurInput);
|
validateAndFormatEurAmountInput(this.eurInput);
|
||||||
this.updateBtcInput(btcInput);
|
this.updateBtcInput();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.eurInput.addEventListener('input', () => {
|
this.eurInput.addEventListener('input', () => {
|
||||||
this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, '');
|
this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, '');
|
||||||
this.updateBtcInput(btcInput);
|
this.updateBtcInput();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.updateBtcInput();
|
||||||
|
|
||||||
this.element = amountArea;
|
this.element = amountArea;
|
||||||
this.parentElement.appendChild(this.element);
|
this.parentElement.appendChild(this.element);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateBtcInput(btcAmountInput) {
|
updateBtcInput() {
|
||||||
const eurToSatRate = 1021;
|
const eurToSatRate = 1021;
|
||||||
const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
|
const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
|
||||||
|
|
||||||
const satsAmount = cleanEurAmount * eurToSatRate;
|
const satsAmount = cleanEurAmount * eurToSatRate;
|
||||||
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
|
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
|
||||||
btcAmountInput.value = formattedSatsAmount;
|
this.btcInput.value = formattedSatsAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue