Skip to content

fix(hooks): thread network through escrow, subscription, and payment-… - #63

Open
AbuJulaybeeb wants to merge 3 commits into
StellarSend:mainfrom
AbuJulaybeeb:fix/59-network-aware-hooks
Open

fix(hooks): thread network through escrow, subscription, and payment-…#63
AbuJulaybeeb wants to merge 3 commits into
StellarSend:mainfrom
AbuJulaybeeb:fix/59-network-aware-hooks

Conversation

@AbuJulaybeeb

Copy link
Copy Markdown

Summary

  • Threaded active Stellar network (testnet | mainnet) through Escrow, Subscription, and Payment Request React Query cache keys and API calls.
  • Updated escrowKeys, subscriptionKeys, and paymentRequestKeys helpers to include network in list and detail query keys.
  • Updated escrowApi, subscriptionApi, and paymentRequestApi in src/lib/api.ts to accept network?: Network and include it in request params or payload bodies.
  • Updated CreateEscrowRequest, CreateSubscriptionRequest, and CreatePaymentRequestPayload types in src/types/index.ts to include optional network?: Network.
  • Added unit tests in src/hooks/networkAwareness.test.ts and src/lib/api.test.ts verifying network-scoped query key generation and API parameter forwarding.
  • Added entry to CHANGELOG.md.

Why

Unlike transaction history hooks (which already threaded network through both React Query keys and Horizon API calls), the Escrow, Subscription, and Payment Request hooks were not reading network from useWallet(). This caused two critical issues:

  1. Client-side cache collisions: Switching networks in Settings with the same public key caused React Query to serve cached data from the previous network without refetching.
  2. Backend request ambiguity: API requests sent no network parameter, leaving the backend unable to scope queries to the intended Stellar network.

Implementation

  • Types: Added network?: Network to CreateEscrowRequest, CreateSubscriptionRequest, and CreatePaymentRequestPayload.
  • API Client: Updated subscriptionApi, paymentRequestApi, and escrowApi methods (list, get, build*, create, release, refund, cancel) to forward network in request parameters and data.
  • Hooks: Updated useEscrowList, useCreateEscrow, useReleaseEscrow, useRefundEscrow, useSubscriptionList, useCreateSubscription, useCancelSubscription, usePaymentRequestList, usePaymentRequest, useCreatePaymentRequest, and useCancelPaymentRequest to destructure network from useWallet() and pass it into cache keys and API calls.
  • Tests: Added tests ensuring query keys change on network switches and confirming API functions forward params: { publicKey, network }.

Testing

  • npm run test (Vitest test suite including networkAwareness.test.ts and api.test.ts)
  • Verified query key differentiation: ['escrows', 'list', pubKey, 'testnet'] vs ['escrows', 'list', pubKey, 'mainnet']
  • Verified API parameter inclusion: escrowApi.list(pubKey, 'testnet') sends { publicKey: pubKey, network: 'testnet' }.

Scope / Risk

  • Scope: src/types/index.ts, src/lib/api.ts, src/hooks/useEscrows.ts, src/hooks/useSubscriptions.ts, src/hooks/usePaymentRequests.ts, CHANGELOG.md.
  • Risk: Low. Existing hook consumer interfaces remain unchanged while gaining network reactivity.

Issue

closes #59

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.

Escrow/Subscription/PaymentRequest hooks and API calls never thread network through — query keys and requests are identical across testnet and mainnet

1 participant