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.eurInput = null;
|
||||
this.btcInput = null;
|
||||
}
|
||||
|
||||
render() {
|
||||
|
|
@ -72,11 +73,11 @@ class AmountInput {
|
|||
btcAmount.id = 'btc-amount';
|
||||
btcAmount.className = 'money-amount-input-area';
|
||||
|
||||
const btcInput = document.createElement('input');
|
||||
btcInput.id = 'input-btc-amount';
|
||||
btcInput.type = 'text';
|
||||
btcInput.className = 'money-input input-money-amount';
|
||||
btcInput.disabled = true;
|
||||
this.btcInput = document.createElement('input');
|
||||
this.btcInput.id = 'input-btc-amount';
|
||||
this.btcInput.type = 'text';
|
||||
this.btcInput.className = 'money-input input-money-amount';
|
||||
this.btcInput.disabled = true;
|
||||
|
||||
const satsSymbol = document.createElement('div');
|
||||
satsSymbol.id = 'sats-symbol';
|
||||
|
|
@ -88,7 +89,7 @@ class AmountInput {
|
|||
satsCharacter.textContent = 'SAT';
|
||||
|
||||
satsSymbol.appendChild(satsCharacter);
|
||||
btcAmount.appendChild(btcInput);
|
||||
btcAmount.appendChild(this.btcInput);
|
||||
btcAmount.appendChild(satsSymbol);
|
||||
|
||||
amountArea.appendChild(eurAmount);
|
||||
|
|
@ -96,25 +97,27 @@ class AmountInput {
|
|||
|
||||
this.eurInput.addEventListener('blur', () => {
|
||||
validateAndFormatEurAmountInput(this.eurInput);
|
||||
this.updateBtcInput(btcInput);
|
||||
this.updateBtcInput();
|
||||
});
|
||||
|
||||
this.eurInput.addEventListener('input', () => {
|
||||
this.eurInput.value = this.eurInput.value.replace(/[^0-9]/g, '');
|
||||
this.updateBtcInput(btcInput);
|
||||
this.updateBtcInput();
|
||||
});
|
||||
|
||||
this.updateBtcInput();
|
||||
|
||||
this.element = amountArea;
|
||||
this.parentElement.appendChild(this.element);
|
||||
}
|
||||
|
||||
updateBtcInput(btcAmountInput) {
|
||||
updateBtcInput() {
|
||||
const eurToSatRate = 1021;
|
||||
const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
|
||||
|
||||
const satsAmount = cleanEurAmount * eurToSatRate;
|
||||
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
|
||||
btcAmountInput.value = formattedSatsAmount;
|
||||
this.btcInput.value = formattedSatsAmount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue