@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/CHANGELOG.md +6 -0
- package/dist/_cjs/connector.js +7 -12
- package/dist/_cjs/provider.js +5 -2
- package/dist/_cjs/store.js +4 -9
- package/dist/_esm/connector.js +7 -13
- package/dist/_esm/provider.js +5 -2
- package/dist/_esm/store.js +4 -10
- package/dist/_types/connector.d.ts.map +1 -1
- package/dist/_types/provider.d.ts.map +1 -1
- package/dist/_types/store.d.ts +4 -4
- package/dist/_types/store.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/connector.ts +8 -14
- package/src/provider.ts +5 -2
- package/src/store.ts +6 -12
- package/tsconfig.build.tsbuildinfo +1 -1
package/package.json
CHANGED
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 =
|
|
136
|
-
|
|
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().
|
|
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,
|
|
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 =
|
|
241
|
-
? kernelAccounts.get(
|
|
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().
|
|
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().
|
|
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.
|
|
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().
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
activeChainId: state.activeChainId,
|
|
109
103
|
}),
|
|
110
104
|
},
|
|
111
105
|
),
|