Skip to content

Conversation

@Matt561
Copy link
Contributor

@Matt561 Matt561 commented Dec 5, 2025

Description

Added new useTronStakeApy hook.

Changes:

  • Added useTronStakeApy hook which fetches all witness data and returns the APY for the Consensys witness and exposes the following properties:
    • isLoading: returns true if actively fetching witness data.
    • errorMessage: error message if fetch fails
    • apyDecimal: Consensys witness/SR annualizedRate in decimal form
    • apyPercent: Consensys witness/SR annualizedRate in percentage form
    • refetch: Allows refetching of witness data
  • Bumped @metamask/stake-sdk to ^3.4.0.
  • Added truncateNumber util. This is used to format the Tron staking APY without rounding.

Note: useTronStakeApy calls getWitnesses from 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

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

N/A

After

N/A

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

Adds useTronStakeApy hook to fetch Consensys TRON witness APY, introduces truncateNumber, exposes tronStakingApiService, and bumps @metamask/stake-sdk to ^3.4.0 with tests.

  • Hooks:
    • Add useTronStakeApy to fetch witnesses via tronStakingApiService.getWitnesses (default TRON_MAINNET), compute apyDecimal/apyPercent, handle loading/error, and support refetch/chainId options.
  • Utils:
    • Add truncateNumber in app/components/UI/Earn/utils/number.ts for 2-decimal truncation without rounding.
  • SDK/Provider:
    • Expose tronStakingApiService from earnApiService.tronStaking in app/components/UI/Stake/sdk/stakeSdkProvider.tsx.
  • Dependencies:
    • Bump @metamask/stake-sdk to ^3.4.0.
  • Tests:
    • Add comprehensive tests for useTronStakeApy and truncateNumber.

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

@Matt561 Matt561 added No QA Needed Apply this label when your PR does not need any QA effort. team-earn team-new-networks labels Dec 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

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 the size-L label Dec 5, 2025
@socket-security
Copy link

socket-security bot commented Dec 5, 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/​stake-sdk@​3.3.0 ⏵ 3.4.0100 +110095 +193 +6100

View full report

@Matt561 Matt561 marked this pull request as ready for review December 5, 2025 22:59
@Matt561 Matt561 requested a review from a team as a code owner December 5, 2025 22:59
…chain to avoid inaccurate values if chain is switched
const fetchConsensysWitness = useCallback(async () => {
try {
setIsLoading(true);

Copy link
Contributor

@zone-live zone-live Dec 9, 2025

Choose a reason for hiding this comment

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

Should we also clear the error on a new fetch? with setErrorMessage(null);
Just in case there's any.
I can add this after its merged.

zone-live
zone-live previously approved these changes Dec 9, 2025
Copy link
Contributor

@zone-live zone-live left a comment

Choose a reason for hiding this comment

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

Just a minor comment. Looks great 💪🏼

@Matt561 Matt561 force-pushed the feat/nwnt-681-add-tron-staking-apy-to-client branch from 9c728cd to 04573a4 Compare December 9, 2025 14:23
aganglada
aganglada previously approved these changes Dec 9, 2025
@Matt561 Matt561 force-pushed the feat/nwnt-681-add-tron-staking-apy-to-client branch from 04573a4 to 1d8376e Compare December 9, 2025 15:20
@Matt561 Matt561 enabled auto-merge December 9, 2025 15:27
zone-live
zone-live previously approved these changes Dec 9, 2025
nickewansmith
nickewansmith previously approved these changes Dec 9, 2025
Copy link
Contributor

@nickewansmith nickewansmith left a comment

Choose a reason for hiding this comment

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

Approved to unblock, with comment

@Matt561 Matt561 added this pull request to the merge queue Dec 9, 2025
@nickewansmith nickewansmith removed this pull request from the merge queue due to a manual request Dec 9, 2025
@Matt561 Matt561 dismissed stale reviews from nickewansmith and zone-live via a42d1d4 December 9, 2025 18:58
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

🔍 Smart E2E Test Selection

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

The PR introduces TRON staking support by:

  1. Upgrading @metamask/stake-sdk from 3.2.0 to 3.4.0 (minor version bump)
  2. Adding a new tronStakingApiService export from stakeSdkProvider
  3. Creating a new useTronStakeApy hook for TRON staking APY
  4. Adding a truncateNumber utility function

The changes are primarily additive (new TRON staking functionality) rather than modifying existing code paths. The stake-sdk upgrade follows semver with a minor version bump, suggesting backward compatibility. However, since this upgrades a core staking SDK dependency and touches the staking infrastructure, running staking-related tests is appropriate.

The existing stake E2E test (stake-action-smoke.spec.ts) uses SmokeTrade tag and tests ETH pooled staking functionality. SmokeStake is also selected to cover any additional staking test coverage that may exist. The changes don't affect confirmations, wallet core, accounts, or other unrelated features.

Unit tests have been added for the new hook and utility function, which increases confidence in the implementation.

View GitHub Actions results

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 9, 2025

@Matt561 Matt561 added this pull request to the merge queue Dec 9, 2025
Merged via the queue into main with commit e434448 Dec 9, 2025
97 checks passed
@Matt561 Matt561 deleted the feat/nwnt-681-add-tron-staking-apy-to-client branch December 9, 2025 22:45
@github-actions github-actions bot locked and limited conversation to collaborators Dec 9, 2025
@metamaskbot metamaskbot added the release-7.62.0 Issue or pull request that will be included in release 7.62.0 label Dec 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

No QA Needed Apply this label when your PR does not need any QA effort. release-7.62.0 Issue or pull request that will be included in release 7.62.0 size-L team-earn team-new-networks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants