Skip to content

fix(wallet-sdk): allow popup messenger access before open()#34

Merged
coffeexcoin merged 3 commits into
mainfrom
claude/fix-wallet-sdk-popup-8nXfD
May 9, 2026
Merged

fix(wallet-sdk): allow popup messenger access before open()#34
coffeexcoin merged 3 commits into
mainfrom
claude/fix-wallet-sdk-popup-8nXfD

Conversation

@coffeexcoin
Copy link
Copy Markdown
Contributor

Wallet.ts calls bindMessengerListeners(handle) synchronously inside
ensureActive(), which means listeners are registered on the popup
handle's messenger before the user-gesture click that mounts the
popup window. The previous popup factory exposed messenger as a
getter that threw "Popup messenger not initialised" until open()
created the bridge — so the iframe→popup downgrade path threw the
moment switchMode("popup") ran (e.g. on browsers without
IntersectionObserver v2 where the parent origin isn't on the wallet
host's trustedHosts allowlist, which is what the agw-wallet-sdk-demo
hit).

Replace the lazy getter with a stable proxy that buffers on()/send()
calls until open() adopts a real bridge, then replays them. waitForReady()
also resolves through the proxy so callers don't need to time their
calls around open(). Behaviour after open() is unchanged.

Wallet.ts calls bindMessengerListeners(handle) synchronously inside
ensureActive(), which means listeners are registered on the popup
handle's messenger before the user-gesture click that mounts the
popup window. The previous popup factory exposed `messenger` as a
getter that threw "Popup messenger not initialised" until open()
created the bridge — so the iframe→popup downgrade path threw the
moment switchMode("popup") ran (e.g. on browsers without
IntersectionObserver v2 where the parent origin isn't on the wallet
host's trustedHosts allowlist, which is what the agw-wallet-sdk-demo
hit).

Replace the lazy getter with a stable proxy that buffers on()/send()
calls until open() adopts a real bridge, then replays them. waitForReady()
also resolves through the proxy so callers don't need to time their
calls around open(). Behaviour after open() is unchanged.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
agw-wallet-sdk-demo Ready Ready Preview, Comment May 9, 2026 0:31am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
agw-nextjs Skipped Skipped May 9, 2026 0:31am
mpp-demo Skipped Skipped May 9, 2026 0:31am

Request Review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

Drop the previous buffered-messenger proxy in favour of Porto's
inverted dependency: factories own listener wiring internally and
consumers route data through callbacks (`DialogHandlers`) plus a
narrow outbound surface (`syncRequest`, `waitForReady`).

- `DialogHandle` no longer exposes `messenger`; the underlying
  Messenger.Bridge is closure-local in each factory.
- `DialogFactory` now takes a `handlers` parameter; each factory
  registers `rpc-response` / `__internal` / `close` listeners on its
  own messenger (the popup factory does it inside `open()` once the
  bridge is constructable).
- `Wallet.ts` builds a single `DialogHandlers` struct and stops
  re-wiring listeners per handle. `bindMessengerListeners` is gone.
- `syncRequest` mirrors Porto's optional-chained `messenger?.send`
  pattern; pre-open calls are no-ops so a stale request stays in
  the consumer's pending map until the next mode switch.

This removes the original "Popup messenger not initialised" error by
construction (no lazy getter exists to throw) and keeps the SDK
mechanically close to upstream Porto for future ports.
@vercel vercel Bot temporarily deployed to Preview – mpp-demo May 9, 2026 12:30 Inactive
@vercel vercel Bot temporarily deployed to Preview – agw-nextjs May 9, 2026 12:30 Inactive
@coffeexcoin coffeexcoin merged commit 24976b9 into main May 9, 2026
13 checks passed
@coffeexcoin coffeexcoin deleted the claude/fix-wallet-sdk-popup-8nXfD branch May 9, 2026 12:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants