Skip to content

Commit

Permalink
Merge pull request #154 from dashpay/v0.7.1-dev
Browse files Browse the repository at this point in the history
v0.7.1-dev to master
  • Loading branch information
pauldelucia authored Jan 8, 2025
2 parents bd70ef3 + c71bd7f commit 590dccd
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dash-evo-tool"
version = "0.7.0"
version = "0.7.1"
license = "MIT"
edition = "2021"
default-run = "dash-evo-tool"
Expand Down
72 changes: 33 additions & 39 deletions src/ui/tools/transition_visualizer_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ impl TransitionVisualizerScreen {
}

fn parse_input(&mut self) {
// Clear previous parse results, but let's not overwrite broadcast_status
// Clear previous parse results...
self.parsed_json = None;

// Reset the broadcast status so we no longer show old errors
// or "Submitting" states from a previous parse/broadcast.
self.broadcast_status = TransitionBroadcastStatus::NotStarted;

// Try to decode the input as hex first
let decoded_bytes = hex::decode(&self.input_data).or_else(|_| {
STANDARD
Expand All @@ -56,7 +60,7 @@ impl TransitionVisualizerScreen {
// Try to deserialize into a StateTransition
match StateTransition::deserialize_from_bytes(&bytes) {
Ok(state_transition) => {
// Convert state transition to JSON
// Convert to JSON
match serde_json::to_string_pretty(&state_transition) {
Ok(json) => self.parsed_json = Some(json),
Err(e) => {
Expand All @@ -68,10 +72,8 @@ impl TransitionVisualizerScreen {
}
}
Err(e) => {
self.broadcast_status = TransitionBroadcastStatus::Error(format!(
"Failed to parse state transition: {}",
e
));
self.broadcast_status =
TransitionBroadcastStatus::Error(format!("Failed to parse: {}", e));
}
}
}
Expand Down Expand Up @@ -119,43 +121,35 @@ impl TransitionVisualizerScreen {

ui.add_space(10.0);

// If we’re not done or not in the middle of broadcasting, we can show the button
// if we are NotStarted or in an Error state, show the button
if matches!(
self.broadcast_status,
TransitionBroadcastStatus::NotStarted | TransitionBroadcastStatus::Error(_)
) {
if let TransitionBroadcastStatus::Submitting(_) = self.broadcast_status {
// Broadcast button
let mut new_style = (**ui.style()).clone();
new_style.spacing.button_padding = egui::vec2(10.0, 5.0);
ui.set_style(new_style);
let button = egui::Button::new(
RichText::new("Broadcast Transition to Platform").color(Color32::WHITE),
)
.fill(Color32::from_rgb(0, 128, 255))
.frame(true)
.rounding(3.0);
if ui.add(button).clicked() {
// Mark as submitting
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs();
self.broadcast_status = TransitionBroadcastStatus::Submitting(now);
// Kick off the backend task
match StateTransition::deserialize_from_bytes(
&hex::decode(&self.input_data).unwrap(),
) {
Ok(state_transition) => {
app_action = AppAction::BackendTask(
BackendTask::BroadcastStateTransition(state_transition),
);
}
Err(e) => {
self.broadcast_status = TransitionBroadcastStatus::Error(
format!("Failed to parse state transition: {}", e),
);
}
let mut new_style = (**ui.style()).clone();
new_style.spacing.button_padding = egui::vec2(10.0, 5.0);
ui.set_style(new_style);

let button = egui::Button::new(
RichText::new("Broadcast Transition to Platform").color(Color32::WHITE),
)
.fill(Color32::from_rgb(0, 128, 255))
.frame(true)
.rounding(3.0);

if ui.add(button).clicked() {
// Mark as submitting
let now = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards")
.as_secs();
self.broadcast_status = TransitionBroadcastStatus::Submitting(now);

if let Some(json) = &self.parsed_json {
if let Ok(state_transition) = serde_json::from_str(json) {
app_action = AppAction::BackendTask(
BackendTask::BroadcastStateTransition(state_transition),
);
}
}
}
Expand Down

0 comments on commit 590dccd

Please sign in to comment.