-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: NWNT-681: Add useTronStakeApy hook #23743
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
base: main
Are you sure you want to change the base?
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.
|
…chain to avoid inaccurate values if chain is switched
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe PR introduces Tron staking support through several focused changes:
All changes are confined to the Stake/Earn feature area:
The changes don't affect core wallet functionality, confirmations, account management, or network switching. The SDK provider is only imported by stake/earn-related components based on the importer analysis. This is a feature addition with proper unit tests, making it a medium-risk change that should be validated with the SmokeStake tag. |
| } finally { | ||
| setIsLoading(false); | ||
| } | ||
| }, [chainId]); |
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: Error message persists after successful fetch
The fetchConsensysWitness function does not clear errorMessage on success. While refetch properly calls setErrorMessage(null) before fetching, the useEffect calls fetchConsensysWitness directly. If chainId changes after a previous fetch failure, the subsequent successful fetch will update apyDecimal and apyPercent but leave the stale errorMessage in state, resulting in an inconsistent hook return where valid APY data coexists with an error message.
|



Description
Added new
useTronStakeApyhook.Changes:
useTronStakeApyhook which fetches all witness data and returns the APY for the Consensys witness and exposes the following properties:trueif actively fetching witness data.annualizedRatein decimal formannualizedRatein percentage form^3.4.0.truncateNumberutil. This is used to format the Tron staking APY without rounding.Note:
useTronStakeApycallsgetWitnessesfrom the stake-sdk which fetches all witnesses data. Meaning if additional data besides the APR is desired this function can be reused elsewhere.Changelog
CHANGELOG entry: added useTronStakeApy hook
Related issues
Fixes: NWNT-681: Add tron staking apy to client
Manual testing steps
Screenshots/Recordings
Before
N/A
After
N/A
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Introduces
useTronStakeApyto fetch Consensys witness APY on Tron (mainnet/Nile), addstruncateNumberutil, wirestronStakingApiService, and bumps@metamask/stake-sdkto ^3.4.0.useTronStakeApy(app/components/UI/Earn/hooks/useTronStakeApy.ts)tronStakingApiService.getWitnesses(chainId)and extracts Consensys APY.isLoading,errorMessage,apyDecimal,apyPercent,refetch; supportsfetchOnMountandChainId.TRON_MAINNET|TRON_NILE.truncateNumberinapp/components/UI/Earn/utils/number.tsfor 2-decimal truncation without rounding.tronStakingApiServicefromapp/components/UI/Stake/sdk/stakeSdkProvider.tsx.useTronStakeApyandtruncateNumber.@metamask/stake-sdkto^3.4.0.Written by Cursor Bugbot for commit 3fae5ca. This will update automatically on new commits. Configure here.