Repository navigation
fix(freighter): readFreighterConnection returns null when getAddress … - #334
Merged
Merged
Conversation
…times out readFreighterConnection is documented to return null when the extension is not reachable, but `await withTimeout(getAddress())` sat outside any try. A slow or locked extension made it reject with FreighterUnavailableError, and callers such as useWallet and WalletStatusBadge fell into their catch and showed "disconnected" instead of "unavailable". The getAddress call is now wrapped: a timeout or rejection returns null, the same as a failed isConnected probe. A locked wallet (getAddress answers with an error) still reports publicKey: null. New __tests__/readFreighterConnection.test.ts covers getAddress never settling (fake timers past the 2.5 s probe timeout), rejecting, answering with an error, and succeeding. The first two fail without this fix. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@Ike-Nathan 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.
Problem
readFreighterConnection()is documented to returnnullwhen the extension isn't reachable. Butawait withTimeout(getAddress())was outside anytry. When the extension was slow or locked, the call rejected withFreighterUnavailableError, and callers such asuseWalletandWalletStatusBadgecaught it and showed "disconnected" instead of "unavailable".Fix
getAddressis now wrapped in atry. A timeout or rejection returnsnull, the same as the existingisConnectedprobe failure.getAddressanswers with anerror, the function returns{ publicKey: null, ... }.lib/freighter.ts).Tests
New
__tests__/readFreighterConnection.test.ts:getAddressnever settles (fake timers past the 2.5 s probe timeout) →nullgetAddressrejects →nullgetAddressanswers with an error (locked wallet) →publicKey: nullThe first two fail without the fix. On the rest of the unit suite there are no new failures: main already has 43 failing tests (the ContractsPage, ContractDetail and FreighterConnect suites, among others), and they fail the same way before and after this change.
Closes #185