Skip to content

fix(wallet): export Starknet embedded key when network is Starknet#498

Merged
chibie merged 1 commit into
mainfrom
fix/starknet-privy-export-wallet
May 8, 2026
Merged

fix(wallet): export Starknet embedded key when network is Starknet#498
chibie merged 1 commit into
mainfrom
fix/starknet-privy-export-wallet

Conversation

@chibie
Copy link
Copy Markdown
Contributor

@chibie chibie commented May 8, 2026

Description

Embedded wallet export was always calling Privy’s exportWallet() with no arguments, so Privy defaulted to HD index 0 (the EVM embedded wallet). Users on Starknet saw the wrong address in the export modal and could not export their Starknet key.

This change adds useHandleExportEmbeddedWallet, which passes exportWallet({ address }) when the selected network is Starknet, using the same address as useWalletAddress() (the Privy Starknet embedded account). Desktop settings and mobile settings both use this handler. EVM behavior is unchanged (exportWallet() with no args).

TypeScript: baseUrl is set on main tsconfig; __tests__ are excluded from the app project and covered by tsconfig.tests.json so tsc is not blocked by Jest matchers. No API or contract changes.

References

None.

Testing

Manual: log in with embedded wallet, select Starknet, open Export wallet from settings (desktop dropdown and mobile settings). Confirm the modal shows the Starknet address and export completes. Switch to an EVM network and confirm export still targets the default EVM embedded flow.

Automated: pnpm exec tsc --noEmit -p tsconfig.json && pnpm exec tsc --noEmit -p tsconfig.tests.json

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • I have added documentation and tests for new/changed functionality in this PR
  • All active GitHub checks for tests, formatting, and security are passing
  • The correct base branch is being used, if not main

By submitting a PR, I agree to Paycrest's Contributor Code of Conduct and Contribution Guide.

Summary by CodeRabbit

Release Notes

  • New Features

    • Wallet export functionality now includes network-specific handling for improved reliability across different blockchain networks.
    • Enhanced error handling with user-friendly notifications during export failures.
    • Wallet export operations now support asynchronous processing.
  • Chores

    • Updated TypeScript configuration and expanded test infrastructure setup.

@chibie chibie requested review from 5ran6 and onahprosper as code owners May 8, 2026 19:48
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e7155085-60d8-4bc3-9e74-8ad97a0d8d53

📥 Commits

Reviewing files that changed from the base of the PR and between 226b277 and cdf963d.

📒 Files selected for processing (6)
  • app/components/MobileDropdown.tsx
  • app/components/SettingsDropdown.tsx
  • app/components/wallet-mobile-modal/SettingsView.tsx
  • app/hooks/useHandleExportEmbeddedWallet.ts
  • tsconfig.json
  • tsconfig.tests.json

📝 Walkthrough

Walkthrough

This PR extracts wallet export functionality from the Privy hook into a dedicated hook that adds network-aware logic, particularly requiring an address parameter for Starknet chains. Two dropdown components are updated to use the new hook, and TypeScript configuration is improved with a dedicated test config.

Changes

Embedded Wallet Export Refactor

Layer / File(s) Summary
Hook Implementation
app/hooks/useHandleExportEmbeddedWallet.ts
New useHandleExportEmbeddedWallet hook returns a memoized async callback. For Starknet, it requires a wallet address and calls exportWallet({ address }); for other networks, it calls exportWallet() without parameters. Errors are caught and surfaced via error toast.
Prop Type Update
app/components/wallet-mobile-modal/SettingsView.tsx
SettingsViewProps.exportWallet signature widened from () => void to () => void | Promise<void> to support async export.
MobileDropdown Integration
app/components/MobileDropdown.tsx
Imports useHandleExportEmbeddedWallet, initializes the handler, and passes it to SettingsView instead of exportWallet from usePrivy.
SettingsDropdown Integration
app/components/SettingsDropdown.tsx
Imports useHandleExportEmbeddedWallet, initializes the handler, and updates the Export wallet menu item to invoke the new handler instead of usePrivy's exportWallet.
TypeScript Configuration
tsconfig.json, tsconfig.tests.json
Root tsconfig.json adds baseUrl: "." and excludes __tests__ directory. New tsconfig.tests.json extends root config and configures Jest, testing-library, and Node types for test files in __tests__/.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant Component as MobileDropdown<br/>SettingsDropdown
  participant Handler as useHandleExportEmbeddedWallet
  participant Toast
  participant Privy as Privy exportWallet

  User->>Component: Click export wallet
  Component->>Handler: Call handleExportEmbeddedWallet()
  Handler->>Handler: Check selected chain
  alt Starknet chain
    Handler->>Handler: Get wallet address
    alt No address available
      Handler->>Toast: Show error (missing address)
    else Address present
      Handler->>Privy: exportWallet({ address })
    end
  else Other chain
    Handler->>Privy: exportWallet()
  end
  alt Export succeeds
    Privy-->>Handler: Success
  else Export fails
    Privy-->>Handler: Error
    Handler->>Toast: Show error (export failed)
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • paycrest/noblocks#387: Both PRs modify how the "exportWallet" handler is provided and used in MobileDropdown/SettingsDropdown/SettingsView components.

Suggested reviewers

  • onahprosper
  • 5ran6

Poem

🐇 A wallet export, now with flair,
Network-aware, it's handled with care,
Starknet takes an address so fine,
While others just export online,
Hopping through chains, the magic is there!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(wallet): export Starknet embedded key when network is Starknet' directly matches the main objective of the PR—fixing wallet export for Starknet network by passing the correct address to Privy's exportWallet function.
Description check ✅ Passed The PR description covers the problem, solution, TypeScript configuration changes, testing approach (manual and automated), and follows the template structure with all major sections completed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/starknet-privy-export-wallet

Comment @coderabbitai help to get the list of available commands and usage tips.

@chibie chibie merged commit b11c375 into main May 8, 2026
1 check passed
@chibie chibie deleted the fix/starknet-privy-export-wallet branch May 8, 2026 19:55
@coderabbitai coderabbitai Bot mentioned this pull request May 22, 2026
4 tasks
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.

1 participant