Skip to content

fix: detect network passphrase mismatch and show prompt modal - #558

Open
abikedaniel22 wants to merge 2 commits into
Fundable-Protocol:mainfrom
abikedaniel22:fix/network-passphrase-mismatch
Open

fix: detect network passphrase mismatch and show prompt modal#558
abikedaniel22 wants to merge 2 commits into
Fundable-Protocol:mainfrom
abikedaniel22:fix/network-passphrase-mismatch

Conversation

@abikedaniel22

@abikedaniel22 abikedaniel22 commented Jul 29, 2026

Copy link
Copy Markdown

Check wallet extension's active network passphrase against the app's configured network (WalletNetwork) during both connect() and signTransaction(). On mismatch:

  • connect(): aborts the connection and shows a blocking modal
  • signTransaction(): throws a descriptive error and shows the modal

The NetworkMismatchModal (rendered inline in StellarWalletProvider) uses the existing Dialog component and gives the user two options:

  1. Dismiss — close the modal and fix their wallet manually
  2. Switch App to — aligns the app's network to match the wallet, which disconnects the current session first

Also exports NETWORK_PASSPHRASES map so consumers can reference the canonical passphrase strings for each WalletNetwork value.

Closes #382

Summary by CodeRabbit

  • New Features
    • Added wallet network mismatch detection during connection and transaction signing.
    • Added a dialog explaining mismatches, showing the detected wallet network and offering options to dismiss or switch networks.
    • Prevented connections and transactions until the wallet and app networks match.
    • Added wallet context status for network mismatch detection.

Check wallet extension's active network passphrase against the app's
configured network (WalletNetwork) during both connect() and
signTransaction(). On mismatch:

- connect(): aborts the connection and shows a blocking modal
- signTransaction(): throws a descriptive error and shows the modal

The NetworkMismatchModal (rendered inline in StellarWalletProvider)
uses the existing Dialog component and gives the user two options:
  1. Dismiss — close the modal and fix their wallet manually
  2. Switch App to <wallet network> — aligns the app's network to match
     the wallet, which disconnects the current session first

Also exports NETWORK_PASSPHRASES map so consumers can reference the
canonical passphrase strings for each WalletNetwork value.

Closes Fundable-Protocol#382
@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@abikedaniel22 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

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 Plus

Run ID: 7775f00b-4ef0-4670-b729-92de6654b2c4

📥 Commits

Reviewing files that changed from the base of the PR and between 39b363b and 4c588c1.

📒 Files selected for processing (1)
  • apps/web/src/providers/StellarWalletProvider.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/web/src/providers/StellarWalletProvider.tsx

📝 Walkthrough

Walkthrough

StellarWalletProvider detects wallet and app network passphrase mismatches during connection and transaction signing. It exposes mismatch state, blocks incompatible operations, and renders controls to dismiss the dialog or switch the app network.

Changes

Wallet network mismatch handling

Layer / File(s) Summary
Network contract and mismatch state
apps/web/src/providers/StellarWalletProvider.tsx
Adds exported network passphrases, mismatch context state, detected wallet network naming, and reset behavior.
Connection and signing validation
apps/web/src/providers/StellarWalletProvider.tsx
Checks wallet networks through getNetwork(), prevents mismatched connections, and rejects signing with a network-specific error.
Mismatch modal and network switching
apps/web/src/providers/StellarWalletProvider.tsx
Adds a mismatch dialog with dismiss and app-network switching actions using setNetwork.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant App
  participant StellarWalletProvider
  participant WalletExtension
  participant MismatchModal
  App->>StellarWalletProvider: connect or signTransaction
  StellarWalletProvider->>WalletExtension: getNetwork()
  WalletExtension-->>StellarWalletProvider: active network passphrase
  StellarWalletProvider->>StellarWalletProvider: compare wallet and app networks
  StellarWalletProvider->>MismatchModal: render mismatch dialog
  MismatchModal->>StellarWalletProvider: dismissMismatchModal or switchAppNetwork
  StellarWalletProvider->>WalletExtension: setNetwork(wallet network)
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly describes the main change: detecting network passphrase mismatches and displaying a prompt modal to the user.
Linked Issues check ✅ Passed The PR implements network passphrase mismatch detection in StellarWalletProvider with a modal prompt, addressing issue #382's requirements to detect mismatches and prompt network switching.
Out of Scope Changes check ✅ Passed All changes focus on network passphrase mismatch detection and handling within StellarWalletProvider, remaining within the scope of issue #382.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 5

🧹 Nitpick comments (1)
apps/web/src/providers/StellarWalletProvider.tsx (1)

416-421: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

No-op try/catch.

This catch only rethrows the caught error unchanged; it can be removed without changing behavior.

♻️ Simplify
-      try {
-        const { signedTxXdr } = await kit.signTransaction(xdr);
-        return signedTxXdr;
-      } catch (error) {
-        throw error;
-      }
+      const { signedTxXdr } = await kit.signTransaction(xdr);
+      return signedTxXdr;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@apps/web/src/providers/StellarWalletProvider.tsx` around lines 416 - 421,
Remove the no-op try/catch around the kit.signTransaction call in the
transaction-signing flow, allowing signedTxXdr to be returned directly while
preserving unchanged error propagation.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/providers/StellarWalletProvider.tsx`:
- Around line 439-449: Store the detected WalletNetwork value alongside
walletNetworkName in checkNetworkPassphrase, including an unset value for
unrecognized passphrases. Update switchAppNetwork to use that stored network
directly instead of reverse-looking up NETWORK_DISPLAY_NAMES, and prevent the
switch action when no recognized network is available. Preserve the existing
mismatch and modal state cleanup for valid switches.
- Around line 228-279: Update checkNetworkPassphrase so fail-open applies only
when walletKit.getNetwork is not implemented. Treat an empty walletPassphrase
and any getNetwork() exception as unsafe by logging the failure, updating the
network mismatch state, and returning false; preserve the existing matching and
known-network mismatch handling.
- Around line 41-47: Update NETWORK_PASSPHRASES and the wallet network handling
to derive the expected passphrase directly from the selected network, using the
pinned stellar-wallets-kit values, especially the SANDBOX passphrase with
September 2022. Remove the duplicated WalletNetwork passphrase mapping so
walletNetworkName() receives the correct value and no longer falls back to
"Unknown".
- Around line 399-424: Update checkNetworkPassphrase to return both its
pass/fail result and the freshly detected wallet network name, then use that
returned name in signTransaction’s mismatch error instead of the captured
walletNetworkName state. Update connect() at its existing call site to
destructure and handle the revised return value while preserving its current
state updates and validation behavior.
- Around line 474-521: Remove the onOpenAutoFocus preventDefault handler from
the networkMismatch DialogContent so Radix can move focus into the modal when it
opens. Preserve the existing Dismiss and switchAppNetwork actions and dialog
behavior.

---

Nitpick comments:
In `@apps/web/src/providers/StellarWalletProvider.tsx`:
- Around line 416-421: Remove the no-op try/catch around the kit.signTransaction
call in the transaction-signing flow, allowing signedTxXdr to be returned
directly while preserving unchanged error propagation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eedcdd7c-3593-4aca-b7ce-ba98f637945e

📥 Commits

Reviewing files that changed from the base of the PR and between 375c936 and 39b363b.

📒 Files selected for processing (1)
  • apps/web/src/providers/StellarWalletProvider.tsx

Comment thread apps/web/src/providers/StellarWalletProvider.tsx
Comment thread apps/web/src/providers/StellarWalletProvider.tsx
Comment thread apps/web/src/providers/StellarWalletProvider.tsx
Comment thread apps/web/src/providers/StellarWalletProvider.tsx
Comment thread apps/web/src/providers/StellarWalletProvider.tsx
@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

1 similar comment
@Idrhas

Idrhas commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates

@abikedaniel22

Copy link
Copy Markdown
Author

Hi mainiainer
I've resolved all conflicts pls check and merge PR

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.

web(StellarWalletProvider): prompt network switch on passphrase mismatch

2 participants