Repository navigation
Guard token storage, gate wallet connect on Freighter install, harden apiRequest - #306
Merged
chonilius merged 3 commits intoAug 24, 2026
Conversation
setToken/clearToken/getToken in auth.ts wrote to and read from localStorage with no try/catch, unlike the identical class of failure ThemeContext.tsx already guards for its own key. localStorage.setItem/ removeItem/getItem throw in real browser conditions (Safari private browsing, a full storage quota, or a policy that disables localStorage entirely) — an unguarded setToken() during login throws synchronously, and if reads throw too, getToken() silently fails on every subsequent page load, leaving the user stuck unable to complete sign-in with no diagnosis of why. Wrapped all three in the same try/catch-and-degrade-gracefully pattern already established in ThemeContext.tsx#toggle (closes MergeFi#190).
isFreighterInstalled() was exported from wallet.ts but never called anywhere in the app — connectWallet() went straight to isAllowed()/ setAllowed()/getAddress() with no upfront "is the extension even installed" check, so a user without Freighter got whatever error those calls happened to throw instead of a clear, purpose-built message. connectWallet() now short-circuits with "Install the Freighter wallet extension to continue." when the extension isn't installed, before touching isAllowed/getAddress, using the dedicated check this codebase already wrote for exactly this (closes MergeFi#191).
apiRequest (used by apiPost, and directly by IssueActions/
MilestoneActions for fund/claim/refund/deposit) called fetch() with no
signal, AbortController, or timeout. If a request simply never
resolved — a stalled TCP connection, a backend that accepts the
connection but never responds — the await never settled, the
surrounding finally never ran, and the action button stayed on its
pending label ("Confirming in wallet...", "Claiming...") forever, with
no way to retry short of reloading. apiRequest now races the fetch
against a 20s AbortSignal.timeout() and throws a clear "Request timed
out — please try again." ApiRequestError, which the existing catch
blocks in IssueActions/MilestoneActions already know how to render
(closes MergeFi#188).
Separately, request() hardcoded `cache: "no-store"` with no per-call
override, unconditionally opting every fetcher that funnels through it
(fetchBounties, fetchMilestones, fetchMaintenancePools,
fetchReputationByUsername) out of Next.js's fetch caching/ISR — even
for /issues, /milestones, and /reputation/[handle], none of which are
dashboards, forcing a full backend round trip on every request.
Reordered so an explicit `cache`/`next` in the caller's init now
overrides the no-store default instead of always being clobbered by
it, so a call site can opt into `{ next: { revalidate: 30 } }` (closes
MergeFi#189).
|
@Temi-suwa18 is attempting to deploy a commit to the chonilius' projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@Temi-suwa18 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! 🚀 |
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
Four small, targeted bug fixes across
lib/auth.ts,lib/wallet.ts, andlib/api.ts:Unguarded token storage (#190) —
setToken/clearToken/getTokeninauth.tscalledlocalStorage.setItem/removeItem/getItemwith no try/catch, unlikeThemeContext.tsx#toggle, which already guards the identical class of failure for its own key.localStoragecalls throw in real conditions (Safari private browsing, a full quota, a policy disabling storage entirely) — an unguardedsetToken()during login throws synchronously, and if reads throw too,getToken()silently fails forever after, leaving the user stuck unable to sign in with no diagnosis of why. Fixed by wrapping all three in the same try/catch-and-degrade pattern already established inThemeContext.tsx.Dead installation check (#191) —
isFreighterInstalled()was exported fromwallet.tsbut never called anywhere;connectWallet()went straight toisAllowed()/setAllowed()/getAddress()with no upfront "is the extension even installed" check, so a user without Freighter got whatever error those calls happened to throw instead of a clear message. Fixed by callingisFreighterInstalled()first inconnectWallet()and short-circuiting with "Install the Freighter wallet extension to continue." before touching the rest of the flow.No request timeout (#188) —
apiRequest(used byapiPost, and directly byIssueActions/MilestoneActionsfor fund/claim/refund/deposit) calledfetch()with nosignal/AbortController/timeout. A stalled connection that never resolves left theawait— and the surroundingfinally { setPending(false) }— hanging forever, so an action button stayed on its pending label indefinitely with no way to retry short of reloading. Fixed by racing the fetch against a 20sAbortSignal.timeout()and throwing a clear"Request timed out — please try again."ApiRequestError, which the existingcatchblocks already render.No cache override (#189) —
request()hardcodedcache: "no-store"with no per-call override, unconditionally opting every fetcher that funnels through it (fetchBounties,fetchMilestones,fetchMaintenancePools,fetchReputationByUsername) out of Next.js's fetch caching/ISR — even for pages like/issues,/milestones,/reputation/[handle]that aren't dashboards and could tolerate slightly stale data. Fixed by reordering so an explicitcache/nextoption in the caller'sinitnow overrides theno-storedefault instead of always being clobbered by it.Changes
src/lib/auth.ts— try/catch around all three localStorage calls.src/lib/wallet.ts—connectWallet()checksisFreighterInstalled()up front.src/lib/api.ts—apiRequestgets a 20s timeout viaAbortSignal.timeout();request()'scachedefault is now overridable viainit.Test plan
npx tsc --noEmit— cleannpx eslint src/lib/auth.ts src/lib/wallet.ts src/lib/api.ts— cleannpx jest src/context/AuthContext.test.tsx src/context/WalletContext.test.tsx src/lib— 58/58 passingCloses #190
Closes #191
Closes #188
Closes #189