Skip to content

Commit

Permalink
rusk-wallet: Implement history pagenation and search
Browse files Browse the repository at this point in the history
  • Loading branch information
Daksh14 committed Jan 13, 2025
1 parent 9e291c8 commit 7ea885a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 20 deletions.
6 changes: 3 additions & 3 deletions rusk-wallet/src/bin/command/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
}
Expand Down Expand Up @@ -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",
)
}
}
Expand Down Expand Up @@ -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 => (),
}
}
}
Expand Down
40 changes: 23 additions & 17 deletions rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions rusk-wallet/src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ use rusk_wallet::{
};
use sha2::{Digest, Sha256};

use crate::command::TransactionHistory;

pub(crate) fn ask_pwd(msg: &str) -> Result<String, InquireError> {
let pwd = Password::new(msg)
.with_display_toggle_enabled()
Expand Down Expand Up @@ -367,6 +369,16 @@ pub(crate) fn request_address(
.prompt()?)
}

pub(crate) fn tx_history_list(
history: &[TransactionHistory],
) -> anyhow::Result<String> {
let header = TransactionHistory::header();
let history_str: Vec<String> =
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<PathBuf> {
let validator = |path_str: &str| {
Expand Down

0 comments on commit 7ea885a

Please sign in to comment.