@openzeppelin/ui-react 1.2.0 → 2.0.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/README.md CHANGED
@@ -25,74 +25,74 @@ pnpm add react react-dom @tanstack/react-query
25
25
 
26
26
  ## Overview
27
27
 
28
- This package provides core React context providers and hooks that centralize the management of global wallet state, active network selection, active adapter instances, and the consumption of adapter-specific UI capabilities.
28
+ This package provides core React context providers and hooks that centralize the management of global wallet state, active network selection, **`EcosystemRuntime` instances** (capability bundles per network), and ecosystem-specific UI kit hooks.
29
29
 
30
- It is a foundational package that can be used to ensure consistent wallet and adapter integration patterns across applications.
30
+ It is a foundational package that can be used to ensure consistent wallet and runtime integration patterns across applications.
31
31
 
32
32
  ## Core Responsibilities
33
33
 
34
- - **Adapter Instance Management:** Provides `AdapterProvider` which maintains a registry of `ContractAdapter` instances, ensuring only one instance exists per network configuration (singleton pattern).
35
- - **Global Wallet/Network State Management:** Provides `WalletStateProvider` which manages:
36
- - The globally selected active network ID and its corresponding `NetworkConfig`.
37
- - The active `ContractAdapter` instance for this global network and its loading state.
38
- - The `EcosystemSpecificReactHooks` (facade hooks) provided by the active adapter.
39
- - Orchestration of rendering the active adapter's UI context provider.
40
- - **Consistent State Access:** Exports consumer hooks for components to access this managed state and functionality.
34
+ - **Runtime instance management:** `RuntimeProvider` keeps a registry of `EcosystemRuntime` instances (one per network id, with disposal on teardown), using a `resolveRuntime` function you supply (typically delegating to an adapter package’s `ecosystemDefinition.createRuntime`).
35
+ - **Global wallet / network state:** `WalletStateProvider` manages:
36
+ - Globally selected network id and `NetworkConfig`
37
+ - The active `EcosystemRuntime` and its loading state (`isRuntimeLoading`)
38
+ - `EcosystemSpecificReactHooks` from the active runtime’s UI kit
39
+ - Orchestration of the active ecosystem’s React UI provider (when configured)
40
+ - **Consistent access:** Hooks expose this state to components.
41
41
 
42
42
  ## Key Exports
43
43
 
44
44
  ### Providers
45
45
 
46
- - `AdapterProvider`: Manages adapter instances. Requires a `resolveAdapter` prop to fetch/create adapters.
47
- - `WalletStateProvider`: Manages global active network/adapter/wallet state.
46
+ - **`RuntimeProvider`**: Registry + loading state; requires `resolveRuntime: (networkConfig) => Promise<EcosystemRuntime>`.
47
+ - **`WalletStateProvider`**: Global active network / runtime / wallet facade hooks; requires `getNetworkConfigById` and optionally `loadConfigModule` for UI kit config modules.
48
48
 
49
49
  ### Hooks
50
50
 
51
- - `useAdapterContext()`: Access `AdapterProvider`'s `getAdapterForNetwork` function.
52
- - `useWalletState()`: Access global state like `activeNetworkId`, `activeAdapter`, `walletFacadeHooks`, and `setActiveNetworkId`.
51
+ - **`useRuntimeContext()`**: Low-level access to `getRuntimeForNetwork` / loading helpers from `RuntimeProvider`.
52
+ - **`useWalletState()`**: `activeNetworkId`, `activeNetworkConfig`, **`activeRuntime`**, **`isRuntimeLoading`**, `walletFacadeHooks`, `setActiveNetworkId`, `reconfigureActiveUiKit`.
53
53
 
54
- ### Derived Hooks
54
+ ### Derived hooks
55
55
 
56
- These hooks abstract wallet interactions and work with any adapter implementing the facade pattern:
56
+ These abstract wallet interactions across ecosystems:
57
57
 
58
- - `useDerivedAccountStatus()`: Returns connection status, address, and current chain ID.
59
- - `useDerivedSwitchChainStatus()`: Returns the `switchChain` function and switching state.
60
- - `useDerivedChainInfo()`: Returns current chain information.
61
- - `useDerivedConnectStatus()`: Returns wallet connection functions and state.
62
- - `useDerivedDisconnect()`: Returns the disconnect function.
63
- - `useWalletReconnectionHandler()`: Detects wallet reconnection and triggers network switch re-queue.
58
+ - `useDerivedAccountStatus()`, `useDerivedSwitchChainStatus()`, `useDerivedChainInfo()`, `useDerivedConnectStatus()`, `useDerivedDisconnect()`, `useWalletReconnectionHandler()`.
64
59
 
65
- ### UI Components
60
+ ### UI components
66
61
 
67
- - `WalletConnectionHeader`: Compact wallet connection status display.
68
- - `WalletConnectionUI`: Full wallet connection interface.
69
- - `WalletConnectionWithSettings`: Wallet connection UI with settings controls.
70
- - `NetworkSwitchManager`: Handles automatic wallet network switching for EVM chains.
62
+ - `WalletConnectionHeader`, `WalletConnectionUI`, `WalletConnectionWithSettings`
63
+ - **`NetworkSwitchManager`**: Pass **`wallet`** and **`networkCatalog`** from the active runtime (see below), plus `targetNetworkId` and optional `onNetworkSwitchComplete`.
71
64
 
72
65
  ## Usage
73
66
 
74
- ### Application Setup
67
+ ### Application setup
75
68
 
76
69
  ```tsx
77
- import { AdapterProvider, WalletStateProvider } from '@openzeppelin/ui-react';
70
+ import { RuntimeProvider, WalletStateProvider } from '@openzeppelin/ui-react';
78
71
 
79
- import { getAdapter, getNetworkById } from './core/ecosystemManager';
72
+ import { ecosystemDefinition } from '@openzeppelin/adapter-evm';
73
+ import { getNetworkById } from './core/ecosystemManager';
74
+
75
+ async function resolveRuntime(networkConfig) {
76
+ return ecosystemDefinition.createRuntime('composer', networkConfig, {
77
+ /* profile-specific options if needed */
78
+ });
79
+ }
80
80
 
81
81
  function AppRoot() {
82
82
  return (
83
- <AdapterProvider resolveAdapter={getAdapter}>
83
+ <RuntimeProvider resolveRuntime={resolveRuntime}>
84
84
  <WalletStateProvider
85
85
  initialNetworkId="ethereum-mainnet"
86
86
  getNetworkConfigById={getNetworkById}
87
87
  >
88
- {/* Your application components */}
88
+ {/* Your application */}
89
89
  </WalletStateProvider>
90
- </AdapterProvider>
90
+ </RuntimeProvider>
91
91
  );
92
92
  }
93
93
  ```
94
94
 
95
- ### Consuming Global State
95
+ ### Consuming global state
96
96
 
97
97
  ```tsx
98
98
  import { useWalletState } from '@openzeppelin/ui-react';
@@ -101,13 +101,13 @@ function MyWalletComponent() {
101
101
  const {
102
102
  activeNetworkId,
103
103
  activeNetworkConfig,
104
- activeAdapter,
105
- isAdapterLoading,
104
+ activeRuntime,
105
+ isRuntimeLoading,
106
106
  walletFacadeHooks,
107
107
  setActiveNetworkId,
108
108
  } = useWalletState();
109
109
 
110
- if (isAdapterLoading || !activeAdapter) {
110
+ if (isRuntimeLoading || !activeRuntime) {
111
111
  return <p>Loading wallet information...</p>;
112
112
  }
113
113
 
@@ -116,33 +116,39 @@ function MyWalletComponent() {
116
116
 
117
117
  return (
118
118
  <div>
119
- <p>Current Network: {activeNetworkConfig?.name || 'None'}</p>
119
+ <p>Current Network: {activeNetworkConfig?.name ?? 'None'}</p>
120
120
  <p>Wallet Connected: {isConnected ? 'Yes' : 'No'}</p>
121
121
  </div>
122
122
  );
123
123
  }
124
124
  ```
125
125
 
126
- ### Using NetworkSwitchManager
126
+ ### NetworkSwitchManager
127
+
128
+ Use capabilities from the active runtime — **not** a monolithic adapter instance:
127
129
 
128
130
  ```tsx
129
131
  import { useState } from 'react';
130
132
 
131
- import { NetworkSwitchManager } from '@openzeppelin/ui-react';
133
+ import { NetworkSwitchManager, useWalletState } from '@openzeppelin/ui-react';
132
134
 
133
135
  function MyApp() {
134
136
  const [networkToSwitchTo, setNetworkToSwitchTo] = useState<string | null>(null);
135
- const adapter = useMyAdapter();
137
+ const { activeRuntime } = useWalletState();
136
138
 
137
139
  const handleNetworkSwitchComplete = () => {
138
140
  setNetworkToSwitchTo(null);
139
141
  };
140
142
 
143
+ const wallet = activeRuntime?.wallet;
144
+ const networkCatalog = activeRuntime?.networkCatalog;
145
+
141
146
  return (
142
147
  <>
143
- {adapter && networkToSwitchTo && (
148
+ {wallet && networkCatalog && networkToSwitchTo && (
144
149
  <NetworkSwitchManager
145
- adapter={adapter}
150
+ wallet={wallet}
151
+ networkCatalog={networkCatalog}
146
152
  targetNetworkId={networkToSwitchTo}
147
153
  onNetworkSwitchComplete={handleNetworkSwitchComplete}
148
154
  />
@@ -157,9 +163,9 @@ function MyApp() {
157
163
  ```text
158
164
  react/
159
165
  ├── src/
160
- │ ├── components/ # UI components (WalletConnection*, NetworkSwitchManager)
161
- │ ├── hooks/ # Context providers and consumer hooks
162
- │ └── index.ts # Main package exports
166
+ │ ├── components/ # WalletConnection*, NetworkSwitchManager
167
+ │ ├── hooks/ # RuntimeProvider, WalletStateProvider, derived hooks
168
+ │ └── index.ts
163
169
  ├── package.json
164
170
  ├── tsconfig.json
165
171
  ├── tsdown.config.ts
@@ -168,25 +174,14 @@ react/
168
174
 
169
175
  ## Dependencies
170
176
 
171
- This package has minimal dependencies to maintain a lightweight footprint:
172
-
173
- - **@openzeppelin/ui-types**: Shared type definitions
174
- - **@openzeppelin/ui-utils**: Shared utility functions
175
- - **@openzeppelin/ui-components**: UI components
176
- - **react**: Peer dependency for React hooks and context
177
- - **react-dom**: Peer dependency for React DOM utilities
178
- - **@tanstack/react-query**: Peer dependency for data fetching
177
+ - **@openzeppelin/ui-types**, **@openzeppelin/ui-utils**, **@openzeppelin/ui-components**
178
+ - **react**, **react-dom**, **@tanstack/react-query** (peers)
179
179
 
180
180
  ## Development
181
181
 
182
182
  ```bash
183
- # Build the package
184
183
  pnpm build
185
-
186
- # Run tests
187
184
  pnpm test
188
-
189
- # Lint
190
185
  pnpm lint
191
186
  ```
192
187