-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 tof64
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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) |
There was a problem hiding this comment.
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.
Fixes #449