Skip to content

Handle Freighter network-mismatch and wallet-state edge cases before signing #2

Closed

Description

@chonilius

Problem

src/lib/wallet.ts#connectWallet and signTransaction call directly into @stellar/freighter-api with no handling for the extension being absent, locked, on the wrong network, or the user rejecting the permission prompt mid-flow. isFreighterInstalled checks freighterIsConnected(), but nothing in WalletContext.tsx or the /connect flow re-verifies network match before a signing operation is attempted from IssueActions.tsx or MilestoneActions.tsx. Given STELLAR_NETWORK is an env-driven constant (TESTNET default) and Freighter itself has an independently user-selected network, there is a realistic scenario where a contributor has Freighter set to Stellar PUBLIC while the app is configured for TESTNET (or vice versa after an env misconfiguration), and signTransaction will happily sign a transaction with the wrong network passphrase, producing a transaction Soroban will reject — but only after the user has already approved it in the extension, burning their attention and creating a confusing "why did my claim fail" support case.

Why this is hard

  • Freighter's API surface (isConnected, isAllowed, setAllowed, getAddress, signTransaction) doesn't expose "what network is the extension currently on" in a stable way across Freighter versions — you'll need to research the current @stellar/freighter-api version pinned in package.json (^6.0.1) and determine what's actually available (e.g. getNetwork/getNetworkDetails) and handle it being undefined on older installed extension versions.
  • You must design a pre-flight check that runs before every signTransaction call site (currently there's only one wrapper, but callers in IssueActions.tsx/MilestoneActions.tsx need to be identified and each guarded) without introducing a race between the check and the actual sign call (user could switch networks in the extension between the two).
  • Error surfaces must be humane: distinguish "extension not installed," "extension locked," "wrong network," "user rejected," and "unknown error" with different UI treatments — right now connectWallet collapses everything into generic thrown Errors.
  • WalletContext's WALLET_KEY localStorage persistence needs to be reconciled: what happens on next page load if the persisted address no longer matches the currently unlocked Freighter account?

Scope

  • Add a network-mismatch pre-flight check used by every signing call site.
  • Expand WalletConnection/error types to a discriminated union covering the failure modes above.
  • Update WalletContext.tsx to expose a networkMismatch boolean and surface it in the connect UI.
  • Add graceful re-sync when the stored address diverges from the live extension address on mount.

Acceptance criteria

  • Simulate (via mocking @stellar/freighter-api) each failure mode and confirm distinct, correct UI messaging.
  • No transaction signing is attempted when a network mismatch is detected; the user is blocked with an actionable message instead.

Activity

  1. added
    very hard
    bug
    security
    on Jul 15, 2026
  2. added
    GrantFox OSS
    Maybe Rewarded
    Official Campaign | FWC26
    on Jul 15, 2026
  3. added
    Stellar Wave
    on Aug 25, 2026
  4. devgodfreytem commented on Aug 25, 2026

    @devgodfreytem
    Contributor

    @devgodfreytem has applied to work on this issue as part of the Stellar Wave Program's 8th wave.

    Hello maintainer, i would love to work on this issue.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @devgodfreytem to this issue.

  5. drips-wave commented on Aug 25, 2026

    @drips-wave

    Congratulations, @devgodfreytem! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on August 31, 2026.

    🧑‍💻 @devgodfreytem: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  6. drips-wave commented on Aug 25, 2026

    @drips-wave

    This issue has been completed by @devgodfreytem as part of the Stellar Wave Program's 8th Wave 🥳

    😎 @devgodfreytem: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  7. removed
    Stellar Wave
    on Oct 15, 2026
  8. added
    Stellar Wave
    on Oct 15, 2026
  9. removed
    Stellar Wave
    on Oct 15, 2026
  10. added
    Stellar Wave
    on Oct 15, 2026
  11. removed
    Stellar Wave
    on Oct 15, 2026
  12. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSMaybe RewardedOfficial Campaign | FWC26Stellar Wavebugsecurityvery hard

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions