Why this matters now: useStellarWallet.ts handles all wallet operations: Freighter connection, Lobstr deep-link connection, in-app wallet creation, wallet import, balance refresh, and disconnection. It's the primary interface between the app and the Stellar blockchain. A bug here could prevent users from connecting wallets, lose funds on import, or show stale balances.
Problem / What: src/hooks/useStellarWallet.ts (233 lines) — no test file. The hook has five wallet operations, two balance refresh functions, error handling with setIsConnecting/setError state, and integration with stellar.ts, lobstr.ts, and walletVault.ts.
Key Challenges:
- Mock
stellar.ts functions: createTestnetAccount, getBalance, getTokenBalance, isValidSecretKey, getPublicKeyFromSecret.
- Mock
lobstr.ts: isLobstrInstalled, openLobstrForSigning.
- Mock
walletVault.ts: saveInAppSecret, clearInAppSecret.
- Mock
useWalletStore Zustand store.
- Test:
connectFreighter — success, extension not found, not connected.
- Test:
connectLobstr — success, not installed, signing cancelled.
- Test:
createInAppWallet — success, network failure.
- Test:
importWallet — valid key, invalid key.
- Test:
disconnectWallet — clears vault and store.
- Test:
refreshBalance — success, network failure.
Acceptance Criteria:
- Test file
src/__tests__/useStellarWallet.test.ts with 15+ test cases.
- All five wallet operations covered.
- Error scenarios for each operation.
- Balance refresh with mocked Horizon responses.
- Disconnect clears vault entry.
- All tests pass with
npm test.
Relevant files/functions:
src/hooks/useStellarWallet.ts (entire file)
src/__tests__/useStellarWallet.test.ts (new)
Out of scope: Real Stellar network interaction tests.
Labels: testing, advanced, wallet
Why this matters now:
useStellarWallet.tshandles all wallet operations: Freighter connection, Lobstr deep-link connection, in-app wallet creation, wallet import, balance refresh, and disconnection. It's the primary interface between the app and the Stellar blockchain. A bug here could prevent users from connecting wallets, lose funds on import, or show stale balances.Problem / What:
src/hooks/useStellarWallet.ts(233 lines) — no test file. The hook has five wallet operations, two balance refresh functions, error handling withsetIsConnecting/setErrorstate, and integration withstellar.ts,lobstr.ts, andwalletVault.ts.Key Challenges:
stellar.tsfunctions:createTestnetAccount,getBalance,getTokenBalance,isValidSecretKey,getPublicKeyFromSecret.lobstr.ts:isLobstrInstalled,openLobstrForSigning.walletVault.ts:saveInAppSecret,clearInAppSecret.useWalletStoreZustand store.connectFreighter— success, extension not found, not connected.connectLobstr— success, not installed, signing cancelled.createInAppWallet— success, network failure.importWallet— valid key, invalid key.disconnectWallet— clears vault and store.refreshBalance— success, network failure.Acceptance Criteria:
src/__tests__/useStellarWallet.test.tswith 15+ test cases.npm test.Relevant files/functions:
src/hooks/useStellarWallet.ts(entire file)src/__tests__/useStellarWallet.test.ts(new)Out of scope: Real Stellar network interaction tests.
Labels:
testing,advanced,wallet