@miden-sdk/miden-wallet-adapter-react 0.13.0
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/MidenFiSignerProvider.tsx +732 -0
- package/WalletProvider.tsx +443 -0
- package/__tests__/MidenFiSignerProvider.test.tsx +426 -0
- package/dist/MidenFiSignerProvider.d.ts +113 -0
- package/dist/MidenFiSignerProvider.js +501 -0
- package/dist/MidenFiSignerProvider.js.map +1 -0
- package/dist/WalletProvider.d.ts +13 -0
- package/dist/WalletProvider.js +302 -0
- package/dist/WalletProvider.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/useLocalStorage.d.ts +2 -0
- package/dist/useLocalStorage.js +39 -0
- package/dist/useLocalStorage.js.map +1 -0
- package/dist/useWallet.d.ts +30 -0
- package/dist/useWallet.js +81 -0
- package/dist/useWallet.js.map +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/vitest.config.js +8 -0
- package/dist/vitest.config.js.map +1 -0
- package/docs/README.md +30 -0
- package/docs/functions/useLocalStorage.md +29 -0
- package/docs/functions/useMidenFiWallet.md +28 -0
- package/docs/functions/useWallet.md +13 -0
- package/docs/interfaces/MidenFiSignerProviderProps.md +87 -0
- package/docs/interfaces/Wallet.md +19 -0
- package/docs/interfaces/WalletContextState.md +235 -0
- package/docs/interfaces/WalletProviderProps.md +65 -0
- package/docs/variables/MidenFiSignerProvider.md +54 -0
- package/docs/variables/WalletContext.md +9 -0
- package/docs/variables/WalletProvider.md +9 -0
- package/index.ts +15 -0
- package/package.json +42 -0
- package/tsconfig.json +16 -0
- package/useLocalStorage.ts +39 -0
- package/useWallet.ts +197 -0
- package/vitest.config.ts +8 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / MidenFiSignerProviderProps
|
|
6
|
+
|
|
7
|
+
# Interface: MidenFiSignerProviderProps
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### allowedPrivateData?
|
|
12
|
+
|
|
13
|
+
> `optional` **allowedPrivateData**: `AllowedPrivateData`
|
|
14
|
+
|
|
15
|
+
Allowed private data types
|
|
16
|
+
|
|
17
|
+
***
|
|
18
|
+
|
|
19
|
+
### appName?
|
|
20
|
+
|
|
21
|
+
> `optional` **appName**: `string`
|
|
22
|
+
|
|
23
|
+
App name passed to the default MidenWalletAdapter
|
|
24
|
+
|
|
25
|
+
***
|
|
26
|
+
|
|
27
|
+
### autoConnect?
|
|
28
|
+
|
|
29
|
+
> `optional` **autoConnect**: `boolean`
|
|
30
|
+
|
|
31
|
+
Auto-connect to previously selected wallet on mount. Defaults to true
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### children
|
|
36
|
+
|
|
37
|
+
> **children**: `ReactNode`
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### localStorageKey?
|
|
42
|
+
|
|
43
|
+
> `optional` **localStorageKey**: `string`
|
|
44
|
+
|
|
45
|
+
LocalStorage key for persisting wallet selection
|
|
46
|
+
|
|
47
|
+
***
|
|
48
|
+
|
|
49
|
+
### network?
|
|
50
|
+
|
|
51
|
+
> `optional` **network**: `WalletAdapterNetwork`
|
|
52
|
+
|
|
53
|
+
Network to connect to
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### onError()?
|
|
58
|
+
|
|
59
|
+
> `optional` **onError**: (`error`) => `void`
|
|
60
|
+
|
|
61
|
+
Error handler
|
|
62
|
+
|
|
63
|
+
#### Parameters
|
|
64
|
+
|
|
65
|
+
##### error
|
|
66
|
+
|
|
67
|
+
`WalletError`
|
|
68
|
+
|
|
69
|
+
#### Returns
|
|
70
|
+
|
|
71
|
+
`void`
|
|
72
|
+
|
|
73
|
+
***
|
|
74
|
+
|
|
75
|
+
### privateDataPermission?
|
|
76
|
+
|
|
77
|
+
> `optional` **privateDataPermission**: `PrivateDataPermission`
|
|
78
|
+
|
|
79
|
+
Private data permission level
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### wallets?
|
|
84
|
+
|
|
85
|
+
> `optional` **wallets**: `Adapter`[]
|
|
86
|
+
|
|
87
|
+
Wallet adapters to use. Defaults to [MidenWalletAdapter]
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / Wallet
|
|
6
|
+
|
|
7
|
+
# Interface: Wallet
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### adapter
|
|
12
|
+
|
|
13
|
+
> **adapter**: `Adapter`
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### readyState
|
|
18
|
+
|
|
19
|
+
> **readyState**: `WalletReadyState`
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / WalletContextState
|
|
6
|
+
|
|
7
|
+
# Interface: WalletContextState
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### address
|
|
12
|
+
|
|
13
|
+
> **address**: `string`
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### autoConnect
|
|
18
|
+
|
|
19
|
+
> **autoConnect**: `boolean`
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### connected
|
|
24
|
+
|
|
25
|
+
> **connected**: `boolean`
|
|
26
|
+
|
|
27
|
+
***
|
|
28
|
+
|
|
29
|
+
### connecting
|
|
30
|
+
|
|
31
|
+
> **connecting**: `boolean`
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### disconnecting
|
|
36
|
+
|
|
37
|
+
> **disconnecting**: `boolean`
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### importPrivateNote()?
|
|
42
|
+
|
|
43
|
+
> `optional` **importPrivateNote**: (`note`) => `Promise`\<`string`\>
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
##### note
|
|
48
|
+
|
|
49
|
+
`Uint8Array`
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`Promise`\<`string`\>
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### publicKey
|
|
58
|
+
|
|
59
|
+
> **publicKey**: `Uint8Array`\<`ArrayBufferLike`\>
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### requestAssets()?
|
|
64
|
+
|
|
65
|
+
> `optional` **requestAssets**: () => `Promise`\<`Asset`[]\>
|
|
66
|
+
|
|
67
|
+
#### Returns
|
|
68
|
+
|
|
69
|
+
`Promise`\<`Asset`[]\>
|
|
70
|
+
|
|
71
|
+
***
|
|
72
|
+
|
|
73
|
+
### requestConsumableNotes()?
|
|
74
|
+
|
|
75
|
+
> `optional` **requestConsumableNotes**: () => `Promise`\<`InputNoteDetails`[]\>
|
|
76
|
+
|
|
77
|
+
#### Returns
|
|
78
|
+
|
|
79
|
+
`Promise`\<`InputNoteDetails`[]\>
|
|
80
|
+
|
|
81
|
+
***
|
|
82
|
+
|
|
83
|
+
### requestConsume()?
|
|
84
|
+
|
|
85
|
+
> `optional` **requestConsume**: (`transaction`) => `Promise`\<`string`\>
|
|
86
|
+
|
|
87
|
+
#### Parameters
|
|
88
|
+
|
|
89
|
+
##### transaction
|
|
90
|
+
|
|
91
|
+
`MidenConsumeTransaction`
|
|
92
|
+
|
|
93
|
+
#### Returns
|
|
94
|
+
|
|
95
|
+
`Promise`\<`string`\>
|
|
96
|
+
|
|
97
|
+
***
|
|
98
|
+
|
|
99
|
+
### requestPrivateNotes()?
|
|
100
|
+
|
|
101
|
+
> `optional` **requestPrivateNotes**: (`noteFilterType`, `noteIds?`) => `Promise`\<`InputNoteDetails`[]\>
|
|
102
|
+
|
|
103
|
+
#### Parameters
|
|
104
|
+
|
|
105
|
+
##### noteFilterType
|
|
106
|
+
|
|
107
|
+
`NoteFilterTypes`
|
|
108
|
+
|
|
109
|
+
##### noteIds?
|
|
110
|
+
|
|
111
|
+
`string`[]
|
|
112
|
+
|
|
113
|
+
#### Returns
|
|
114
|
+
|
|
115
|
+
`Promise`\<`InputNoteDetails`[]\>
|
|
116
|
+
|
|
117
|
+
***
|
|
118
|
+
|
|
119
|
+
### requestSend()?
|
|
120
|
+
|
|
121
|
+
> `optional` **requestSend**: (`transaction`) => `Promise`\<`string`\>
|
|
122
|
+
|
|
123
|
+
#### Parameters
|
|
124
|
+
|
|
125
|
+
##### transaction
|
|
126
|
+
|
|
127
|
+
`MidenSendTransaction`
|
|
128
|
+
|
|
129
|
+
#### Returns
|
|
130
|
+
|
|
131
|
+
`Promise`\<`string`\>
|
|
132
|
+
|
|
133
|
+
***
|
|
134
|
+
|
|
135
|
+
### requestTransaction()?
|
|
136
|
+
|
|
137
|
+
> `optional` **requestTransaction**: (`transaction`) => `Promise`\<`string`\>
|
|
138
|
+
|
|
139
|
+
#### Parameters
|
|
140
|
+
|
|
141
|
+
##### transaction
|
|
142
|
+
|
|
143
|
+
`MidenTransaction`
|
|
144
|
+
|
|
145
|
+
#### Returns
|
|
146
|
+
|
|
147
|
+
`Promise`\<`string`\>
|
|
148
|
+
|
|
149
|
+
***
|
|
150
|
+
|
|
151
|
+
### signBytes()?
|
|
152
|
+
|
|
153
|
+
> `optional` **signBytes**: (`data`, `kind`) => `Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
154
|
+
|
|
155
|
+
#### Parameters
|
|
156
|
+
|
|
157
|
+
##### data
|
|
158
|
+
|
|
159
|
+
`Uint8Array`
|
|
160
|
+
|
|
161
|
+
##### kind
|
|
162
|
+
|
|
163
|
+
`SignKind`
|
|
164
|
+
|
|
165
|
+
#### Returns
|
|
166
|
+
|
|
167
|
+
`Promise`\<`Uint8Array`\<`ArrayBufferLike`\>\>
|
|
168
|
+
|
|
169
|
+
***
|
|
170
|
+
|
|
171
|
+
### waitForTransaction()?
|
|
172
|
+
|
|
173
|
+
> `optional` **waitForTransaction**: (`txId`, `timeout?`) => `Promise`\<`TransactionOutput`\>
|
|
174
|
+
|
|
175
|
+
#### Parameters
|
|
176
|
+
|
|
177
|
+
##### txId
|
|
178
|
+
|
|
179
|
+
`string`
|
|
180
|
+
|
|
181
|
+
##### timeout?
|
|
182
|
+
|
|
183
|
+
`number`
|
|
184
|
+
|
|
185
|
+
#### Returns
|
|
186
|
+
|
|
187
|
+
`Promise`\<`TransactionOutput`\>
|
|
188
|
+
|
|
189
|
+
***
|
|
190
|
+
|
|
191
|
+
### wallet
|
|
192
|
+
|
|
193
|
+
> **wallet**: [`Wallet`](Wallet.md)
|
|
194
|
+
|
|
195
|
+
***
|
|
196
|
+
|
|
197
|
+
### wallets
|
|
198
|
+
|
|
199
|
+
> **wallets**: [`Wallet`](Wallet.md)[]
|
|
200
|
+
|
|
201
|
+
## Methods
|
|
202
|
+
|
|
203
|
+
### connect()
|
|
204
|
+
|
|
205
|
+
> **connect**(): `Promise`\<`void`\>
|
|
206
|
+
|
|
207
|
+
#### Returns
|
|
208
|
+
|
|
209
|
+
`Promise`\<`void`\>
|
|
210
|
+
|
|
211
|
+
***
|
|
212
|
+
|
|
213
|
+
### disconnect()
|
|
214
|
+
|
|
215
|
+
> **disconnect**(): `Promise`\<`void`\>
|
|
216
|
+
|
|
217
|
+
#### Returns
|
|
218
|
+
|
|
219
|
+
`Promise`\<`void`\>
|
|
220
|
+
|
|
221
|
+
***
|
|
222
|
+
|
|
223
|
+
### select()
|
|
224
|
+
|
|
225
|
+
> **select**(`walletName`): `void`
|
|
226
|
+
|
|
227
|
+
#### Parameters
|
|
228
|
+
|
|
229
|
+
##### walletName
|
|
230
|
+
|
|
231
|
+
`WalletName`
|
|
232
|
+
|
|
233
|
+
#### Returns
|
|
234
|
+
|
|
235
|
+
`void`
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / WalletProviderProps
|
|
6
|
+
|
|
7
|
+
# Interface: WalletProviderProps
|
|
8
|
+
|
|
9
|
+
## Properties
|
|
10
|
+
|
|
11
|
+
### allowedPrivateData?
|
|
12
|
+
|
|
13
|
+
> `optional` **allowedPrivateData**: `AllowedPrivateData`
|
|
14
|
+
|
|
15
|
+
***
|
|
16
|
+
|
|
17
|
+
### autoConnect?
|
|
18
|
+
|
|
19
|
+
> `optional` **autoConnect**: `boolean`
|
|
20
|
+
|
|
21
|
+
***
|
|
22
|
+
|
|
23
|
+
### children
|
|
24
|
+
|
|
25
|
+
> **children**: `ReactNode`
|
|
26
|
+
|
|
27
|
+
***
|
|
28
|
+
|
|
29
|
+
### localStorageKey?
|
|
30
|
+
|
|
31
|
+
> `optional` **localStorageKey**: `string`
|
|
32
|
+
|
|
33
|
+
***
|
|
34
|
+
|
|
35
|
+
### network?
|
|
36
|
+
|
|
37
|
+
> `optional` **network**: `WalletAdapterNetwork`
|
|
38
|
+
|
|
39
|
+
***
|
|
40
|
+
|
|
41
|
+
### onError()?
|
|
42
|
+
|
|
43
|
+
> `optional` **onError**: (`error`) => `void`
|
|
44
|
+
|
|
45
|
+
#### Parameters
|
|
46
|
+
|
|
47
|
+
##### error
|
|
48
|
+
|
|
49
|
+
`WalletError`
|
|
50
|
+
|
|
51
|
+
#### Returns
|
|
52
|
+
|
|
53
|
+
`void`
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
### privateDataPermission?
|
|
58
|
+
|
|
59
|
+
> `optional` **privateDataPermission**: `PrivateDataPermission`
|
|
60
|
+
|
|
61
|
+
***
|
|
62
|
+
|
|
63
|
+
### wallets
|
|
64
|
+
|
|
65
|
+
> **wallets**: `Adapter`[]
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / MidenFiSignerProvider
|
|
6
|
+
|
|
7
|
+
# Variable: MidenFiSignerProvider
|
|
8
|
+
|
|
9
|
+
> `const` **MidenFiSignerProvider**: `FC`\<[`MidenFiSignerProviderProps`](../interfaces/MidenFiSignerProviderProps.md)\>
|
|
10
|
+
|
|
11
|
+
MidenFiSignerProvider bridges the MidenFi wallet with MidenProvider.
|
|
12
|
+
|
|
13
|
+
This is a unified provider that handles both wallet connection and signer context.
|
|
14
|
+
|
|
15
|
+
## Examples
|
|
16
|
+
|
|
17
|
+
```tsx
|
|
18
|
+
// Simplest usage - uses MidenWalletAdapter by default
|
|
19
|
+
<MidenFiSignerProvider>
|
|
20
|
+
<MidenProvider config={{ rpcUrl: "testnet" }}>
|
|
21
|
+
<App />
|
|
22
|
+
</MidenProvider>
|
|
23
|
+
</MidenFiSignerProvider>
|
|
24
|
+
|
|
25
|
+
// With custom options
|
|
26
|
+
<MidenFiSignerProvider
|
|
27
|
+
appName="My DApp"
|
|
28
|
+
network={WalletAdapterNetwork.Testnet}
|
|
29
|
+
autoConnect={true}
|
|
30
|
+
>
|
|
31
|
+
<MidenProvider config={{ rpcUrl: "testnet" }}>
|
|
32
|
+
<App />
|
|
33
|
+
</MidenProvider>
|
|
34
|
+
</MidenFiSignerProvider>
|
|
35
|
+
|
|
36
|
+
// With custom wallets
|
|
37
|
+
<MidenFiSignerProvider wallets={[new CustomWalletAdapter()]}>
|
|
38
|
+
<MidenProvider config={{ rpcUrl: "testnet" }}>
|
|
39
|
+
<App />
|
|
40
|
+
</MidenProvider>
|
|
41
|
+
</MidenFiSignerProvider>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
For wallet operations, use the useMidenFiWallet hook:
|
|
45
|
+
|
|
46
|
+
```tsx
|
|
47
|
+
const { connected, connect, disconnect, select, wallets } = useMidenFiWallet();
|
|
48
|
+
|
|
49
|
+
// If multiple wallets, select one first
|
|
50
|
+
select(wallets[0].adapter.name);
|
|
51
|
+
|
|
52
|
+
// Then connect
|
|
53
|
+
await connect();
|
|
54
|
+
```
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / WalletContext
|
|
6
|
+
|
|
7
|
+
# Variable: WalletContext
|
|
8
|
+
|
|
9
|
+
> `const` **WalletContext**: `Context`\<[`WalletContextState`](../interfaces/WalletContextState.md)\>
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
[**@miden-sdk/miden-wallet-adapter-react**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[@miden-sdk/miden-wallet-adapter-react](../README.md) / WalletProvider
|
|
6
|
+
|
|
7
|
+
# Variable: WalletProvider
|
|
8
|
+
|
|
9
|
+
> `const` **WalletProvider**: `FC`\<[`WalletProviderProps`](../interfaces/WalletProviderProps.md)\>
|
package/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Legacy exports for backward compatibility
|
|
2
|
+
export * from './WalletProvider';
|
|
3
|
+
export * from './useLocalStorage';
|
|
4
|
+
export * from './useWallet';
|
|
5
|
+
|
|
6
|
+
// MidenFi Signer Provider - unified provider for @miden-sdk/react integration
|
|
7
|
+
export {
|
|
8
|
+
MidenFiSignerProvider,
|
|
9
|
+
useMidenFiWallet,
|
|
10
|
+
WalletContext,
|
|
11
|
+
type MidenFiSignerProviderProps,
|
|
12
|
+
type Wallet,
|
|
13
|
+
type WalletContextState,
|
|
14
|
+
type MidenFiWalletContextState,
|
|
15
|
+
} from './MidenFiSignerProvider';
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@miden-sdk/miden-wallet-adapter-react",
|
|
3
|
+
"version": "0.13.0",
|
|
4
|
+
"description": "Core react infrastructure for connecting Miden-compatible wallets to your dApp.",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/demox-labs/miden-wallet-adapter.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Demox Labs",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc",
|
|
16
|
+
"clean": "rimraf dist/ node_modules/",
|
|
17
|
+
"doc": "typedoc --disableSources --plugin typedoc-plugin-markdown --entryPoints index.ts",
|
|
18
|
+
"test": "vitest run"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@miden-sdk/miden-wallet-adapter-base": "workspace:^",
|
|
22
|
+
"@miden-sdk/miden-wallet-adapter-miden": "workspace:^"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@miden-sdk/miden-sdk": "^0.13.0",
|
|
26
|
+
"@miden-sdk/react": "^0.13.0",
|
|
27
|
+
"@testing-library/react": "^14.0.0",
|
|
28
|
+
"jsdom": "^24.0.0",
|
|
29
|
+
"react": "^19.1.1",
|
|
30
|
+
"react-dom": "^19.1.1",
|
|
31
|
+
"vitest": "^1.0.0"
|
|
32
|
+
},
|
|
33
|
+
"peerDependencies": {
|
|
34
|
+
"@miden-sdk/react": "^0.13.0",
|
|
35
|
+
"react": "^18.0.0 || ^19.0.0"
|
|
36
|
+
},
|
|
37
|
+
"peerDependenciesMeta": {
|
|
38
|
+
"@miden-sdk/react": {
|
|
39
|
+
"optional": true
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"jsx": "react-jsx",
|
|
4
|
+
"target": "ESNext",
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "dist",
|
|
8
|
+
"sourceMap": true,
|
|
9
|
+
"moduleResolution": "node",
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"skipLibCheck": true
|
|
14
|
+
},
|
|
15
|
+
"exclude": ["node_modules", "dist", "__tests__"]
|
|
16
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Dispatch, SetStateAction } from 'react';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
|
|
4
|
+
export function useLocalStorage<T>(key: string, defaultState: T): [T, Dispatch<SetStateAction<T>>] {
|
|
5
|
+
const state = useState<T>(() => {
|
|
6
|
+
try {
|
|
7
|
+
const value = localStorage.getItem(key);
|
|
8
|
+
if (value) return JSON.parse(value) as T;
|
|
9
|
+
} catch (error: any) {
|
|
10
|
+
if (typeof window !== 'undefined') {
|
|
11
|
+
console.error(error);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return defaultState;
|
|
16
|
+
});
|
|
17
|
+
const value = state[0];
|
|
18
|
+
|
|
19
|
+
const isFirstRender = useRef(true);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (isFirstRender.current) {
|
|
22
|
+
isFirstRender.current = false;
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
try {
|
|
26
|
+
if (value === null) {
|
|
27
|
+
localStorage.removeItem(key);
|
|
28
|
+
} else {
|
|
29
|
+
localStorage.setItem(key, JSON.stringify(value));
|
|
30
|
+
}
|
|
31
|
+
} catch (error: any) {
|
|
32
|
+
if (typeof window !== 'undefined') {
|
|
33
|
+
console.error(error);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}, [value, key]);
|
|
37
|
+
|
|
38
|
+
return state;
|
|
39
|
+
}
|