- #4 ePIC miners report their firmware family as "UMC OS"; colour that row light blue in the Firmware column (was falling through to the theme default / black), matching the existing ePIC colour. - #5 Configure-pools dialog: widen the "+" buttons so the glyph shows; the dropdown "add" entry now reads "Add new"; user-added values can be removed via a "Remove saved value" submenu (pool_prefs::remove_saved); dropped the intro tidbit and narrowed the window. - #6 Restore-to-stock confirmation: the miner list is now a height-capped, scrollable text box instead of one unbounded label, so restoring hundreds at once stays usable. Removed the "Flash firmware..." right-click option for now (the in-app flash path is parked while it is reworked). - #7 Replaced the brain (control board) and fan Health icons with the new operator-supplied artwork, image-traced from PNG to SVG (potrace) and stripped of explicit fills so the Health column's per-state recolouring still applies. Headless selftest passes (fixtures render through the real widgets); all GUI unit tests pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Djv3oncM4LxTS5tb61Ako6
132 lines
4.8 KiB
Rust
132 lines
4.8 KiB
Rust
//! Dropdown presets + user-saved values for the Configure-pools dialog (round 15
|
|
//! #1). Each pool field (address / account / worker / password) has a "+" menu
|
|
//! offering built-in presets (pool stratums, worker placeholders) plus values the
|
|
//! user has saved, and the user can add the current box value to the saved list.
|
|
//! Saved lists persist one-per-line under the config dir.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
const CONFIG_DIR: &str = ".config/alkane-toolkit";
|
|
|
|
/// Which pool field a "+" menu belongs to.
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
pub enum PoolField {
|
|
Address,
|
|
Account,
|
|
Worker,
|
|
Password,
|
|
}
|
|
|
|
impl PoolField {
|
|
fn saved_file(self) -> &'static str {
|
|
match self {
|
|
PoolField::Address => "pool-addresses.txt",
|
|
PoolField::Account => "pool-accounts.txt",
|
|
PoolField::Worker => "pool-workers.txt",
|
|
PoolField::Password => "pool-passwords.txt",
|
|
}
|
|
}
|
|
|
|
/// Built-in presets offered before the user's saved values.
|
|
pub fn presets(self) -> Vec<&'static str> {
|
|
match self {
|
|
// Top Bitcoin pools by hashrate with their primary stratum endpoints
|
|
// (researched round 15; verify in-app before relying on any one).
|
|
PoolField::Address => POOL_STRATUMS.iter().map(|(_, u)| *u).collect(),
|
|
PoolField::Account => Vec::new(),
|
|
// Per-miner worker-name placeholders (see MinerRow::expand_worker_template).
|
|
PoolField::Worker => vec![
|
|
"{ip1}", "{ip2}", "{ip3}", "{ip4}", "{serial}", "{mac}", "{nameplate-hr}",
|
|
"{brand}", "{model}", "{submodel}", "{cpu}", "{cb}", "{firmware}", "{hostname}",
|
|
],
|
|
PoolField::Password => vec!["x"],
|
|
}
|
|
}
|
|
}
|
|
|
|
/// (pool name, primary stratum URL). Used for the address dropdown labels.
|
|
pub const POOL_STRATUMS: &[(&str, &str)] = &[
|
|
("Foundry USA", "stratum+tcp://btc.foundryusapool.com:3333"),
|
|
("AntPool", "stratum+tcp://ss.antpool.com:3333"),
|
|
("F2Pool", "stratum+tcp://btc.f2pool.com:1314"),
|
|
("ViaBTC", "stratum+tcp://btc.viabtc.io:3333"),
|
|
("SpiderPool", "stratum+tcp://btc-us.spiderpool.com:2309"),
|
|
("Binance Pool", "stratum+tcp://bs.poolbinance.com:3333"),
|
|
("Luxor", "stratum+tcp://btc.global.luxor.tech:700"),
|
|
("SBI Crypto", "stratum+tcp://us1.sbicrypto.com:3333"),
|
|
("Braiins Pool", "stratum+tcp://stratum.braiins.com:3333"),
|
|
("ULTIMUSPOOL", "stratum+tcp://bs.ultimuspool.com:8888"),
|
|
("SECPOOL", "stratum+tcp://btc.secpool.com:3333"),
|
|
];
|
|
|
|
fn config_path(file: &str) -> PathBuf {
|
|
let home = std::env::var("HOME").unwrap_or_else(|_| ".".into());
|
|
PathBuf::from(home).join(CONFIG_DIR).join(file)
|
|
}
|
|
|
|
/// The user's saved values for `field`, in save order (most recent last).
|
|
pub fn load_saved(field: PoolField) -> Vec<String> {
|
|
std::fs::read_to_string(config_path(field.saved_file()))
|
|
.ok()
|
|
.map(|s| s.lines().map(str::trim).filter(|l| !l.is_empty()).map(String::from).collect())
|
|
.unwrap_or_default()
|
|
}
|
|
|
|
/// Add `value` to `field`'s saved list (deduplicated, no-op if empty/already
|
|
/// present or already a preset). Returns true if it was newly added.
|
|
pub fn add_saved(field: PoolField, value: &str) -> bool {
|
|
let value = value.trim();
|
|
if value.is_empty() {
|
|
return false;
|
|
}
|
|
if field.presets().iter().any(|p| *p == value) {
|
|
return false;
|
|
}
|
|
let mut saved = load_saved(field);
|
|
if saved.iter().any(|s| s == value) {
|
|
return false;
|
|
}
|
|
saved.push(value.to_string());
|
|
let p = config_path(field.saved_file());
|
|
if let Some(dir) = p.parent() {
|
|
let _ = std::fs::create_dir_all(dir);
|
|
}
|
|
let _ = std::fs::write(p, saved.join("\n"));
|
|
true
|
|
}
|
|
|
|
/// Remove `value` from `field`'s saved list (round 16 #5). Returns true if it was
|
|
/// present and removed. Presets cannot be removed (they are not in the saved file).
|
|
pub fn remove_saved(field: PoolField, value: &str) -> bool {
|
|
let value = value.trim();
|
|
let mut saved = load_saved(field);
|
|
let before = saved.len();
|
|
saved.retain(|s| s != value);
|
|
if saved.len() == before {
|
|
return false;
|
|
}
|
|
let p = config_path(field.saved_file());
|
|
let _ = std::fs::write(p, saved.join("\n"));
|
|
true
|
|
}
|
|
|
|
/// The full dropdown list for a field: presets first, then the user's saved
|
|
/// values. For the address field each entry is labelled with the pool name.
|
|
pub fn dropdown_entries(field: PoolField) -> Vec<(String, String)> {
|
|
// (label, value)
|
|
let mut out: Vec<(String, String)> = Vec::new();
|
|
if field == PoolField::Address {
|
|
for (name, url) in POOL_STRATUMS {
|
|
out.push((format!("{name} -- {url}"), url.to_string()));
|
|
}
|
|
} else {
|
|
for p in field.presets() {
|
|
out.push((p.to_string(), p.to_string()));
|
|
}
|
|
}
|
|
for s in load_saved(field) {
|
|
out.push((s.clone(), s));
|
|
}
|
|
out
|
|
}
|