Переглянути джерело

drk: print 0 when there is no balance in the wallet

ghassmo 4 роки тому
батько
коміт
3ddd853d99
1 змінених файлів з 6 додано та 4 видалено
  1. 6 4
      src/bin/drk.rs

+ 6 - 4
src/bin/drk.rs

@@ -181,11 +181,12 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
 
         if matches.is_present("balances") {
             let reply = client.get_balances().await?;
-            let mut table = Table::new();
-            table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
-            table.set_titles(row!["token", "amount", "network"]);
 
-            if reply.as_object().is_some() {
+            if reply.as_object().is_some() && !reply.as_object().unwrap().is_empty() {
+                let mut table = Table::new();
+                table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
+                table.set_titles(row!["token", "amount", "network"]);
+
                 for (tkn, data) in reply.as_object().unwrap() {
                     table.add_row(row![
                         tkn,
@@ -193,6 +194,7 @@ async fn start(config: &DrkConfig, options: ArgMatches<'_>) -> Result<()> {
                         data[1].as_str().unwrap()
                     ]);
                 }
+
                 table.printstd();
             } else {
                 println!("Balances: {}", "0".to_string());