Przeglądaj źródła

app/wallet: format displayed addresses as "abcd efgh...wxyz 1234"

x 2 tygodni temu
rodzic
commit
63216dbb0a

+ 1 - 1
bin/app/src/app/schema/wallet/send_step2.rs

@@ -410,7 +410,7 @@ pub async fn make(
             }
             if let Some(recipient_str) = &data.recipient_str {
                 let recipient_node = sg_root.lookup_node("/window/content/wallet/send_step3_layer/send_recipient_value3").unwrap();
-                recipient_node.set_property_str(atom, Role::App, "text", recipient_str).unwrap();
+                recipient_node.set_property_str(atom, Role::App, "text", format_address(recipient_str)).unwrap();
             }
 
             // Reset error message when transitioning from step2 to step3

+ 1 - 1
bin/app/src/app/schema/wallet/send_step3.rs

@@ -576,7 +576,7 @@ pub async fn make(
                     amount_token_node.set_property_str(atom, Role::App, "text", &token_symbol).unwrap();
                 }
                 if let Some(recipient_node) = sg_root.lookup_node("/window/content/wallet/send_step4_layer/send_recipient_value4") {
-                    recipient_node.set_property_str(atom, Role::App, "text", &recipient_str).unwrap();
+                    recipient_node.set_property_str(atom, Role::App, "text", format_address(&recipient_str)).unwrap();
                 }
                 if let Some(amount_node) = sg_root.lookup_node("/window/content/wallet/send_step4_layer/send_amount_wrapper4/send_amount_text4") {
                     amount_node.set_property_str(atom, Role::App, "text", &amount).unwrap();

+ 16 - 0
bin/app/src/app/schema/wallet/util.rs

@@ -40,6 +40,22 @@ use crate::{
 
 use super::data::*;
 
+/// Format an address for display: first 8 and last 8 chars, space-grouped
+/// in pairs of 4, e.g. "abcd efgh...wxyz 1234".
+pub fn format_address(addr: &str) -> String {
+    let chars: Vec<char> = addr.chars().collect();
+    if chars.len() <= 16 {
+        return addr.to_string()
+    }
+    let group = |c: &[char]| -> String {
+        let s: String = c.iter().collect();
+        format!("{} {}", &s[..4], &s[4..])
+    };
+    let head = group(&chars[..8]);
+    let tail = group(&chars[chars.len() - 8..]);
+    format!("{head}...{tail}")
+}
+
 pub async fn get_balance(sg_root: &SceneNodePtr, token_id: &TokenId) -> u64 {
     let Some(drk_node) = sg_root.lookup_node("/plugin/drk") else { return 0 };
     let Ok(Some(response_data)) = drk_node.call_method("get_balances", vec![]).await else {