Skip to content

feat(wallet): add settings toggle for staging Pay config#1039

Open
ganchoradkov wants to merge 2 commits into
mainfrom
feat/pay-env-staging-toggle
Open

feat(wallet): add settings toggle for staging Pay config#1039
ganchoradkov wants to merge 2 commits into
mainfrom
feat/pay-env-staging-toggle

Conversation

@ganchoradkov

Copy link
Copy Markdown
Member

Summary

Adds a Pay Environment toggle to the react-wallet-v2 settings page that defaults to production and switches to the staging Pay environment only when enabled.

Previously the staging branch was gated behind process.env.PAY_ENV, which is not exposed to the browser bundle (no NEXT_PUBLIC_ prefix), making the staging config effectively unreachable client-side. This replaces that with a persisted, user-controllable toggle.

Changes

  • src/store/SettingsStore.ts — new payStagingEnabled state (default false), a PAY_STAGING localStorage key, and a togglePayStagingEnabled() action, following the existing toggle pattern.
  • src/utils/WalletConnectUtil.tscreateWalletKit derives useStaging from SettingsStore.state.payStagingEnabled (falling back to NEXT_PUBLIC_PAY_ENV for env-based setups). Staging appId/baseUrl are used only when opted in; production is the default.
  • src/pages/settings.tsx — a Production/Staging switch with a hint that a page reload is required to apply.

Flow

flowchart TD
    A[Settings page toggle] -->|togglePayStagingEnabled| B[SettingsStore.payStagingEnabled]
    B --> C[localStorage: PAY_STAGING]
    C -->|on reload| D[createWalletKit]
    E[NEXT_PUBLIC_PAY_ENV fallback] --> D
    D -->|useStaging?| F{Pay env}
    F -->|true| G[staging appId + baseUrl]
    F -->|false default| H[production appId + apiKey + baseUrl]
Loading

Note

walletkit is created once during initialization, so changing the toggle requires a page reload to take effect — documented in the UI hint rather than wiring up live re-initialization.

🤖 Generated with Claude Code

Add a Pay Environment toggle in the react-wallet-v2 settings page that
defaults to production and switches to the staging Pay environment when
enabled. The toggle state is persisted to localStorage and read by
createWalletKit, which now selects the staging appId/baseUrl when the
toggle is on (or NEXT_PUBLIC_PAY_ENV is set to a non-production value).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 9, 2026 08:36
@vercel

vercel Bot commented Jun 9, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
decentralized-relay-wallet Ready Ready Preview, Comment Jun 9, 2026 11:05am
pos-dapp Ready Ready Preview, Comment Jun 9, 2026 11:05am
react-wallet-v2 Ready Ready Preview, Comment Jun 9, 2026 11:05am
wdk-wallet-example Error Error Jun 9, 2026 11:05am
6 Skipped Deployments
Project Deployment Actions Updated (UTC)
appkit-react-wagmi-example Ignored Ignored Jun 9, 2026 11:05am
appkit-solana Ignored Ignored Jun 9, 2026 11:05am
chain-abstraction-demo Ignored Ignored Preview Jun 9, 2026 11:05am
malicious-dapp-verify-simulation Ignored Ignored Preview Jun 9, 2026 11:05am
react-dapp-v2 Ignored Ignored Preview Jun 9, 2026 11:05am
smart-sessions-demo Ignored Ignored Preview Jun 9, 2026 11:05am

Request Review

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a persisted “Pay Environment” toggle in the React wallet settings to allow opting into WalletConnect Pay’s staging environment client-side (defaulting to production), replacing the prior non-browser-exposed env gating.

Changes:

  • Add payStagingEnabled setting persisted to localStorage with a toggle action.
  • Derive Pay env selection in createWalletKit() from settings (with env fallback) and use staging/prod Pay endpoints accordingly.
  • Add a Production/Staging switch to the settings page with a reload hint.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
advanced/wallets/react-wallet-v2/src/utils/WalletConnectUtil.ts Derives Pay env from settings/env and configures WalletKit Pay settings; adjusts session typing in updateSignClientChainId.
advanced/wallets/react-wallet-v2/src/store/SettingsStore.ts Introduces payStagingEnabled state, PAY_STAGING storage key, and a toggle action.
advanced/wallets/react-wallet-v2/src/pages/settings.tsx Adds the Pay Environment toggle UI and reload hint text.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +21 to +23
const env = process.env.NEXT_PUBLIC_PAY_ENV || 'production'
// Defaults to production. The settings toggle (or NEXT_PUBLIC_PAY_ENV=staging) opts into staging.
const useStaging = SettingsStore.state.payStagingEnabled || env !== 'production'
Comment on lines +45 to +56
payConfig: {
...(useStaging
? {
appId: stagingPayAppId,
baseUrl: stagingPayUrl
}
: {
appId: payProjectId,
apiKey,
baseUrl: prodPayUrl
})
}
Comment on lines +73 to +77
Object.values(sessions as unknown as Record<string, SessionTypes.Struct>).forEach(
async (session: SessionTypes.Struct) => {
await walletkit.updateSession({
topic: session.topic,
namespaces: {
Add a PayEnvPill component that surfaces the active Pay environment
(production / staging) driven by the settings toggle, and render it in
the PaymentOptionsModal header and SessionCheckoutModal title row.

Also log the resolved Pay environment and the payment link uri before
fetching payment options to aid debugging.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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