Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change monitor gas price logic calculation #385

Merged
merged 5 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmd/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -568,7 +569,15 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu
ms.BlocksLock.RUnlock()
renderedBlocks = renderedBlocksTemp

skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, ms.GasPrice, ms.PeerCount, ms.ChainID, rpcUrl)
// First initialization will render no gas price because the GasPriceChart will have no data.
if skeleton.GasPriceChart.Data == nil {
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, "--", ms.PeerCount, ms.ChainID, rpcUrl)
} else {
// Under normal cases, the gas price will be derived from the last element of the GasPriceChart with 2 decimal places precision.
gasPriceStr := strconv.FormatFloat(skeleton.GasPriceChart.Data[len(skeleton.GasPriceChart.Data)-1]/1000000000, 'f', 2, 64)
jhkimqd marked this conversation as resolved.
Show resolved Hide resolved
skeleton.Current.Text = ui.GetCurrentText(skeleton.Current, ms.HeadBlock, gasPriceStr, ms.PeerCount, ms.ChainID, rpcUrl)
}

if txPoolStatusSupported {
skeleton.TxPool.Text = ui.GetTxPoolText(skeleton.TxPool, ms.TxPoolStatus.pending, ms.TxPoolStatus.queued)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/monitor/ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ type UiSkeleton struct {
Receipts *widgets.List
}

func GetCurrentText(widget *widgets.Paragraph, headBlock, gasPrice *big.Int, peerCount uint64, chainID *big.Int, rpcURL string) string {
func GetCurrentText(widget *widgets.Paragraph, headBlock *big.Int, gasPrice string, peerCount uint64, chainID *big.Int, rpcURL string) string {
// First column
height := fmt.Sprintf("Height: %s", headBlock.String())
timeInfo := fmt.Sprintf("Time: %s", time.Now().Format("02 Jan 06 15:04:05 MST"))
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", new(big.Int).Div(gasPrice, metrics.UnitShannon).String())
gasPriceString := fmt.Sprintf("Gas Price: %s gwei", gasPrice)
peers := fmt.Sprintf("Peers: %d", peerCount)

// Second column
Expand Down