Skip to content

fix: add withdrawal validation with balance and liquidity checks (#89) - #94

Merged
EmeditWeb merged 1 commit into
StepFi-app:mainfrom
Emeka-12:feat/withdraw-validation
Jul 29, 2026
Merged

fix: add withdrawal validation with balance and liquidity checks (#89)#94
EmeditWeb merged 1 commit into
StepFi-app:mainfrom
Emeka-12:feat/withdraw-validation

Conversation

@Emeka-12

@Emeka-12 Emeka-12 commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem this solves

The withdrawal form on the Sponsors page validates only that the share amount is a positive number. It never checks the requested shares against the sponsor's actual share balance or against the pool's available liquidity. This leads to sponsors signing and submitting transactions that are guaranteed to fail on-chain, and the Preview Value block quotes payouts for shares the user does not own.
Closes #89

What was built

  • GET /liquidity/my-summary — Added \getMySummary()\ to \sponsors.service.ts\ with typed \MySummary\ response in \ ypes/index.ts. No API calls in the page file.
  • Position query — Fetched in \Sponsors.tsx\ with TanStack Query (matching the existing \poolInfo\ pattern), enabled only when the wallet is connected.
  • Over-balance validation — Blocks submission and shows an inline error when requested shares exceed the sponsor's balance.
  • Over-liquidity validation — Blocks submission and shows its own distinct inline error when the estimated payout exceeds \poolInfo.availableLiquidity.
  • Max button — Fills the input field with the sponsor's full share balance.
  • Preview suppression — The Preview Value block is hidden when the amount fails validation.
  • Loading/error/empty states — Button disabled while position loads. Query failure shows an error card. Zero-share sponsors see an empty state.
  • Submit button — Disabled when any validation error exists, while position is loading, or when the amount is not positive.
  • Tests — 13 new tests covering over-balance, over-liquidity, exact-balance boundary, zero-share sponsor, Max button, preview suppression, loading state, error state, and not-connected state.

How it was tested


  • pm run build\ — passes with zero errors

  • pm test\ — all 49 tests pass across 10 test files (13 new tests added)
  • Manual verification of each validation state via unit tests

Files touched

  • \src/pages/Sponsors.tsx\
  • \src/services/sponsors.service.ts\
  • \src/services/queryKeys.ts\
  • \src/types/index.ts\
  • \src/pages/tests/Sponsors.test.tsx\
  • \src/lucide-react.d.ts\ (pre-existing missing declaration fix)
  • \context/progress-tracker.md\

Closes #89

@Emeka-12
Emeka-12 requested a review from EmeditWeb as a code owner July 29, 2026 22:01

@EmeditWeb EmeditWeb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

great job, LGTM

@EmeditWeb
EmeditWeb merged commit b664802 into StepFi-app:main Jul 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: validate withdrawal against share balance and available liquidity

3 participants