Skip to content

Commit

Permalink
Render constants page
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 22, 2023
1 parent 9895586 commit 5b13977
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/app/dashboard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ impl<'a, CI: ChainInfo> DashBoard<'a, CI> {
selected_pallet: None,
tab_titles: vec![String::from("Blocks"), String::from("Events"), String::from("Pallets")],
selected_tab: 0,
pallet_info_titles: vec![String::from("Events"), String::from("Errors"), String::from("Storages"), String::from("Calls")],
pallet_info_titles: vec![
String::from("Constants"),
String::from("Events"),
String::from("Errors"),
String::from("Storages"),
String::from("Calls"),
],
selected_pallet_info_tab: 0,
}
}
Expand Down
42 changes: 38 additions & 4 deletions src/app/dashboard/tab_pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use ratatui::{
style::Stylize,
widgets::*,
};
use scale_value::Value;
// this crate
use super::DashBoard;
use crate::networks::ChainInfo;
Expand Down Expand Up @@ -63,14 +64,47 @@ fn render_pallet_info<CI: ChainInfo>(f: &mut Frame, dash_board: &mut DashBoard<C
f.render_widget(tabs, chunks[0]);

match dash_board.selected_pallet_info_tab {
0 => render_pallet_events_page(f, dash_board, chunks[1]),
1 => render_pallet_errors_page(f, dash_board, chunks[1]),
2 => render_pallet_storages_page(f, dash_board, chunks[1]),
3 => render_pallet_calls_page(f, dash_board, chunks[1]),
0 => render_pallet_constants_page(f, dash_board, chunks[1]),
1 => render_pallet_events_page(f, dash_board, chunks[1]),
2 => render_pallet_errors_page(f, dash_board, chunks[1]),
3 => render_pallet_storages_page(f, dash_board, chunks[1]),
4 => render_pallet_calls_page(f, dash_board, chunks[1]),
_ => {},
};
}
fn render_pallet_constants_page<CI: ChainInfo>(f: &mut Frame, dash_board: &mut DashBoard<CI>, area: Rect) {
let block_style = Block::default()
.title_style(Style::default().bold().italic())
.borders(Borders::ALL)
.border_type(BorderType::Double)
.padding(Padding::horizontal(2))
.style(Style::default().fg(Color::Yellow));

if let Some((id, name)) = dash_board.selected_pallet.clone() {
let pallet = dash_board.metadata.pallets().find(|p| p.name() == name && p.index() == id);
if let Some(pallet) = pallet {
let constants: Vec<ListItem> = pallet
.constants()
.into_iter()
.map(|c| {
let ty_id = c.ty();
let mut bytes = c.value();
let value = scale_value::scale::decode_as_type(&mut bytes, ty_id, dash_board.metadata.types()).unwrap();
ListItem::new(vec![Line::from(Span::styled(format!("> {} : {}", c.name(), value), Style::default().fg(Color::Yellow)))])
})
.collect();

if constants.len() != 0 {
let l = List::new(constants).block(block_style);
f.render_widget(l, area);
} else {
let text = "None".to_string();
let paragraph = Paragraph::new(text).block(block_style).wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
}
}
}
}
fn render_pallet_events_page<CI: ChainInfo>(f: &mut Frame, dash_board: &mut DashBoard<CI>, area: Rect) {
let block_style = Block::default()
.title_style(Style::default().bold().italic())
Expand Down

0 comments on commit 5b13977

Please sign in to comment.