Skip to content

Commit

Permalink
Render storage page
Browse files Browse the repository at this point in the history
  • Loading branch information
boundless-forest committed Dec 22, 2023
1 parent 5b13977 commit dea64be
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
37 changes: 32 additions & 5 deletions src/app/dashboard/tab_pallets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ use ratatui::{
style::Stylize,
widgets::*,
};
use scale_value::Value;
// this crate
use super::DashBoard;
use crate::networks::ChainInfo;
use crate::{handler::print_storage_type, networks::ChainInfo};

pub fn draw_pallets_tab<CI: ChainInfo>(f: &mut Frame, app: &mut DashBoard<CI>, area: Rect) {
let chunks = Layout::default()
Expand Down Expand Up @@ -132,11 +131,39 @@ fn render_pallet_storages_page<CI: ChainInfo>(f: &mut Frame, dash_board: &mut Da
.title_style(Style::default().bold().italic())
.borders(Borders::ALL)
.border_type(BorderType::Double)
.padding(Padding::horizontal(2))
.style(Style::default().fg(Color::Yellow));

let text = "Storages Page".to_string();
let paragraph = Paragraph::new(text).block(block_style).wrap(Wrap { trim: true });
f.render_widget(paragraph, area);
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 {
if let Some(s) = pallet.storage() {
let storages: Vec<ListItem> = s
.entries()
.into_iter()
.map(|e| {
ListItem::new(vec![Line::from(Span::styled(
format!("> {} : {}", e.name(), &print_storage_type(e.entry_type().clone(), &dash_board.metadata)),
Style::default().fg(Color::Yellow),
))])
})
.collect();

if storages.len() != 0 {
let l = List::new(storages).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);
}
} 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_calls_page<CI: ChainInfo>(f: &mut Frame, dash_board: &mut DashBoard<CI>, area: Rect) {
let block_style = Block::default()
Expand Down
4 changes: 3 additions & 1 deletion src/handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod printer;

pub use crate::handler::printer::print_storage_type;

// std
use std::{
fs::File,
Expand Down Expand Up @@ -30,7 +32,7 @@ use crate::{
RuntimeCommand, POLKADOT_CLI,
},
errors::AppError,
handler::printer::{print_result, print_storage_type, print_usage},
handler::printer::{print_result, print_usage},
networks::{ChainInfo, Network},
rpc::{single_map_storage_key, AccountBalances, AccountNonce, ChainApi, RpcClient, RpcError, StateApi, SubscribeApi, SystemApi},
};
Expand Down

0 comments on commit dea64be

Please sign in to comment.