chore: Added styles to printing f8a03dba
stevedylandev · 2025-07-07 23:59 3 file(s) · +139 −9
Cargo.lock +78 −0
180 180
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
181 181
182 182
[[package]]
183 +
name = "colored"
184 +
version = "2.2.0"
185 +
source = "registry+https://github.com/rust-lang/crates.io-index"
186 +
checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c"
187 +
dependencies = [
188 +
 "lazy_static",
189 +
 "windows-sys 0.59.0",
190 +
]
191 +
192 +
[[package]]
193 +
name = "console"
194 +
version = "0.15.11"
195 +
source = "registry+https://github.com/rust-lang/crates.io-index"
196 +
checksum = "054ccb5b10f9f2cbf51eb355ca1d05c2d279ce1804688d0db74b4733a5aeafd8"
197 +
dependencies = [
198 +
 "encode_unicode",
199 +
 "libc",
200 +
 "once_cell",
201 +
 "unicode-width",
202 +
 "windows-sys 0.59.0",
203 +
]
204 +
205 +
[[package]]
183 206
name = "core-foundation"
184 207
version = "0.9.4"
185 208
source = "registry+https://github.com/rust-lang/crates.io-index"
226 249
 "quote",
227 250
 "syn",
228 251
]
252 +
253 +
[[package]]
254 +
name = "encode_unicode"
255 +
version = "1.0.0"
256 +
source = "registry+https://github.com/rust-lang/crates.io-index"
257 +
checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0"
229 258
230 259
[[package]]
231 260
name = "encoding_rs"
626 655
]
627 656
628 657
[[package]]
658 +
name = "indicatif"
659 +
version = "0.17.11"
660 +
source = "registry+https://github.com/rust-lang/crates.io-index"
661 +
checksum = "183b3088984b400f4cfac3620d5e076c84da5364016b4f49473de574b2586235"
662 +
dependencies = [
663 +
 "console",
664 +
 "number_prefix",
665 +
 "portable-atomic",
666 +
 "unicode-width",
667 +
 "web-time",
668 +
]
669 +
670 +
[[package]]
629 671
name = "io-uring"
630 672
version = "0.7.8"
631 673
source = "registry+https://github.com/rust-lang/crates.io-index"
663 705
 "once_cell",
664 706
 "wasm-bindgen",
665 707
]
708 +
709 +
[[package]]
710 +
name = "lazy_static"
711 +
version = "1.5.0"
712 +
source = "registry+https://github.com/rust-lang/crates.io-index"
713 +
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
666 714
667 715
[[package]]
668 716
name = "libc"
758 806
]
759 807
760 808
[[package]]
809 +
name = "number_prefix"
810 +
version = "0.4.0"
811 +
source = "registry+https://github.com/rust-lang/crates.io-index"
812 +
checksum = "830b246a0e5f20af87141b25c173cd1b609bd7779a4617d6ec582abaf90870f3"
813 +
814 +
[[package]]
761 815
name = "object"
762 816
version = "0.36.7"
763 817
source = "registry+https://github.com/rust-lang/crates.io-index"
874 928
version = "0.3.32"
875 929
source = "registry+https://github.com/rust-lang/crates.io-index"
876 930
checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
931 +
932 +
[[package]]
933 +
name = "portable-atomic"
934 +
version = "1.11.1"
935 +
source = "registry+https://github.com/rust-lang/crates.io-index"
936 +
checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483"
877 937
878 938
[[package]]
879 939
name = "potential_utf"
1373 1433
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
1374 1434
1375 1435
[[package]]
1436 +
name = "unicode-width"
1437 +
version = "0.2.1"
1438 +
source = "registry+https://github.com/rust-lang/crates.io-index"
1439 +
checksum = "4a1a07cc7db3810833284e8d372ccdc6da29741639ecc70c9ec107df0fa6154c"
1440 +
1441 +
[[package]]
1376 1442
name = "url"
1377 1443
version = "2.5.4"
1378 1444
source = "registry+https://github.com/rust-lang/crates.io-index"
1406 1472
version = "0.0.1"
1407 1473
dependencies = [
1408 1474
 "clap",
1475 +
 "colored",
1409 1476
 "dirs",
1410 1477
 "futures",
1478 +
 "indicatif",
1411 1479
 "reqwest",
1412 1480
 "serde",
1413 1481
 "serde_json",
1515 1583
version = "0.3.77"
1516 1584
source = "registry+https://github.com/rust-lang/crates.io-index"
1517 1585
checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2"
1586 +
dependencies = [
1587 +
 "js-sys",
1588 +
 "wasm-bindgen",
1589 +
]
1590 +
1591 +
[[package]]
1592 +
name = "web-time"
1593 +
version = "1.1.0"
1594 +
source = "registry+https://github.com/rust-lang/crates.io-index"
1595 +
checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb"
1518 1596
dependencies = [
1519 1597
 "js-sys",
1520 1598
 "wasm-bindgen",
Cargo.toml +2 −0
12 12
futures = "0.3"
13 13
toml = "0.8"
14 14
dirs = "5.0"
15 +
indicatif = "0.17"
16 +
colored = "2.0"
src/main.rs +59 −9
7 7
use tokio::task::JoinHandle;
8 8
use toml;
9 9
use dirs;
10 +
use indicatif::{ProgressBar, ProgressStyle};
11 +
use colored::*;
10 12
11 13
#[derive(Serialize)]
12 14
struct JsonRpcRequest {
18 20
19 21
#[derive(Deserialize)]
20 22
struct JsonRpcResponse {
21 -
  // id: u32,
22 -
  // jsoonrpc: String,
23 23
  result: String,
24 24
}
25 25
66 66
}
67 67
68 68
enum BalanceResult {
69 -
  Native(f64, String), // Just balance and network_name
69 +
  Native(f64, String),
70 70
  Token(TokenBalance),
71 71
}
72 72
205 205
  Err(format!("Failed to parse balance for token {} on network {}", token.symbol, network.name).into())
206 206
}
207 207
208 +
fn get_eth_logo() -> &'static str {
209 +
r#"    --------------4%--------------
210 +
    -------------44HH-------------
211 +
    ------------444HHH------------
212 +
    -----------4444HHHH-----------
213 +
    ---------~44444HHHHH~---------
214 +
    --------4444444HHHHHHW--------
215 +
    -------4444HHHHWWWWHHHH-------
216 +
    ------KHHHHHHHHWWWWWWWWW------
217 +
    ---------HHHHHHWWWWWW---------
218 +
    -------44---HHHWWW---HH-------
219 +
    --------~444?----4HHH~--------
220 +
    ----------44444HHHHH----------
221 +
    -----------L444HHHq-----------
222 +
    -------------44HH-------------
223 +
    --------------4H--------------"#
224 +
}
225 +
208 226
async fn fetch_all_balances(
209 227
  address: &str,
210 228
  networks: HashMap<u64, Network>
212 230
  let client = Client::new();
213 231
214 232
  let mut tasks: Vec<JoinHandle<Result<BalanceResult, Box<dyn Error + Send + Sync>>>> = Vec::new();
233 +
234 +
  let spinner = ProgressBar::new_spinner();
235 +
  spinner.set_style(
236 +
      ProgressStyle::default_spinner()
237 +
          .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ ")
238 +
          .template("{spinner:.green} {msg}")
239 +
          .unwrap()
240 +
  );
241 +
  spinner.set_message("Fetching balances...");
215 242
216 243
  for (_, network) in &networks {
217 244
    let client_clone = client.clone();
242 269
243 270
  let results = join_all(tasks).await;
244 271
272 +
  spinner.finish_and_clear();
273 +
245 274
  let mut balances = Vec::new();
246 275
  for result in results {
247 276
    match result {
297 326
    if balances.is_empty(){
298 327
      println!("No balances found for address {}", address);
299 328
    } else {
300 -
      println!("Balances for {}", address);
301 -
      println!("------------------------");
302 -
303 329
      let mut network_balances: HashMap<String, Vec<String>> = HashMap::new();
304 330
305 331
      for balance in balances {
315 341
        }
316 342
      }
317 343
344 +
      let logo = get_eth_logo();
345 +
      let logo_lines: Vec<&str> = logo.lines().collect();
346 +
      let logo_height = logo_lines.len();
347 +
348 +
      println!();
349 +
      let address_display = format!("{}", address.bright_green());
350 +
      println!("{}", format!("Wallet: {}", address_display).bright_cyan());
351 +
      println!("{}", "=".repeat(50).bright_blue());
352 +
353 +
      let mut info_lines = Vec::new();
354 +
318 355
      for (network, balances) in network_balances {
319 -
        println!("Network: {}", network);
356 +
        if !info_lines.is_empty() {
357 +
          info_lines.push("".to_string());
358 +
        }
359 +
        info_lines.push(format!("{}: ", network.bright_yellow()));
320 360
        for balance in balances {
321 -
          println!(" {}", balance);
361 +
          info_lines.push(format!("  {} {}", "•".bright_green(), balance.bright_white()));
322 362
        }
323 -
        println!();
324 363
      }
364 +
365 +
      let display_lines = std::cmp::max(logo_height, info_lines.len());
366 +
367 +
      for i in 0..display_lines {
368 +
        let logo_line = if i < logo_height { logo_lines[i] } else { "" };
369 +
        let info_line = if i < info_lines.len() { &info_lines[i] } else { "" };
370 +
371 +
        println!("{}    {}", logo_line.bright_cyan(), info_line);
372 +
      }
373 +
374 +
      println!();
325 375
    }
326 376
327 377
    Ok(())