-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
chore: adds localization method and other improvements #23927
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
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. |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe changes are focused on Tron staking functionality with the following key modifications:
The stake E2E test ( The risk is medium because:
|
There was a problem hiding this 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
metamask-mobile/app/components/UI/AssetOverview/AssetOverview.tsx
Lines 592 to 639 in 3871f24
| // 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
metamask-mobile/app/components/UI/AssetOverview/AssetOverview.tsx
Lines 514 to 535 in 3871f24
| // 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) { |
|
Matt561
left a comment
There was a problem hiding this 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.
| "insufficient_balance": "You don't have enough resource balance to do this action." | ||
| } |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 💪🏼



Description
Changelog
CHANGELOG entry: null
Related issues
Fixes:
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
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.
EarnInputView/EarnWithdrawInputView: Right action for TRX shows preview or setsMaxwithout EVM modal; passestronAccountIdto navigation result handler.useTronStake/useTronUnstake: exposetronAccountId.handleTronStakingNavigationResult: refreshes balances viaMultichainBalancesController.updateBalance(accountId)on success.getLocalizedErrorMessagemapping (e.g.,InsufficientBalance→stake.tron.errors.insufficient_balance).locales/languages/en.jsonwithstake.tron.errors.insufficient_balance.selectAssetfor TRON (balance,balanceFiat) instead of navigation params.@metamask/tron-wallet-snapto^1.16.1.Written by Cursor Bugbot for commit 3871f24. This will update automatically on new commits. Configure here.