Conversation
Closes bcnmy#212. toWalletClient() selected the browser branch purely from the unresolved signer's transport key ("custom") and then built custom(window?.ethereum) unconditionally. When a user connects without a wallet extension (e.g. via a 3rd-party email / web2 connector), window.ethereum is undefined, so custom(undefined) produced a transport that threw "Cannot read properties of undefined (reading 'request')" from toNexusAccount. Only take the injected-provider branch when window.ethereum is actually present; otherwise fall back to the resolved local signer and the provided transport. Adds unit tests asserting toWalletClient no longer throws (and uses the resolved signer account) when the transport key is "custom" but no provider is injected.
This branch has not been deployed
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.
What
Closes #212.
toNexusAccountthrowsTypeError: Cannot read properties of undefined (reading 'request')when the user has no wallet extension installed (window.ethereum === undefined) — e.g. when they connect via a 3rd-party email / web2 connector.Root cause
toWalletClient()decided the browser branch purely from the unresolved signer's transport key (=== "custom") and then builtcustom(window?.ethereum)unconditionally. The?.guardswindow, notwindow.ethereum, socustom(undefined)produced a transport whose.requestis missing — the error surfaces later insidecreateWalletClient/toNexusAccount.Fix
Only take the injected-provider branch when an EIP-1193 provider is actually present on
window.ethereum. Otherwise fall back to the resolved local signer and the providedtransport(the same path non-browser signers already use). Also guardstypeof windowfor non-browser (SSR/node) environments.Tests
Added
src/sdk/account/utils/toWalletClient.test.ts:toWalletClientno longer throws when the transport key is"custom"but no provider is injected.Verified genuine RED→GREEN: both tests fail against the current code and pass with the fix.
Validation
vitest run(the two new tests) → 2 passedtsc --noEmit→ no errors in the changed filesbiome checkon changed files → clean (exit 0)First-time contributor — happy to adjust the approach or naming.
PR-Codex overview
This PR focuses on improving the handling of the
toWalletClientfunction when the signer is created with acustomtransport key but no injected provider (likewindow.ethereum) is available. It ensures that the application does not crash in such scenarios and falls back to the resolved signer.Detailed summary
toWalletClientto check for an injected provider before using it.toWalletClient.test.tsto cover scenarios where the provider is undefined.window.ethereumis not available.