@chipi-stack/chipi-react 11.22.0 → 12.1.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/dist/hooks.d.mts +471 -69
- package/dist/hooks.d.ts +471 -69
- package/dist/hooks.js +474 -4
- package/dist/hooks.js.map +1 -1
- package/dist/hooks.mjs +469 -6
- package/dist/hooks.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +474 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +469 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/hooks.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useMutation, useQueryClient, useQuery } from '@tanstack/react-query';
|
|
2
|
-
import { createContext, useContext } from 'react';
|
|
2
|
+
import { createContext, useMemo, useCallback, useState, useEffect, useContext } from 'react';
|
|
3
3
|
import '@chipi-stack/backend';
|
|
4
4
|
import 'react/jsx-runtime';
|
|
5
5
|
import { ChipiApiError } from '@chipi-stack/shared';
|
|
@@ -80,6 +80,367 @@ function useGetWallet(input) {
|
|
|
80
80
|
fetchWallet
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
+
function useChipiWallet(config) {
|
|
84
|
+
const { chipiSDK } = useChipiContext();
|
|
85
|
+
const queryClient = useQueryClient();
|
|
86
|
+
const {
|
|
87
|
+
externalUserId,
|
|
88
|
+
getBearerToken,
|
|
89
|
+
defaultToken = "USDC",
|
|
90
|
+
enabled = true
|
|
91
|
+
} = config;
|
|
92
|
+
const isEnabled = Boolean(
|
|
93
|
+
enabled && externalUserId && externalUserId.trim() !== ""
|
|
94
|
+
);
|
|
95
|
+
const walletQuery = useQuery({
|
|
96
|
+
queryKey: ["chipi-wallet", externalUserId],
|
|
97
|
+
queryFn: async () => {
|
|
98
|
+
if (!externalUserId) return null;
|
|
99
|
+
const bearerToken = await getBearerToken();
|
|
100
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
101
|
+
return chipiSDK.getWallet({ externalUserId }, bearerToken);
|
|
102
|
+
},
|
|
103
|
+
enabled: isEnabled,
|
|
104
|
+
retry: (failureCount, error) => {
|
|
105
|
+
if (error instanceof ChipiApiError || error?.status) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return failureCount < 3;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
const walletPublicKey = walletQuery.data?.wallet.publicKey;
|
|
112
|
+
const balanceQuery = useQuery({
|
|
113
|
+
queryKey: ["chipi-wallet-balance", walletPublicKey, defaultToken],
|
|
114
|
+
queryFn: async () => {
|
|
115
|
+
if (!walletPublicKey) throw new Error("No wallet");
|
|
116
|
+
const bearerToken = await getBearerToken();
|
|
117
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
118
|
+
return chipiSDK.getTokenBalance(
|
|
119
|
+
{
|
|
120
|
+
chain: "STARKNET",
|
|
121
|
+
chainToken: defaultToken,
|
|
122
|
+
walletPublicKey
|
|
123
|
+
},
|
|
124
|
+
bearerToken
|
|
125
|
+
);
|
|
126
|
+
},
|
|
127
|
+
enabled: Boolean(walletPublicKey),
|
|
128
|
+
retry: (failureCount, error) => {
|
|
129
|
+
if (error instanceof ChipiApiError || error?.status) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return failureCount < 3;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
const createWalletMutation = useMutation({
|
|
136
|
+
mutationFn: async ({ encryptKey, walletType = "CHIPI" }) => {
|
|
137
|
+
if (!externalUserId) throw new Error("External user ID is required");
|
|
138
|
+
const bearerToken = await getBearerToken();
|
|
139
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
140
|
+
return chipiSDK.createWallet({
|
|
141
|
+
params: {
|
|
142
|
+
encryptKey,
|
|
143
|
+
externalUserId,
|
|
144
|
+
walletType
|
|
145
|
+
},
|
|
146
|
+
bearerToken
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
onSuccess: () => {
|
|
150
|
+
queryClient.invalidateQueries({
|
|
151
|
+
queryKey: ["chipi-wallet", externalUserId]
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
const wallet = useMemo(() => {
|
|
156
|
+
if (walletQuery.isLoading) return void 0;
|
|
157
|
+
if (!walletQuery.data) return null;
|
|
158
|
+
const data = walletQuery.data;
|
|
159
|
+
return {
|
|
160
|
+
...data,
|
|
161
|
+
supportsSessionKeys: data.wallet.walletType === "CHIPI",
|
|
162
|
+
shortAddress: formatAddress(data.wallet.publicKey)
|
|
163
|
+
};
|
|
164
|
+
}, [walletQuery.data, walletQuery.isLoading]);
|
|
165
|
+
const formattedBalance = useMemo(() => {
|
|
166
|
+
if (!balanceQuery.data?.balance) return "0.00";
|
|
167
|
+
const num = Number(balanceQuery.data.balance);
|
|
168
|
+
return num.toLocaleString(void 0, {
|
|
169
|
+
minimumFractionDigits: 2,
|
|
170
|
+
maximumFractionDigits: defaultToken === "ETH" || defaultToken === "STRK" ? 6 : 2
|
|
171
|
+
});
|
|
172
|
+
}, [balanceQuery.data, defaultToken]);
|
|
173
|
+
const refetchWallet = useCallback(async () => {
|
|
174
|
+
await walletQuery.refetch();
|
|
175
|
+
}, [walletQuery]);
|
|
176
|
+
const refetchBalance = useCallback(async () => {
|
|
177
|
+
await balanceQuery.refetch();
|
|
178
|
+
}, [balanceQuery]);
|
|
179
|
+
const refetchAll = useCallback(async () => {
|
|
180
|
+
await Promise.all([walletQuery.refetch(), balanceQuery.refetch()]);
|
|
181
|
+
}, [walletQuery, balanceQuery]);
|
|
182
|
+
const createWallet = useCallback(
|
|
183
|
+
async (params) => {
|
|
184
|
+
return createWalletMutation.mutateAsync(params);
|
|
185
|
+
},
|
|
186
|
+
[createWalletMutation]
|
|
187
|
+
);
|
|
188
|
+
return {
|
|
189
|
+
// Wallet data
|
|
190
|
+
wallet,
|
|
191
|
+
hasWallet: wallet !== null && wallet !== void 0,
|
|
192
|
+
isLoadingWallet: walletQuery.isLoading,
|
|
193
|
+
walletError: walletQuery.error,
|
|
194
|
+
// Balance data
|
|
195
|
+
balance: balanceQuery.data,
|
|
196
|
+
formattedBalance,
|
|
197
|
+
isLoadingBalance: balanceQuery.isLoading,
|
|
198
|
+
// Create wallet
|
|
199
|
+
createWallet,
|
|
200
|
+
isCreating: createWalletMutation.isPending,
|
|
201
|
+
createdWallet: createWalletMutation.data,
|
|
202
|
+
// Actions
|
|
203
|
+
refetchWallet,
|
|
204
|
+
refetchBalance,
|
|
205
|
+
refetchAll
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
function formatAddress(address, chars = 6) {
|
|
209
|
+
if (!address || address.length < chars * 2) return address;
|
|
210
|
+
return `${address.slice(0, chars + 2)}...${address.slice(-chars)}`;
|
|
211
|
+
}
|
|
212
|
+
function useChipiSession(config) {
|
|
213
|
+
const { chipiSDK } = useChipiContext();
|
|
214
|
+
const queryClient = useQueryClient();
|
|
215
|
+
const {
|
|
216
|
+
wallet,
|
|
217
|
+
encryptKey,
|
|
218
|
+
getBearerToken,
|
|
219
|
+
storedSession,
|
|
220
|
+
onSessionCreated,
|
|
221
|
+
defaultDurationSeconds = 21600,
|
|
222
|
+
// 6 hours
|
|
223
|
+
defaultMaxCalls = 1e3,
|
|
224
|
+
autoCheckStatus = true
|
|
225
|
+
} = config;
|
|
226
|
+
const [localSession, setLocalSession] = useState(
|
|
227
|
+
storedSession ?? null
|
|
228
|
+
);
|
|
229
|
+
const [error, setError] = useState(null);
|
|
230
|
+
useEffect(() => {
|
|
231
|
+
if (storedSession) {
|
|
232
|
+
setLocalSession(storedSession);
|
|
233
|
+
}
|
|
234
|
+
}, [storedSession]);
|
|
235
|
+
const supportsSession = useMemo(() => {
|
|
236
|
+
if (!wallet) return false;
|
|
237
|
+
return wallet.walletType === "CHIPI";
|
|
238
|
+
}, [wallet]);
|
|
239
|
+
const sessionStatusQuery = useQuery({
|
|
240
|
+
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey],
|
|
241
|
+
queryFn: async () => {
|
|
242
|
+
if (!wallet?.publicKey || !localSession?.publicKey) return null;
|
|
243
|
+
return chipiSDK.sessions.getSessionData({
|
|
244
|
+
walletAddress: wallet.publicKey,
|
|
245
|
+
sessionPublicKey: localSession.publicKey
|
|
246
|
+
});
|
|
247
|
+
},
|
|
248
|
+
enabled: Boolean(
|
|
249
|
+
autoCheckStatus && wallet?.publicKey && localSession?.publicKey && supportsSession
|
|
250
|
+
),
|
|
251
|
+
staleTime: 3e4
|
|
252
|
+
// 30 seconds
|
|
253
|
+
});
|
|
254
|
+
const sessionState = useMemo(() => {
|
|
255
|
+
if (!localSession) return "none";
|
|
256
|
+
const status = sessionStatusQuery.data;
|
|
257
|
+
if (status) {
|
|
258
|
+
if (!status.isActive) return "revoked";
|
|
259
|
+
if (status.validUntil * 1e3 < Date.now()) return "expired";
|
|
260
|
+
if (status.remainingCalls <= 0) return "expired";
|
|
261
|
+
return "active";
|
|
262
|
+
}
|
|
263
|
+
if (localSession.validUntil * 1e3 < Date.now()) return "expired";
|
|
264
|
+
return "created";
|
|
265
|
+
}, [localSession, sessionStatusQuery.data]);
|
|
266
|
+
const hasActiveSession = sessionState === "active";
|
|
267
|
+
const isSessionExpired = sessionState === "expired";
|
|
268
|
+
const remainingCalls = sessionStatusQuery.data?.remainingCalls;
|
|
269
|
+
const createSessionMutation = useMutation({
|
|
270
|
+
mutationFn: async (params = {}) => {
|
|
271
|
+
if (!encryptKey) throw new Error("Encryption key (PIN) is required");
|
|
272
|
+
if (!supportsSession) throw new Error("Wallet does not support sessions. Only CHIPI wallets support session keys.");
|
|
273
|
+
const sessionData = chipiSDK.sessions.createSessionKey({
|
|
274
|
+
encryptKey,
|
|
275
|
+
durationSeconds: params.durationSeconds ?? defaultDurationSeconds
|
|
276
|
+
});
|
|
277
|
+
return sessionData;
|
|
278
|
+
},
|
|
279
|
+
onSuccess: async (sessionData) => {
|
|
280
|
+
setLocalSession(sessionData);
|
|
281
|
+
setError(null);
|
|
282
|
+
if (onSessionCreated) {
|
|
283
|
+
await onSessionCreated(sessionData);
|
|
284
|
+
}
|
|
285
|
+
},
|
|
286
|
+
onError: (err) => {
|
|
287
|
+
setError(err);
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
const registerSessionMutation = useMutation({
|
|
291
|
+
mutationFn: async (sessionConfig = {}) => {
|
|
292
|
+
if (!wallet) throw new Error("Wallet is required");
|
|
293
|
+
if (!localSession) throw new Error("No session to register. Call createSession first.");
|
|
294
|
+
if (!encryptKey) throw new Error("Encryption key (PIN) is required");
|
|
295
|
+
if (!supportsSession) throw new Error("Wallet does not support sessions");
|
|
296
|
+
const bearerToken = await getBearerToken();
|
|
297
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
298
|
+
const txHash = await chipiSDK.sessions.addSessionKeyToContract(
|
|
299
|
+
{
|
|
300
|
+
encryptKey,
|
|
301
|
+
wallet,
|
|
302
|
+
sessionConfig: {
|
|
303
|
+
sessionPublicKey: localSession.publicKey,
|
|
304
|
+
validUntil: sessionConfig.validUntil ?? localSession.validUntil,
|
|
305
|
+
maxCalls: sessionConfig.maxCalls ?? defaultMaxCalls,
|
|
306
|
+
allowedEntrypoints: sessionConfig.allowedEntrypoints ?? []
|
|
307
|
+
}
|
|
308
|
+
},
|
|
309
|
+
bearerToken
|
|
310
|
+
);
|
|
311
|
+
return txHash;
|
|
312
|
+
},
|
|
313
|
+
onSuccess: () => {
|
|
314
|
+
setError(null);
|
|
315
|
+
queryClient.invalidateQueries({
|
|
316
|
+
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
317
|
+
});
|
|
318
|
+
},
|
|
319
|
+
onError: (err) => {
|
|
320
|
+
setError(err);
|
|
321
|
+
}
|
|
322
|
+
});
|
|
323
|
+
const revokeSessionMutation = useMutation({
|
|
324
|
+
mutationFn: async () => {
|
|
325
|
+
if (!wallet) throw new Error("Wallet is required");
|
|
326
|
+
if (!localSession) throw new Error("No session to revoke");
|
|
327
|
+
if (!encryptKey) throw new Error("Encryption key (PIN) is required");
|
|
328
|
+
if (!supportsSession) throw new Error("Wallet does not support sessions");
|
|
329
|
+
const bearerToken = await getBearerToken();
|
|
330
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
331
|
+
const txHash = await chipiSDK.sessions.revokeSessionKey(
|
|
332
|
+
{
|
|
333
|
+
encryptKey,
|
|
334
|
+
wallet,
|
|
335
|
+
sessionPublicKey: localSession.publicKey
|
|
336
|
+
},
|
|
337
|
+
bearerToken
|
|
338
|
+
);
|
|
339
|
+
return txHash;
|
|
340
|
+
},
|
|
341
|
+
onSuccess: () => {
|
|
342
|
+
setError(null);
|
|
343
|
+
queryClient.invalidateQueries({
|
|
344
|
+
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
345
|
+
});
|
|
346
|
+
},
|
|
347
|
+
onError: (err) => {
|
|
348
|
+
setError(err);
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
const executeWithSessionMutation = useMutation({
|
|
352
|
+
mutationFn: async (calls) => {
|
|
353
|
+
if (!wallet) throw new Error("Wallet is required");
|
|
354
|
+
if (!localSession) throw new Error("No active session");
|
|
355
|
+
if (!encryptKey) throw new Error("Encryption key (PIN) is required");
|
|
356
|
+
if (!hasActiveSession) throw new Error("Session is not active. Register the session first.");
|
|
357
|
+
const bearerToken = await getBearerToken();
|
|
358
|
+
if (!bearerToken) throw new Error("Bearer token is required");
|
|
359
|
+
const txHash = await chipiSDK.executeTransactionWithSession({
|
|
360
|
+
params: {
|
|
361
|
+
encryptKey,
|
|
362
|
+
wallet,
|
|
363
|
+
session: localSession,
|
|
364
|
+
calls
|
|
365
|
+
},
|
|
366
|
+
bearerToken
|
|
367
|
+
});
|
|
368
|
+
return txHash;
|
|
369
|
+
},
|
|
370
|
+
onSuccess: () => {
|
|
371
|
+
setError(null);
|
|
372
|
+
queryClient.invalidateQueries({
|
|
373
|
+
queryKey: ["chipi-session-status", wallet?.publicKey, localSession?.publicKey]
|
|
374
|
+
});
|
|
375
|
+
},
|
|
376
|
+
onError: (err) => {
|
|
377
|
+
setError(err);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
const createSession = useCallback(
|
|
381
|
+
async (params) => {
|
|
382
|
+
return createSessionMutation.mutateAsync(params ?? {});
|
|
383
|
+
},
|
|
384
|
+
[createSessionMutation]
|
|
385
|
+
);
|
|
386
|
+
const registerSession = useCallback(
|
|
387
|
+
async (sessionConfig) => {
|
|
388
|
+
return registerSessionMutation.mutateAsync(sessionConfig ?? {});
|
|
389
|
+
},
|
|
390
|
+
[registerSessionMutation]
|
|
391
|
+
);
|
|
392
|
+
const revokeSession = useCallback(async () => {
|
|
393
|
+
return revokeSessionMutation.mutateAsync();
|
|
394
|
+
}, [revokeSessionMutation]);
|
|
395
|
+
const executeWithSession = useCallback(
|
|
396
|
+
async (calls) => {
|
|
397
|
+
return executeWithSessionMutation.mutateAsync(calls);
|
|
398
|
+
},
|
|
399
|
+
[executeWithSessionMutation]
|
|
400
|
+
);
|
|
401
|
+
const clearSession = useCallback(() => {
|
|
402
|
+
setLocalSession(null);
|
|
403
|
+
setError(null);
|
|
404
|
+
}, []);
|
|
405
|
+
const refetchStatus = useCallback(async () => {
|
|
406
|
+
await sessionStatusQuery.refetch();
|
|
407
|
+
}, [sessionStatusQuery]);
|
|
408
|
+
const combinedError = useMemo(() => {
|
|
409
|
+
return error || createSessionMutation.error || registerSessionMutation.error || revokeSessionMutation.error || executeWithSessionMutation.error || sessionStatusQuery.error || null;
|
|
410
|
+
}, [
|
|
411
|
+
error,
|
|
412
|
+
createSessionMutation.error,
|
|
413
|
+
registerSessionMutation.error,
|
|
414
|
+
revokeSessionMutation.error,
|
|
415
|
+
executeWithSessionMutation.error,
|
|
416
|
+
sessionStatusQuery.error
|
|
417
|
+
]);
|
|
418
|
+
return {
|
|
419
|
+
// Session data
|
|
420
|
+
session: localSession,
|
|
421
|
+
sessionStatus: sessionStatusQuery.data ?? void 0,
|
|
422
|
+
sessionState,
|
|
423
|
+
hasActiveSession,
|
|
424
|
+
isSessionExpired,
|
|
425
|
+
remainingCalls,
|
|
426
|
+
supportsSession,
|
|
427
|
+
// Actions
|
|
428
|
+
createSession,
|
|
429
|
+
registerSession,
|
|
430
|
+
revokeSession,
|
|
431
|
+
executeWithSession,
|
|
432
|
+
clearSession,
|
|
433
|
+
refetchStatus,
|
|
434
|
+
// Loading states
|
|
435
|
+
isCreating: createSessionMutation.isPending,
|
|
436
|
+
isRegistering: registerSessionMutation.isPending,
|
|
437
|
+
isRevoking: revokeSessionMutation.isPending,
|
|
438
|
+
isExecuting: executeWithSessionMutation.isPending,
|
|
439
|
+
isLoadingStatus: sessionStatusQuery.isLoading,
|
|
440
|
+
// Errors
|
|
441
|
+
error: combinedError
|
|
442
|
+
};
|
|
443
|
+
}
|
|
83
444
|
function useTransfer() {
|
|
84
445
|
const { chipiSDK } = useChipiContext();
|
|
85
446
|
const mutation = useMutation(
|
|
@@ -407,8 +768,15 @@ function useRecordSendTransaction() {
|
|
|
407
768
|
function useGetTokenBalance(input) {
|
|
408
769
|
const { chipiSDK } = useChipiContext();
|
|
409
770
|
const queryClient = useQueryClient();
|
|
771
|
+
const buildQueryKey = (params) => [
|
|
772
|
+
"chain-token-balance",
|
|
773
|
+
params?.chainToken ?? null,
|
|
774
|
+
params?.chain ?? null,
|
|
775
|
+
params?.walletPublicKey ?? null,
|
|
776
|
+
params?.externalUserId ?? null
|
|
777
|
+
];
|
|
410
778
|
const query = useQuery({
|
|
411
|
-
queryKey:
|
|
779
|
+
queryKey: buildQueryKey(input?.params),
|
|
412
780
|
queryFn: async () => {
|
|
413
781
|
if (!input || !input.params || !input.getBearerToken) throw new Error("Input is required");
|
|
414
782
|
const bearerToken = await input.getBearerToken();
|
|
@@ -416,17 +784,17 @@ function useGetTokenBalance(input) {
|
|
|
416
784
|
return chipiSDK.getTokenBalance(input.params, bearerToken);
|
|
417
785
|
},
|
|
418
786
|
enabled: Boolean(input?.params && input?.getBearerToken),
|
|
419
|
-
...input?.queryOptions,
|
|
420
787
|
retry: (failureCount, error) => {
|
|
421
788
|
if (error instanceof ChipiApiError || error?.status) {
|
|
422
789
|
return false;
|
|
423
790
|
}
|
|
424
791
|
return failureCount < 3;
|
|
425
|
-
}
|
|
792
|
+
},
|
|
793
|
+
...input?.queryOptions
|
|
426
794
|
});
|
|
427
795
|
const fetchTokenBalance = async (newInput) => {
|
|
428
796
|
return queryClient.fetchQuery({
|
|
429
|
-
queryKey:
|
|
797
|
+
queryKey: buildQueryKey(newInput?.params),
|
|
430
798
|
queryFn: async () => {
|
|
431
799
|
if (!newInput || !newInput.getBearerToken || !newInput.params) throw new Error("Input is required");
|
|
432
800
|
const bearerToken = await newInput.getBearerToken();
|
|
@@ -530,7 +898,102 @@ function useCreateUser() {
|
|
|
530
898
|
reset: mutation.reset
|
|
531
899
|
};
|
|
532
900
|
}
|
|
901
|
+
function useCreateSessionKey() {
|
|
902
|
+
const { chipiSDK } = useChipiContext();
|
|
903
|
+
const mutation = useMutation({
|
|
904
|
+
mutationFn: async (params) => chipiSDK.sessions.createSessionKey(params)
|
|
905
|
+
});
|
|
906
|
+
return {
|
|
907
|
+
createSessionKey: mutation.mutate,
|
|
908
|
+
createSessionKeyAsync: mutation.mutateAsync,
|
|
909
|
+
data: mutation.data,
|
|
910
|
+
isLoading: mutation.isPending,
|
|
911
|
+
isError: mutation.isError,
|
|
912
|
+
error: mutation.error,
|
|
913
|
+
isSuccess: mutation.isSuccess,
|
|
914
|
+
reset: mutation.reset
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
function useAddSessionKeyToContract() {
|
|
918
|
+
const { chipiSDK } = useChipiContext();
|
|
919
|
+
const mutation = useMutation({
|
|
920
|
+
mutationFn: (input) => chipiSDK.sessions.addSessionKeyToContract(
|
|
921
|
+
input.params,
|
|
922
|
+
input.bearerToken
|
|
923
|
+
)
|
|
924
|
+
});
|
|
925
|
+
return {
|
|
926
|
+
addSessionKeyToContract: mutation.mutate,
|
|
927
|
+
addSessionKeyToContractAsync: mutation.mutateAsync,
|
|
928
|
+
data: mutation.data,
|
|
929
|
+
isLoading: mutation.isPending,
|
|
930
|
+
isError: mutation.isError,
|
|
931
|
+
error: mutation.error,
|
|
932
|
+
isSuccess: mutation.isSuccess,
|
|
933
|
+
reset: mutation.reset
|
|
934
|
+
};
|
|
935
|
+
}
|
|
936
|
+
function useRevokeSessionKey() {
|
|
937
|
+
const { chipiSDK } = useChipiContext();
|
|
938
|
+
const mutation = useMutation({
|
|
939
|
+
mutationFn: (input) => chipiSDK.sessions.revokeSessionKey(input.params, input.bearerToken)
|
|
940
|
+
});
|
|
941
|
+
return {
|
|
942
|
+
revokeSessionKey: mutation.mutate,
|
|
943
|
+
revokeSessionKeyAsync: mutation.mutateAsync,
|
|
944
|
+
data: mutation.data,
|
|
945
|
+
isLoading: mutation.isPending,
|
|
946
|
+
isError: mutation.isError,
|
|
947
|
+
error: mutation.error,
|
|
948
|
+
isSuccess: mutation.isSuccess,
|
|
949
|
+
reset: mutation.reset
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function useGetSessionData(params, options) {
|
|
953
|
+
const { chipiSDK } = useChipiContext();
|
|
954
|
+
const query = useQuery({
|
|
955
|
+
queryKey: [
|
|
956
|
+
"sessionData",
|
|
957
|
+
params?.walletAddress,
|
|
958
|
+
params?.sessionPublicKey
|
|
959
|
+
],
|
|
960
|
+
queryFn: () => {
|
|
961
|
+
if (!params) {
|
|
962
|
+
throw new Error("Session data params are required");
|
|
963
|
+
}
|
|
964
|
+
return chipiSDK.sessions.getSessionData(params);
|
|
965
|
+
},
|
|
966
|
+
enabled: options?.enabled !== false && params !== null
|
|
967
|
+
});
|
|
968
|
+
return {
|
|
969
|
+
data: query.data,
|
|
970
|
+
isLoading: query.isLoading,
|
|
971
|
+
isError: query.isError,
|
|
972
|
+
error: query.error,
|
|
973
|
+
isSuccess: query.isSuccess,
|
|
974
|
+
refetch: query.refetch
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function useExecuteWithSession() {
|
|
978
|
+
const { chipiSDK } = useChipiContext();
|
|
979
|
+
const mutation = useMutation({
|
|
980
|
+
mutationFn: (input) => chipiSDK.executeTransactionWithSession({
|
|
981
|
+
params: input.params,
|
|
982
|
+
bearerToken: input.bearerToken
|
|
983
|
+
})
|
|
984
|
+
});
|
|
985
|
+
return {
|
|
986
|
+
executeWithSession: mutation.mutate,
|
|
987
|
+
executeWithSessionAsync: mutation.mutateAsync,
|
|
988
|
+
data: mutation.data,
|
|
989
|
+
isLoading: mutation.isPending,
|
|
990
|
+
isError: mutation.isError,
|
|
991
|
+
error: mutation.error,
|
|
992
|
+
isSuccess: mutation.isSuccess,
|
|
993
|
+
reset: mutation.reset
|
|
994
|
+
};
|
|
995
|
+
}
|
|
533
996
|
|
|
534
|
-
export { useApprove, useCallAnyContract, useCreateSkuTransaction, useCreateUser, useCreateWallet, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useRecordSendTransaction, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
|
997
|
+
export { useAddSessionKeyToContract, useApprove, useCallAnyContract, useChipiSession, useChipiWallet, useCreateSessionKey, useCreateSkuTransaction, useCreateUser, useCreateWallet, useExecuteWithSession, useGetSessionData, useGetSku, useGetSkuList, useGetSkuTransaction, useGetTokenBalance, useGetTransactionList, useGetUser, useGetWallet, useRecordSendTransaction, useRevokeSessionKey, useStakeVesuUsdc, useTransfer, useWithdrawVesuUsdc };
|
|
535
998
|
//# sourceMappingURL=hooks.mjs.map
|
|
536
999
|
//# sourceMappingURL=hooks.mjs.map
|