From cca4402126dbd28b0c815e7283ffb21b112b90c1 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Mon, 17 Mar 2025 17:21:43 +0100 Subject: [PATCH] separate price setting behaviour --- src/front/pages/offers.js | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/front/pages/offers.js b/src/front/pages/offers.js index c71d233..bb88c43 100644 --- a/src/front/pages/offers.js +++ b/src/front/pages/offers.js @@ -18,15 +18,6 @@ class PriceDisplay { } render() { - - const marketPrice = this.priceProvidingCallback() - const marketPriceString = formatNumberWithSpaces(marketPrice); - const offerPriceString = formatNumberWithSpaces( - Math.round(marketPrice * ( - 1 + this.premiumProvidingCallback() - )) - ); - const container = document.createElement("div"); container.id = "premium-price-display-area"; @@ -36,7 +27,7 @@ class PriceDisplay { const offerSpan = document.createElement("span"); offerSpan.id = "offer-price"; - offerSpan.textContent = offerPriceString; + this.offerPriceSpan = offerSpan offerParagraph.appendChild(offerSpan); offerParagraph.append("€/BTC"); @@ -47,7 +38,7 @@ class PriceDisplay { const marketSpan = document.createElement("span"); marketSpan.id = "market-price"; - marketSpan.textContent = marketPriceString; + this.marketPriceSpan = marketSpan marketParagraph.appendChild(marketSpan); marketParagraph.append("€/BTC)"); @@ -55,12 +46,25 @@ class PriceDisplay { container.appendChild(offerParagraph); container.appendChild(marketParagraph); + this.updatePrices(); + this.element = container; this.parentElement.appendChild(this.element); } - update() {} + updatePrices() { + const marketPrice = this.priceProvidingCallback() + const marketPriceString = formatNumberWithSpaces(marketPrice); + const offerPriceString = formatNumberWithSpaces( + Math.round(marketPrice * ( + 1 + this.premiumProvidingCallback() + )) + ); + + this.marketPriceSpan.innerText = marketPriceString; + this.offerPriceSpan.innerText = offerPriceString; + } } function offersPage() {