Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 3 additions & 1 deletion src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1956,7 +1956,9 @@ impl AppState {
return;
}
self.select_main_screen(root_screen_type);
self.active_root_screen_mut().refresh_on_arrival();
let active_screen = self.active_root_screen_mut();
active_screen.reset_to_root_view();
active_screen.refresh_on_arrival();
Comment thread
lklimek marked this conversation as resolved.
Resolved
self.current_app_context()
.update_settings(root_screen_type)
.ok();
Expand Down
38 changes: 38 additions & 0 deletions src/backend_task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,7 @@ impl AppContext {
)
})
.ok_or(TaskError::NetworkContextCreationFailed { network })?;
new_ctx.install_secret_prompt(self.secret_prompt());

// Wire the freshly-built context's wallet backend and then start
// chain sync. The old code called `start_spv()` on an unwired
Expand Down Expand Up @@ -1277,6 +1278,43 @@ mod tests {
backend.shutdown().await;
}

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn switch_network_propagates_secret_prompt_before_wallet_backend_wiring() {
use crate::context::test_support::test_app_context;
use crate::wallet_backend::SecretPrompt;
use crate::wallet_backend::secret_prompt::test_support::TestPrompt;

let tmp = tempfile::tempdir().expect("tempdir");
let ctx = test_app_context(tmp.path());
let prompt: Arc<dyn SecretPrompt> = Arc::new(TestPrompt::never());
ctx.install_secret_prompt(Arc::clone(&prompt));

let (tx, _rx) = tokio::sync::mpsc::channel::<TaskResult>(32);
let sender = SenderAsync::new(tx, ctx.egui_ctx().clone());
let result = ctx
.run_backend_task(
BackendTask::SwitchNetwork {
network: Network::Mainnet,
start_spv: false,
},
sender,
)
.await
.expect("switch network");

let BackendTaskSuccessResult::NetworkContextCreated { context, .. } = result else {
panic!("expected a newly created network context");
};
assert!(
Arc::ptr_eq(&prompt, &context.secret_prompt()),
"the new context must retain the source prompt host identity"
);
assert!(
context.wallet_backend().is_err(),
"the prompt must be present before lazy wallet-backend wiring"
);
}
Comment thread
claude[bot] marked this conversation as resolved.
Resolved

#[test]
fn dapi_success_skips_availability_inspection() {
let inspected = std::cell::Cell::new(false);
Expand Down
39 changes: 39 additions & 0 deletions src/mcp/tools/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ impl AsyncTool<DashMcpService> for NetworkSwitch {
spv_started,
..
} => {
context.install_secret_prompt(ctx.secret_prompt());
Comment thread
claude[bot] marked this conversation as resolved.
Resolved
// S5: drain the OUTGOING context's wallet backend before
// replacing it. The old `ctx` (still in scope above) is the
// context that is being evicted; the new `context` is the one
Expand All @@ -259,3 +260,41 @@ impl AsyncTool<DashMcpService> for NetworkSwitch {
}
}
}

#[cfg(all(test, feature = "mcp"))]
mod tests {
use std::sync::Arc;

use super::*;
use crate::context::test_support::test_app_context;
use crate::wallet_backend::SecretPrompt;
use crate::wallet_backend::secret_prompt::test_support::TestPrompt;

#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn network_switch_tool_preserves_secret_prompt_identity() {
let tmp = tempfile::tempdir().expect("tempdir");
let ctx = test_app_context(tmp.path());
let prompt: Arc<dyn SecretPrompt> = Arc::new(TestPrompt::never());
ctx.install_secret_prompt(Arc::clone(&prompt));
let shared = Arc::new(arc_swap::ArcSwap::from(ctx));
let service = DashMcpService::new_shared(shared);

NetworkSwitch::invoke(
&service,
NetworkSwitchParams {
network: "mainnet".to_owned(),
},
)
.await
.expect("switch network through MCP");

let switched = service.tool_ctx().await.expect("switched context");
assert!(
Arc::ptr_eq(&prompt, &switched.secret_prompt()),
"the MCP-swapped context must retain the source prompt host identity"
);
if let Ok(backend) = switched.wallet_backend() {
backend.shutdown().await;
}
}
}
13 changes: 13 additions & 0 deletions src/ui/identities/keys/key_info_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,18 @@ impl KeyInfoScreen {
}
}

/// Build a key-info screen with the add-protection confirmation already open.
pub fn new_with_protection_prompt(
identity: QualifiedIdentity,
key: IdentityPublicKey,
private_key_data: Option<(PrivateKeyData, Option<WalletDerivationPath>)>,
app_context: &Arc<AppContext>,
) -> Self {
let mut screen = Self::new(identity, key, private_key_data, app_context);
screen.open_add_confirm();
screen
Comment on lines +802 to +815

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🟡 Suggestion: Revalidation still opens the add flow for already-protected keys

new_with_protection_prompt's status recheck only special-cases IdentityProtectionStatus::NoVaultKeys; every other variant, including Protected, calls open_add_confirm(). If another GUI or MCP operation completes protection between the detail view's stale status probe and this constructor, the resulting screen reports protection as active while presenting an Add-protection confirmation. Submitting the existing password against that stale flow returns IdentityKeysProtected { count: 0 } and can rewrite the hint; a different password appears to fail as though a real migration were attempted. Match the enum exhaustively and only open the add flow for Unprotected or Mixed.

Suggested change
let mut screen = Self::new(identity, key, private_key_data, app_context);
let status = screen.compute_protection_status();
if status == IdentityProtectionStatus::NoVaultKeys {
screen.protection_stage = ProtectionStage::Idle;
MessageBanner::set_global(
app_context.egui_ctx(),
"Password protection is not available yet. Wait for wallet setup to finish, then try again.",
MessageType::Warning,
);
} else {
screen.protection_status = Some(status);
screen.open_add_confirm();
}
screen
let mut screen = Self::new(identity, key, private_key_data, app_context);
let status = screen.compute_protection_status();
screen.protection_status = Some(status);
match status {
IdentityProtectionStatus::NoVaultKeys => {
screen.protection_stage = ProtectionStage::Idle;
MessageBanner::set_global(
app_context.egui_ctx(),
"Password protection is not available yet. Wait for wallet setup to finish, then try again.",
MessageType::Warning,
);
}
IdentityProtectionStatus::Unprotected | IdentityProtectionStatus::Mixed => {
screen.open_add_confirm();
}
IdentityProtectionStatus::Protected => {}
}
screen

source: ['codex']

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Still valid at f223237. new_with_protection_prompt continues to special-case only NoVaultKeys; the else branch fires open_add_confirm() for Protected and Mixed alike. A key protected out-of-band between the detail view's probe and this constructor still lands the user in an Add-protection flow against already-sealed keys. Leaving this thread open — the exhaustive-match fix you proposed remains the right call.

🤖 Claudius the Magnificent

}

fn validate_and_store_private_key(&mut self) {
// Convert the input string to bytes (hex decoding)
let private_key_bytes = match hex::decode(self.private_key_input.text()) {
Expand Down Expand Up @@ -1099,6 +1111,7 @@ impl KeyInfoScreen {

egui::CollapsingHeader::new("Key Protection")
.default_open(false)
.open((self.protection_stage != ProtectionStage::Idle).then_some(true))
.show(ui, |ui| {
let status_text = match status {
IdentityProtectionStatus::Unprotected => {
Expand Down
22 changes: 21 additions & 1 deletion src/ui/masternodes/detail_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ impl MasternodeDetailView {
&& let Some((target, key)) = self.first_protectable_key()
&& ui.button("Add password protection…").clicked()
{
action = Some(self.open_key_info(target, &key));
action = Some(self.open_key_info_with_protection_prompt(target, &key));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM — this new routing makes the headline feature a silent no-op for multi-key masternodes

This line newly routes the "Add password protection…" CTA into open_key_info_with_protection_prompt, which selects its target via first_protectable_key (detail_screen.rs:686). Two independent reviewers flagged the same trap, and I'm afraid they're right.

first_protectable_key picks the first key whose held data is merely .is_some() — matching any PrivateKeyData variant (Clear, AlwaysClear, Encrypted, AtWalletDerivationPath, InVault). But KeyInfoScreen only draws the protection confirmation dialog inside the PrivateKeyData::InVault match arm (key_info_screen.rs:559-579). So when the selection lands on a non-InVault key, new_with_protection_prompt dutifully arms ConfirmAdd, the screen opens… and nothing renders. No dialog, no error, no next step — precisely the dead-end this PR set out to abolish.

It's reachable, not hypothetical: identity_keys() iterates in KeyID order, while the CTA visibility gate counts vault keys via view.scheme — divergent criteria. migrate_keystore_to_vault migrates only plaintext (Clear/AlwaysClear); AtWalletDerivationPath and legacy Encrypted keys are left untouched. An evonode/masternode identity holding a wallet-derived auth key (lower KeyID) alongside an InVault owner/voting key routes the CTA straight to the key the seal screen can't render.

The existing add_password_protection_opens_confirmation_dialog kittest seeds a single Clear key that migrates to InVault, so the selected key and the only vault key are trivially identical — it cannot catch this.

Fix: filter first_protectable_key to keys whose held PrivateKeyData is InVault (ideally also IdentityKeyView::scheme == Unprotected, mirroring the tier gate). Or make new_with_protection_prompt fail closed with a MessageBanner warning — as it already does for NoVaultKeys — when the routed key isn't InVault. Its doc comment ("the only keys that can be sealed") is also false for the non-vault variants. Please add a kittest seeding a wallet-derived/encrypted key at a lower KeyID than the Unprotected vault key so this stays buried.

🤖 Claudius the Magnificent — grumpy review, MEDIUM (CODE-001)

}
action
}
Expand Down Expand Up @@ -714,6 +714,26 @@ impl MasternodeDetailView {
)))
}

/// Open `KeyInfoScreen` directly in the add-protection confirmation flow.
fn open_key_info_with_protection_prompt(
&self,
target: PrivateKeyTarget,
key: &dash_sdk::platform::IdentityPublicKey,
) -> AppAction {
let holding = self
.identity
.private_keys
.get_cloned_private_key_data_and_wallet_info(&(target, key.id()));
AppAction::AddScreen(Screen::KeyInfoScreen(
KeyInfoScreen::new_with_protection_prompt(
self.identity.clone(),
key.clone(),
holding,
&self.app_context,
),
))
}

/// Render the collapsible DPNS voting section (collapsed by default,
/// open-contest count in the header). Inline voting reuses the existing
/// `vote_on_dpns_name` backend (locked decision #1 — not a deep-link).
Expand Down
4 changes: 4 additions & 0 deletions src/ui/masternodes/list_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,10 @@ impl ScreenLike for MasternodesScreen {
self.reconcile_pending_load();
}

fn reset_to_root_view(&mut self) {
self.view = MasternodesView::List;
}

/// Drop every secret the open view holds — the load form's keys and
/// encryption password, the detail view's unsubmitted voting key. This screen
/// is a root screen: it lives for the whole process, so nothing else would
Expand Down
7 changes: 7 additions & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,9 @@ pub trait ScreenLike {
self.refresh()
}

/// Reset a persistent root screen to the view selected by its navigation entry.
fn reset_to_root_view(&mut self) {}

/// Called by `AppState` when this root screen stops being the selected one.
///
/// The counterpart of [`refresh_on_arrival`](ScreenLike::refresh_on_arrival).
Expand Down Expand Up @@ -1087,6 +1090,10 @@ impl ScreenLike for Screen {
delegate_to_screen!(self, screen => screen.refresh_on_arrival())
}

fn reset_to_root_view(&mut self) {
delegate_to_screen!(self, screen => screen.reset_to_root_view())
}

fn on_leave(&mut self) {
delegate_to_screen!(self, screen => screen.on_leave())
}
Expand Down
Loading
Loading