From ab6bc1c80d3d03e889d03a76b58ed37ad8548b89 Mon Sep 17 00:00:00 2001 From: Jesse Lee Date: Wed, 8 Nov 2023 13:59:24 -0500 Subject: [PATCH] replace window off set with start block value for the screen --- cmd/monitor/monitor.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/cmd/monitor/monitor.go b/cmd/monitor/monitor.go index 1079aff2..d0e2db37 100644 --- a/cmd/monitor/monitor.go +++ b/cmd/monitor/monitor.go @@ -109,9 +109,11 @@ func monitor(ctx context.Context) error { if err != nil { continue } - if !isUiRendered { go func() { + if ms.TopDisplayedBlock == nil { + ms.TopDisplayedBlock = ms.HeadBlock + } errChan <- renderMonitorUI(ctx, ec, ms, rpc) }() isUiRendered = true @@ -213,9 +215,6 @@ func fetchBlocks(ctx context.Context, ec *ethclient.Client, ms *monitorStatus, r } ms.HeadBlock = new(big.Int).SetUint64(cs.HeadBlock) - if ms.TopDisplayedBlock == nil { - ms.TopDisplayedBlock = ms.HeadBlock - } ms.ChainID = cs.ChainID ms.PeerCount = cs.PeerCount ms.GasPrice = cs.GasPrice @@ -377,8 +376,6 @@ func updateAllBlocks(ms *monitorStatus) []rpctypes.PolyBlock { } } - // Assuming blocks need to be sorted, you'd sort them here. - // This assumes that metrics.SortableBlocks is a type that can be sorted. sort.Sort(metrics.SortableBlocks(blocks)) return blocks @@ -402,7 +399,6 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu var setBlock = false var allBlocks metrics.SortableBlocks var renderedBlocks metrics.SortableBlocks - // windowOffset := 0 redraw := func(ms *monitorStatus, force ...bool) { log.Debug().Interface("ms", ms).Msg("Redrawing") @@ -629,18 +625,18 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu setBlock = true } case "": - // windowOffset = 0 + ms.TopDisplayedBlock = ms.HeadBlock blockTable.SelectedRow = 1 setBlock = true case "g": if previousKey == "g" { - // windowOffset = 0 + ms.TopDisplayedBlock = ms.HeadBlock blockTable.SelectedRow = 1 setBlock = true } case "G", "": if len(renderedBlocks) < windowSize { - // windowOffset = 0 + ms.TopDisplayedBlock = ms.HeadBlock blockTable.SelectedRow = len(renderedBlocks) } else { // windowOffset = len(allBlocks) - windowSize