Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 32 additions & 4 deletions src/app_dir.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use directories::{ProjectDirs, UserDirs};
use dash_sdk::dpp::dashcore::Network;
use directories::ProjectDirs;
use std::fs;
use std::path::PathBuf;
use dash_sdk::dpp::dashcore::Network;

const QUALIFIER: &str = ""; // Typically empty on macOS and Linux
const ORGANIZATION: &str = "";
Expand Down Expand Up @@ -43,7 +43,10 @@ pub fn core_user_data_dir_path() -> Result<PathBuf, std::io::Error> {
}
}

pub fn core_cookie_path(network: Network, devnet_name: &Option<String>) -> Result<PathBuf, std::io::Error> {
pub fn core_cookie_path(
network: Network,
devnet_name: &Option<String>,
) -> Result<PathBuf, std::io::Error> {
core_user_data_dir_path().map(|path| {
let network_dir = match network {
Network::Dash => "",
Expand Down Expand Up @@ -87,13 +90,38 @@ pub fn copy_env_file_if_not_exists() {
app_user_data_dir_path().expect("Failed to determine application data directory");
let env_file_in_app_dir = app_data_dir.join(".env".to_string());
if !env_file_in_app_dir.exists() || !env_file_in_app_dir.is_file() {
// Get the directory where the executable is located
let exe_dir = std::env::current_exe()

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.

I think it would be better to embed the default .env file inside the binary. Looks like include_bytes! can do the job, but I didn't test this.

.ok()
.and_then(|path| path.parent().map(|p| p.to_path_buf()));

if let Some(exe_dir) = exe_dir {
let env_example_file_in_exe_dir = exe_dir.join(".env.example");
if env_example_file_in_exe_dir.exists() && env_example_file_in_exe_dir.is_file() {
fs::copy(&env_example_file_in_exe_dir, env_file_in_app_dir)
.expect("Failed to copy env file");
return;
}

let env_file_in_exe_dir = exe_dir.join(".env");
if env_file_in_exe_dir.exists() && env_file_in_exe_dir.is_file() {
fs::copy(&env_file_in_exe_dir, env_file_in_app_dir)
.expect("Failed to copy env file");
return;
}
}

// Fallback to current working directory
let env_example_file_in_exe_dir = PathBuf::from(".env.example");
if env_example_file_in_exe_dir.exists() && env_example_file_in_exe_dir.is_file() {
fs::copy(&env_example_file_in_exe_dir, env_file_in_app_dir)
.expect("Failed to copy env file");
} else {
let env_file_in_exe_dir = PathBuf::from(".env");
fs::copy(&env_file_in_exe_dir, env_file_in_app_dir).expect("Failed to copy env file");
if env_file_in_exe_dir.exists() && env_file_in_exe_dir.is_file() {
fs::copy(&env_file_in_exe_dir, env_file_in_app_dir)
.expect("Failed to copy env file");
}
}
}
}
6 changes: 4 additions & 2 deletions src/backend_task/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ impl AppContext {
let config = Config::load().map_err(|e| format!("Failed to load config: {}", e))?;

// Get chain locks
let mainnet_result =
Self::get_best_chain_lock(config.config_for_network(Network::Dash), Network::Dash);
let mainnet_result = Self::get_best_chain_lock(
config.config_for_network(Network::Dash),
Network::Dash,
);
let testnet_result = Self::get_best_chain_lock(
config.config_for_network(Network::Testnet),
Network::Testnet,
Expand Down
14 changes: 12 additions & 2 deletions src/backend_task/core/start_dash_qt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,18 @@ impl AppContext {

if overwrite_dash_conf {
// Construct the full path to the config file
let current_dir = env::current_dir()?;
let config_path = current_dir.join(config_file);
// Try to get the directory where the executable is located first
let config_path = if let Ok(exe_path) = env::current_exe() {
if let Some(exe_dir) = exe_path.parent() {
exe_dir.join(config_file)
} else {
// Fallback to current working directory
env::current_dir()?.join(config_file)
}
} else {
// Fallback to current working directory
env::current_dir()?.join(config_file)
};
command.arg(format!("-conf={}", config_path.display()));
} else if network == Network::Testnet {
command.arg("-testnet");
Expand Down
6 changes: 4 additions & 2 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ impl AppContext {
"http://{}:{}",
network_config.core_host, network_config.core_rpc_port
);
let cookie_path = core_cookie_path(network, &network_config.devnet_name).expect("expected to get cookie path");
let cookie_path = core_cookie_path(network, &network_config.devnet_name)
.expect("expected to get cookie path");

// Try cookie authentication first
let core_client = match Client::new(&addr, Auth::CookieFile(cookie_path.clone())) {
Expand All @@ -106,7 +107,8 @@ impl AppContext {
),
)
}
}.expect("Failed to create CoreClient");
}
.expect("Failed to create CoreClient");

let wallets: BTreeMap<_, _> = db
.get_wallets(&network)
Expand Down
12 changes: 6 additions & 6 deletions src/ui/identities/add_existing_identity_screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ impl AddExistingIdentityScreen {
.on_hover_text("Alias is optional. It is only used to help identify the identity in Dash Evo Tool. It isn't saved to Dash Platform.");
if response.clicked() {
self.show_pop_up_info = Some("Alias is optional. It is only used to help identify the identity in Dash Evo Tool. It isn't saved to Dash Platform.".to_string());
}
}
});
ui.text_edit_singleline(&mut self.alias_input);
ui.label("");
Expand Down Expand Up @@ -224,14 +224,14 @@ impl AddExistingIdentityScreen {
// First column: the label & info icon, combined horizontally
ui.horizontal(|ui| {
ui.label(format!("Private Key {} (Hex or WIF):", i + 1));

let info_icon = egui::Label::new("ℹ").sense(egui::Sense::click());
let response = ui
.add(info_icon)
.on_hover_text("You don't need to add all or even any private keys here. \
Private keys can be added later. However, without private keys, \
you won't be able to sign any transactions.");

if response.clicked() {
self.show_pop_up_info = Some(
"You don't need to add all or even any private keys here. \
Expand All @@ -244,15 +244,15 @@ impl AddExistingIdentityScreen {

// Second column: the text field
ui.text_edit_singleline(key);

// Third column: the remove button
if ui.button("-").clicked() {
keys_to_remove.push(i);
}

ui.end_row();
}

// Remove the keys after the loop to avoid borrowing conflicts
for i in keys_to_remove.iter().rev() {
self.keys_input.remove(*i);
Expand Down