From 4f9a498f413547436958202014c7fef5c78baa84 Mon Sep 17 00:00:00 2001 From: Klesti Selimaj Date: Wed, 15 Jul 2026 08:19:21 -0400 Subject: [PATCH] Added system --- src/formatting.rs | 14 +++++++++++++- src/main.rs | 23 ++++++++++++----------- src/types.rs | 15 +++++++++++++++ 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index 2eff77f..c05f91f 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -1,4 +1,4 @@ -use crate::types::{Account, ActivePosition, WatchListItem}; +use crate::types::{Account, ActivePosition, System, WatchListItem}; pub trait Formatted { fn get_formatted(&self) -> Vec; @@ -55,6 +55,18 @@ impl Formatted for Account { } } +impl Formatted for System { + fn get_formatted(&self) -> Vec { + vec![ + Property("Feed", format!("{:?}", self.feed)), + Property("Exchange", self.exchange.clone()), + Property("DEX", self.dex.clone()), + Property("Latency", format!("{} ms", self.latency)), + ] + .get_formatted() + } +} + impl Formatted for Property { fn get_formatted(&self) -> Vec { vec![format!("\x1b[91m{}\x1b[0m", self.0), self.1.clone()] diff --git a/src/main.rs b/src/main.rs index 2b1de93..646219a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,7 @@ use pulse_ui::{ use crate::{ formatting::{Formatted, apply_padding}, - types::{Account, ActivePosition, WatchListItem}, + types::{Account, ActivePosition, System, WatchListItem}, }; pub struct PulseTradeApp { @@ -26,6 +26,7 @@ pub struct PulseTradeApp { watch_list: State>, active_positions: State>, account: State, + system: State, } impl App for PulseTradeApp { @@ -178,16 +179,10 @@ impl App for PulseTradeApp { ), ( LayoutItem::Widget(Size::Flex(1)), - Box::new( - vec![ - " SYSTEM", - " Feed: Connected", - " Exchange: Binance", - " DEX: DEX SCREENER", - " Latency: 18 ms", - ] - .join("\n"), - ), + Box::new(format![ + " SYSTEM\n{}", + apply_padding(self.system.lock().await.get_formatted()).join("\n") + ]), ), ]), ); @@ -209,6 +204,12 @@ async fn main() { realized: 2_182.49, margin: 0.0, }), + system: ctx.use_state(System { + feed: types::Feed::Connected, + exchange: "Binance".to_string(), + dex: "DEX SCREENER".to_string(), + latency: 18, + }), }) .await; } diff --git a/src/types.rs b/src/types.rs index 3c3b4c1..7167380 100644 --- a/src/types.rs +++ b/src/types.rs @@ -17,3 +17,18 @@ pub struct Account { pub realized: f64, pub margin: f64, } + +#[derive(Debug, Clone, Copy)] +pub enum Feed { + Connected, + Disconnected, + Connecting, + Failed, +} + +pub struct System { + pub feed: Feed, + pub exchange: String, + pub dex: String, + pub latency: u16, +}