Skip to content

Commit

Permalink
Improve tx list scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcph4 committed Jan 13, 2025
1 parent 38781c1 commit 841928a
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions src/ui/app.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use alloy::{consensus::Transaction, rpc::types::Header};
use alloy::{
consensus::Transaction as AbstractTransaction,
rpc::types::{Header, Transaction},
};
use chrono::{TimeZone, Utc};
use ratatui::{
layout::{Constraint, Layout, Rect},
Expand Down Expand Up @@ -79,9 +82,22 @@ impl App {
}

pub fn on_enter(&mut self) {
if self.get_selected().is_some() {
if self.get_selected_header().is_some() {
self.view = View::Block;
}

match self.view {
View::Default => {
if self.get_selected_header().is_some() {
self.view = View::Block
}
}
View::Block => {
if self.get_selected_transaction().is_some() {
todo!()
}
}
}
}

pub fn on_up(&mut self) {
Expand All @@ -108,21 +124,20 @@ impl App {
self.block_headers.items.push(latest_header.clone());
}

if let Some(selected_header) = self.get_selected() {
if let Some(selected_header) = self.get_selected_header() {
if !matches!(self.view, View::Block) {
if let Some(selected_block) =
db.block(selected_header.hash).unwrap()
{
self.selected_block = selected_block;
self.transactions = StatefulList::with_items(
self.selected_block
.transactions
.clone()
.into_transactions()
.collect(),
);
}
} else {
self.transactions = StatefulList::with_items(
self.selected_block
.transactions
.clone()
.into_transactions()
.collect(),
);
}
}
}
Expand Down Expand Up @@ -334,10 +349,17 @@ impl App {
xs.clone()
}

fn get_selected(&self) -> Option<&Header> {
fn get_selected_header(&self) -> Option<&Header> {
self.block_headers
.state
.selected()
.and_then(|offset| self.block_headers.items.get(offset))
}

fn get_selected_transaction(&self) -> Option<&Transaction> {
self.transactions
.state
.selected()
.and_then(|offset| self.transactions.items.get(offset))
}
}

0 comments on commit 841928a

Please sign in to comment.