fix(wallet-sdk): allow popup messenger access before open()#34
Merged
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
|
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.
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.
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
messengeras agetter 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.