Skip to content

fix(worker): cleanup eth formatting #503

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
Open

Conversation

JannikSt
Copy link
Member

No description provided.

@JannikSt JannikSt requested a review from Copilot June 19, 2025 03:20
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

This PR standardizes Ether amount formatting by replacing manual wei-to-ether conversions with the format_ether utility across provider operations, CLI commands, and an example.

  • Imported and used format_ether in place of manual division by 10^18.
  • Cleaned up various Console::info and println! calls for consistency.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/worker/src/operations/provider.rs Replaced manual wei division with format_ether in log messages.
crates/worker/src/cli/command.rs Switched CLI output to use format_ether, added import and calls.
crates/dev-utils/examples/transfer_eth.rs Updated example to format balances via format_ether.
Comments suppressed due to low confidence (2)

crates/worker/src/operations/provider.rs:226

  • [nitpick] The label "Balance" is ambiguous in the context of both token and ETH balances; consider making it more specific (e.g., "Token balance").
            Console::info("Balance", &format_ether(balance));

crates/worker/src/operations/provider.rs:274

  • [nitpick] This duplicate log also uses the generic label "Balance"; renaming it to distinguish token balance from ETH balance would improve clarity.
            Console::info("Balance", &format_ether(balance));

Console::info(
"ETH Balance",
&format!("{:.6} ETH", { f64::from(eth_balance) / 10f64.powf(18.0) }),
&format!("{} ETH", format_ether(U256::from(eth_balance))),
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The U256::from(eth_balance) is redundant since eth_balance is already a U256; you can pass eth_balance directly to format_ether to simplify the code.

Suggested change
&format!("{} ETH", format_ether(U256::from(eth_balance))),
&format!("{} ETH", format_ether(eth_balance)),

Copilot uses AI. Check for mistakes.

Console::info(
"ETH Balance",
&format!("{:.6} ETH", { f64::from(eth_balance) / 10f64.powf(18.0) }),
&format!("{} ETH", format_ether(U256::from(eth_balance))),
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Consider passing eth_balance directly to format_ether instead of wrapping it in U256::from, to reduce unnecessary conversions.

Suggested change
&format!("{} ETH", format_ether(U256::from(eth_balance))),
&format!("{} ETH", format_ether(eth_balance)),

Copilot uses AI. Check for mistakes.

"Required stake",
&format!("{}", required_stake / U256::from(10u128.pow(18))),
);
Console::info("Required stake", &format_ether(required_stake).to_string());
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

Calling .to_string() on the result of format_ether is redundant since it already returns a String; you can pass &format_ether(required_stake) directly.

Suggested change
Console::info("Required stake", &format_ether(required_stake).to_string());
Console::info("Required stake", &format_ether(required_stake));

Copilot uses AI. Check for mistakes.

@@ -879,7 +877,7 @@ pub async fn execute_command(
.await
.unwrap();

let format_balance = format!("{}", provider_balance / U256::from(10u128.pow(18)));
let format_balance = format_ether(provider_balance).to_string();
Copy link
Preview

Copilot AI Jun 19, 2025

Choose a reason for hiding this comment

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

The .to_string() here clones the string returned by format_ether; consider using the String directly to avoid an extra allocation.

Suggested change
let format_balance = format_ether(provider_balance).to_string();
let format_balance = format_ether(provider_balance);

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.

1 participant