Skip to content

Show XLM minimum reserve warning before sending #7

Description

@MJ-RWA

Trivial complexity — 100 pts

Summary

Stellar requires every account to maintain a minimum XLM balance (base reserve = 0.5 XLM × (2 + number of trustlines)). If a user tries to send an amount that would drop them below this minimum, the transaction fails with op_underfunded. StellarFlow should warn users before they attempt the transaction.

Files to Modify

  • Modify: src/lib/stellar.ts — add calculateMinimumReserve and getSpendableBalance
  • Modify: src/pages/SendPage.tsx — add reserve warning and fix Max button
  • Modify: src/pages/DashboardPage.tsx — optionally show spendable balance vs total

Implementation Notes

In stellar.ts:

export function calculateMinimumReserve(numTrustlines: number): number {
  return (2 + numTrustlines) * 0.5;
}
export function getSpendableBalance(xlmBalance: string, numTrustlines: number): string {
  const total = parseFloat(xlmBalance);
  const reserve = calculateMinimumReserve(numTrustlines);
  return Math.max(0, total - reserve - 0.001).toFixed(4);
}

In SendPage: count non-XLM balances for trustline count, show AlertTriangle warning when amount > spendable, update Max button to use getSpendableBalance when asset === 'XLM'.

Acceptance Criteria

  • Yellow warning appears when entered XLM amount would breach minimum reserve
  • Warning shows the exact minimum reserve and maximum sendable amount
  • Max button fills the spendable amount (total minus reserve minus fee buffer), not the raw balance
  • calculateMinimumReserve correctly accounts for the number of existing trustlines
  • Warning disappears when amount is reduced to a valid value
  • No warning shown when sending USDC

Screen Recording Requirements

  1. Account with ~2 XLM and one USDC trustline (min reserve = 1.5 XLM, spendable ≈ 0.5 XLM)
  2. Enter an amount above the spendable balance → yellow warning appears
  3. Click Max → field fills with the spendable amount, not the total balance
  4. Enter a valid amount below spendable → warning disappears

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions