From 06c8485d3c574b9dec02e981fabe486e52eb7d17 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Tue, 5 May 2026 19:25:43 +0700 Subject: [PATCH] fix(platform-wallet): persist wallet.network instead of stale SDK reference MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `register_wallet` was building the registration changeset's `WalletMetadataEntry { network, .. }` from `self.sdk.network`. The manager's SDK reference is bound at `configure(...)` time and isn't refreshed when the host app switches networks at runtime, so a wallet created after a network switch — say, the user flips iOS from Testnet to Local and creates a regtest wallet — would derive correctly under `Network::Regtest` but get persisted with the testnet SDK's network. Downstream the Swift example app's `WalletsContentView` filters by `platformState.currentNetwork.rawValue`, so the freshly-created wallet silently disappears from the Local list (the SwiftData row exists, but with `networkRaw = 1` instead of `3`). Capture `wallet.network` before the move into `insert_wallet` and use that for `WalletMetadataEntry`. The two values normally agree; this just decouples them cleanly when they don't, which is the only case where the bug surfaces. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../src/manager/wallet_lifecycle.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs b/packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs index 1042feb440a..7c23537390e 100644 --- a/packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs +++ b/packages/rs-platform-wallet/src/manager/wallet_lifecycle.rs @@ -100,6 +100,21 @@ impl PlatformWalletManager

{ ) -> Result, PlatformWalletError> { let wallet_info = ManagedWalletInfo::from_wallet(&wallet, 0); + // Capture the wallet's intrinsic network before the move into + // `insert_wallet` below — the persisted metadata's network + // must reflect the wallet itself, not the manager's SDK + // reference. The two normally agree, but the manager's SDK + // is bound at `configure(...)` time and is not refreshed when + // the host app switches networks at runtime, so reading + // `self.sdk.network` here would silently misattribute a + // wallet created on a freshly-switched-to network (e.g., a + // user on Testnet flips to Local and creates a regtest + // wallet — the wallet itself derives correctly under + // `Network::Regtest`, but the persister callback would + // record `Testnet` and the row would never appear under + // Local in the host UI). + let wallet_network = wallet.network; + let balance = Arc::new(WalletBalance::new()); // Snapshot per-account xpubs and address-pool entries BEFORE @@ -205,7 +220,7 @@ impl PlatformWalletManager

{ let mut registration_changeset = PlatformWalletChangeSet { wallet_metadata: Some(WalletMetadataEntry { - network: self.sdk.network, + network: wallet_network, birth_height, }), account_registrations: account_specs