Repository navigation
feat: dpns subscreens #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -130,6 +131,38 @@ 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Collect the identifiers from local qualified identities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let local_identifiers: Vec<_> = local_qualified_identities | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .map(|identity| identity.identity.id()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Filter the contested names by checking if they were awarded to any local identifier | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let owned_contested_names: Vec<ContestedName> = all_contested_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .into_iter() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .filter(|contested_name| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if let Some(awarded_to) = &contested_name.awarded_to { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| local_identifiers.contains(awarded_to) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| false | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .collect(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider optimizing the filtering logic. The current implementation creates intermediate vectors which could be avoided for better performance. Consider this more efficient implementation using iterator chaining: - // Collect the identifiers from local qualified identities
- let local_identifiers: Vec<_> = local_qualified_identities
- .iter()
- .map(|identity| identity.identity.id())
- .collect();
-
- // Filter the contested names by checking if they were awarded to any local identifier
- let owned_contested_names: Vec<ContestedName> = all_contested_names
- .into_iter()
- .filter(|contested_name| {
- if let Some(awarded_to) = &contested_name.awarded_to {
- local_identifiers.contains(awarded_to)
- } else {
- false
- }
- })
- .collect();
+ 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();📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use crate::context::AppContext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use crate::{app::AppAction, ui::RootScreenType}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use egui::{Context, Frame, Margin, SidePanel}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| use std::sync::Arc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pub fn add_dpns_subscreen_chooser_panel(ctx: &Context, app_context: &Arc<AppContext>) -> AppAction { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let mut action = AppAction::None; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let subscreens = vec!["Active contests", "Past contests", "My usernames"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider using an enum for subscreen names. Using string literals for screen names makes the code more prone to typos and harder to maintain. Consider defining an enum for the subscreens. enum DPNSSubscreenType {
ActiveContests,
PastContests,
MyUsernames,
}
impl DPNSSubscreenType {
fn display_name(&self) -> &'static str {
match self {
Self::ActiveContests => "Active contests",
Self::PastContests => "Past contests",
Self::MyUsernames => "My usernames",
}
}
}
// Then use it like:
let subscreens = vec![
DPNSSubscreenType::ActiveContests,
DPNSSubscreenType::PastContests,
DPNSSubscreenType::MyUsernames,
]; |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .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).clicked() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Handle navigation based on which subscreen is selected | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| match subscreen { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Active contests" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action = AppAction::SetMainScreen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RootScreenType::RootScreenDPNSActiveContests, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Past contests" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action = AppAction::SetMainScreen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RootScreenType::RootScreenDPNSPastContests, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "My usernames" => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action = AppAction::SetMainScreen( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RootScreenType::RootScreenDPNSOwnedNames, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _ => {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ui.add_space(5.0); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+27
to
+52
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ...
}
}
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Several improvements for the UI implementation.
Here's how you could improve the implementation: -pub fn add_dpns_subscreen_chooser_panel(ctx: &Context, app_context: &Arc<AppContext>) -> AppAction {
+pub fn add_dpns_subscreen_chooser_panel(ctx: &Context) -> AppAction {
let mut action = AppAction::None;
- let subscreens = vec!["Active contests", "Past contests", "My usernames"];
+ let subscreens = vec![
+ ("Active contests", RootScreenType::RootScreenDPNSActiveContests),
+ ("Past contests", RootScreenType::RootScreenDPNSPastContests),
+ ("My usernames", RootScreenType::RootScreenDPNSOwnedNames),
+ ];
// ... panel setup ...
ui.vertical(|ui| {
ui.label("DPNS Subscreens");
ui.add_space(10.0);
- for subscreen in subscreens {
+ for (label, screen_type) in subscreens {
// Show the subscreen name as a clickable option
- if ui.button(subscreen).clicked() {
- match subscreen {
- "Active contests" => {
- action = AppAction::SetMainScreen(
- RootScreenType::RootScreenDPNSActiveContests,
- )
- }
- "Past contests" => {
- action = AppAction::SetMainScreen(
- RootScreenType::RootScreenDPNSPastContests,
- )
- }
- "My usernames" => {
- action = AppAction::SetMainScreen(
- RootScreenType::RootScreenDPNSOwnedNames,
- )
- }
- _ => {}
- }
+ let button = egui::Button::new(label)
+ .wrap(false)
+ .sense(egui::Sense::click());
+ if ui.add_enabled(true, button)
+ .on_hover_text(format!("View {}", label.to_lowercase()))
+ .clicked() {
+ action = AppAction::SetMainScreen(screen_type);
}
ui.add_space(5.0);
}
});📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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; |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's fine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QuantumExplorer, understood.
(_/)
( •_• )