Skip to content

Commit

Permalink
feat: report session mining stats (#259)
Browse files Browse the repository at this point in the history
* feat: report session mining stats

Continued simplifying UI:
- Removed buttons. Just push keys now. Easy.
- Moved mining to top, 'since that what we're interested in.
- Borders are green when active. Nice visual feedback
- Consolidated both mining panels into a single one.

Monitor wallet.tranaction stream to get notifications about mined
blocks.

Pro: It works with very little lift.
Con: You wait until your block is confirmed before the UI picks up that
it is mined. This should hopefully be very low lag since we're
submitting to a local node that will validate it immediately.

* chore: remove dead code
  • Loading branch information
CjS77 authored Nov 29, 2023
1 parent 2195f86 commit 9fc0663
Show file tree
Hide file tree
Showing 20 changed files with 315 additions and 656 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions cli/src/component/elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ use ratatui::{
widgets::{Block, Borders},
};

pub fn block_with_title(title: Option<&str>, focus: bool) -> Block<'_> {
let color = if focus { Color::LightGreen } else { Color::White };
let border_style = if focus {
pub fn block_with_title(title: Option<&str>, highlight: bool) -> Block<'_> {
let color = if highlight { Color::LightGreen } else { Color::White };
let border_style = if highlight {
Style::default().fg(color).add_modifier(Modifier::BOLD)
} else {
Style::default().fg(color).add_modifier(Modifier::DIM)
Expand Down
56 changes: 6 additions & 50 deletions cli/src/component/normal/base_node.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright 2023. The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use std::time::Duration;

use crossterm::event::{KeyCode, KeyModifiers};
use ratatui::{
backend::Backend,
Expand All @@ -14,20 +12,14 @@ use ratatui::{
use crate::{
component::{
elements::block_with_title,
widgets::{
status_line::{StatusLine, StatusReportGetter},
ChronoButton,
ChronoGetter,
},
widgets::status_line::{StatusLine, StatusReportGetter},
Component,
ComponentEvent,
ComponentEvent::KeyEvent,
Frame,
Input,
Pass,
},
focus_id,
state::{focus, AppState, Focus},
state::AppState,
};

#[derive(Default)]
Expand Down Expand Up @@ -67,38 +59,18 @@ impl StatusReportGetter for BaseNodeStatus {
}
}

static BUTTON: Focus = focus_id!();

struct BaseNodeGetter;

impl ChronoGetter for BaseNodeGetter {
fn get_duration(&self, _state: &AppState) -> Option<Duration> {
None
}

fn get_label(&self, state: &AppState) -> &str {
if state.state.config.session.is_base_node_active() {
"Pause"
} else {
"Start node"
}
}
}

pub struct BaseNodeWidget {
status: StatusLine<BaseNodeStatus>,
button: ChronoButton<BaseNodeGetter>,
}

impl BaseNodeWidget {
pub fn new() -> Self {
Self {
status: StatusLine::new(BaseNodeStatus::default()),
button: ChronoButton::new(BaseNodeGetter, BUTTON),
}
}

pub fn toggle_base_node(&mut self, state: &mut AppState) {
pub fn toggle_base_node(state: &mut AppState) {
let session = &mut state.state.config.session;
session.base_layer_active = !session.base_layer_active;
state.update_state();
Expand All @@ -111,25 +83,10 @@ impl Input for BaseNodeWidget {
fn on_event(&mut self, event: ComponentEvent, state: &mut AppState) -> Option<Self::Output> {
if let KeyEvent(key) = event {
if key.code == KeyCode::Char('b') && key.modifiers.contains(KeyModifiers::CONTROL) {
self.toggle_base_node(state);
Self::toggle_base_node(state);
return Some(());
}
}
if state.focus_on == focus::BASE_NODE {
match event.pass() {
Pass::Up | Pass::Prev => {
state.focus_on(focus::MERGED_MINING);
},
Pass::Down | Pass::Next => {
state.focus_on(focus::WALLET);
},
Pass::Enter | Pass::Space => {
self.toggle_base_node(state);
return Some(());
},
_ => {},
}
}
None
}
}
Expand All @@ -138,8 +95,8 @@ impl<B: Backend> Component<B> for BaseNodeWidget {
type State = AppState;

fn draw(&self, f: &mut Frame<B>, rect: Rect, state: &Self::State) {
let block = block_with_title(Some("Base Node [Ctrl-B]"), state.focus_on == focus::BASE_NODE)
.padding(Padding::new(1, 1, 1, 1));
let node_active = state.state.config.session.is_base_node_active();
let block = block_with_title(Some("Base Node [Ctrl-B]"), node_active).padding(Padding::new(1, 1, 1, 1));
let inner_rect = block.inner(rect);
f.render_widget(block, rect);

Expand All @@ -151,6 +108,5 @@ impl<B: Backend> Component<B> for BaseNodeWidget {
.split(inner_rect);

self.status.draw(f, h_chunks[0], state);
self.button.draw(f, h_chunks[2], state);
}
}
78 changes: 0 additions & 78 deletions cli/src/component/normal/mining/amount.rs

This file was deleted.

30 changes: 30 additions & 0 deletions cli/src/component/normal/mining/helpers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2023. The Tari Project
// SPDX-License-Identifier: BSD-3-Clause

use ratatui::style::Color;

use crate::{component::normal::mining::status_badge::StatusGetter, state::AppState};

pub struct MergeMiningStatus;

impl StatusGetter for MergeMiningStatus {
fn get_status(&self, state: &AppState) -> (&str, Color) {
if state.state.config.session.merge_layer_active {
("⚒️ Press [M] to stop Merge Mining", Color::Green)
} else {
("Press [M] to start Merge mining", Color::Gray)
}
}
}

pub struct ShaMiningStatus;

impl StatusGetter for ShaMiningStatus {
fn get_status(&self, state: &AppState) -> (&str, Color) {
if state.state.config.session.sha3x_layer_active {
("⚒️ Press [T] to stop SHA3X mining", Color::Yellow)
} else {
("Press [T] to start SHA3X mining", Color::Gray)
}
}
}
Loading

0 comments on commit 9fc0663

Please sign in to comment.