Skip to content

Implement Wallet Asset Balances and Safe Maximum Stake Calculation #576

Description

@grantfox-oss

Package: packages/frontend

Complexity: Medium

Problem

StakingInterface.tsx calculates percentage presets from a hard-coded BALANCE = 1000. A user can therefore select an amount unrelated to the connected wallet's USDC balance. The interface also cannot distinguish insufficient token balance, missing trustline, or insufficient XLM for transaction fees.

Goal

Use live Stellar account data to make stake amounts accurate and prevent avoidable failed transactions.

Acceptance criteria

  • Add a reusable wallet-balance hook/service that loads native XLM and the configured stake asset balance for the active network and connected address.
  • Validate the stake asset by issuer and asset code or SAC contract ID; do not identify USDC by symbol alone.
  • The 25%, 50%, 75%, and MAX controls use the spendable stake-asset balance rather than a constant.
  • MAX respects the contract minimum/maximum stake rules and retains the required XLM reserve/fee buffer where applicable.
  • The interface displays distinct states for disconnected wallet, account not funded, missing trustline, stale RPC response, zero balance, and insufficient fee balance.
  • Stake submission is disabled when the amount is non-positive, exceeds the spendable balance, violates contract limits, or the market is no longer active.
  • Asset amounts preserve Stellar's 7-decimal precision internally and are formatted consistently for display.
  • Balance data refreshes after wallet/network changes and after a successful stake without causing duplicate requests.
  • Unit tests cover decimal conversion and MAX calculation; component tests cover each disabled/error state.
  • No hard-coded wallet balance remains in the staking production path.

Technical pointers

  • packages/frontend/src/components/StakingInterface.tsx
  • packages/frontend/src/components/StakeInput.tsx
  • packages/frontend/src/hooks/useWallet.ts
  • packages/frontend/src/components/WalletContext.tsx
  • packages/frontend/src/components/GasFeeDisplay.tsx

Out of scope

  • Adding a new wallet provider
  • Gas sponsorship or paymaster behavior
  • Changing the stake token configured by a market

Activity

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

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignenhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions