Skip to content

fix(web): wire availableBalance into DepositTab to prevent failed deposits (#1063) - #1094

Merged
collinsezedike merged 2 commits into
drydocs:mainfrom
Yasir-TechGuy:fix/deposit-overbalance-guard-1063
Oct 18, 2026
Merged

collinsezedike merged 2 commits into
drydocs:mainfrom
Yasir-TechGuy:fix/deposit-overbalance-guard-1063

Conversation

@Yasir-TechGuy

Copy link
Copy Markdown
Contributor

Summary

  • Fixes the dead code path in DepositTab ([Bug] The over-balance deposit guard never runs in the app #1063): Previously, VaultPanel rendered <DepositTab /> without passing the availableBalance prop. Because the prop was optional, DepositTab silently skipped the over-balance validation, allowing users to submit deposits larger than their wallet balance.
  • Added useUsdcBalance hook: Fetches the connected wallet's USDC balance directly from Horizon using fetchBalances — the exact same source used by useTrustlines for the deposit's trustline check.
  • Wired the balance into the UI: VaultPanel now consumes useUsdcBalance and passes the value into <DepositTab availableBalance={...} />.
  • Fail-open on data errors: If the Horizon fetch fails or the wallet has no USDC trustline, the hook returns undefined. This preserves the existing optional behavior so transient network errors don't permanently lock users out of deposits.
  • Added VaultPanel-level regression tests: Ensures that if a future developer removes the availableBalance prop, the test suite fails. The tests explicitly assert that the exceedsBalance error is shown and the submit button is disabled when the wallet balance is lower than the typed amount.

Test plan

  • pnpm lint && pnpm typecheck && pnpm test pass locally
  • Verified UI behavior manually:
    • With mocked balance = 10 USDC, typing 100 USDC shows vaultPanel.validation.exceedsBalance and disables vault-deposit-submit.
    • With mocked balance = 100 USDC, typing 50 USDC leaves submit enabled.

Closes #1063

@vercel

vercel Bot commented Oct 17, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Collins' projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@Yasir-TechGuy Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Yasir-TechGuy

Copy link
Copy Markdown
Contributor Author

Hi @collinsezedike Please check it out

@Yasir-TechGuy
Yasir-TechGuy force-pushed the fix/deposit-overbalance-guard-1063 branch from 455867a to 402f16c Compare October 17, 2026 19:27

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Yasir-TechGuy, thank you for the fix. The guard is wired correctly and the VaultPanel test exercises it, but the branch cannot merge as it stands.

The Commit Messages check fails: the commit subject fix(web): wire availableBalance into DepositTab to prevent failed deposits is 74 characters and the limit is 72. Amend or squash it to a shorter subject with no issue reference, for example fix(web): wire availableBalance into the deposit guard.

There is one correctness note on the hook inline.

Comment thread apps/web/src/hooks/useUsdcBalance.ts Outdated
@Yasir-TechGuy
Yasir-TechGuy force-pushed the fix/deposit-overbalance-guard-1063 branch from 0fc51f8 to 1dde25e Compare October 18, 2026 05:36
@Yasir-TechGuy

Copy link
Copy Markdown
Contributor Author

Thanks @collinsezedike — both points addressed in the latest push (1dde25e):

  1. Commit subject shortened to fix(web): wire availableBalance into the deposit guard (54 chars, no issue suffix). Body is just Closes #1063.

  2. Balance is refetched after a successful deposit. useUsdcBalance now returns { balance, refetch }. Internally, refetch() bumps a nonce that's in the effect's dependency array, so calling it re-runs the Horizon fetch. VaultPanel.executeDeposit calls refetchBalance() inside the if (ok) branch, so any successful deposit immediately updates the guard.

    Added two tests in VaultPanel.test.tsx:

    • calls refetchBalance() when the deposit succeeds — asserts refetch fires exactly once after deposit() resolves true.
    • does not refetch when the deposit fails — asserts refetch is not called when deposit() resolves false.

All four local checks pass: format, lint, typecheck, tests (359/359). CI should be green on the new SHA.

Thanks for catching the stale-balance bug — that would have been an on-chain revert we didn't prevent.

@Yasir-TechGuy

Copy link
Copy Markdown
Contributor Author

Please @collinsezedike i have also applied to work on the last 2 unassiged issue in your repo, please kindly assign them to me, i will do a great job

@collinsezedike collinsezedike left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Yasir-TechGuy thank you for the contribution. There are more open issues if you would like to keep going.

@collinsezedike
collinsezedike merged commit e387e62 into drydocs:main Oct 18, 2026
10 of 11 checks passed
@Yasir-TechGuy

Yasir-TechGuy commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@Yasir-TechGuy thank you for the contribution. There are more open issues if you would like to keep going.

@collinsezedike Yes I would like to. Please kindly assign the unassigned issues to me. I have applied for them already 🙏

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.

[Bug] The over-balance deposit guard never runs in the app

2 participants