@zerodev/wallet-react 0.0.1-alpha.1 → 0.0.1-alpha.11
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 +74 -0
- package/README.md +30 -17
- package/dist/_cjs/actions.js +62 -24
- package/dist/_cjs/connector.js +82 -48
- package/dist/_cjs/hooks/useExportPrivateKey.js +18 -0
- package/dist/_cjs/hooks/useGetUserEmail.js +19 -0
- package/dist/_cjs/index.js +8 -1
- package/dist/_cjs/oauth.js +60 -55
- package/dist/_cjs/provider.js +5 -2
- package/dist/_cjs/store.js +4 -9
- package/dist/_esm/actions.js +74 -27
- package/dist/_esm/connector.js +98 -55
- package/dist/_esm/hooks/useExportPrivateKey.js +18 -0
- package/dist/_esm/hooks/useGetUserEmail.js +19 -0
- package/dist/_esm/index.js +3 -1
- package/dist/_esm/oauth.js +71 -53
- package/dist/_esm/provider.js +5 -2
- package/dist/_esm/store.js +4 -10
- package/dist/_types/actions.d.ts +35 -6
- package/dist/_types/actions.d.ts.map +1 -1
- package/dist/_types/connector.d.ts +0 -2
- package/dist/_types/connector.d.ts.map +1 -1
- package/dist/_types/hooks/useExportPrivateKey.d.ts +18 -0
- package/dist/_types/hooks/useExportPrivateKey.d.ts.map +1 -0
- package/dist/_types/hooks/useGetUserEmail.d.ts +18 -0
- package/dist/_types/hooks/useGetUserEmail.d.ts.map +1 -0
- package/dist/_types/index.d.ts +4 -2
- package/dist/_types/index.d.ts.map +1 -1
- package/dist/_types/oauth.d.ts +25 -12
- package/dist/_types/oauth.d.ts.map +1 -1
- package/dist/_types/provider.d.ts.map +1 -1
- package/dist/_types/store.d.ts +11 -7
- package/dist/_types/store.d.ts.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/actions.test.ts +895 -0
- package/src/actions.ts +124 -44
- package/src/connector.ts +117 -65
- package/src/hooks/useExportPrivateKey.ts +57 -0
- package/src/hooks/useGetUserEmail.ts +52 -0
- package/src/index.ts +9 -2
- package/src/oauth.test.ts +445 -0
- package/src/oauth.ts +97 -78
- package/src/provider.ts +5 -2
- package/src/store.ts +15 -16
- package/tsconfig.build.tsbuildinfo +1 -1
package/src/store.ts
CHANGED
|
@@ -10,7 +10,12 @@ import type { LocalAccount } from 'viem'
|
|
|
10
10
|
import type { SmartAccount } from 'viem/account-abstraction'
|
|
11
11
|
import { create } from 'zustand'
|
|
12
12
|
import { persist, subscribeWithSelector } from 'zustand/middleware'
|
|
13
|
-
|
|
13
|
+
|
|
14
|
+
// Internal OAuth config stored in the state (derived from connector params)
|
|
15
|
+
type InternalOAuthConfig = {
|
|
16
|
+
backendUrl: string
|
|
17
|
+
projectId: string
|
|
18
|
+
}
|
|
14
19
|
|
|
15
20
|
export type ZeroDevWalletState = {
|
|
16
21
|
// Core
|
|
@@ -19,15 +24,15 @@ export type ZeroDevWalletState = {
|
|
|
19
24
|
session: ZeroDevWalletSession | null
|
|
20
25
|
|
|
21
26
|
// Multi-chain support
|
|
22
|
-
|
|
27
|
+
activeChainId: number | null
|
|
23
28
|
kernelAccounts: Map<number, SmartAccount<KernelSmartAccountImplementation>>
|
|
24
29
|
kernelClients: Map<number, KernelAccountClient>
|
|
25
30
|
|
|
26
31
|
// Session expiry
|
|
27
32
|
isExpiring: boolean
|
|
28
33
|
|
|
29
|
-
// OAuth config (
|
|
30
|
-
oauthConfig:
|
|
34
|
+
// OAuth config (derived from connector params)
|
|
35
|
+
oauthConfig: InternalOAuthConfig | null
|
|
31
36
|
|
|
32
37
|
// Actions
|
|
33
38
|
setWallet: (wallet: ZeroDevWalletSDK) => void
|
|
@@ -38,9 +43,9 @@ export type ZeroDevWalletState = {
|
|
|
38
43
|
) => void
|
|
39
44
|
setKernelClient: (chainId: number, client: KernelAccountClient) => void
|
|
40
45
|
setSession: (session: ZeroDevWalletSession | null) => void
|
|
41
|
-
|
|
46
|
+
setActiveChainId: (chainId: number | null) => void
|
|
42
47
|
setIsExpiring: (isExpiring: boolean) => void
|
|
43
|
-
setOAuthConfig: (config:
|
|
48
|
+
setOAuthConfig: (config: InternalOAuthConfig | null) => void
|
|
44
49
|
clear: () => void
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -53,7 +58,7 @@ export const createZeroDevWalletStore = () =>
|
|
|
53
58
|
wallet: null,
|
|
54
59
|
eoaAccount: null,
|
|
55
60
|
session: null,
|
|
56
|
-
|
|
61
|
+
activeChainId: null,
|
|
57
62
|
kernelAccounts: new Map(),
|
|
58
63
|
kernelClients: new Map(),
|
|
59
64
|
isExpiring: false,
|
|
@@ -78,13 +83,7 @@ export const createZeroDevWalletStore = () =>
|
|
|
78
83
|
|
|
79
84
|
setSession: (session) => set({ session }),
|
|
80
85
|
|
|
81
|
-
|
|
82
|
-
const { chainIds } = get()
|
|
83
|
-
// Move chainId to front, remove duplicates
|
|
84
|
-
set({
|
|
85
|
-
chainIds: [chainId, ...chainIds.filter((id) => id !== chainId)],
|
|
86
|
-
})
|
|
87
|
-
},
|
|
86
|
+
setActiveChainId: (chainId) => set({ activeChainId: chainId }),
|
|
88
87
|
|
|
89
88
|
setIsExpiring: (isExpiring) => set({ isExpiring }),
|
|
90
89
|
|
|
@@ -97,7 +96,7 @@ export const createZeroDevWalletStore = () =>
|
|
|
97
96
|
kernelAccounts: new Map(),
|
|
98
97
|
kernelClients: new Map(),
|
|
99
98
|
isExpiring: false,
|
|
100
|
-
|
|
99
|
+
activeChainId: null,
|
|
101
100
|
}),
|
|
102
101
|
}),
|
|
103
102
|
{
|
|
@@ -105,7 +104,7 @@ export const createZeroDevWalletStore = () =>
|
|
|
105
104
|
// Only persist session data, not clients or accounts
|
|
106
105
|
partialize: (state) => ({
|
|
107
106
|
session: state.session,
|
|
108
|
-
|
|
107
|
+
activeChainId: state.activeChainId,
|
|
109
108
|
}),
|
|
110
109
|
},
|
|
111
110
|
),
|