feat(dev): auto-init wallet from VITE_DEV_NSEC for local testing#448
Conversation
Add dev-only shortcut that bypasses onboarding and unlock screens when VITE_DEV_NSEC is set in .env.local. Converts the NSEC to a private key and calls initWallet() automatically once the ASP server info is ready. This is gated behind import.meta.env.DEV so it is completely tree-shaken out of production builds and has zero effect when the env var is absent. Saves significant time during local development — no more re-entering the seed phrase on every page reload or new worktree.
|
Hey team — are you guys OK with this? This is a small dev-only QoL improvement so I don't have to re-enter the NSEC seed phrase every time I reload or switch branches during local testing. It's gated behind If any of you want to use it too, just add |
WalkthroughDevelopment-only wallet auto-initialization has been added. When DEV mode is enabled with VITE_DEV_NSEC set, the wallet automatically initializes using the provided NSEC, bypassing onboarding and unlock. The loading screen is preserved during this initialization process. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can generate walkthrough in a markdown collapsible section to save space.Enable the |
Deploying wallet-bitcoin with
|
| Latest commit: |
323133f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f249e9e7.wallet-bitcoin.pages.dev |
| Branch Preview URL: | https://wt-dev-nsec-bypass-20260318.wallet-bitcoin.pages.dev |
🔍 Review —
|
Deploying wallet-mutinynet with
|
| Latest commit: |
323133f
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://715d5b15.arkade-wallet.pages.dev |
| Branch Preview URL: | https://wt-dev-nsec-bypass-20260318.arkade-wallet.pages.dev |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/providers/wallet.tsx (1)
135-152: Consider adding a guard ref to prevent overlapping initialization attempts.If
aspInfo.urlchanges whileinitWalletis in-flight (beforeinitializedbecomestrue), the effect will re-fire and start a second concurrent initialization. While unlikely in practice during dev startup, overlappinginitSvcWorkerWalletcalls could leave the service worker in an inconsistent state.🛡️ Optional: add an `initializingRef` guard
+ const devInitializing = useRef(false) + // dev-only: auto-initialize wallet from VITE_DEV_NSEC, bypassing onboarding and unlock useEffect(() => { if (!import.meta.env.DEV || !import.meta.env.VITE_DEV_NSEC) return if (initialized) return if (!aspInfo.url) return + if (devInitializing.current) return const autoInit = async () => { + devInitializing.current = true try { const privateKey = nsecToPrivateKey(import.meta.env.VITE_DEV_NSEC) await initWallet(privateKey) } catch (err) { consoleError(err, 'Dev auto-init failed') + } finally { + devInitializing.current = false } } autoInit() - // eslint-disable-next-line react-hooks/exhaustive-deps + // eslint-disable-next-line react-hooks/exhaustive-deps -- initWallet is intentionally excluded; including it would cause infinite re-runs }, [aspInfo.url, initialized])🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/providers/wallet.tsx` around lines 135 - 152, The effect can start overlapping initWallet runs when aspInfo.url changes; add a guard ref (e.g., initializingRef = useRef(false)) and check it at the top of the useEffect/autoinit to return early if already initializing, set initializingRef.current = true before calling initWallet, and clear it in a finally block (or keep it set if initialized becomes true) so only one initWallet(nsecToPrivateKey(...)) / initSvcWorkerWallet flow runs at a time; reference the existing useEffect, initialized, aspInfo.url, autoInit, nsecToPrivateKey and initWallet symbols when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/providers/wallet.tsx`:
- Around line 135-152: The effect can start overlapping initWallet runs when
aspInfo.url changes; add a guard ref (e.g., initializingRef = useRef(false)) and
check it at the top of the useEffect/autoinit to return early if already
initializing, set initializingRef.current = true before calling initWallet, and
clear it in a finally block (or keep it set if initialized becomes true) so only
one initWallet(nsecToPrivateKey(...)) / initSvcWorkerWallet flow runs at a time;
reference the existing useEffect, initialized, aspInfo.url, autoInit,
nsecToPrivateKey and initWallet symbols when making the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: caa2550e-1295-4b90-8f5c-b687b4dee8da
📒 Files selected for processing (2)
src/App.tsxsrc/providers/wallet.tsx
…os#448) Add dev-only shortcut that bypasses onboarding and unlock screens when VITE_DEV_NSEC is set in .env.local. Converts the NSEC to a private key and calls initWallet() automatically once the ASP server info is ready. This is gated behind import.meta.env.DEV so it is completely tree-shaken out of production builds and has zero effect when the env var is absent. Saves significant time during local development — no more re-entering the seed phrase on every page reload or new worktree. Co-authored-by: Sahil Chaturvedi <sahilc0@users.noreply.github.com>
Summary
Adds a dev-only shortcut that automatically initializes the wallet from a
VITE_DEV_NSECenvironment variable, completely bypassing the onboarding and unlock screens during local development.Why
Every time you reload the page, switch worktrees, or start a new dev session, you currently have to manually enter your NSEC seed phrase and go through the full onboarding flow before you can test anything. This is extremely slow when doing UI passes, debugging, or testing features that have nothing to do with onboarding.
What it does
wallet.tsx— Adds auseEffectthat checks forVITE_DEV_NSECwhen the app boots. If present, it converts the NSEC to a private key and callsinitWallet()directly, skipping both onboarding and the unlock screen.App.tsx— Adds a routing guard that prevents redirecting to the Init/Unlock screens while the dev auto-init is in progress. The user sees the normal loading screen until the wallet is ready, then lands straight in the wallet.Safety
import.meta.env.DEV, so it's tree-shaken out of production buildsVITE_DEV_NSECis not set, the code does absolutely nothing — zero impact for other developers or production.env.localwhich is already in.gitignore— it never touches git or GitHubHow to use
Add this to your
.env.local:Then
pnpm start— the wallet boots straight into the main screen, no onboarding, no unlock.Test plan
VITE_DEV_NSECset: app boots directly into wallet, no onboarding/unlock screens shownVITE_DEV_NSEC: app behaves exactly as before (normal onboarding/unlock flow)Summary by CodeRabbit
Note: This release contains development-focused improvements with no end-user feature changes.