fix: detect network passphrase mismatch and show prompt modal - #558
fix: detect network passphrase mismatch and show prompt modal#558abikedaniel22 wants to merge 2 commits into
Conversation
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
|
@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! 🚀 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughStellarWalletProvider 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. ChangesWallet network mismatch handling
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)
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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 |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (1)
apps/web/src/providers/StellarWalletProvider.tsx (1)
416-421: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueNo-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
📒 Files selected for processing (1)
apps/web/src/providers/StellarWalletProvider.tsx
|
dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates |
1 similar comment
|
dont forget to offramp using https://stellar.fundable.finance/offramp its fast, free and p2p rates |
|
Hi mainiainer |
Check wallet extension's active network passphrase against the app's configured network (WalletNetwork) during both connect() and signTransaction(). On mismatch:
The NetworkMismatchModal (rendered inline in StellarWalletProvider) uses the existing Dialog component and gives the user two options:
Also exports NETWORK_PASSPHRASES map so consumers can reference the canonical passphrase strings for each WalletNetwork value.
Closes #382
Summary by CodeRabbit