-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Bug Report
Summary
When projectId is an empty string or contains only whitespace (which happens when an environment variable is missing or has a trailing newline in a .env file), the WalletConnect connector initializes without throwing any error. The QR modal never appears and connections silently fail, with no indication of what went wrong.
Reproduction
import { createConfig, http } from 'wagmi'
import { mainnet } from 'wagmi/chains'
import { walletConnect } from 'wagmi/connectors'
// Missing env var scenario — VITE_WC_PROJECT_ID is undefined
const projectId = import.meta.env.VITE_WC_PROJECT_ID ?? ''
const config = createConfig({
chains: [mainnet],
transports: { [mainnet.id]: http() },
connectors: [
walletConnect({ projectId }), // no error thrown here
],
})
// Later, when the user tries to connect:
// → QR modal never opens
// → No error surfaces
// → User is stuck with no feedbackExpected Behavior
walletConnect({ projectId: '' }) should throw immediately with a clear error message pointing to https://cloud.walletconnect.com.
Actual Behavior
No error is thrown. The connector is created successfully, but connections silently fail at runtime when the user attempts to connect.
Context
This is a common pain point when deploying to environments where VITE_WC_PROJECT_ID / REACT_APP_WC_PROJECT_ID / NEXT_PUBLIC_WC_PROJECT_ID is not set, or when .env files have trailing newlines that corrupt the value. The current behavior forces developers to add their own manual validation guard.
Proposed Fix
Validate and trim projectId at connector creation time, throwing a BaseError with a clear message and link to cloud.walletconnect.com.