From a534196095ca40e9b7b8b6cd5f3f0f8e05a576aa Mon Sep 17 00:00:00 2001 From: recy21 Date: Mon, 4 Dec 2023 21:10:00 +0100 Subject: [PATCH 1/4] (NOBIDS) Fix mainCurrencyPrices undefined error --- services/services.go | 1 + static/js/banner.js | 20 +++++++++++--------- types/templates.go | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/services/services.go b/services/services.go index 13505c2cbe..fee03b22b4 100644 --- a/services/services.go +++ b/services/services.go @@ -1134,6 +1134,7 @@ func LatestSlotVizMetrics() []*types.SlotVizEpochs { // LatestState returns statistics about the current eth2 state func LatestState() *types.LatestState { data := &types.LatestState{} + data.ChainID = utils.Config.Chain.Id data.CurrentEpoch = LatestEpoch() data.CurrentSlot = LatestSlot() data.CurrentFinalizedEpoch = LatestFinalizedEpoch() diff --git a/static/js/banner.js b/static/js/banner.js index 514b4f7a89..f484670b95 100644 --- a/static/js/banner.js +++ b/static/js/banner.js @@ -47,15 +47,17 @@ function updateBanner() { slotHandle.setAttribute("href", "/slot/" + data.currentSlot) } - var ethPriceHandle = document.getElementById("banner-eth-price-data") - - try { - let userCurrency = getCookie("currency") - if (userCurrency == data.rates.mainCurrency) userCurrency = data.rates.tickerCurrency - var price = data.rates.mainCurrencyPrices[userCurrency] - ethPriceHandle.innerHTML = `${price.symbol} ${price.truncPrice}${addCommas(price.roundPrice)}` - } catch (err) { - console.error("failed updating banner-price:", err) + if (data && data.chainID === 1 ) { + var ethPriceHandle = document.getElementById("banner-eth-price-data") + try { + let userCurrency = getCookie("currency") + if (!userCurrency) userCurrency = data.rates.tickerCurrency + else if (userCurrency == data.rates.mainCurrency) userCurrency = data.rates.tickerCurrency + var price = data.rates.mainCurrencyTickerPrices[userCurrency] + ethPriceHandle.innerHTML = `${price.symbol} ${price.truncPrice}${addCommas(price.roundPrice)}` + } catch (err) { + console.error("failed updating banner-price:", err) + } } var finDelayDataHandle = document.getElementById("banner-fin-data") diff --git a/types/templates.go b/types/templates.go index 9781b6ea74..aa5bd59974 100644 --- a/types/templates.go +++ b/types/templates.go @@ -126,6 +126,7 @@ type Meta struct { // LatestState is a struct to hold data for the banner type LatestState struct { + ChainID uint64 `json:"chainID"` LastProposedSlot uint64 `json:"lastProposedSlot"` CurrentSlot uint64 `json:"currentSlot"` CurrentEpoch uint64 `json:"currentEpoch"` From 679b4280e7ab4125a2cc0b4a6bca3a35b8ee8a79 Mon Sep 17 00:00:00 2001 From: recy21 Date: Mon, 4 Dec 2023 22:38:12 +0100 Subject: [PATCH 2/4] (NOBIDS) Style fix --- static/js/banner.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/js/banner.js b/static/js/banner.js index f484670b95..cded0061db 100644 --- a/static/js/banner.js +++ b/static/js/banner.js @@ -47,7 +47,7 @@ function updateBanner() { slotHandle.setAttribute("href", "/slot/" + data.currentSlot) } - if (data && data.chainID === 1 ) { + if (data && data.chainID === 1) { var ethPriceHandle = document.getElementById("banner-eth-price-data") try { let userCurrency = getCookie("currency") From e7385c0a241ac5076ce2b454741222ef521f2c73 Mon Sep 17 00:00:00 2001 From: recy21 Date: Tue, 5 Dec 2023 15:55:47 +0100 Subject: [PATCH 3/4] (NOBIDS) Make the "mainnet" check easier --- services/services.go | 1 - static/js/banner.js | 4 ++-- types/templates.go | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/services/services.go b/services/services.go index fee03b22b4..13505c2cbe 100644 --- a/services/services.go +++ b/services/services.go @@ -1134,7 +1134,6 @@ func LatestSlotVizMetrics() []*types.SlotVizEpochs { // LatestState returns statistics about the current eth2 state func LatestState() *types.LatestState { data := &types.LatestState{} - data.ChainID = utils.Config.Chain.Id data.CurrentEpoch = LatestEpoch() data.CurrentSlot = LatestSlot() data.CurrentFinalizedEpoch = LatestFinalizedEpoch() diff --git a/static/js/banner.js b/static/js/banner.js index cded0061db..dfe6015903 100644 --- a/static/js/banner.js +++ b/static/js/banner.js @@ -47,8 +47,8 @@ function updateBanner() { slotHandle.setAttribute("href", "/slot/" + data.currentSlot) } - if (data && data.chainID === 1) { - var ethPriceHandle = document.getElementById("banner-eth-price-data") + var ethPriceHandle = document.getElementById("banner-eth-price-data") + if (ethPriceHandle) { try { let userCurrency = getCookie("currency") if (!userCurrency) userCurrency = data.rates.tickerCurrency diff --git a/types/templates.go b/types/templates.go index aa5bd59974..9781b6ea74 100644 --- a/types/templates.go +++ b/types/templates.go @@ -126,7 +126,6 @@ type Meta struct { // LatestState is a struct to hold data for the banner type LatestState struct { - ChainID uint64 `json:"chainID"` LastProposedSlot uint64 `json:"lastProposedSlot"` CurrentSlot uint64 `json:"currentSlot"` CurrentEpoch uint64 `json:"currentEpoch"` From 547b61d5253f8a20fd201bfb92c4762d6d080f29 Mon Sep 17 00:00:00 2001 From: recy21 <98810395+recy21@users.noreply.github.com> Date: Tue, 5 Dec 2023 15:58:13 +0100 Subject: [PATCH 4/4] Update static/js/banner.js Co-authored-by: Stefan Benker <114066135+D13ce@users.noreply.github.com> --- static/js/banner.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/static/js/banner.js b/static/js/banner.js index dfe6015903..ba06b7ebb0 100644 --- a/static/js/banner.js +++ b/static/js/banner.js @@ -51,8 +51,7 @@ function updateBanner() { if (ethPriceHandle) { try { let userCurrency = getCookie("currency") - if (!userCurrency) userCurrency = data.rates.tickerCurrency - else if (userCurrency == data.rates.mainCurrency) userCurrency = data.rates.tickerCurrency + if (!userCurrency || userCurrency == data.rates.mainCurrency) userCurrency = data.rates.tickerCurrency var price = data.rates.mainCurrencyTickerPrices[userCurrency] ethPriceHandle.innerHTML = `${price.symbol} ${price.truncPrice}${addCommas(price.roundPrice)}` } catch (err) {