From 0af9eb54fdb5afe362c3165db9f190d72315fd9d Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 13 Jun 2025 12:54:43 +0700 Subject: [PATCH 1/3] ok --- src/app.rs | 16 +++++++++---- src/database/settings.rs | 39 ++++++++++++++++++++++++-------- src/ui/network_chooser_screen.rs | 7 ++++++ 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/app.rs b/src/app.rs index 4bdd7929a..f8cfc6e8b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -194,11 +194,19 @@ impl AppState { TokensScreen::new(&mainnet_app_context, TokensSubscreen::TokenCreator); let (custom_dash_qt_path, overwrite_dash_conf) = match settings.clone() { - Some((.., Some(db_custom_dash_qt_path), db_overwrite_dash_qt)) => { - (Some(db_custom_dash_qt_path), db_overwrite_dash_qt) + Some((.., custom_dash_qt_path, db_overwrite_dash_conf)) => { + // Use the stored settings, even if custom_dash_qt_path is None + let dash_qt_path = custom_dash_qt_path.or_else(|| { + // If no custom path is set, try to find dash-qt in PATH + which::which("dash-qt") + .map(|path| path.to_string_lossy().to_string()) + .inspect_err(|e| tracing::warn!("failed to find dash-qt: {}", e)) + .ok() + }); + (dash_qt_path, db_overwrite_dash_conf) } - _ => { - // Find `dash-qt` executable in the system PATH as default, and overwrite dash.conf + None => { + // Only use defaults if there are no settings at all let dash_qt = which::which("dash-qt") .map(|path| path.to_string_lossy().to_string()) .inspect_err(|e| tracing::warn!("failed to find dash-qt: {}", e)) diff --git a/src/database/settings.rs b/src/database/settings.rs index b4e301cc9..9c295a1f1 100644 --- a/src/database/settings.rs +++ b/src/database/settings.rs @@ -1,3 +1,4 @@ +use crate::database::initialization::DEFAULT_DB_VERSION; use crate::database::Database; use crate::model::password_info::PasswordInfo; use crate::ui::RootScreenType; @@ -16,12 +17,11 @@ impl Database { let screen_type_int = start_root_screen.to_int(); self.execute( "INSERT INTO settings (id, network, start_root_screen, database_version) - VALUES (1, ?, ?, 1) + VALUES (1, ?, ?, ?) ON CONFLICT(id) DO UPDATE SET network = excluded.network, - start_root_screen = excluded.start_root_screen, - database_version = excluded.database_version", - params![network_str, screen_type_int], + start_root_screen = excluded.start_root_screen", + params![network_str, screen_type_int, DEFAULT_DB_VERSION], )?; Ok(()) } @@ -62,15 +62,34 @@ impl Database { } pub fn add_custom_dash_qt_columns(&self, conn: &rusqlite::Connection) -> Result<()> { - conn.execute( - "ALTER TABLE settings ADD COLUMN custom_dash_qt_path TEXT DEFAULT NULL;", - (), + // Check if custom_dash_qt_path column exists + let custom_dash_qt_path_exists: bool = conn.query_row( + "SELECT COUNT(*) FROM pragma_table_info('settings') WHERE name='custom_dash_qt_path'", + [], + |row| row.get::<_, i32>(0).map(|count| count > 0), )?; - conn.execute( - "ALTER TABLE settings ADD COLUMN overwrite_dash_conf INTEGER DEFAULT NULL;", - (), + + if !custom_dash_qt_path_exists { + conn.execute( + "ALTER TABLE settings ADD COLUMN custom_dash_qt_path TEXT DEFAULT NULL;", + (), + )?; + } + + // Check if overwrite_dash_conf column exists + let overwrite_dash_conf_exists: bool = conn.query_row( + "SELECT COUNT(*) FROM pragma_table_info('settings') WHERE name='overwrite_dash_conf'", + [], + |row| row.get::<_, i32>(0).map(|count| count > 0), )?; + if !overwrite_dash_conf_exists { + conn.execute( + "ALTER TABLE settings ADD COLUMN overwrite_dash_conf INTEGER DEFAULT NULL;", + (), + )?; + } + Ok(()) } diff --git a/src/ui/network_chooser_screen.rs b/src/ui/network_chooser_screen.rs index e3470933f..92b8fca1b 100644 --- a/src/ui/network_chooser_screen.rs +++ b/src/ui/network_chooser_screen.rs @@ -589,6 +589,13 @@ impl ScreenLike for NetworkChooserScreen { // Reset collapsing states when arriving at this screen // This ensures dropdowns are closed when navigating back self.should_reset_collapsing_states = true; + + // Reload settings from database to ensure we have the latest values + if let Ok(Some((_, _, _, custom_dash_qt_path, overwrite_dash_conf))) = + self.current_app_context().get_settings() { + self.custom_dash_qt_path = custom_dash_qt_path; + self.overwrite_dash_conf = overwrite_dash_conf; + } } fn display_message(&mut self, message: &str, _message_type: super::MessageType) { From d5f36fc0bd94d7db85b7033618148ff094d58076 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 13 Jun 2025 12:58:14 +0700 Subject: [PATCH 2/3] fix --- src/database/settings.rs | 36 ++++++++---------------------------- 1 file changed, 8 insertions(+), 28 deletions(-) diff --git a/src/database/settings.rs b/src/database/settings.rs index 9c295a1f1..a388d006a 100644 --- a/src/database/settings.rs +++ b/src/database/settings.rs @@ -1,4 +1,3 @@ -use crate::database::initialization::DEFAULT_DB_VERSION; use crate::database::Database; use crate::model::password_info::PasswordInfo; use crate::ui::RootScreenType; @@ -17,11 +16,11 @@ impl Database { let screen_type_int = start_root_screen.to_int(); self.execute( "INSERT INTO settings (id, network, start_root_screen, database_version) - VALUES (1, ?, ?, ?) + VALUES (1, ?, ?, 1) ON CONFLICT(id) DO UPDATE SET network = excluded.network, start_root_screen = excluded.start_root_screen", - params![network_str, screen_type_int, DEFAULT_DB_VERSION], + params![network_str, screen_type_int], )?; Ok(()) } @@ -62,34 +61,15 @@ impl Database { } pub fn add_custom_dash_qt_columns(&self, conn: &rusqlite::Connection) -> Result<()> { - // Check if custom_dash_qt_path column exists - let custom_dash_qt_path_exists: bool = conn.query_row( - "SELECT COUNT(*) FROM pragma_table_info('settings') WHERE name='custom_dash_qt_path'", - [], - |row| row.get::<_, i32>(0).map(|count| count > 0), + conn.execute( + "ALTER TABLE settings ADD COLUMN custom_dash_qt_path TEXT DEFAULT NULL;", + (), )?; - - if !custom_dash_qt_path_exists { - conn.execute( - "ALTER TABLE settings ADD COLUMN custom_dash_qt_path TEXT DEFAULT NULL;", - (), - )?; - } - - // Check if overwrite_dash_conf column exists - let overwrite_dash_conf_exists: bool = conn.query_row( - "SELECT COUNT(*) FROM pragma_table_info('settings') WHERE name='overwrite_dash_conf'", - [], - |row| row.get::<_, i32>(0).map(|count| count > 0), + conn.execute( + "ALTER TABLE settings ADD COLUMN overwrite_dash_conf INTEGER DEFAULT NULL;", + (), )?; - if !overwrite_dash_conf_exists { - conn.execute( - "ALTER TABLE settings ADD COLUMN overwrite_dash_conf INTEGER DEFAULT NULL;", - (), - )?; - } - Ok(()) } From 67427730d8d312439aaf4b6d8e42fbe91650e749 Mon Sep 17 00:00:00 2001 From: pauldelucia Date: Fri, 13 Jun 2025 13:03:55 +0700 Subject: [PATCH 3/3] fmt --- src/backend_task/contract.rs | 17 +++++++++-------- .../qualified_identity_public_key.rs | 13 +++++++++---- src/ui/network_chooser_screen.rs | 7 ++++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/backend_task/contract.rs b/src/backend_task/contract.rs index 982993c33..cbc40eb5e 100644 --- a/src/backend_task/contract.rs +++ b/src/backend_task/contract.rs @@ -124,14 +124,15 @@ impl AppContext { token_infos.push(token_info); } - let contract_description_info = document_option.map(|document| ContractDescriptionInfo { - data_contract_id: contract.id(), - description: document - .get("description") - .and_then(|v| v.as_text()) - .unwrap_or_default() - .to_string(), - }); + let contract_description_info = + document_option.map(|document| ContractDescriptionInfo { + data_contract_id: contract.id(), + description: document + .get("description") + .and_then(|v| v.as_text()) + .unwrap_or_default() + .to_string(), + }); results.insert( contract.id(), diff --git a/src/model/qualified_identity/qualified_identity_public_key.rs b/src/model/qualified_identity/qualified_identity_public_key.rs index 6c6ff5276..c6d6193d3 100644 --- a/src/model/qualified_identity/qualified_identity_public_key.rs +++ b/src/model/qualified_identity/qualified_identity_public_key.rs @@ -50,8 +50,9 @@ impl QualifiedIdentityPublicKey { if value.data().len() == 20 { // This is actually a hash, treat it as ECDSA_HASH160 let hash160_data = value.data().as_slice(); - let pubkey_hash = PubkeyHash::from_slice(hash160_data) - .expect("Expected valid 20-byte pubkey hash for ECDSA_SECP256K1 with hash data"); + let pubkey_hash = PubkeyHash::from_slice(hash160_data).expect( + "Expected valid 20-byte pubkey hash for ECDSA_SECP256K1 with hash data", + ); let address = Address::new(network, Payload::PubkeyHash(pubkey_hash)); @@ -78,7 +79,9 @@ impl QualifiedIdentityPublicKey { } if let Some(testnet_address) = testnet_address.as_ref() { - if let Some(derivation_path) = wallet.known_addresses.get(testnet_address) { + if let Some(derivation_path) = + wallet.known_addresses.get(testnet_address) + { in_wallet_at_derivation_path = Some(WalletDerivationPath { wallet_seed_hash: wallet.seed_hash(), derivation_path: derivation_path.clone(), @@ -117,7 +120,9 @@ impl QualifiedIdentityPublicKey { } if let Some(testnet_address) = testnet_address.as_ref() { - if let Some(derivation_path) = wallet.known_addresses.get(testnet_address) { + if let Some(derivation_path) = + wallet.known_addresses.get(testnet_address) + { in_wallet_at_derivation_path = Some(WalletDerivationPath { wallet_seed_hash: wallet.seed_hash(), derivation_path: derivation_path.clone(), diff --git a/src/ui/network_chooser_screen.rs b/src/ui/network_chooser_screen.rs index 92b8fca1b..b9255fb3c 100644 --- a/src/ui/network_chooser_screen.rs +++ b/src/ui/network_chooser_screen.rs @@ -589,10 +589,11 @@ impl ScreenLike for NetworkChooserScreen { // Reset collapsing states when arriving at this screen // This ensures dropdowns are closed when navigating back self.should_reset_collapsing_states = true; - + // Reload settings from database to ensure we have the latest values - if let Ok(Some((_, _, _, custom_dash_qt_path, overwrite_dash_conf))) = - self.current_app_context().get_settings() { + if let Ok(Some((_, _, _, custom_dash_qt_path, overwrite_dash_conf))) = + self.current_app_context().get_settings() + { self.custom_dash_qt_path = custom_dash_qt_path; self.overwrite_dash_conf = overwrite_dash_conf; }