From 182e2bde063537065547639b187f06efa0cb2c7e Mon Sep 17 00:00:00 2001 From: Philemon Ukane Date: Sat, 21 Sep 2024 00:32:45 +0100 Subject: [PATCH] multi: remove /statistics, /stats and redirect /stats to homepage (#2008) Signed-off-by: Philemon Ukane --- cmd/dcrdata/internal/explorer/explorer.go | 6 +- .../internal/explorer/explorerroutes.go | 89 +------ cmd/dcrdata/main.go | 7 +- cmd/dcrdata/public/scss/application.scss | 1 - cmd/dcrdata/public/scss/stats_page.scss | 115 --------- cmd/dcrdata/views/extras.tmpl | 2 +- cmd/dcrdata/views/statistics.tmpl | 224 ------------------ 7 files changed, 7 insertions(+), 437 deletions(-) delete mode 100644 cmd/dcrdata/public/scss/stats_page.scss delete mode 100644 cmd/dcrdata/views/statistics.tmpl diff --git a/cmd/dcrdata/internal/explorer/explorer.go b/cmd/dcrdata/internal/explorer/explorer.go index bfbbaf9e8..660338544 100644 --- a/cmd/dcrdata/internal/explorer/explorer.go +++ b/cmd/dcrdata/internal/explorer/explorer.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2022, The Decred developers +// Copyright (c) 2018-2024, The Decred developers // Copyright (c) 2017, The dcrdata developers // See LICENSE for details. @@ -366,7 +366,7 @@ func New(cfg *ExplorerConfig) *explorerUI { tmpls := []string{"home", "blocks", "mempool", "block", "tx", "address", "rawtx", "status", "parameters", "agenda", "agendas", "charts", - "sidechains", "disapproved", "ticketpool", "visualblocks", "statistics", + "sidechains", "disapproved", "ticketpool", "visualblocks", "windows", "timelisting", "addresstable", "proposals", "proposal", "market", "insight_root", "attackcost", "treasury", "treasurytable", "verify_message"} @@ -671,8 +671,6 @@ func (exp *explorerUI) addRoutes() { exp.Mux.Get("/address/{x}", redirect("address")) exp.Mux.Get("/decodetx", redirect("decodetx")) - - exp.Mux.Get("/stats", redirect("statistics")) } // Simulate ticket purchase and re-investment over a full year for a given diff --git a/cmd/dcrdata/internal/explorer/explorerroutes.go b/cmd/dcrdata/internal/explorer/explorerroutes.go index 2cf68169c..323601806 100644 --- a/cmd/dcrdata/internal/explorer/explorerroutes.go +++ b/cmd/dcrdata/internal/explorer/explorerroutes.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2022, The Decred developers +// Copyright (c) 2018-2024, The Decred developers // Copyright (c) 2017, The dcrdata developers // See LICENSE for details. @@ -2458,93 +2458,6 @@ func (exp *explorerUI) HandleApiRequestsOnSync(w http.ResponseWriter, r *http.Re io.WriteString(w, str) } -// StatsPage is the page handler for the "/stats" path. -func (exp *explorerUI) StatsPage(w http.ResponseWriter, r *http.Request) { - // Get current PoW difficulty. - powDiff, err := exp.dataSource.CurrentDifficulty() - if err != nil { - log.Errorf("Failed to get Difficulty: %v", err) - } - - // Subsidies - dcp0010Height := exp.dataSource.DCP0010ActivationHeight() - dcp0012Height := exp.dataSource.DCP0012ActivationHeight() - ultSubsidy := txhelpers.UltimateSubsidy(exp.ChainParams, dcp0010Height, dcp0012Height) - bestBlockHeight, err := exp.dataSource.GetHeight() - if err != nil { - log.Errorf("GetHeight failed: %v", err) - exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", - ExpStatusError) - return - } - blockSubsidy := exp.dataSource.BlockSubsidy(bestBlockHeight, - exp.ChainParams.TicketsPerBlock) - - // Safely retrieve the inventory pointer, which can be reset in StoreMPData. - inv := exp.MempoolInventory() - - // Prevent modifications to the shared inventory struct (e.g. in the - // MempoolMonitor) while we retrieve the number of votes and tickets. - inv.RLock() - numVotes := inv.NumVotes - numTickets := inv.NumTickets - inv.RUnlock() - - exp.pageData.RLock() - stats := types.StatsInfo{ - TotalSupply: exp.pageData.HomeInfo.CoinSupply, - UltimateSupply: ultSubsidy, - TotalSupplyPercentage: float64(exp.pageData.HomeInfo.CoinSupply) / - float64(ultSubsidy) * 100, - ProjectFunds: exp.pageData.HomeInfo.DevFund, - ProjectAddress: exp.pageData.HomeInfo.DevAddress, - PoWDiff: exp.pageData.HomeInfo.Difficulty, - BlockReward: blockSubsidy.Total, - NextBlockReward: exp.pageData.HomeInfo.NBlockSubsidy.Total, - PoWReward: exp.pageData.HomeInfo.NBlockSubsidy.PoW, - PoSReward: exp.pageData.HomeInfo.NBlockSubsidy.PoS, - ProjectFundReward: exp.pageData.HomeInfo.NBlockSubsidy.Dev, - VotesInMempool: numVotes, - TicketsInMempool: numTickets, - TicketPrice: exp.pageData.HomeInfo.StakeDiff, - NextEstimatedTicketPrice: exp.pageData.HomeInfo.NextExpectedStakeDiff, - TicketPoolSize: exp.pageData.HomeInfo.PoolInfo.Size, - TicketPoolSizePerToTarget: float64(exp.pageData.HomeInfo.PoolInfo.Size) / - float64(exp.ChainParams.TicketPoolSize*exp.ChainParams.TicketsPerBlock) * 100, - TicketPoolValue: exp.pageData.HomeInfo.PoolInfo.Value, - TPVOfTotalSupplyPeecentage: exp.pageData.HomeInfo.PoolInfo.Percentage, - TicketsROI: exp.pageData.HomeInfo.TicketReward, - RewardPeriod: exp.pageData.HomeInfo.RewardPeriod, - ASR: exp.pageData.HomeInfo.ASR, - APR: exp.pageData.HomeInfo.ASR, - IdxBlockInWindow: exp.pageData.HomeInfo.IdxBlockInWindow, - WindowSize: exp.pageData.HomeInfo.Params.WindowSize, - BlockTime: exp.pageData.HomeInfo.Params.BlockTime, - IdxInRewardWindow: exp.pageData.HomeInfo.IdxInRewardWindow, - RewardWindowSize: exp.pageData.HomeInfo.Params.RewardWindowSize, - HashRate: powDiff * math.Pow(2, 32) / - exp.ChainParams.TargetTimePerBlock.Seconds() / math.Pow(10, 15), - } - exp.pageData.RUnlock() - - str, err := exp.templates.exec("statistics", struct { - *CommonPageData - Stats types.StatsInfo - }{ - CommonPageData: exp.commonData(r), - Stats: stats, - }) - - if err != nil { - log.Errorf("Template execute failure: %v", err) - exp.StatusPage(w, defaultErrorCode, defaultErrorMessage, "", ExpStatusError) - return - } - w.Header().Set("Content-Type", "text/html") - w.WriteHeader(http.StatusOK) - io.WriteString(w, str) -} - // MarketPage is the page handler for the "/market" path. func (exp *explorerUI) MarketPage(w http.ResponseWriter, r *http.Request) { str, err := exp.templates.exec("market", struct { diff --git a/cmd/dcrdata/main.go b/cmd/dcrdata/main.go index bfc68f06a..ca925862d 100644 --- a/cmd/dcrdata/main.go +++ b/cmd/dcrdata/main.go @@ -1,4 +1,4 @@ -// Copyright (c) 2018-2022, The Decred developers +// Copyright (c) 2018-2024, The Decred developers // Copyright (c) 2017, Jonathan Chappelow // See LICENSE for details. @@ -779,10 +779,9 @@ func _main(ctx context.Context) error { r.Get("/search", explore.Search) r.Get("/charts", explore.Charts) r.Get("/ticketpool", explore.Ticketpool) - r.Get("/stats", explore.StatsPage) r.Get("/market", explore.MarketPage) - r.Get("/statistics", func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/stats", http.StatusPermanentRedirect) + r.Get("/stats", func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, "/", http.StatusPermanentRedirect) }) // MenuFormParser will typically redirect, but going to the homepage as a // fallback. diff --git a/cmd/dcrdata/public/scss/application.scss b/cmd/dcrdata/public/scss/application.scss index 4dd978d99..cac11d2c6 100644 --- a/cmd/dcrdata/public/scss/application.scss +++ b/cmd/dcrdata/public/scss/application.scss @@ -42,7 +42,6 @@ @import "./table"; @import "./keyboard_navigation"; @import "./connection"; -@import "./stats_page"; @import "./animation"; @import "./voting"; @import "./transaction"; diff --git a/cmd/dcrdata/public/scss/stats_page.scss b/cmd/dcrdata/public/scss/stats_page.scss deleted file mode 100644 index b8393d853..000000000 --- a/cmd/dcrdata/public/scss/stats_page.scss +++ /dev/null @@ -1,115 +0,0 @@ -/* Stats Page */ -.card { - background-color: #fff; - box-shadow: 0 4px 8px 0 #e6eaed; - width: 250px; - height: 220px; - margin: auto; - margin-bottom: 20px; - margin-left: 20px; - float: left; - padding-bottom: 10px; - border-radius: 10px; - transition: all 0.2s ease-in-out; -} - -.card :hover { - overflow: hidden; - white-space: normal; -} - -.card-header { - text-transform: uppercase; - background-color: #e6eaed; - color: #8997a5; - text-align: center; - font-style: bold; - font-size: 16px; -} - -.card-body { - background-color: #fff; - color: #3d5873; - text-align: center; - overflow: hidden; - text-overflow: ellipsis; - white-space: nowrap; -} - -.stat-headers { - color: #3d5873; - text-align: center; - font-size: 30px; -} - -.stat-link { - color: #2970ff; - font-size: 14px; -} - -.stat-data { - font-style: bold; - color: #3d5873; - margin: auto; - font-size: 25px; -} - -.decimal { - margin-left: -2px; - margin-right: 0; -} - -.no-decimal .dot { - display: none; -} - -.no-decimal .decimal { - display: none; -} - -.stat-details { - color: #96a0a9; - font-size: 14px; -} - -.card-body-padding-top { - padding-top: 2.3em; -} - -.block-rewards { - background-color: #a1c6e7; -} - -.proof-of-stake { - background-color: #e7c1a1; -} - -.network-statistics { - background-color: #a1e7d9; -} - -@media screen and (max-width: 1200px) { - .stat-headers { - margin-left: -146px; - } -} - -@media screen and (max-width: 926px) { - .stat-headers { - margin-left: -25px; - } - - #proof-stake-header { - margin-left: 0; - } -} - -@media screen and (max-width: 570px) { - .stat-headers { - margin-left: 0; - } - - #proof-stake-header { - margin-left: 38px; - } -} diff --git a/cmd/dcrdata/views/extras.tmpl b/cmd/dcrdata/views/extras.tmpl index b18893172..de7de93da 100644 --- a/cmd/dcrdata/views/extras.tmpl +++ b/cmd/dcrdata/views/extras.tmpl @@ -67,7 +67,7 @@ - + diff --git a/cmd/dcrdata/views/statistics.tmpl b/cmd/dcrdata/views/statistics.tmpl deleted file mode 100644 index a9027be50..000000000 --- a/cmd/dcrdata/views/statistics.tmpl +++ /dev/null @@ -1,224 +0,0 @@ -{{define "statistics"}} - - - {{ template "html-head" headData .CommonPageData "Decred Statistics"}} - {{ template "navbar" . }} - {{with .Stats}} -
-
-
-
Network Stats
-
-
Total Supply
-
- {{template "decimalParts" (amountAsDecimalPartsTrimmed .TotalSupply 2 true)}} -
- DCR - {{if .TotalSupplyPercentage}} -
- {{printf "%.2f" .TotalSupplyPercentage}}% mined of {{template "decimalParts" (amountAsDecimalParts .UltimateSupply true)}} - {{end}} -
-
-
-
Proof-of-Work Difficulty
-
- {{template "decimalParts" (float64AsDecimalParts .PoWDiff 0 true)}} -
- show chart -
-
-
-
Hash Rate
-
- {{printf "%.2f" .HashRate}} -
- PHash/s -
-
-
-
Project Fund
-
- {{ template "decimalParts" (amountAsDecimalPartsTrimmed .ProjectFunds 2 true)}} -
- DCR -
- show address -
-
-
- -
-
Block Rewards
-
-
Block Reward Adjustment
-
-
-
-
-
-
-
-
-
- block {{.IdxInRewardWindow}} of {{.RewardWindowSize}}
- ({{remaining .IdxInRewardWindow .RewardWindowSize .BlockTime}})
-
-
- Curent {{template "decimalParts" (amountAsDecimalParts .BlockReward true)}} DCR -
- Next (est.) {{template "decimalParts" (amountAsDecimalParts .NextBlockReward true)}} DCR -
-
-
-
-
Block Reward
-
- {{template "decimalParts" (amountAsDecimalParts .BlockReward true)}} -
- DCR -
-
-
-
Proof-Of-Work Reward
-
- {{template "decimalParts" (amountAsDecimalParts .PoWReward true)}} -
- DCR per block -
- can be lower if less than 5 votes are mined - -
-
-
-
Project Fund Subsidy
-
- {{template "decimalParts" (amountAsDecimalParts .ProjectFundReward true)}} -
- DCR per block -
-
-
-
-
Proof-of-Stake Stats
-
-
Tickets In Mempool
-
- {{.TicketsInMempool}} -
- Ticket{{if gt .TicketsInMempool 1}}s{{end}} -
-
-
-
Votes In Mempool
-
- {{.VotesInMempool}} -
- Vote{{if gt .VotesInMempool 1}}s{{end}} -
-
-
-
Ticket Price
-
- {{template "decimalParts" (float64AsDecimalParts .TicketPrice 8 false)}} -
- DCR -
-
-
-
Ticket Price Adjustment
-
-
-
-
-
-
-
-
-
- {{.IdxBlockInWindow}} of {{.WindowSize}}
- ({{remaining .IdxBlockInWindow .WindowSize .BlockTime}})
-
-
- Curent: {{template "decimalParts" (float64AsDecimalParts .TicketPrice 8 false)}} DCR -
- Next: {{template "decimalParts" (float64AsDecimalParts .NextEstimatedTicketPrice 8 false)}} DCR -
-
-
-
-
Proof-Of-Stake Reward
-
- {{template "decimalParts" (amountAsDecimalParts ( divide .PoSReward 5) true)}} -
- DCR per ticket -
-
-
-
Ticket Rewards
-
- - +{{printf "%.2f" .TicketsROI}}% - -
- - per ticket, ~{{.RewardPeriod}} to vote - -
- ({{printf "%.2f" .APR}}% / year) -
- rough approximation -
-
-
-
Ticket Pool Size
-
- {{intComma .TicketPoolSize}} -
- {{if ge .TicketPoolSizePerToTarget 100.0}} - +{{printf "%.2f" (floatsubtract .TicketPoolSizePerToTarget 100.0)}}% above target 40,960 - {{else}} - -{{printf "%.2f" (floatsubtract 100.0 .TicketPoolSizePerToTarget)}}% below target 40,960 - {{end}} -
-
-
-
Ticket Pool Value
-
- {{template "decimalParts" (float64AsDecimalParts .TicketPoolValue 8 true)}} -
- DCR -
- {{printf "%.2f" .TPVOfTotalSupplyPeecentage}}% of total supply -
-
-
-
-
- {{end}} - {{template "footer" . }} - - -{{end}}