From 40bc3386d5afdc94c2b9eef80cf65fa6caa844ea Mon Sep 17 00:00:00 2001 From: Simon B Date: Sat, 13 Jan 2018 19:27:40 +0100 Subject: [PATCH] User experience ux1 (#610) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * better error messages when `wallet restore` fails * wallet info: show height, and where we got the height number from * make "grin wallet listen" show some more lifesigns, so users can know it's running fine --- wallet/src/info.rs | 20 +++++--------------- wallet/src/restore.rs | 14 ++++++++++++-- wallet/src/server.rs | 7 ++++--- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/wallet/src/info.rs b/wallet/src/info.rs index 3d8746eab..72d407cde 100644 --- a/wallet/src/info.rs +++ b/wallet/src/info.rs @@ -17,19 +17,17 @@ use keychain::Keychain; use core::core::amount_to_hr_string; use types::{WalletConfig, WalletData, OutputStatus}; use prettytable; -use term; -use std::io::prelude::*; pub fn show_info(config: &WalletConfig, keychain: &Keychain) { let result = checker::refresh_outputs(&config, &keychain); let _ = WalletData::read_wallet(&config.data_file_dir, |wallet_data| { - let current_height = match checker::get_tip_from_node(config) { - Ok(tip) => tip.height, + let (current_height, from) = match checker::get_tip_from_node(config) { + Ok(tip) => (tip.height, "from server node"), Err(_) => match wallet_data.outputs.values().map(|out| out.height).max() { - Some(height) => height, - None => 0, + Some(height) => (height, "from wallet"), + None => (0, "node/wallet unavailable"), }, }; let mut unspent_total=0; @@ -55,15 +53,7 @@ pub fn show_info(config: &WalletConfig, keychain: &Keychain) { } }; - - println!(); - let title=format!("Wallet Summary Info - Block Height: {}", current_height); - let mut t = term::stdout().unwrap(); - t.fg(term::color::MAGENTA).unwrap(); - writeln!(t, "{}", title).unwrap(); - writeln!(t, "--------------------------").unwrap(); - t.reset().unwrap(); - + println!("\n____ Wallet Summary Info at {} ({}) ____\n", current_height, from); let mut table = table!( [bFG->"Total", FG->amount_to_hr_string(unspent_total+unconfirmed_total)], [bFY->"Awaiting Confirmation", FY->amount_to_hr_string(unconfirmed_total)], diff --git a/wallet/src/restore.rs b/wallet/src/restore.rs index ee4e9d877..351a30117 100644 --- a/wallet/src/restore.rs +++ b/wallet/src/restore.rs @@ -28,7 +28,12 @@ pub fn get_chain_height(config: &WalletConfig) -> Result { Ok(tip) => Ok(tip.height), Err(e) => { // if we got anything other than 200 back from server, bye - error!(LOGGER, "Restore failed... unable to contact node: {}", e); + error!( + LOGGER, + "get_chain_height: Restore failed... unable to contact API {}. Error: {}", + config.check_node_api_http_addr, + e + ); Err(Error::Node(e)) } } @@ -106,7 +111,12 @@ pub fn utxos_batch_block( Ok(outputs) => Ok(outputs), Err(e) => { // if we got anything other than 200 back from server, bye - error!(LOGGER, "Restore failed... unable to contact node: {}", e); + error!( + LOGGER, + "utxos_batch_block: Restore failed... unable to contact API {}. Error: {}", + config.check_node_api_http_addr, + e + ); Err(Error::Node(e)) } } diff --git a/wallet/src/server.rs b/wallet/src/server.rs index 5f1fd3ba8..748739af6 100644 --- a/wallet/src/server.rs +++ b/wallet/src/server.rs @@ -43,7 +43,8 @@ pub fn start_rest_apis(wallet_config: WalletConfig, keychain: Keychain) { let mut apis = ApiServer::new("/v1".to_string()); apis.register_handler(router); - apis.start(wallet_config.api_listen_addr()).unwrap_or_else(|e| { - error!(LOGGER, "Failed to start Grin wallet receiver: {}.", e); - }); + match apis.start(wallet_config.api_listen_addr()) { + Err(e) => error!(LOGGER, "Failed to start Grin wallet listener: {}.", e), + Ok(_) => info!(LOGGER, "Wallet listener started"), + }; }