diff --git a/cmd/monitor/monitor.go b/cmd/monitor/monitor.go index 2a30e6d9..0e0ccc17 100644 --- a/cmd/monitor/monitor.go +++ b/cmd/monitor/monitor.go @@ -471,7 +471,21 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu baseFee := ms.SelectedBlock.BaseFee() if transactionList.SelectedRow != 0 { - ms.SelectedTransaction = ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1] + transactions := ms.SelectedBlock.Transactions() + if len(transactions) > 0 { + index := transactionList.SelectedRow - 1 + if index >= 0 && index < len(transactions) { + ms.SelectedTransaction = transactions[index] + } else { + log.Error(). + Int("row", transactionList.SelectedRow). + Msg("Selected row is out of range for transactions") + } + } else { + log.Debug(). + Int("block", int(ms.SelectedBlock.Number().Uint64())). + Msg("No transactions available in the selected block") + } transactionInformationList.Rows = ui.GetSimpleTxFields(ms.SelectedTransaction, ms.ChainID, baseFee) } termui.Clear() @@ -484,7 +498,22 @@ func renderMonitorUI(ctx context.Context, ec *ethclient.Client, ms *monitorStatu return } else if currentMode == monitorModeTransaction { baseFee := ms.SelectedBlock.BaseFee() - skeleton.TxInfo.Rows = ui.GetSimpleTxFields(ms.SelectedBlock.Transactions()[transactionList.SelectedRow-1], ms.ChainID, baseFee) + transactions := ms.SelectedBlock.Transactions() + if len(transactions) > 0 { + index := transactionList.SelectedRow - 1 + if index > 0 && index < len(transactions) { + tx := transactions[index] + skeleton.TxInfo.Rows = ui.GetSimpleTxFields(tx, ms.ChainID, baseFee) + } else { + log.Error(). + Int("row", transactionList.SelectedRow). + Msg("Selected row is out of range for transactions") + } + } else { + log.Debug(). + Int("block", int(ms.SelectedBlock.Number().Uint64())). + Msg("No transactions available in the selected block") + } skeleton.Receipts.Rows = ui.GetSimpleReceipt(ctx, rpc, ms.SelectedTransaction) termui.Clear()