Skip to content

Conversation

@zone-live
Copy link
Contributor

@zone-live zone-live commented Dec 11, 2025

Description

  • Improves Tron error handling by showing user friendly error messages instead of raw error codes.
  • Updates TRX staking input so Max skips the EVM modal.
  • Triggers Tron balances update after the staking operation.
  • Tron snap update to the latest version

Changelog

CHANGELOG entry: null

Related issues

Fixes:

Manual testing steps

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

Before

After

Pre-merge author checklist

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.

Note

Refines Tron staking/unstaking UX (Max/preview), localizes errors, refreshes balances after actions, uses live Tron balances in Asset Overview, and bumps tron-wallet-snap.

  • Tron staking/unstaking UX:
    • EarnInputView/EarnWithdrawInputView: Right action for TRX shows preview or sets Max without EVM modal; passes tronAccountId to navigation result handler.
    • Hooks useTronStake/useTronUnstake: expose tronAccountId.
    • handleTronStakingNavigationResult: refreshes balances via MultichainBalancesController.updateBalance(accountId) on success.
  • Error localization:
    • Add getLocalizedErrorMessage mapping (e.g., InsufficientBalancestake.tron.errors.insufficient_balance).
    • Update locales/languages/en.json with stake.tron.errors.insufficient_balance.
  • Asset Overview (TRON):
    • Prefer live asset data via selectAsset for TRON (balance, balanceFiat) instead of navigation params.
  • Dependencies:
    • Bump @metamask/tron-wallet-snap to ^1.16.1.
  • Tests:
    • Add/update tests for TRX Max behavior (no MaxInputModal), account ID exposure, balance refresh, and error localization.

Written by Cursor Bugbot for commit 3871f24. This will update automatically on new commits. Configure here.

@zone-live zone-live requested a review from a team as a code owner December 11, 2025 15:12
@github-actions
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@github-actions github-actions bot added size-M and removed size-S labels Dec 12, 2025
@zone-live zone-live changed the title chore: adds localization method chore: adds localization method and other improvements Dec 12, 2025
@zone-live zone-live requested a review from aganglada December 12, 2025 11:52
@socket-security
Copy link

socket-security bot commented Dec 12, 2025

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Updatednpm/​@​metamask/​tron-wallet-snap@​1.16.0 ⏵ 1.16.1100 +110080 +198 +1100

View full report

aganglada
aganglada previously approved these changes Dec 12, 2025
@github-actions
Copy link
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: SmokeStake, SmokeAssets, SmokeTrade
  • Risk Level: medium
  • AI Confidence: 80%
click to see 🤖 AI reasoning details

The changes are focused on Tron staking functionality with the following key modifications:

  1. Package update: Minor patch version bump of @metamask/tron-wallet-snap (1.16.0 → 1.16.1) - low risk dependency update.

  2. Tron staking improvements:

    • Added tronAccountId to stake/unstake hooks for balance refresh
    • Added automatic balance refresh after successful stake/unstake via MultichainBalancesController.updateBalance()
    • Added error localization for Tron staking errors
    • Fixed Max button behavior for Tron (skip EVM-specific MaxInputModal)
  3. AssetOverview changes: Added live balance fetching for Tron assets using selectAsset selector to ensure immediate balance updates after staking operations.

The stake E2E test (stake-action-smoke.spec.ts) uses the SmokeTrade tag, so that should be included. The changes also affect asset display (SmokeAssets) and staking features (SmokeStake).

The risk is medium because:

  • Changes touch core balance display logic in AssetOverview
  • Uses Engine.context.MultichainBalancesController which is a core component
  • However, changes are well-scoped to Tron-specific functionality with feature flags (ONLY_INCLUDE_IF(tron))
  • Comprehensive unit tests were added for the new functionality

View GitHub Actions results

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Bug: Localized balance breaks fiat calculation

When isTronChain is true, balance may now come from selectAsset (liveAsset.balance), which is already localized/formatted (e.g., contains commas or a leading <). The later parseFloat(String(balance)) can misparse these values, producing incorrect mainBalance when balanceFiat is missing or not yet available.

app/components/UI/AssetOverview/AssetOverview.tsx#L592-L639

// Calculate fiat balance if not provided in asset (e.g., when coming from trending view)
let balanceFiatSource = asset.balanceFiat;
///: BEGIN:ONLY_INCLUDE_IF(tron)
if (isTronChain && liveAsset?.balanceFiat != null) {
balanceFiatSource = liveAsset.balanceFiat;
}
///: END:ONLY_INCLUDE_IF
let mainBalance = balanceFiatSource || '';
if (!mainBalance && balance != null) {
// Convert balance to number for calculations
const balanceNumber =
typeof balance === 'number' ? balance : parseFloat(String(balance));
if (balanceNumber > 0 && !isNaN(balanceNumber)) {
if (isNonEvmAsset && multichainAssetRates?.rate) {
// For non-EVM assets, use multichainAssetRates directly
const rate = Number(multichainAssetRates.rate);
const balanceFiatNumber = balanceNumber * rate;
mainBalance =
balanceFiatNumber >= 0.01 || balanceFiatNumber === 0
? addCurrencySymbol(balanceFiatNumber, currentCurrency)
: `< ${addCurrencySymbol('0.01', currentCurrency)}`;
} else if (!isNonEvmAsset) {
// For EVM assets, calculate fiat balance directly using balance, market price, and conversion rate
const tickerConversionRate =
conversionRateByTicker?.[nativeCurrency]?.conversionRate;
if (
tickerConversionRate &&
marketDataRate !== undefined &&
isFinite(marketDataRate)
) {
const balanceFiatNumber = balanceToFiatNumber(
balanceNumber,
tickerConversionRate,
marketDataRate,
);
if (isFinite(balanceFiatNumber)) {
mainBalance =
balanceFiatNumber >= 0.01 || balanceFiatNumber === 0
? addCurrencySymbol(balanceFiatNumber, currentCurrency)
: `< ${addCurrencySymbol('0.01', currentCurrency)}`;
}
}
}
}
}

app/components/UI/AssetOverview/AssetOverview.tsx#L514-L535

// Determine the balance source - prefer live data for Tron, otherwise use asset prop
let balanceSource = asset.balance;
///: BEGIN:ONLY_INCLUDE_IF(tron)
if (isTronChain && liveAsset?.balance != null) {
balanceSource = liveAsset.balance;
}
///: END:ONLY_INCLUDE_IF
if (isMultichainAccountsState2Enabled && balanceSource != null) {
// When state2 is enabled and asset has balance, use it directly
balance = balanceSource;
} else if (isMultichainAsset) {
balance = balanceSource
? formatWithThreshold(
parseFloat(balanceSource),
minimumDisplayThreshold,
I18n.locale,
{ minimumFractionDigits: 0, maximumFractionDigits: 5 },
)
: 0;
} else if (isEthOrNative) {

Fix in Cursor Fix in Web


@sonarqubecloud
Copy link

Copy link
Contributor

@Matt561 Matt561 left a comment

Choose a reason for hiding this comment

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

1 minor copy-related comment but pre-approving so you're not blocked.

Comment on lines +5723 to +5724
"insufficient_balance": "You don't have enough resource balance to do this action."
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: This reads a bit strangely. Is there another way we can word this? Would any of the following work?

  • "Insufficient {{resource}}"
  • "Insufficient {{resource}} balance"

Plugging in energy or bandwidth would make the error more descriptive for the user. Maybe this is more helpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yap, and we'll do this afterwards, this is just to act as a quick band aid, more will come 💪🏼

@zone-live zone-live added this pull request to the merge queue Dec 17, 2025
Merged via the queue into main with commit 118250c Dec 17, 2025
91 checks passed
@zone-live zone-live deleted the NWNT-localize-error-message branch December 17, 2025 18:26
@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2025
@metamaskbot metamaskbot added the release-7.62.0 Issue or pull request that will be included in release 7.62.0 label Dec 17, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.62.0 Issue or pull request that will be included in release 7.62.0 size-M team-new-networks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants