@openzeppelin/ui-builder-adapter-evm 0.15.0 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openzeppelin/ui-builder-adapter-evm",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "private": false,
5
5
  "description": "EVM Adapter for UI Builder",
6
6
  "keywords": [
@@ -99,6 +99,7 @@ export class WagmiWalletImplementation {
99
99
  private unsubscribe?: ReturnType<typeof watchAccount>;
100
100
  private initialized: boolean = false;
101
101
  private walletConnectProjectId?: string;
102
+ private rpcConfigUnsubscribe?: () => void;
102
103
 
103
104
  /**
104
105
  * Constructs the WagmiWalletImplementation.
@@ -121,9 +122,50 @@ export class WagmiWalletImplementation {
121
122
  LOG_SYSTEM,
122
123
  'WagmiWalletImplementation instance initialized (Wagmi config creation deferred).'
123
124
  );
125
+ // Subscribe to RPC configuration changes to invalidate cached config
126
+ this.setupRpcConfigListener();
124
127
  // No config created here by default anymore.
125
128
  }
126
129
 
130
+ /**
131
+ * Sets up a listener for RPC configuration changes to invalidate the cached Wagmi config
132
+ * when user changes RPC settings.
133
+ */
134
+ private setupRpcConfigListener(): void {
135
+ // Import dynamically to avoid circular dependencies
136
+ import('@openzeppelin/ui-builder-utils')
137
+ .then(({ userRpcConfigService }) => {
138
+ // Subscribe to all RPC config changes
139
+ this.rpcConfigUnsubscribe = userRpcConfigService.subscribe('*', (event) => {
140
+ if (event.type === 'rpc-config-changed' || event.type === 'rpc-config-cleared') {
141
+ logger.info(
142
+ LOG_SYSTEM,
143
+ `RPC config changed for network ${event.networkId}. Invalidating cached Wagmi config.`
144
+ );
145
+ // Invalidate the cached config to force recreation with new RPC settings
146
+ this.defaultInstanceConfig = null;
147
+ }
148
+ });
149
+ })
150
+ .catch((error) => {
151
+ logger.error(LOG_SYSTEM, 'Failed to setup RPC config listener:', error);
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Cleanup method to unsubscribe from RPC config changes
157
+ */
158
+ public cleanup(): void {
159
+ if (this.rpcConfigUnsubscribe) {
160
+ this.rpcConfigUnsubscribe();
161
+ this.rpcConfigUnsubscribe = undefined;
162
+ }
163
+ if (this.unsubscribe) {
164
+ this.unsubscribe();
165
+ this.unsubscribe = undefined;
166
+ }
167
+ }
168
+
127
169
  /**
128
170
  * Sets the externally determined, currently active WagmiConfig instance.
129
171
  * This is typically called by EvmUiKitManager after it has resolved the appropriate
@@ -333,8 +375,12 @@ export class WagmiWalletImplementation {
333
375
  );
334
376
  }
335
377
 
336
- // Always rebuild default config to reflect latest RPC overrides/user settings
337
- this.defaultInstanceConfig = this.createDefaultConfig();
378
+ // Reuse existing default config if available, only create if needed
379
+ // This ensures wallet connection state is preserved across network switches
380
+ // Config is automatically invalidated when RPC settings change via setupRpcConfigListener()
381
+ if (!this.defaultInstanceConfig) {
382
+ this.defaultInstanceConfig = this.createDefaultConfig();
383
+ }
338
384
  return this.defaultInstanceConfig;
339
385
  }
340
386