Skip to content

feat: wallet state machine, WalletConnect, account activation and connect-in-place - #168

Merged
Marvell69 merged 2 commits into
OracleDesk:developfrom
QueenGiba:feat/wallet-flow-walletconnect-account-state
Oct 18, 2026
Merged

Marvell69 merged 2 commits into
OracleDesk:developfrom
QueenGiba:feat/wallet-flow-walletconnect-account-state

Conversation

@QueenGiba

Copy link
Copy Markdown
Contributor

Summary

This PR reworks the wallet flow in four connected parts, since they all touch WalletProvider:

  • Explicit wallet state machine (Refactor WalletProvider into an explicit, testable state machine #32). The provider's logic moves into a pure reducer (lib/stellar/wallet-machine.ts) with named states, typed events and effects as data. A small interpreter (lib/stellar/wallet-interpreter.ts) runs the effects against a WalletKitAdapter interface, so the races are testable without an extension or DOM. Late results after a disconnect or account change are dropped by an epoch counter. Concurrent ensureSession() calls share one sign-in. WalletContextValue keeps its shape.
  • Stay on the page after connecting, sign in only when needed (Preserve the user's page after connecting and defer backend sign-in until needed #33). openModal() no longer redirects to /markets. openModal({ returnTo }) navigates only to a same-origin path (lib/navigation.ts). Connecting never triggers the SEP-10 signature; withSession(fn, why) signs in right before a protected call. RequireWallet replaces the admin connect gates, the admin "Switch wallet" button disconnects before reopening the picker, and premium keeps the chosen tier when the wallet connects.
  • WalletConnect for mobile wallets (Add WalletConnect-based mobile wallet support #31). Registered only when NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID is set, through a dynamic import, so the default bundle is unchanged. APP_URL and the chain (stellar:testnet / stellar:pubnet) come from config. A missing WalletConnect session maps to "Connect your mobile wallet again".
  • Unfunded accounts (Detect unfunded accounts and show XLM balance and activation state #34). The wallet menu shows an XLM balance next to USDC and an "Account not activated" state, with a Friendbot link on testnet only (URL from the RPC). Write hooks refuse an unfunded account with an account-not-found error before building a transaction. describeError maps "Account not found" and similar errors to that kind. Account polling is faster while unfunded.

Closes

Closes #31
Closes #32
Closes #33
Closes #34

Not in this PR

  • Bundle-size measurement script (scripts/measure-bundle.mjs) and numbers.
  • Capability model (canSignMessage, etc.) and the "approve in your wallet app" waiting UI.
  • RequireSession component and session-expiry handling beyond the reconnect message.
  • Build-time errors inside every write hook are not yet wrapped as UserFacingErrors; only the guard and describeError mapping are covered.

Testing

Unit tests added: lib/stellar/__tests__/wallet-machine.test.ts (transitions, races, and a no-navigate-without-connect property over event sequences), lib/__tests__/navigation.test.ts, and new cases in lib/stellar/__tests__/errors.test.ts.

Not run in this PR: npm run typecheck, npm run lint, npm test and npm run build. The lockfile on develop does not match package.json, so npm ci fails before any check runs. Manual steps are in docs/manual-test.md (steps 3, 5 and 5a).

…nect-in-place

- Pure wallet state machine with an interpreter and kit adapter (OracleDesk#32)
- openModal stays on the current page; returnTo is validated; no sign-in on connect; withSession (OracleDesk#33)
- WalletConnect module behind NEXT_PUBLIC_WALLETCONNECT_PROJECT_ID (OracleDesk#31)
- XLM balance, account activation state, Friendbot link and write guard for unfunded accounts (OracleDesk#34)
@vercel

vercel Bot commented Oct 18, 2026

Copy link
Copy Markdown

@QueenGiba is attempting to deploy a commit to the Marvel's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave

drips-wave Bot commented Oct 18, 2026

Copy link
Copy Markdown

@QueenGiba 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

@Marvell69
Marvell69 merged commit 529912f into OracleDesk:develop Oct 18, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants