mirror of
https://code.gri.mw/GUI/grim.git
synced 2026-07-17 20:28:55 +00:00
Build 19: open-wallet shortcuts, Pay QR scan, configurable pairing, hide yellow
- Lower-left sidebar cards are now individual shortcuts: tapping the identity chip opens identity settings, tapping the node card jumps straight to the Node menu (was: both opened generic settings). - Pay screen gains a scan-to-pay QR puck top-right that opens the camera and prefills the recipient while keeping the typed amount (reuses the Home scan + SendFlow::request_scan/prefill_amount path). - Replace the USD-only "fiat preview" with a configurable "Pairing": Off / USD / EUR / GBP / JPY / CNY / Bitcoin / Sats (default USD). price.rs now fetches GRIN against any vs_currency (sats price vs btc, ×1e8) and caches per code; a Settings → Pairing sub-page picks it; the Pay, send, and balance previews all route through one pairing_preview() helper. - Hide the Yellow theme from the picker (cycle is Dark ↔ Light now); the ThemeKind::Yellow tokens stay defined — it's beta, not removed. Verified live on :2 (Default wallet): node card → Node menu; identity chip → identity settings; QR puck renders top-right of Pay; Pairing → Sats shows "≈ 1,912 sats" for 50ツ over a live BTC rate, resets to USD; theme cycles Dark↔Light, never Yellow. 34 lib tests green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
+98
-8
@@ -75,8 +75,10 @@ pub struct AppConfig {
|
||||
density: Option<String>,
|
||||
/// Identifier of the last opened wallet to boot into.
|
||||
last_wallet_id: Option<i64>,
|
||||
/// Show fiat (USD) preview alongside amounts.
|
||||
/// Show fiat (USD) preview alongside amounts (legacy; migrated to pairing).
|
||||
fiat_preview: Option<bool>,
|
||||
/// Amount pairing code: off|usd|eur|gbp|jpy|cny|btc|sats (default usd).
|
||||
pairing: Option<String>,
|
||||
|
||||
/// Flag to use proxy for network requests.
|
||||
use_proxy: Option<bool>,
|
||||
@@ -93,6 +95,85 @@ pub struct AppConfig {
|
||||
app_update: Option<AppUpdate>,
|
||||
}
|
||||
|
||||
/// What the amount preview is paired to: nothing, a fiat currency, or bitcoin.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Pairing {
|
||||
Off,
|
||||
Usd,
|
||||
Eur,
|
||||
Gbp,
|
||||
Jpy,
|
||||
Cny,
|
||||
Btc,
|
||||
Sats,
|
||||
}
|
||||
|
||||
impl Pairing {
|
||||
/// All variants, in picker order.
|
||||
pub const ALL: [Pairing; 8] = [
|
||||
Pairing::Off,
|
||||
Pairing::Usd,
|
||||
Pairing::Eur,
|
||||
Pairing::Gbp,
|
||||
Pairing::Jpy,
|
||||
Pairing::Cny,
|
||||
Pairing::Btc,
|
||||
Pairing::Sats,
|
||||
];
|
||||
|
||||
/// Stable config code.
|
||||
pub fn code(&self) -> &'static str {
|
||||
match self {
|
||||
Pairing::Off => "off",
|
||||
Pairing::Usd => "usd",
|
||||
Pairing::Eur => "eur",
|
||||
Pairing::Gbp => "gbp",
|
||||
Pairing::Jpy => "jpy",
|
||||
Pairing::Cny => "cny",
|
||||
Pairing::Btc => "btc",
|
||||
Pairing::Sats => "sats",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn from_code(s: &str) -> Option<Pairing> {
|
||||
Some(match s {
|
||||
"off" => Pairing::Off,
|
||||
"usd" => Pairing::Usd,
|
||||
"eur" => Pairing::Eur,
|
||||
"gbp" => Pairing::Gbp,
|
||||
"jpy" => Pairing::Jpy,
|
||||
"cny" => Pairing::Cny,
|
||||
"btc" => Pairing::Btc,
|
||||
"sats" => Pairing::Sats,
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The CoinGecko `vs_currency` to price against (sats prices vs btc).
|
||||
/// `None` when pairing is off.
|
||||
pub fn vs_currency(&self) -> Option<&'static str> {
|
||||
match self {
|
||||
Pairing::Off => None,
|
||||
Pairing::Sats => Some("btc"),
|
||||
other => Some(other.code()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Human label for the picker / settings row.
|
||||
pub fn label(&self) -> &'static str {
|
||||
match self {
|
||||
Pairing::Off => "Off",
|
||||
Pairing::Usd => "USD",
|
||||
Pairing::Eur => "EUR",
|
||||
Pairing::Gbp => "GBP",
|
||||
Pairing::Jpy => "JPY",
|
||||
Pairing::Cny => "CNY",
|
||||
Pairing::Btc => "Bitcoin",
|
||||
Pairing::Sats => "Sats",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
@@ -112,6 +193,7 @@ impl Default for AppConfig {
|
||||
density: None,
|
||||
last_wallet_id: None,
|
||||
fiat_preview: None,
|
||||
pairing: None,
|
||||
use_proxy: None,
|
||||
use_socks_proxy: None,
|
||||
http_proxy_url: None,
|
||||
@@ -363,17 +445,25 @@ impl AppConfig {
|
||||
w_config.save();
|
||||
}
|
||||
|
||||
/// Check if fiat (USD) preview is enabled (default on).
|
||||
pub fn fiat_preview() -> bool {
|
||||
/// What amount previews are paired to (default USD). Migrates the legacy
|
||||
/// `fiat_preview = false` to `Off`.
|
||||
pub fn pairing() -> Pairing {
|
||||
let r_config = Settings::app_config_to_read();
|
||||
r_config.fiat_preview.unwrap_or(true)
|
||||
if let Some(code) = r_config.pairing.clone() {
|
||||
if let Some(p) = Pairing::from_code(&code) {
|
||||
return p;
|
||||
}
|
||||
}
|
||||
match r_config.fiat_preview {
|
||||
Some(false) => Pairing::Off,
|
||||
_ => Pairing::Usd,
|
||||
}
|
||||
}
|
||||
|
||||
/// Toggle fiat preview.
|
||||
pub fn toggle_fiat_preview() {
|
||||
let enabled = Self::fiat_preview();
|
||||
/// Save the amount pairing.
|
||||
pub fn set_pairing(p: Pairing) {
|
||||
let mut w_config = Settings::app_config_to_update();
|
||||
w_config.fiat_preview = Some(!enabled);
|
||||
w_config.pairing = Some(p.code().to_string());
|
||||
w_config.save();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user