everything inside class
This commit is contained in:
parent
36cbfd2712
commit
fa8569f0c5
1 changed files with 29 additions and 29 deletions
|
|
@ -4,33 +4,6 @@ const BuyOrSellButtonGroup = require('../components/BuyOrSellButtonGroup');
|
|||
const PremiumSelector = require('../components/PremiumSelector');
|
||||
const PriceDisplay = require('../components/PriceDisplay');
|
||||
|
||||
function readIntFromEurAmountInput(eurAmountInput) {
|
||||
const eurAmountFieldValue = eurAmountInput.value;
|
||||
const regularExpression = /([\d\s]+)/;
|
||||
const matchResult = eurAmountFieldValue.match(regularExpression);
|
||||
|
||||
if (!matchResult) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const numberString = matchResult[1];
|
||||
const cleanInputNumber = parseInt(numberString.replace(/\s/gi, ''));
|
||||
|
||||
return cleanInputNumber;
|
||||
}
|
||||
|
||||
function validateAndFormatEurAmountInput(eurAmountInput) {
|
||||
const cleanInputNumber = readIntFromEurAmountInput(eurAmountInput);
|
||||
eurAmountInput.classList.remove('input-is-valid', 'input-is-invalid');
|
||||
if (cleanInputNumber) {
|
||||
eurAmountInput.value = formatNumberWithSpaces(cleanInputNumber);
|
||||
eurAmountInput.classList.add('input-is-valid');
|
||||
return;
|
||||
}
|
||||
|
||||
eurAmountInput.classList.add('input-is-invalid');
|
||||
}
|
||||
|
||||
class AmountInput {
|
||||
constructor({ parentElement, id }) {
|
||||
this.element = null;
|
||||
|
|
@ -96,7 +69,7 @@ class AmountInput {
|
|||
amountArea.appendChild(btcAmount);
|
||||
|
||||
this.eurInput.addEventListener('blur', () => {
|
||||
validateAndFormatEurAmountInput(this.eurInput);
|
||||
this.validateAndFormatEurAmountInput(this.eurInput);
|
||||
this.updateBtcInput();
|
||||
});
|
||||
|
||||
|
|
@ -111,9 +84,36 @@ class AmountInput {
|
|||
this.parentElement.appendChild(this.element);
|
||||
}
|
||||
|
||||
get intEurAmount() {
|
||||
const eurAmountFieldValue = this.eurInput.value;
|
||||
const regularExpression = /([\d\s]+)/;
|
||||
const matchResult = eurAmountFieldValue.match(regularExpression);
|
||||
|
||||
if (!matchResult) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const numberString = matchResult[1];
|
||||
const cleanInputNumber = parseInt(numberString.replace(/\s/gi, ''));
|
||||
|
||||
return cleanInputNumber;
|
||||
}
|
||||
|
||||
validateAndFormatEurAmountInput(eurAmountInput) {
|
||||
const cleanInputNumber = this.intEurAmount;
|
||||
eurAmountInput.classList.remove('input-is-valid', 'input-is-invalid');
|
||||
if (cleanInputNumber) {
|
||||
eurAmountInput.value = formatNumberWithSpaces(cleanInputNumber);
|
||||
eurAmountInput.classList.add('input-is-valid');
|
||||
return;
|
||||
}
|
||||
|
||||
eurAmountInput.classList.add('input-is-invalid');
|
||||
}
|
||||
|
||||
updateBtcInput() {
|
||||
const eurToSatRate = 1021;
|
||||
const cleanEurAmount = readIntFromEurAmountInput(this.eurInput);
|
||||
const cleanEurAmount = this.intEurAmount;
|
||||
|
||||
const satsAmount = cleanEurAmount * eurToSatRate;
|
||||
const formattedSatsAmount = formatNumberWithSpaces(satsAmount);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue