Skip to content

connectWallet() can return undefined typed as string #369

Open

Description

@presidojay1

src/lib/wallet.ts:30-36:

export async function connectWallet(): Promise<string> {
  const result = await requestAccess();
  if (result.error) {
    throw new WalletError(result.error.message ?? 'Could not connect to Freighter');
  }
  return result.address;
}

Only result.error is checked. currentWalletAddress two functions down
(:38-42) checks both — if (result.error || !result.address) return null —
which shows the API can return a success with no address (user closes the
Freighter popup without choosing an account, a locked wallet that resolves
without erroring, an account list that comes back empty).

In that case connectWallet returns undefined through a Promise<string>
signature, and src/components/wallet-connect-button.tsx:44-45 PATCHes it
straight to the backend:

const address = await connectWallet();
await apiFetch('/users/me/wallet', { method: 'PATCH', body: { stellarPublicKey: address } });

JSON.stringify({ stellarPublicKey: undefined }) drops the key entirely, so
the request body is {} — the user gets whatever the backend's validator says
about a missing field, with no hint that the wallet never handed over an
address.

Fix: mirror currentWalletAddress's guard and throw a WalletError ("No
account was selected in Freighter") when result.address is falsy. Add the case
to src/lib/wallet.test.ts.

Activity

  1. added
    bug
    on Nov 12, 2026
  2. added
    Stellar Wave
    on Nov 21, 2026
  3. Lebmont8 commented on Nov 21, 2026

    @Lebmont8

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

    Hello, I'm interested in taking this issue on.

    I'm a full-stack developer with 4+ years of experience, working with TypeScript and frontend integrations. I'll build this to match the patterns already used elsewhere in the project, with tests covering the new behavior.

    Planned approach, based on the acceptance criteria:

    • Reject a missing or empty Freighter address with a clear WalletError, matching currentWalletAddress's guard
    • Keep successful connections and existing wallet error messages unchanged
    • Extend wallet.test.ts to cover no account selected, a valid address, and an extension error
    • Verify the failed connection cannot proceed to the wallet-update request, then run the frontend checks

    Looking forward to contributing — please assign this issue to me.

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

  4. hameedx01 commented on Nov 25, 2026

    @hameedx01

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

    Hi, Maintainer, i would like to work on this issue, pls can you kindly assign it to me?.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stellar Wavebug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions