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

Introduces useTronStakeApy to fetch Consensys witness APY on Tron (mainnet/Nile), adds truncateNumber util, wires tronStakingApiService, and bumps @metamask/stake-sdk to ^3.4.0.

  • Earn:
    • Hook: Add useTronStakeApy (app/components/UI/Earn/hooks/useTronStakeApy.ts)
      • Fetches witnesses via tronStakingApiService.getWitnesses(chainId) and extracts Consensys APY.
      • Exposes isLoading, errorMessage, apyDecimal, apyPercent, refetch; supports fetchOnMount and ChainId.TRON_MAINNET|TRON_NILE.
    • Utils: Add truncateNumber in app/components/UI/Earn/utils/number.ts for 2-decimal truncation without rounding.
  • SDK provider:
    • Export tronStakingApiService from app/components/UI/Stake/sdk/stakeSdkProvider.tsx.
  • Tests:
    • Add comprehensive tests for useTronStakeApy and truncateNumber.
  • Dependencies:
    • Bump @metamask/stake-sdk to ^3.4.0.

Written by Cursor Bugbot for commit 3fae5ca. 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
@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

🔍 Smart E2E Test Selection

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

The PR introduces Tron staking support through several focused changes:

  1. SDK Upgrade: @metamask/stake-sdk upgraded from v3.2.0 to v3.4.0 - this is a minor version bump that likely adds Tron staking support

  2. New Tron Staking Service: A new tronStakingApiService export is added to stakeSdkProvider.tsx which exposes Tron staking functionality from the upgraded SDK

  3. New Hook - useTronStakeApy: Creates a React hook for fetching Tron staking APY from Consensys witnesses for both TRON_MAINNET and TRON_NILE chains

  4. Utility Function: A new truncateNumber function for formatting APY display values

All changes are confined to the Stake/Earn feature area:

  • app/components/UI/Stake/sdk/ - SDK provider modifications
  • app/components/UI/Earn/hooks/ - New Tron APY hook
  • app/components/UI/Earn/utils/ - Number formatting utilities

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.

View GitHub Actions results

} finally {
setIsLoading(false);
}
}, [chainId]);
Copy link

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.

Fix in Cursor Fix in Web

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

No QA Needed Apply this label when your PR does not need any QA effort. size-L team-earn team-new-networks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants