Skip to content

Commit

Permalink
rusk-wallet: Remove option for new address when max addresses is reached
Browse files Browse the repository at this point in the history
  • Loading branch information
moCello committed Oct 4, 2024
1 parent c729539 commit 2f003fd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
51 changes: 22 additions & 29 deletions rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@ pub(crate) async fn run_loop(
AddrSelect::Exit => std::process::exit(0),
};

// create phoenix and moonlight addresses for easier printing
let phoenix_addr = Address::Phoenix {
pk: *wallet.phoenix_pk(addr_idx)?,
};
let moonlight_addr = Address::Bls {
pk: *wallet.bls_pk(addr_idx)?,
};

let is_synced = wallet.is_synced().await?;

loop {
Expand All @@ -89,24 +81,30 @@ pub(crate) async fn run_loop(
// display address information
println!();
println!();
// display phoenix balance and keys information
if is_synced {
println!(
"{0: <20} - Total: {moonlight_bal}",
"Moonlight Balance",
"{0: <23} - Spendable: {phoenix_spendable}",
"Phoenix Balance",
);
println!("{0: <23} - Total: {phoenix_total}", "",);
}
println!("{moonlight_addr}");
let phoenix_addr = Address::Phoenix {
pk: *wallet.phoenix_pk(addr_idx)?,
};
println!("{phoenix_addr}\n");

println!();
// display moonlight balance and keys information
if is_synced {
println!(
"{0: <20} - Spendable: {phoenix_spendable}",
"Phoenix Balance",
"{0: <23} - Total: {moonlight_bal}",
"Moonlight Balance",
);
println!("{0: <20} - Total: {phoenix_total}", "",);
}
println!("{phoenix_addr}");
println!();
let moonlight_addr = Address::Bls {
pk: *wallet.bls_pk(addr_idx)?,
};
println!("{moonlight_addr}\n");

// request operation to perform
let op = match wallet.is_online().await {
Expand Down Expand Up @@ -191,18 +189,13 @@ fn menu_addr(wallet: &Wallet<WalletFile>) -> anyhow::Result<AddrSelect> {

let remaining_addresses =
MAX_ADDRESSES.saturating_sub(total_addresses as usize);
let mut action_menu = Menu::new()
.separator()
.add(AddrSelect::NewAddress, "New address");

// show warning if less than
if remaining_addresses < 5 {
action_menu = action_menu.separator().separator_msg(format!(
"\x1b[93m{}\x1b[0m This wallet only supports up to {MAX_ADDRESSES} addresses, you have {} addresses ",
"Warning:",
total_addresses
));
}

let mut action_menu = Menu::new();
if remaining_addresses > 0 {
action_menu = action_menu
.separator()
.add(AddrSelect::NewAddress, "New address")
};

if let Some(rx) = &wallet.state()?.sync_rx {
if let Ok(status) = rx.try_recv() {
Expand Down
2 changes: 1 addition & 1 deletion rusk-wallet/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ mod tests {
use super::*;
use tempfile::tempdir;

const TEST_ADDR: &str = "Phoenix Address:\n2w7fRQW23Jn9Bgm1GQW9eC2bD9U883dAwqP7HAr2F8g1syzPQaPYrxSyyVZ81yDS5C1rv9L8KjdPBsvYawSx3QCW";
const TEST_ADDR: &str = "Phoenix Address - 2w7fRQW23Jn9Bgm1GQW9eC2bD9U883dAwqP7HAr2F8g1syzPQaPYrxSyyVZ81yDS5C1rv9L8KjdPBsvYawSx3QCW";

#[derive(Debug, Clone)]
struct WalletFile {
Expand Down
8 changes: 4 additions & 4 deletions rusk-wallet/src/wallet/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ impl Address {
// Moonlight/Stake for Bls)
fn addr_kind_str(&self) -> String {
match self {
Address::Phoenix { pk: _ } => "Phoenix Address:".to_string(),
Address::Bls { pk: _ } => "Moonlight/Stake Address:".to_string(),
Address::Phoenix { pk: _ } => "Phoenix Address".to_string(),
Address::Bls { pk: _ } => "Moonlight/Stake Address".to_string(),
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}\n{}",
"{:<23} - {}",
self.addr_kind_str(),
bs58::encode(self.to_bytes()).into_string()
)
Expand All @@ -159,7 +159,7 @@ impl fmt::Debug for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}\n{}",
"{:<23} - {}",
self.addr_kind_str(),
bs58::encode(self.to_bytes()).into_string()
)
Expand Down

0 comments on commit 2f003fd

Please sign in to comment.