Explorar el Código

app/wallet: add scan progress next to blockchain indicator

darkfi hace 3 días
padre
commit
cc4d600367

+ 6 - 0
bin/app/src/app/schema/wallet/data.rs

@@ -61,6 +61,9 @@ mod android_ui_consts {
     pub const SETTINGS_ICON_SIZE: f32 = 140.;
     pub const SETTINGS_ICON_SIZE: f32 = 140.;
     pub const NETLOGO_SCALE: f32 = 7.;
     pub const NETLOGO_SCALE: f32 = 7.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 120.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 120.;
+
+    pub const PROGRESS_FONTSIZE: f32 = 36.;
+    pub const PROGRESS_MARGIN: f32 = 10.;
 }
 }
 
 
 #[cfg(target_os = "android")]
 #[cfg(target_os = "android")]
@@ -117,6 +120,9 @@ mod ui_consts {
     pub const SETTINGS_ICON_SIZE: f32 = 60.;
     pub const SETTINGS_ICON_SIZE: f32 = 60.;
     pub const NETLOGO_SCALE: f32 = 3.5;
     pub const NETLOGO_SCALE: f32 = 3.5;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 50.;
     pub const EMOJI_PICKER_ICON_SIZE: f32 = 50.;
+
+    pub const PROGRESS_FONTSIZE: f32 = 14.;
+    pub const PROGRESS_MARGIN: f32 = 5.;
 }
 }
 
 
 pub use ui_consts::*;
 pub use ui_consts::*;

+ 49 - 11
bin/app/src/app/schema/wallet/netstatus.rs

@@ -18,9 +18,12 @@
 
 
 use crate::{
 use crate::{
     app::{
     app::{
+        node::create_text,
         schema::{
         schema::{
             create_layer, create_vector_art,
             create_layer, create_vector_art,
-            wallet::data::{NETLOGO_SCALE, NETSTATUS_ICON_SIZE},
+            wallet::data::{
+                NETLOGO_SCALE, NETSTATUS_ICON_SIZE, PROGRESS_FONTSIZE, PROGRESS_MARGIN,
+            },
         },
         },
         App,
         App,
     },
     },
@@ -28,27 +31,28 @@ use crate::{
     prop::{PropertyAtomicGuard, PropertyFloat32, Role},
     prop::{PropertyAtomicGuard, PropertyFloat32, Role},
     scene::SceneNodePtr,
     scene::SceneNodePtr,
     shape,
     shape,
-    ui::{Layer, VectorArt},
+    ui::{Layer, Text, VectorArt},
     util::i18n::I18nBabelFish,
     util::i18n::I18nBabelFish,
 };
 };
 
 
 pub async fn make(
 pub async fn make(
     app: &App,
     app: &App,
     wallet_layer: SceneNodePtr,
     wallet_layer: SceneNodePtr,
-    _i18n_fish: &I18nBabelFish,
-    _window_scale: PropertyFloat32,
+    i18n_fish: &I18nBabelFish,
+    window_scale: PropertyFloat32,
 ) -> SceneNodePtr {
 ) -> SceneNodePtr {
     let atom = &mut PropertyAtomicGuard::none();
     let atom = &mut PropertyAtomicGuard::none();
 
 
     let mut cc = expr::Compiler::new();
     let mut cc = expr::Compiler::new();
     cc.add_const_f32("NETSTATUS_ICON_SIZE", NETSTATUS_ICON_SIZE);
     cc.add_const_f32("NETSTATUS_ICON_SIZE", NETSTATUS_ICON_SIZE);
+    cc.add_const_f32("PROGRESS_MARGIN", PROGRESS_MARGIN);
 
 
     let netlayer_node = create_layer("netstatus_layer");
     let netlayer_node = create_layer("netstatus_layer");
     let prop = netlayer_node.get_property("rect").unwrap();
     let prop = netlayer_node.get_property("rect").unwrap();
-    let code = cc.compile("w - NETSTATUS_ICON_SIZE").unwrap();
-    prop.set_expr(atom, Role::App, 0, code).unwrap();
+    prop.set_f32(atom, Role::App, 0, 0.).unwrap();
     prop.set_f32(atom, Role::App, 1, 0.).unwrap();
     prop.set_f32(atom, Role::App, 1, 0.).unwrap();
-    prop.set_f32(atom, Role::App, 2, 1000.).unwrap();
+    let code = cc.compile("w").unwrap();
+    prop.set_expr(atom, Role::App, 2, code).unwrap();
     prop.set_f32(atom, Role::App, 3, 1000.).unwrap();
     prop.set_f32(atom, Role::App, 3, 1000.).unwrap();
     netlayer_node.set_property_bool(atom, Role::App, "is_visible", true).unwrap();
     netlayer_node.set_property_bool(atom, Role::App, "is_visible", true).unwrap();
     netlayer_node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
     netlayer_node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
@@ -57,9 +61,40 @@ pub async fn make(
         .await;
         .await;
     wallet_layer.link(netlayer_node.clone());
     wallet_layer.link(netlayer_node.clone());
 
 
+    // Scan progress text
+    let node = create_text("progress");
+    let prop = node.get_property("rect").unwrap();
+    prop.set_f32(atom, Role::App, 0, 0.).unwrap();
+    prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2. - PROGRESS_FONTSIZE / 2.).unwrap();
+    let code = cc.compile("w - NETSTATUS_ICON_SIZE - PROGRESS_MARGIN").unwrap();
+    prop.set_expr(atom, Role::App, 2, code).unwrap();
+    prop.set_f32(atom, Role::App, 3, PROGRESS_FONTSIZE).unwrap();
+    node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
+    node.set_property_f32(atom, Role::App, "font_size", PROGRESS_FONTSIZE).unwrap();
+    node.set_property_enum(atom, Role::App, "text_align", "end").unwrap();
+    let prop = node.get_property("text_color").unwrap();
+    prop.set_f32(atom, Role::App, 0, 1.).unwrap();
+    prop.set_f32(atom, Role::App, 1, 1.).unwrap();
+    prop.set_f32(atom, Role::App, 2, 1.).unwrap();
+    prop.set_f32(atom, Role::App, 3, 1.).unwrap();
+    node.set_property_u32(atom, Role::App, "z_index", 3).unwrap();
+    let node = node
+        .setup(|me| {
+            Text::new(
+                me,
+                window_scale.clone(),
+                app.renderer.clone(),
+                i18n_fish.clone(),
+                app.redraw_trigger.clone(),
+            )
+        })
+        .await;
+    netlayer_node.link(node);
+
     let node = create_vector_art("net0");
     let node = create_vector_art("net0");
     let prop = node.get_property("rect").unwrap();
     let prop = node.get_property("rect").unwrap();
-    prop.set_f32(atom, Role::App, 0, NETSTATUS_ICON_SIZE / 2.).unwrap();
+    let code = cc.compile("w - NETSTATUS_ICON_SIZE / 2").unwrap();
+    prop.set_expr(atom, Role::App, 0, code).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
@@ -77,7 +112,8 @@ pub async fn make(
 
 
     let node = create_vector_art("net1");
     let node = create_vector_art("net1");
     let prop = node.get_property("rect").unwrap();
     let prop = node.get_property("rect").unwrap();
-    prop.set_f32(atom, Role::App, 0, NETSTATUS_ICON_SIZE / 2.).unwrap();
+    let code = cc.compile("w - NETSTATUS_ICON_SIZE / 2").unwrap();
+    prop.set_expr(atom, Role::App, 0, code).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
@@ -95,7 +131,8 @@ pub async fn make(
 
 
     let node = create_vector_art("net2");
     let node = create_vector_art("net2");
     let prop = node.get_property("rect").unwrap();
     let prop = node.get_property("rect").unwrap();
-    prop.set_f32(atom, Role::App, 0, NETSTATUS_ICON_SIZE / 2.).unwrap();
+    let code = cc.compile("w - NETSTATUS_ICON_SIZE / 2").unwrap();
+    prop.set_expr(atom, Role::App, 0, code).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
@@ -113,7 +150,8 @@ pub async fn make(
 
 
     let node = create_vector_art("net3");
     let node = create_vector_art("net3");
     let prop = node.get_property("rect").unwrap();
     let prop = node.get_property("rect").unwrap();
-    prop.set_f32(atom, Role::App, 0, NETSTATUS_ICON_SIZE / 2.).unwrap();
+    let code = cc.compile("w - NETSTATUS_ICON_SIZE / 2").unwrap();
+    prop.set_expr(atom, Role::App, 0, code).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_f32(atom, Role::App, 1, NETSTATUS_ICON_SIZE / 2.).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 2, expr::load_var("w")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();
     prop.set_expr(atom, Role::App, 3, expr::load_var("h")).unwrap();

+ 7 - 1
bin/app/src/main.rs

@@ -473,9 +473,15 @@ async fn load_plugins(
             let net3_is_visible = PropertyBool::wrap(&net3, Role::App, "is_visible", 0).unwrap();
             let net3_is_visible = PropertyBool::wrap(&net3, Role::App, "is_visible", 0).unwrap();
 
 
             while let Ok(data) = recvr.recv().await {
             while let Ok(data) = recvr.recv().await {
-                let status: u8 = deserialize(&data).unwrap();
+                let (status, desc): (u8, String) = deserialize(&data).unwrap();
                 let atom = &mut redraw2.make_guard(gfxtag!("blockchain netstatus change"));
                 let atom = &mut redraw2.make_guard(gfxtag!("blockchain netstatus change"));
 
 
+                if let Some(progress_node) =
+                    sg_root2.lookup_node("/window/content/wallet/netstatus_layer/progress")
+                {
+                    progress_node.set_property_str(atom, Role::App, "text", &desc).unwrap();
+                }
+
                 match status {
                 match status {
                     1 => {
                     1 => {
                         net0_is_visible.set(atom, false);
                         net0_is_visible.set(atom, false);

+ 35 - 7
bin/app/src/plugin/drk.rs

@@ -704,9 +704,17 @@ impl DrkPlugin {
                     }
                     }
                 };
                 };
                 let status: u8 = if progress > 0.5 { 2 } else { 1 };
                 let status: u8 = if progress > 0.5 { 2 } else { 1 };
-                if let Some(node) = self2.node.upgrade() {
-                    let _ = node.trigger("connect", serialize(&status)).await;
-                }
+                let Some(node) = self2.node.upgrade() else { continue };
+                let start_height = first_height.unwrap();
+                let blocks_scanned = height - start_height;
+                let total_blocks = final_height - start_height;
+                let percentage = if total_blocks > 0 {
+                    (blocks_scanned as f32 / total_blocks as f32 * 100.0) as u32
+                } else {
+                    0
+                };
+                let desc = format!("{}/{} [{}%]", blocks_scanned, total_blocks, percentage);
+                let _ = node.trigger("connect", serialize(&(status, desc))).await;
             }
             }
         });
         });
 
 
@@ -723,7 +731,12 @@ impl DrkPlugin {
                 let ex = ex_.clone();
                 let ex = ex_.clone();
                 let progress_pub = self2.scan_progress_pub.clone();
                 let progress_pub = self2.scan_progress_pub.clone();
 
 
-                let _ = self2.node.upgrade().unwrap().trigger("connect", serialize(&0u8)).await;
+                let _ = self2
+                    .node
+                    .upgrade()
+                    .unwrap()
+                    .trigger("connect", serialize(&(0u8, String::new())))
+                    .await;
 
 
                 if let Err(e) = drk
                 if let Err(e) = drk
                     .read()
                     .read()
@@ -732,7 +745,12 @@ impl DrkPlugin {
                     .await
                     .await
                 {
                 {
                     e!("Failed during drk scanning: {e}");
                     e!("Failed during drk scanning: {e}");
-                    let _ = self2.node.upgrade().unwrap().trigger("connect", serialize(&0u8)).await;
+                    let _ = self2
+                        .node
+                        .upgrade()
+                        .unwrap()
+                        .trigger("connect", serialize(&(0u8, String::new())))
+                        .await;
 
 
                     // Wait before retrying
                     // Wait before retrying
                     i!("Retrying connection to darkfid in {} seconds...", DARKFID_RETRY_TIME);
                     i!("Retrying connection to darkfid in {} seconds...", DARKFID_RETRY_TIME);
@@ -740,7 +758,12 @@ impl DrkPlugin {
                     continue
                     continue
                 }
                 }
 
 
-                let _ = self2.node.upgrade().unwrap().trigger("connect", serialize(&3u8)).await;
+                let _ = self2
+                    .node
+                    .upgrade()
+                    .unwrap()
+                    .trigger("connect", serialize(&(3u8, String::new())))
+                    .await;
 
 
                 self2.emit_balances_updated().await;
                 self2.emit_balances_updated().await;
 
 
@@ -761,7 +784,12 @@ impl DrkPlugin {
                     }
                     }
                 }
                 }
 
 
-                let _ = self2.node.upgrade().unwrap().trigger("connect", serialize(&0u8)).await;
+                let _ = self2
+                    .node
+                    .upgrade()
+                    .unwrap()
+                    .trigger("connect", serialize(&(0u8, String::new())))
+                    .await;
 
 
                 // Wait before retrying
                 // Wait before retrying
                 i!("Retrying connection to darkfid in {} seconds...", DARKFID_RETRY_TIME);
                 i!("Retrying connection to darkfid in {} seconds...", DARKFID_RETRY_TIME);