-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
🧭 Overview
BridgeWise allows users to bridge assets across multiple chains (Stellar and EVM).
To provide a seamless UX, it must support dynamic network switching, enabling users to:
- Switch between chains without reconnecting wallets manually
- Automatically adjust fees, slippage, and quotes based on the active network
- Maintain consistent state across UI components and hooks
This issue complements the Wallet Adapter Layer (Issue #13) and Dynamic Fee Estimation Engine (Issue #16).
🎯 Problem
- Users must manually switch networks, which is error-prone and interrupts UX
- Fee and slippage calculations can become inaccurate if the network changes mid-session
- Developers embedding BridgeWise currently have no API for dynamic network switching
- Without automated switching, cross-chain transfers may fail or become inefficient
💡 Proposed Solution
Implement Dynamic Network Switching Support that:
- Detects the currently active network via the wallet adapter
- Allows users to switch networks dynamically through the UI or programmatically
- Updates dependent modules:
- Fee estimation (
useFeeEstimate()) - Slippage monitoring (
useSlippageAlert()) - Smart bridge ranking (
useBridgeQuotes())
- Fee estimation (
- Provides hooks and events for developers to respond to network changes
🛠 Scope of Work
1️⃣ Network Detection
getCurrentNetwork(): stringfrom wallet adapter- Subscribe to network change events via wallets
- Ensure cross-chain awareness for Stellar and EVM chains
2️⃣ Network Switching Logic
switchNetwork(targetChain: string)function exposed to SDK users- Validate that the target chain is supported by connected wallet
- Automatically update dependent calculations (fees, slippage, quotes)
3️⃣ Hook Implementation
useNetworkSwitcher()hook:- Returns:
currentNetworkswitchNetwork(targetChain: string)isSwitchingerrors
- SSR-safe for Next.js
- Compatible with headless mode
- Returns:
4️⃣ UI Integration
<BridgeCompare />and<BridgeStatus />reflect network changes automatically- Optional network selector dropdown in SDK demo
- Display warnings if user attempts to switch to unsupported chain
5️⃣ Error Handling & Fallbacks
- Graceful failure if wallet does not support network switch
- Provide structured error messages for developers
- Avoid breaking UI or quote calculations during network transitions
📊 Expected Outcome
- Users can switch networks dynamically without disconnecting wallets
- Dependent modules update automatically with accurate fees, slippage, and quotes
- Developers have hooks and events for custom handling
- Cross-chain transfers remain consistent and reliable
✅ Acceptance Criteria
- Network detection integrated with wallet adapter
-
switchNetwork()function implemented and reliable -
useNetworkSwitcher()hook available and SSR-safe - Integration with
<BridgeCompare />and<BridgeStatus /> - Warnings and errors handled gracefully
- UI updates dependent modules automatically
- Unit tests covering switching logic, hooks, and UI updates
- Documentation updated with usage examples
📈 Measurable Impact
- Seamless multi-chain UX for end-users
- Reduced failed transfers due to network mismatches
- Developers can embed SDK confidently across multiple networks
- Supports scalable adoption of BridgeWise
🧪 Testing Requirements
- Simulate network switches across Stellar and EVM chains
- Verify hooks update correctly and SSR-safe
- Test fee and slippage recalculation on network change
- Validate UI components reflect active network
- Confirm fallback behavior when network unsupported
📚 Documentation Requirements
- Add “Dynamic Network Switching” section in README
- Provide hook usage example:
const { currentNetwork, switchNetwork } = useNetworkSwitcher();
switchNetwork("Polygon");- Include UI integration and supported networks
- Document error handling and fallback strategies
Reactions are currently unavailable