From 7ea885a15d5f488bb8ddd5ad0c05db55b34098f0 Mon Sep 17 00:00:00 2001 From: Daksh <41485688+Daksh14@users.noreply.github.com> Date: Sat, 28 Dec 2024 16:08:21 -0500 Subject: [PATCH] rusk-wallet: Implement history pagenation and search --- rusk-wallet/src/bin/command/history.rs | 6 ++-- rusk-wallet/src/bin/interactive.rs | 40 +++++++++++++++----------- rusk-wallet/src/bin/io/prompt.rs | 12 ++++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/rusk-wallet/src/bin/command/history.rs b/rusk-wallet/src/bin/command/history.rs index 950ff88b64..9eb361a964 100644 --- a/rusk-wallet/src/bin/command/history.rs +++ b/rusk-wallet/src/bin/command/history.rs @@ -27,7 +27,7 @@ pub struct TransactionHistory { impl TransactionHistory { pub fn header() -> String { format!( - "{: ^9} | {: ^64} | {: ^8} | {: ^17} | {: ^12} | {: ^8}", + "{: ^9} | {: ^64} | {: ^8} | {: ^17} | {: ^12} | {: ^8}\n", "BLOCK", "TX_ID", "METHOD", "AMOUNT", "FEE", "TRANSACTION_TYPE" ) } @@ -60,7 +60,7 @@ impl Display for TransactionHistory { write!( f, - "{height: >9} | {tx_id} | {contract: ^8} | {dusk: >+17.9} | {fee} | {tx_type}", + "{height: >9} | {tx_id} | {contract: ^8} | {dusk: >+17.9} | {fee} | {tx_type}\n", ) } } @@ -149,7 +149,7 @@ pub(crate) async fn transaction_from_notes( // No outgoing txs found, this note should belong to a // preconfigured genesis state - None => println!("??? val {}", note_amount), + None => (), } } } diff --git a/rusk-wallet/src/bin/interactive.rs b/rusk-wallet/src/bin/interactive.rs index 969a0cd3ab..10c0beabdc 100644 --- a/rusk-wallet/src/bin/interactive.rs +++ b/rusk-wallet/src/bin/interactive.rs @@ -88,26 +88,32 @@ pub(crate) async fn run_loop( // run command prompt::hide_cursor()?; let res = cmd.run(wallet, settings).await?; - prompt::show_cursor()?; + // output results - println!("\r{}", res); - if let RunResult::Tx(hash) = res { - let tx_id = hex::encode(hash.to_bytes()); - - // Wait for transaction confirmation - // from network - let gql = GraphQL::new( - settings.state.to_string(), - io::status::interactive, - )?; - gql.wait_for(&tx_id).await?; - - if let Some(explorer) = &settings.explorer { - let url = format!("{explorer}{tx_id}"); - println!("> URL: {url}"); - prompt::launch_explorer(url)?; + match res { + RunResult::Tx(hash) => { + let tx_id = hex::encode(hash.to_bytes()); + + // Wait for transaction confirmation + // from network + let gql = GraphQL::new( + settings.state.to_string(), + io::status::interactive, + )?; + gql.wait_for(&tx_id).await?; + + if let Some(explorer) = &settings.explorer { + let url = format!("{explorer}{tx_id}"); + println!("> URL: {url}"); + prompt::launch_explorer(url)?; + } + } + RunResult::History(ref history) => { + crate::prompt::tx_history_list(&history); + println!(); } + _ => println!("\r{}", res), } } } diff --git a/rusk-wallet/src/bin/io/prompt.rs b/rusk-wallet/src/bin/io/prompt.rs index 7d941b5f41..92884d472a 100644 --- a/rusk-wallet/src/bin/io/prompt.rs +++ b/rusk-wallet/src/bin/io/prompt.rs @@ -32,6 +32,8 @@ use rusk_wallet::{ }; use sha2::{Digest, Sha256}; +use crate::command::TransactionHistory; + pub(crate) fn ask_pwd(msg: &str) -> Result { let pwd = Password::new(msg) .with_display_toggle_enabled() @@ -367,6 +369,16 @@ pub(crate) fn request_address( .prompt()?) } +pub(crate) fn tx_history_list( + history: &[TransactionHistory], +) -> anyhow::Result { + let header = TransactionHistory::header(); + let history_str: Vec = + history.iter().map(|history| history.to_string()).collect(); + + Ok(Select::new(header.as_str(), history_str).prompt()?) +} + /// Request contract WASM file location pub(crate) fn request_contract_code() -> anyhow::Result { let validator = |path_str: &str| {