Skip to content

Provide staking metadata for Tron non-stakers#999

Open
DRadmir wants to merge 1 commit intomainfrom
tron-balance-fix
Open

Provide staking metadata for Tron non-stakers#999
DRadmir wants to merge 1 commit intomainfrom
tron-balance-fix

Conversation

@DRadmir
Copy link
Contributor

@DRadmir DRadmir commented Mar 10, 2026

Fix Tron bandwidth showing 0/0 for non-staking accounts.

Now get_account_usage is called for all activated accounts. For non-staking ones, the usage is mapped via map_metadata_from_usage with votes=0, so bandwidth correctly shows 600/600.

When an account has an address but is not staking, fetch account usage and map it to staking metadata via map_metadata_from_usage, returning a zeroed staking AssetBalance with that metadata. Also restructure the conditional to avoid the combined let/if pattern, remove a redundant clone when mapping staking balances, and add the map_metadata_from_usage import.
@semanticdiff-com
Copy link

semanticdiff-com bot commented Mar 10, 2026

Review changes with  SemanticDiff

Changed Files
File Status
  crates/gem_tron/src/provider/balances.rs  47% smaller

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a display anomaly for Tron accounts that are not engaged in staking. Previously, these accounts would show incorrect bandwidth information. The changes ensure that all activated accounts have their usage data properly retrieved and mapped, leading to an accurate representation of their available bandwidth.

Highlights

  • Tron Bandwidth Display Fix: Resolved an issue where Tron accounts not actively staking were incorrectly showing '0/0' for bandwidth usage.
  • Account Usage for Non-Stakers: The get_account_usage function is now called for all activated Tron accounts, regardless of their staking status.
  • Metadata Mapping for Non-Stakers: For non-staking accounts, the usage data is now mapped via map_metadata_from_usage with votes=0, ensuring bandwidth correctly displays as '600/600'.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • crates/gem_tron/src/provider/balances.rs
    • Imported the map_metadata_from_usage function to facilitate mapping account usage data.
    • Modified the get_balance_staking function to include logic for non-staking accounts, fetching their usage and applying appropriate metadata.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the get_balance_staking function in crates/gem_tron/src/provider/balances.rs to properly handle non-staking accounts by fetching their usage and mapping metadata, returning a zero-value staking balance with this metadata. An improvement opportunity was noted to avoid an inefficient account.clone() operation, suggesting to clone only the address field for better performance.

{
let (reward, usage) = futures::try_join!(self.get_reward(&address), self.get_account_usage(&address))?;
Ok(Some(map_staking_balance(&account.clone(), &reward, &usage)?))
if let Some(address) = account.clone().address {
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The account.clone() on this line creates a full clone of the TronAccount struct just to access its address field. This can be inefficient if TronAccount is a large struct. It's more efficient to clone only the address field itself, which is an Option<String>.

Consider using account.address.clone() instead to avoid unnecessary cloning of the entire account object.

Suggested change
if let Some(address) = account.clone().address {
if let Some(address) = account.address.clone() {

{
let (reward, usage) = futures::try_join!(self.get_reward(&address), self.get_account_usage(&address))?;
Ok(Some(map_staking_balance(&account.clone(), &reward, &usage)?))
if let Some(address) = account.clone().address {
Copy link
Contributor

Choose a reason for hiding this comment

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

add method map_balance_staking in balance_mapper.rs and add unit test, see other examples

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.

2 participants