Skip to content

Commit

Permalink
Merge pull request #2571 from dusk-network/mocello/fix_stake_issues
Browse files Browse the repository at this point in the history
rusk-wallet: Fix stake issues
  • Loading branch information
moCello authored Oct 2, 2024
2 parents ec26154 + b62d8eb commit f15bbcd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
12 changes: 6 additions & 6 deletions rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ fn transaction_op_menu_moonlight(
.add(Memo, "Moonlight Transfer with Memo")
.add(Stake, "Moonlight Stake")
.add(Unstake, "Moonlight Unstake")
.add(Withdraw, "Moonlight Withdraw")
.add(Withdraw, "Moonlight Withdraw Stake Reward")
.add(ContractDeploy, "Moonlight Contract Deploy")
.add(ContractCall, "Moonlight Contract call")
.add(ContractCall, "Moonlight Contract Call")
//.add(History, "Moonlight Transaction History")
.separator()
.add(Back, "Back");
Expand Down Expand Up @@ -264,7 +264,7 @@ fn transaction_op_menu_moonlight(
})),
Stake => AddrOp::Run(Box::new(Command::MoonlightStake {
addr: Some(addr),
amt: prompt::request_token_amt("stake", moonlight_bal)?,
amt: prompt::request_stake_token_amt(moonlight_bal)?,
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Expand Down Expand Up @@ -314,9 +314,9 @@ fn transaction_op_menu_phoenix(
.add(Memo, "Phoenix Transfer with Memo")
.add(Stake, "Phoenix Stake")
.add(Unstake, "Phoenix Unstake")
.add(Withdraw, "Phoenix Withdraw")
.add(Withdraw, "Phoenix Withdraw Stake Reward")
.add(ContractDeploy, "Phoenix Contract Deploy")
.add(ContractCall, "Phoenix Contract call")
.add(ContractCall, "Phoenix Contract Call")
.add(History, "Phoenix Transaction History")
.separator()
.add(Back, "Back");
Expand Down Expand Up @@ -351,7 +351,7 @@ fn transaction_op_menu_phoenix(
})),
Stake => AddrOp::Run(Box::new(Command::PhoenixStake {
addr: Some(addr),
amt: prompt::request_token_amt("stake", phoenix_balance)?,
amt: prompt::request_stake_token_amt(phoenix_balance)?,
gas_limit: prompt::request_gas_limit(DEFAULT_STAKE_GAS_LIMIT)?,
gas_price: prompt::request_gas_price()?,
})),
Expand Down
31 changes: 19 additions & 12 deletions rusk-wallet/src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crossterm::{

use anyhow::Result;
use bip39::{ErrorKind, Language, Mnemonic};
use execution_core::stake::MINIMUM_STAKE;
use requestty::Question;

use rusk_wallet::gas;
Expand Down Expand Up @@ -236,15 +237,15 @@ fn check_valid_denom(
}
}

/// Request amount of tokens that can be 0
pub(crate) fn request_optional_token_amt(
/// Request an amount of token larger than a given min.
fn request_token(
action: &str,
min: Dusk,
balance: Dusk,
) -> anyhow::Result<Dusk> {
let min = Dusk::from(0);
let question = requestty::Question::float("amt")
.message(format!("Introduce the amount of DUSK to {}:", action))
.default(MIN_CONVERTIBLE.into())
.default(min.into())
.validate_on_key(|f, _| check_valid_denom(f, min, balance).is_ok())
.validate(|f, _| check_valid_denom(f, min, balance))
.build();
Expand All @@ -260,16 +261,22 @@ pub(crate) fn request_token_amt(
balance: Dusk,
) -> anyhow::Result<Dusk> {
let min = MIN_CONVERTIBLE;
let question = requestty::Question::float("amt")
.message(format!("Introduce the amount of DUSK to {}:", action))
.default(min.into())
.validate_on_key(|f, _| check_valid_denom(f, min, balance).is_ok())
.validate(|f, _| check_valid_denom(f, min, balance))
.build();
request_token(action, min, balance)
}

let a = requestty::prompt_one(question)?;
/// Request amount of tokens that can be 0
pub(crate) fn request_optional_token_amt(
action: &str,
balance: Dusk,
) -> anyhow::Result<Dusk> {
let min = Dusk::from(0);
request_token(action, min, balance)
}

Ok(a.as_float().expect("answer to be a float").into())
/// Request amount of tokens that can be 0
pub(crate) fn request_stake_token_amt(balance: Dusk) -> anyhow::Result<Dusk> {
let min: Dusk = MINIMUM_STAKE.into();
request_token("stake", min, balance)
}

/// Request gas limit
Expand Down

0 comments on commit f15bbcd

Please sign in to comment.