Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::database::Database;
use crate::logging::initialize_logger;
use crate::platform::{BackendTask, BackendTaskSuccessResult};
use crate::ui::document_query_screen::DocumentQueryScreen;
use crate::ui::dpns_contested_names_screen::DPNSContestedNamesScreen;
use crate::ui::dpns_contested_names_screen::{DPNSContestedNamesScreen, DPNSSubscreen};
use crate::ui::identities::identities_screen::IdentitiesScreen;
use crate::ui::network_chooser_screen::NetworkChooserScreen;
use crate::ui::transition_visualizer_screen::TransitionVisualizerScreen;
Expand Down Expand Up @@ -116,7 +116,12 @@ impl AppState {
let testnet_app_context = AppContext::new(Network::Testnet, db.clone());

let mut identities_screen = IdentitiesScreen::new(&mainnet_app_context);
let mut dpns_contested_names_screen = DPNSContestedNamesScreen::new(&mainnet_app_context);
let mut dpns_active_contests_screen =
DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Active);
let mut dpns_past_contests_screen =
DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Past);
let mut dpns_my_usernames_screen =
DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Owned);
Comment on lines +119 to +124

@coderabbitai coderabbitai Bot Oct 23, 2024

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider extracting DPNS screen initialization logic

While the initialization is correct, consider extracting this into a helper method to reduce code duplication and improve maintainability.

+ fn create_dpns_screens(app_context: &Arc<AppContext>) -> (
+     DPNSContestedNamesScreen,
+     DPNSContestedNamesScreen,
+     DPNSContestedNamesScreen,
+ ) {
+     (
+         DPNSContestedNamesScreen::new(app_context, DPNSSubscreen::Active),
+         DPNSContestedNamesScreen::new(app_context, DPNSSubscreen::Past),
+         DPNSContestedNamesScreen::new(app_context, DPNSSubscreen::Owned),
+     )
+ }

- let mut dpns_active_contests_screen =
-     DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Active);
- let mut dpns_past_contests_screen =
-     DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Past);
- let mut dpns_my_usernames_screen =
-     DPNSContestedNamesScreen::new(&mainnet_app_context, DPNSSubscreen::Owned);
+ let (mut dpns_active_contests_screen, mut dpns_past_contests_screen, mut dpns_my_usernames_screen) =
+     create_dpns_screens(&mainnet_app_context);

Committable suggestion was skipped due to low confidence.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's fine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuantumExplorer, understood.

(_/)
( •_• )

let mut transition_visualizer_screen =
TransitionVisualizerScreen::new(&mainnet_app_context);
let mut document_query_screen = DocumentQueryScreen::new(&mainnet_app_context);
Expand All @@ -136,7 +141,12 @@ impl AppState {
if network == Network::Testnet && testnet_app_context.is_some() {
let testnet_app_context = testnet_app_context.as_ref().unwrap();
identities_screen = IdentitiesScreen::new(testnet_app_context);
dpns_contested_names_screen = DPNSContestedNamesScreen::new(testnet_app_context);
dpns_active_contests_screen =
DPNSContestedNamesScreen::new(&testnet_app_context, DPNSSubscreen::Active);
dpns_past_contests_screen =
DPNSContestedNamesScreen::new(&testnet_app_context, DPNSSubscreen::Past);
dpns_my_usernames_screen =
DPNSContestedNamesScreen::new(&testnet_app_context, DPNSSubscreen::Owned);
transition_visualizer_screen = TransitionVisualizerScreen::new(testnet_app_context);
document_query_screen = DocumentQueryScreen::new(testnet_app_context);
}
Expand All @@ -156,8 +166,16 @@ impl AppState {
Screen::IdentitiesScreen(identities_screen),
),
(
RootScreenType::RootScreenDPNSContestedNames,
Screen::DPNSContestedNamesScreen(dpns_contested_names_screen),
RootScreenType::RootScreenDPNSActiveContests,
Screen::DPNSContestedNamesScreen(dpns_active_contests_screen),
),
(
RootScreenType::RootScreenDPNSPastContests,
Screen::DPNSContestedNamesScreen(dpns_past_contests_screen),
),
(
RootScreenType::RootScreenDPNSOwnedNames,
Screen::DPNSContestedNamesScreen(dpns_my_usernames_screen),
),
(
RootScreenType::RootScreenTransitionVisualizerScreen,
Expand Down
29 changes: 29 additions & 0 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::sdk_wrapper::initialize_sdk;
use crate::ui::RootScreenType;
use dash_sdk::dashcore_rpc::{Auth, Client};
use dash_sdk::dpp::dashcore::Network;
use dash_sdk::dpp::identity::accessors::IdentityGettersV0;
use dash_sdk::dpp::identity::Identity;
use dash_sdk::dpp::system_data_contracts::{load_system_data_contract, SystemDataContract};
use dash_sdk::dpp::version::PlatformVersion;
Expand Down Expand Up @@ -130,6 +131,34 @@ impl AppContext {
self.db.get_ongoing_contested_names(self)
}

pub fn owned_contested_names(&self) -> Result<Vec<ContestedName>> {
let all_contested_names = self.all_contested_names().unwrap_or_else(|e| {
tracing::error!("Failed to load contested names: {:?}", e);
Vec::new() // Use default value if loading fails
});
let local_qualified_identities =
self.load_local_qualified_identities().unwrap_or_else(|e| {
tracing::error!("Failed to load local qualified identities: {:?}", e);
Vec::new() // Use default value if loading fails
});

let owned_contested_names = all_contested_names
.into_iter()
.filter(|contested_name| {
contested_name
.awarded_to
.as_ref()
.map_or(false, |awarded_to| {
local_qualified_identities
.iter()
.any(|identity| identity.identity.id() == awarded_to)
})
})
.collect();

Ok(owned_contested_names)
}

/// Updates the `start_root_screen` in the settings table
pub fn update_settings(&self, root_screen_type: RootScreenType) -> Result<()> {
self.db
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() -> eframe::Result<()> {
..Default::default()
};
eframe::run_native(
"Identity Manager",
"Dash Evo Tool",
native_options,
Box::new(|_cc| Ok(Box::new(app::AppState::new()))),
)
Expand Down
57 changes: 57 additions & 0 deletions src/ui/components/dpns_subscreen_chooser_panel.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use crate::ui::dpns_contested_names_screen::DPNSSubscreen;
use crate::{app::AppAction, ui::RootScreenType};
use egui::{Context, Frame, Margin, SidePanel};

pub fn add_dpns_subscreen_chooser_panel(ctx: &Context) -> AppAction {
let mut action = AppAction::None;

let subscreens = vec![
DPNSSubscreen::Active,
DPNSSubscreen::Past,
DPNSSubscreen::Owned,
];

SidePanel::left("dpns_subscreen_chooser_panel")
.default_width(250.0)
.frame(
Frame::none()
.fill(ctx.style().visuals.panel_fill)
.inner_margin(Margin::same(10.0)),
)
Comment on lines +14 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider adding accessibility attributes to the panel.

While the panel setup is well-structured, consider adding accessibility attributes such as ARIA labels to improve screen reader support.

 SidePanel::left("dpns_subscreen_chooser_panel")
     .default_width(250.0)
+    .id(egui::Id::new("dpns_navigation_panel"))
     .frame(
         Frame::none()
             .fill(ctx.style().visuals.panel_fill)
             .inner_margin(Margin::same(10.0)),
     )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
SidePanel::left("dpns_subscreen_chooser_panel")
.default_width(250.0)
.frame(
Frame::none()
.fill(ctx.style().visuals.panel_fill)
.inner_margin(Margin::same(10.0)),
)
SidePanel::left("dpns_subscreen_chooser_panel")
.default_width(250.0)
.id(egui::Id::new("dpns_navigation_panel"))
.frame(
Frame::none()
.fill(ctx.style().visuals.panel_fill)
.inner_margin(Margin::same(10.0)),
)

.show(ctx, |ui| {
// Display subscreen names
ui.vertical(|ui| {
ui.label("DPNS Subscreens");
ui.add_space(10.0);

for subscreen in subscreens {
// Show the subscreen name as a clickable option
if ui.button(subscreen.display_name()).clicked() {
// Handle navigation based on which subscreen is selected
match subscreen {
DPNSSubscreen::Active => {
action = AppAction::SetMainScreen(
RootScreenType::RootScreenDPNSActiveContests,
)
}
DPNSSubscreen::Past => {
action = AppAction::SetMainScreen(
RootScreenType::RootScreenDPNSPastContests,
)
}
DPNSSubscreen::Owned => {
action = AppAction::SetMainScreen(
RootScreenType::RootScreenDPNSOwnedNames,
)
}
_ => {}
}
}

ui.add_space(5.0);
}
Comment on lines +27 to +52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Enhance user experience with tooltips and keyboard navigation.

Consider adding tooltips and improving keyboard navigation for better user experience.

 for subscreen in subscreens {
-    if ui.button(subscreen.display_name()).clicked() {
+    let button = egui::Button::new(subscreen.display_name())
+        .shortcut_text(format!("Alt+{}", (subscreen as u8 + 1)))
+        .wrap(false);
+    if ui.add(button)
+        .on_hover_text(format!("View {}", subscreen.display_name().to_lowercase()))
+        .clicked() {
         match subscreen {
             // ... existing match arms ...
         }
     }

Committable suggestion was skipped due to low confidence.

});
});

action
}
2 changes: 1 addition & 1 deletion src/ui/components/left_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn add_left_panel(
("I", RootScreenType::RootScreenIdentities, "identity.png"),
(
"C",
RootScreenType::RootScreenDPNSContestedNames,
RootScreenType::RootScreenDPNSActiveContests,
"voting.png",
),
("Q", RootScreenType::RootScreenDocumentQuery, "doc.png"),
Expand Down
1 change: 1 addition & 0 deletions src/ui/components/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod contract_chooser_panel;
pub mod dpns_subscreen_chooser_panel;
pub mod entropy_grid;
pub mod left_panel;
pub mod top_panel;
Loading