feat: harden wallet state, API timeouts, and mutation retries - #713
Open
francescoricc1 wants to merge 4 commits into
Open
feat: harden wallet state, API timeouts, and mutation retries#713francescoricc1 wants to merge 4 commits into
francescoricc1 wants to merge 4 commits into
Conversation
initApiClientWithToken only set a token when one existed, so logout (setToken(null) then re-init) left the previous JWT cached in the client and continued sending an Authorization header on later calls. Add explicit clearToken() and invoke it whenever the store token is falsy. Closes TrusTrove#637 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
None of the fetch wrappers passed an AbortSignal, so a hung backend or dropped connection left requests pending indefinitely and polling hooks stacked new calls on top of stuck ones. Add a 20s timeout for every request and thread react-query's own query signal through the polling queryFns so in-flight calls cancel on unmount/refetch. Closes TrusTrove#638 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
All useMutation calls used react-query's default retry: 0, so a single transient 503/504 gateway blip failed money-moving actions outright. Add a shared mutationRetryPolicy (bounded 3-attempt retry with exponential backoff capped at 8s) that only retries transient 5xx/network errors, never user rejections or permanent 4xx errors, and attach status codes to API errors so the policy can classify them. Closes TrusTrove#639 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
The Zustand wallet store persisted address/network/role but not `connected`, so after a reload the address rehydrated while `connected` reset to false. Queries keyed on address fired while the UI (which gates on connected && address) showed a disconnected wallet. Persist `connected` and clear a stale rehydrated address/network when the store restarts disconnected, so no address-keyed query runs while disconnected. Closes TrusTrove#636 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
Contributor
|
@francescoricc1 is attempting to deploy a commit to the K1NGD4VID Team on Vercel. A member of the Team first needs to authorize it. |
|
MergeKeeper review Scope: in scope for linked issue The PR successfully resolves the four linked issues (#636, #637, #638, and #639) without introducing unrelated changes. Reviewed commit: |
|
MergeKeeper merge status Status: blocked Reason: Next steps:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Second repository-wide audit wave covering four functional edge cases in
apps/web: stale auth tokens, hung requests, missing retry on financial mutations, and a wallet state desync after reload. One commit per issue.Changes
apiClientkeeps a stale bearer token after logout, sending it on subsequent requests #637 — stale bearer token after logout:ApiClient.clearToken()now invoked byinitApiClientWithTokenwhenever the store token is falsy, so a logged-out session stops sending anAuthorizationheader. Covered by a unit test.AbortController, so hung requests never resolve #638 — hung requests never resolve: bothApiClient.fetchandapiFetchnow build anAbortSignalthat times out after 20s, while threading react-query's own querysignalthrough the pollingqueryFns (usePool,useInvoices,useStats,useEvents) so in-flight requests cancel on unmount/refetch. Covered by timeout + external-abort tests.mutationRetryPolicyapplied to everyuseMutation(useInvoices,usePool,useProfile) — up to 3 attempts with exponential backoff (1s→8s cap), retrying only transient 502/503/504 or network errors, never user rejections or permanent 4xx. Errors now carry their HTTP status for classification. Covered by 503-then-success retry tests.connectedflag is not persisted, causing UI/query desync after page reload #636 — walletconnectedflag not persisted:partializenow persistsconnected, and a rehydration guard clears a stale rehydratedaddress/networkwhen the store restarts disconnected, so address-keyed queries never fire against a wallet the UI shows as disconnected. Covered by rehydration regression tests.Testing
Unit tests added alongside each fix following existing vitest patterns (
apps/web/lib/api.test.ts,apps/web/store/wallet.test.ts).Closes #636
Closes #637
Closes #638
Closes #639