Repository navigation
[1625] [frontend] Map Freighter wallet errors to error codes and use backoff in wallet polling - #1699
Merged
Conversation
added 5 commits
October 19, 2026 06:42
Freighter surfaces some failures in-band (`{ address: "", error }`)
instead of throwing, and `useWalletConnection` dropped that payload, so
every `getAddress` failure collapsed into a generic NO_ADDRESS error.
- add `classifyFreighterApiError` so in-band Freighter payloads map onto
the existing wallet error codes (and therefore the existing i18n keys
rendered by `WalletConnect`)
- classify `getAddress` errors before falling back to NO_ADDRESS
- route every `wallet_session_start` write through new
`getWalletSessionStart` / `startWalletSession` helpers in
`lib/walletSession`, and read it from `AuthContext` via the same helper
- replace the fixed `setInterval` wallet poll with a recursive
`setTimeout` that backs off exponentially (capped) after consecutive
failures and resets on success
- cover the error mapping, the session-start write and the polling
backoff with unit tests
Closes 1625
|
@ToryMic 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.
Closes #1625
Closes 1625
Summary
useWalletConnectiontreated everygetAddressfailure as "no address": Freighterreports some failures in-band (
{ address: "", error: { code, message } })instead of throwing, and that payload was silently dropped. Wallet polling was also
a fixed
setInterval, so a failing/absent Freighter extension was polled forever atthe same rate.
This PR maps those in-band errors onto the existing wallet error codes (and the
existing i18n keys), funnels every
wallet_session_startwrite through one helper,and replaces the fixed interval with a capped exponential backoff.
Changes
Freighter errors map to codes + i18n keys
frontend/src/lib/walletConnectionState.ts: newclassifyFreighterApiError()which classifies an in-band Freighter payload (
getAddress,isAllowed,isConnected, …) with the same rules as thrown errors and keeps the originalmessage plus the Freighter code for diagnostics.
frontend/src/hooks/useWalletConnection.ts:performConnectnow classifiesgetAddress().errorbefore falling back toNO_ADDRESS, dispatchingCONNECT_FAILEDwith a typed error. The UI keeps rendering copy fromwalletErrorI18nKeys(code)(WalletConnect), so a user rejection now shows therejection copy instead of the generic "no address" text.
wallet_session_starthas a single writerfrontend/src/lib/walletSession.ts: newWALLET_SESSION_START_KEY,getWalletSessionStart()andstartWalletSession().useWalletConnection.tsandfrontend/src/context/AuthContext.tsxnow read/writethat key only through these helpers (no direct
localStorageaccess for this key).Polling backs off after failures
useWalletConnection.ts: the poll loop is now a recursivesetTimeoutusing theexported pure helper
getWalletPollDelay(consecutiveFailures). The delay doublesper consecutive failure (10s → 20s → 40s → …) and is capped at 60s (1.6s in
tests); any successful poll resets the counter. Errors during a poll are caught,
logged and counted as a failure instead of escaping the
setIntervalcallback.Tests
frontend/src/hooks/useWalletConnection.test.tsx:{ address: "", error: { code: 3, message: "User rejected the request." } })produces
USER_REJECTED+ the matchingwalletErrorI18nKeys, notNO_ADDRESS;PERMISSION_DENIEDand keeps the message + code;NO_ADDRESS;wallet_session_startthroughlib/walletSession;getWalletPollDelaygrows per failure and is capped;(the fixed 100ms test interval would poll ~15 times).
frontend/src/lib/walletConnectionState.test.ts:classifyFreighterApiErrorcases (rejection, permission, not-installed → non-retryable, unknown payload,
code suffix).
frontend/src/lib/walletSession.test.ts: session-start helper cases.frontend/src/components/SessionExpiryWarning.test.tsx: mock switched toimportOriginalso the real session helpers stay available.Verification
TZ=UTC npx vitest run→ 129 files / 1391 tests passingnpm run lint→ 0 errors (37 pre-existing warnings, unchanged)npx tsc -b→ cleannpm run build→ exit 0npm run check-size→ 7/7 checks passedNotes
Contracts lint + test + build,Rust + WASM CI,Cargo Security Audit,Slither,NPM/PNPM Audit,GitHub Dependency ReviewandGovernance & PR Standards Validationfail identically onmain(verified againstthe current baseline PRs); they are unrelated to this change.