Conversation
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.
Summary of ChangesHello, 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
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| 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 { |
There was a problem hiding this comment.
add method map_balance_staking in balance_mapper.rs and add unit test, see other examples
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.