Skip to content

Commit 48c63c9

Browse files
runway-github[bot]ulissesferreirazone-live
authored
chore(runway): cherry-pick fix(tron): max energy and bandwidth incorrectly set to 1 instead of 0 cp-7.61.6 (#24376)
- fix(tron): max energy and bandwidth incorrectly set to 1 instead of 0 cp-7.61.6 (#24368) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Fix Tron resources calculation and default value. ## **Changelog** <!-- If this PR is not End-User-Facing and should not show up in the CHANGELOG, you can choose to either: 1. Write `CHANGELOG entry: null` 2. Label with `no-changelog` If this PR is End-User-Facing, please write a short User-Facing description in the past tense like: `CHANGELOG entry: Added a new tab for users to see their NFTs` `CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker` (This helps the Release Engineer do their job more quickly and accurately) --> CHANGELOG entry: null ## **Related issues** Fixes: ## **Manual testing steps** ```gherkin Feature: my feature name Scenario: user [verb for user action] Given [describe expected initial app state] When user [verb for user action] Then [describe expected outcome] ``` ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I’ve followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile Coding Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Fix Tron resources calculation and defaults** > > - In `useTronResources`, keep actual `max` values from data (can be `0`) and compute `percentage` using `Math.max(1, max)` to avoid division by zero > - Remove prior clamping of `max` to at least `1` for energy/bandwidth > - Update tests in `useTronResources.test.ts` to expect `max: 0` when resources are absent and validate parsing/percentage behavior > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit df247ca. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net> [ae67bf2](ae67bf2) Co-authored-by: Ulisses Ferreira <ulisses@hey.com> Co-authored-by: Antonio Regadas <antonio.regadas@consensys.net>
1 parent 8580b73 commit 48c63c9

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

app/components/UI/AssetOverview/TronEnergyBandwidthDetail/useTronResources.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ describe('useTronResources', () => {
7676
expect(result.current.energy).toEqual({
7777
type: 'energy',
7878
current: 0,
79-
max: 1,
79+
max: 0,
8080
percentage: 0,
8181
});
8282

8383
expect(result.current.bandwidth).toEqual({
8484
type: 'bandwidth',
8585
current: 0,
86-
max: 1,
86+
max: 0,
8787
percentage: 0,
8888
});
8989
});

app/components/UI/AssetOverview/TronEnergyBandwidthDetail/useTronResources.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ function createResource(
2121
max: number,
2222
): TronResource {
2323
const currentBN = new BigNumber(current);
24-
const maxBN = new BigNumber(max);
25-
const percentageBN = currentBN.dividedBy(maxBN).multipliedBy(100);
24+
// Use max of 1 only for percentage calculation to avoid division by zero
25+
const divisor = new BigNumber(Math.max(1, max));
26+
const percentageBN = currentBN.dividedBy(divisor).multipliedBy(100);
2627

2728
const percentage = BigNumber.min(
2829
100,
@@ -32,7 +33,7 @@ function createResource(
3233
return {
3334
type,
3435
current,
35-
max,
36+
max, // Keep actual max for display (can be 0)
3637
percentage,
3738
};
3839
}
@@ -91,12 +92,13 @@ export const useTronResources = (): {
9192
const maxEnergyValue = parseValue(maxEnergy?.balance);
9293
const maxBandwidthValue = parseValue(maxBandwidth?.balance);
9394

94-
const energyMax = Math.max(1, maxEnergyValue);
95-
const bandwidthMax = Math.max(1, maxBandwidthValue);
96-
9795
return {
98-
energy: createResource('energy', energyCurrent, energyMax),
99-
bandwidth: createResource('bandwidth', bandwidthCurrent, bandwidthMax),
96+
energy: createResource('energy', energyCurrent, maxEnergyValue),
97+
bandwidth: createResource(
98+
'bandwidth',
99+
bandwidthCurrent,
100+
maxBandwidthValue,
101+
),
100102
};
101103
}, [tronResources]);
102104
};

0 commit comments

Comments
 (0)