Skip to content

[Frontend] Pool deposit/withdraw optimistic update fires on build-tx success, not on signed-submit, so balances bump then revert before the transaction is signed #1107

Description

@grantfox-oss

Telegram (ask questions / claim the issue here first): https://t.me/+DOylgFv1jyJlNzM0

Why this matters

useDepositToPool (useApi.ts:1569) and useWithdrawFromPool (useApi.ts:1639) carry full optimistic-update/rollback logic, but their mutationFn only calls /pool/build-deposit / /pool/build-withdraw which return an UNSIGNED xdr (lines 1581,1651) - no signing or submission happens in the mutation. onMutate optimistically increments pool.stats.totalDeposits and depositor.depositAmount (lines 1598-1610), then onSettled immediately invalidates pool.stats and pool.depositor (lines 1627-1630), refetching the pre-deposit server values and wiping the optimistic bump within ~one round-trip - all before useDepositOperation even calls signTransaction/submitPoolTransaction (useRepaymentOperation.ts:160-163). Net effect: the user briefly sees an inflated pool/portfolio balance that does not correspond to any settled (or even signed) deposit, and if they then reject the wallet signature the number still flickered up with no deposit; onError rollback (lines 1615-1625) only covers a failed build, never a failed sign/submit.

Acceptance criteria

  • Move the optimistic increment so it reflects an actually submitted transaction (e.g., after submitPoolTransaction succeeds) rather than after the build step
  • Do not invalidate pool.stats/pool.depositor in the build mutation's onSettled, or defer invalidation until the deposit/withdraw is submitted
  • Ensure rollback covers signing/submission failures, not only build failures

Files to touch

  • frontend/src/app/hooks/useApi.ts
  • frontend/src/app/hooks/useRepaymentOperation.ts

Out of scope

  • The unused useRepayLoan optimistic hook (defined but never imported)

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingfrontendIssues related to frontend developmentuiUser Interface related issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions