Skip to content

fix(bug): fix staking console log #453

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

varun-doshi
Copy link

Fixes #449

@JannikSt JannikSt requested a review from Copilot June 13, 2025 13:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Update console log messages to display staking amounts as human-readable decimal values instead of raw U256 divisions.

  • Convert U256 stake values to f64 and divide by 10^18 for display
  • Applied change in three separate staking approval prompts

@@ -239,7 +239,7 @@ impl ProviderOperations {
}
if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {} tokens?",
stake / U256::from(10u128.pow(18))
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The conversion from U256 to f64 via to_string() and parse is duplicated in multiple prompts. Consider extracting this logic into a shared helper (e.g., format_token_amount) to reduce repetition and improve readability.

Copilot uses AI. Check for mistakes.

@@ -239,7 +239,7 @@ impl ProviderOperations {
}
if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {} tokens?",
stake / U256::from(10u128.pow(18))
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using unwrap_or(0.0) will silently fallback on parse errors, potentially hiding conversion issues. It would be safer to handle parse errors explicitly or ensure the stake string is always a valid number.

Suggested change
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
match stake.to_string().parse::<f64>() {
Ok(parsed_stake) => parsed_stake / 10f64.powf(18.0),
Err(_) => {
Console::user_error("Failed to parse stake value as a number.");
return Err(ProviderError::InvalidStakeValue);
}
}

Copilot uses AI. Check for mistakes.

@@ -239,7 +239,7 @@ impl ProviderOperations {
}
if !self.prompt_user_confirmation(&format!(
"Do you want to approve staking {} tokens?",
stake / U256::from(10u128.pow(18))
stake.to_string().parse::<f64>().unwrap_or(0.0) / 10f64.powf(18.0)
Copy link
Preview

Copilot AI Jun 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Converting large U256 values to f64 can lose precision or overflow, leading to inaccurate amounts. Consider using a decimal or big-number formatting library to preserve full precision.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Fix staking console log
1 participant