fix: always extract special assets to prevent stale balances#234
Merged
ulissesferreira merged 3 commits intomainfrom Mar 11, 2026
Merged
fix: always extract special assets to prevent stale balances#234ulissesferreira merged 3 commits intomainfrom
ulissesferreira merged 3 commits intomainfrom
Conversation
Four special assets (staked-for-bandwidth, staked-for-energy, ready-for-withdrawal, in-lock-period) were only extracted when their balance was greater than zero. When the balance dropped to zero, the asset was not passed to saveMany, so the repository kept the old non-zero value and no push event updated MetaMask. This caused stale non-zero balances to persist on the client indefinitely. Now all special assets are always extracted regardless of their balance, matching the pattern already used by staking-rewards, bandwidth, and energy. This is safe because all four assets are in ESSENTIAL_ASSETS, so saveMany already handles zero-amount essential assets correctly (they are never placed in the removed list). Changes: - #extractStakedNativeAssets: removed conditional guards, always returns both staked-for-bandwidth and staked-for-energy - #extractReadyForWithdrawalAssets -> #extractReadyForWithdrawalAsset: changed to always return a single AssetEntity (matching #extractStakingRewardsAsset pattern) - #extractInLockPeriodAssets -> #extractInLockPeriodAsset: same refactor - Updated 6 test assertions from toBeUndefined() to toBeDefined() with rawAmount '0' Made-with: Cursor
Made-with: Cursor
Made-with: Cursor
Closed
Contributor
Author
|
@metamaskbot publish-preview |
Contributor
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
maxime-oe
approved these changes
Mar 11, 2026
|
lgtm |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes a stale-state bug where 4 special assets showed stale non-zero balances on the client after their on-chain balance dropped to zero.
Root cause: The extraction methods for staked-for-bandwidth, staked-for-energy, ready-for-withdrawal, and in-lock-period conditionally returned
[]when the computed amount was 0. SincesaveManyuses upsert semantics (only processes assets in the input array), omitting an asset meant no state update and no push event — the repository kept the old non-zero value indefinitely.Fix: Always extract all special assets regardless of their balance, matching the pattern already used by
#extractStakingRewardsAsset,#extractBandwidth, and#extractEnergy. This is safe because all affected assets are inESSENTIAL_ASSETS, sosaveManyalready handles zero-amount essential assets correctly (they are never placed in theremovedlist).Changes
#extractStakedNativeAssets: Removedif (stakedBandwidthAmount > 0)andif (stakedEnergyAmount > 0)guards. Method now always returns exactly 2 entries.#extractReadyForWithdrawalAssets->#extractReadyForWithdrawalAsset: Changed from returningAssetEntity[](with conditional[]) to returning a singleAssetEntityalways. Matches the#extractStakingRewardsAssetpattern.#extractInLockPeriodAssets->#extractInLockPeriodAsset: Same refactor.#extractAssetscoordinator to use the new singular return types.toBeUndefined()totoBeDefined()+rawAmount: '0'.Assets affected
sTRX-BANDWIDTH)sTRX-ENERGY)trx-ready-for-withdrawal)trx-in-lock-period)