@zerodev/wallet-react 0.0.1-alpha.4 → 0.0.1-alpha.5

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": "@zerodev/wallet-react",
3
- "version": "0.0.1-alpha.4",
3
+ "version": "0.0.1-alpha.5",
4
4
  "description": "React hooks for ZeroDev Wallet SDK",
5
5
  "sideEffects": false,
6
6
  "main": "./dist/_cjs/index.js",
package/src/connector.ts CHANGED
@@ -75,10 +75,6 @@ export function zeroDevWallet(
75
75
  store = createZeroDevWalletStore()
76
76
  store.getState().setWallet(wallet)
77
77
 
78
- // Initialize chainIds
79
- const chainIds = params.chains.map((c) => c.id)
80
- store.setState({ chainIds })
81
-
82
78
  // Store OAuth config if provided
83
79
  if (params.oauthConfig) {
84
80
  store.getState().setOAuthConfig(params.oauthConfig)
@@ -132,10 +128,8 @@ export function zeroDevWallet(
132
128
  const state = store.getState()
133
129
 
134
130
  // Determine active chain
135
- const activeChainId = chainId || state.chainIds[0]
136
- if (!activeChainId) {
137
- throw new Error('No chain configured')
138
- }
131
+ const activeChainId =
132
+ chainId ?? state.activeChainId ?? params.chains[0].id
139
133
 
140
134
  // If reconnecting and already have kernel account, return immediately
141
135
  if (isReconnecting && state.kernelAccounts.has(activeChainId)) {
@@ -198,7 +192,7 @@ export function zeroDevWallet(
198
192
  }
199
193
 
200
194
  // Set as active chain
201
- store.getState().setActiveChain(activeChainId)
195
+ store.getState().setActiveChainId(activeChainId)
202
196
 
203
197
  // Get fresh state after updates
204
198
  const freshState = store.getState()
@@ -229,7 +223,7 @@ export function zeroDevWallet(
229
223
 
230
224
  async getAccounts() {
231
225
  if (!store) return []
232
- const { eoaAccount, kernelAccounts, chainIds } = store.getState()
226
+ const { eoaAccount, kernelAccounts, activeChainId } = store.getState()
233
227
 
234
228
  // Return EOA address if we have it (EIP-7702: EOA address = kernel address)
235
229
  if (eoaAccount) {
@@ -237,15 +231,15 @@ export function zeroDevWallet(
237
231
  }
238
232
 
239
233
  // Fallback: check kernel accounts
240
- const activeAccount = chainIds[0]
241
- ? kernelAccounts.get(chainIds[0])
234
+ const activeAccount = activeChainId
235
+ ? kernelAccounts.get(activeChainId)
242
236
  : null
243
237
  return activeAccount ? [activeAccount.address] : []
244
238
  },
245
239
 
246
240
  async getChainId() {
247
241
  if (!store) return params.chains[0].id
248
- return store.getState().chainIds[0] || params.chains[0].id
242
+ return store.getState().activeChainId ?? params.chains[0].id
249
243
  },
250
244
 
251
245
  async getProvider() {
@@ -264,7 +258,7 @@ export function zeroDevWallet(
264
258
  }
265
259
 
266
260
  // Update active chain
267
- store.getState().setActiveChain(chainId)
261
+ store.getState().setActiveChainId(chainId)
268
262
 
269
263
  // Create kernel account for new chain if doesn't exist
270
264
  if (!state.kernelAccounts.has(chainId)) {
package/src/provider.ts CHANGED
@@ -115,7 +115,10 @@ export function createProvider({
115
115
 
116
116
  async request({ method, params }: { method: string; params?: any[] }) {
117
117
  const state = store.getState()
118
- const activeChainId = state.chainIds[0]
118
+ const activeChainId = state.activeChainId
119
+ if (!activeChainId) {
120
+ throw new Error('No active chain')
121
+ }
119
122
 
120
123
  switch (method) {
121
124
  case 'eth_accounts': {
@@ -219,7 +222,7 @@ export function createProvider({
219
222
  const chainId_number = parseInt(chainId, 16)
220
223
 
221
224
  // Update active chain
222
- store.getState().setActiveChain(chainId_number)
225
+ store.getState().setActiveChainId(chainId_number)
223
226
 
224
227
  // Emit chainChanged event
225
228
  emitter.emit('chainChanged', chainId)
package/src/store.ts CHANGED
@@ -19,7 +19,7 @@ export type ZeroDevWalletState = {
19
19
  session: ZeroDevWalletSession | null
20
20
 
21
21
  // Multi-chain support
22
- chainIds: number[] // [activeChain, ...otherChains]
22
+ activeChainId: number | null
23
23
  kernelAccounts: Map<number, SmartAccount<KernelSmartAccountImplementation>>
24
24
  kernelClients: Map<number, KernelAccountClient>
25
25
 
@@ -38,7 +38,7 @@ export type ZeroDevWalletState = {
38
38
  ) => void
39
39
  setKernelClient: (chainId: number, client: KernelAccountClient) => void
40
40
  setSession: (session: ZeroDevWalletSession | null) => void
41
- setActiveChain: (chainId: number) => void
41
+ setActiveChainId: (chainId: number | null) => void
42
42
  setIsExpiring: (isExpiring: boolean) => void
43
43
  setOAuthConfig: (config: OAuthConfig | null) => void
44
44
  clear: () => void
@@ -53,7 +53,7 @@ export const createZeroDevWalletStore = () =>
53
53
  wallet: null,
54
54
  eoaAccount: null,
55
55
  session: null,
56
- chainIds: [],
56
+ activeChainId: null,
57
57
  kernelAccounts: new Map(),
58
58
  kernelClients: new Map(),
59
59
  isExpiring: false,
@@ -78,13 +78,7 @@ export const createZeroDevWalletStore = () =>
78
78
 
79
79
  setSession: (session) => set({ session }),
80
80
 
81
- setActiveChain: (chainId) => {
82
- const { chainIds } = get()
83
- // Move chainId to front, remove duplicates
84
- set({
85
- chainIds: [chainId, ...chainIds.filter((id) => id !== chainId)],
86
- })
87
- },
81
+ setActiveChainId: (chainId) => set({ activeChainId: chainId }),
88
82
 
89
83
  setIsExpiring: (isExpiring) => set({ isExpiring }),
90
84
 
@@ -97,7 +91,7 @@ export const createZeroDevWalletStore = () =>
97
91
  kernelAccounts: new Map(),
98
92
  kernelClients: new Map(),
99
93
  isExpiring: false,
100
- chainIds: [],
94
+ activeChainId: null,
101
95
  }),
102
96
  }),
103
97
  {
@@ -105,7 +99,7 @@ export const createZeroDevWalletStore = () =>
105
99
  // Only persist session data, not clients or accounts
106
100
  partialize: (state) => ({
107
101
  session: state.session,
108
- chainIds: state.chainIds,
102
+ activeChainId: state.activeChainId,
109
103
  }),
110
104
  },
111
105
  ),