@frak-labs/react-sdk 0.0.3
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/LICENSE +674 -0
- package/README.md +8 -0
- package/dist/index.cjs +389 -0
- package/dist/index.d.cts +298 -0
- package/dist/index.d.ts +298 -0
- package/dist/index.js +389 -0
- package/package.json +76 -0
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Frak Wallet React SDK
|
|
2
|
+
|
|
3
|
+
This SDK help any dApps, or gated content provider, use the [Frak Wallet](https://wallet.frak.id/) as a regular wallet, with smoother UX for your end-users (pay for his gas fees, check the paywall options, track his consumption etc.)
|
|
4
|
+
|
|
5
|
+
Checkout our documentation for more information's about the usage:
|
|
6
|
+
- [React client usage](https://docs.frak.id/wallet-sdk/getting-started/react)
|
|
7
|
+
- [Core client usage](https://docs.frak.id/wallet-sdk/getting-started/javascript)
|
|
8
|
+
- [CDN / Browser usage](https://docs.frak.id/wallet-sdk/getting-started/cdn)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/provider/FrakConfigProvider.ts
|
|
2
|
+
var _react = require('react');
|
|
3
|
+
var FrakConfigContext = _react.createContext.call(void 0,
|
|
4
|
+
void 0
|
|
5
|
+
);
|
|
6
|
+
function FrakConfigProvider(parameters) {
|
|
7
|
+
const { children, config } = parameters;
|
|
8
|
+
return _react.createElement.call(void 0,
|
|
9
|
+
FrakConfigContext.Provider,
|
|
10
|
+
{
|
|
11
|
+
value: {
|
|
12
|
+
...config,
|
|
13
|
+
walletUrl: _nullishCoalesce(config.walletUrl, () => ( "https://wallet.frak.id")),
|
|
14
|
+
domain: _nullishCoalesce(_nullishCoalesce(config.domain, () => ( (typeof window !== "undefined" ? _optionalChain([window, 'optionalAccess', _ => _.location, 'optionalAccess', _2 => _2.host]) : void 0))), () => ( "not-found"))
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
children
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// src/provider/FrakIFrameClientProvider.ts
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
var _coresdk = require('@frak-labs/core-sdk');
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// src/hook/useFrakConfig.ts
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
function useFrakConfig() {
|
|
37
|
+
const config = _react.useContext.call(void 0, FrakConfigContext);
|
|
38
|
+
if (!config) {
|
|
39
|
+
throw new (0, _coresdk.FrakRpcError)(
|
|
40
|
+
_coresdk.RpcErrorCodes.configError,
|
|
41
|
+
"Frak config not found"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/hook/useFrakClient.ts
|
|
48
|
+
|
|
49
|
+
function useFrakClient() {
|
|
50
|
+
return _react.useContext.call(void 0, FrakIFrameClientContext);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/hook/useWalletStatus.ts
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
var _actions = require('@frak-labs/core-sdk/actions');
|
|
58
|
+
var _reactquery = require('@tanstack/react-query');
|
|
59
|
+
|
|
60
|
+
function useWalletStatus() {
|
|
61
|
+
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
62
|
+
const client = useFrakClient();
|
|
63
|
+
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
64
|
+
(event) => {
|
|
65
|
+
queryClient.setQueryData(
|
|
66
|
+
["frak-sdk", "wallet-status-listener"],
|
|
67
|
+
event
|
|
68
|
+
);
|
|
69
|
+
},
|
|
70
|
+
[queryClient]
|
|
71
|
+
);
|
|
72
|
+
return _reactquery.useQuery.call(void 0, {
|
|
73
|
+
gcTime: 0,
|
|
74
|
+
staleTime: 0,
|
|
75
|
+
queryKey: ["frak-sdk", "wallet-status-listener"],
|
|
76
|
+
queryFn: async () => {
|
|
77
|
+
if (!client) {
|
|
78
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
79
|
+
}
|
|
80
|
+
return _actions.watchWalletStatus.call(void 0, client, newStatusUpdated);
|
|
81
|
+
},
|
|
82
|
+
enabled: !!client
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/hook/useSendTransaction.ts
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
function useSendTransactionAction({
|
|
95
|
+
mutations
|
|
96
|
+
} = {}) {
|
|
97
|
+
const client = useFrakClient();
|
|
98
|
+
return _reactquery.useMutation.call(void 0, {
|
|
99
|
+
...mutations,
|
|
100
|
+
mutationKey: ["frak-sdk", "send-transaction"],
|
|
101
|
+
mutationFn: async (params) => {
|
|
102
|
+
if (!client) {
|
|
103
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
104
|
+
}
|
|
105
|
+
return _actions.sendTransaction.call(void 0, client, params);
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// src/hook/useSiweAuthenticate.ts
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
function useSiweAuthenticate({
|
|
119
|
+
mutations
|
|
120
|
+
} = {}) {
|
|
121
|
+
const client = useFrakClient();
|
|
122
|
+
return _reactquery.useMutation.call(void 0, {
|
|
123
|
+
...mutations,
|
|
124
|
+
mutationKey: [
|
|
125
|
+
"frak-sdk",
|
|
126
|
+
"siwe-authenticate",
|
|
127
|
+
_nullishCoalesce(_optionalChain([client, 'optionalAccess', _3 => _3.config, 'access', _4 => _4.domain]), () => ( "no-domain"))
|
|
128
|
+
],
|
|
129
|
+
mutationFn: async (params) => {
|
|
130
|
+
if (!client) {
|
|
131
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
132
|
+
}
|
|
133
|
+
return _actions.siweAuthenticate.call(void 0, client, params);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// src/hook/helper/useReferralInteraction.ts
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
// src/hook/utils/useFrakContext.ts
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
// src/hook/utils/useWindowLocation.ts
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
// src/hook/utils/useMounted.ts
|
|
156
|
+
|
|
157
|
+
function useMounted() {
|
|
158
|
+
const [mounted, setMounted] = _react.useState.call(void 0, false);
|
|
159
|
+
_react.useEffect.call(void 0, () => {
|
|
160
|
+
setMounted(true);
|
|
161
|
+
}, []);
|
|
162
|
+
return mounted;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// src/hook/utils/useWindowLocation.ts
|
|
166
|
+
function useWindowLocation() {
|
|
167
|
+
const isMounted = useMounted();
|
|
168
|
+
const [location, setLocation] = _react.useState.call(void 0,
|
|
169
|
+
isMounted ? window.location : void 0
|
|
170
|
+
);
|
|
171
|
+
_react.useEffect.call(void 0, () => {
|
|
172
|
+
if (!isMounted) return;
|
|
173
|
+
function setWindowLocation() {
|
|
174
|
+
setLocation(window.location);
|
|
175
|
+
}
|
|
176
|
+
if (!location) {
|
|
177
|
+
setWindowLocation();
|
|
178
|
+
}
|
|
179
|
+
window.addEventListener("popstate", setWindowLocation);
|
|
180
|
+
return () => {
|
|
181
|
+
window.removeEventListener("popstate", setWindowLocation);
|
|
182
|
+
};
|
|
183
|
+
}, [isMounted, location]);
|
|
184
|
+
const href = _react.useMemo.call(void 0, () => _optionalChain([location, 'optionalAccess', _5 => _5.href]), [_optionalChain([location, 'optionalAccess', _6 => _6.href])]);
|
|
185
|
+
return { location, href };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// src/hook/utils/useFrakContext.ts
|
|
189
|
+
function useFrakContext() {
|
|
190
|
+
const { location } = useWindowLocation();
|
|
191
|
+
const frakContext = _react.useMemo.call(void 0, () => {
|
|
192
|
+
if (!_optionalChain([location, 'optionalAccess', _7 => _7.href])) return null;
|
|
193
|
+
return _coresdk.FrakContextManager.parse({ url: location.href });
|
|
194
|
+
}, [_optionalChain([location, 'optionalAccess', _8 => _8.href])]);
|
|
195
|
+
const updateContext = _react.useCallback.call(void 0,
|
|
196
|
+
(newContext) => {
|
|
197
|
+
console.log("Updating context", { newContext });
|
|
198
|
+
_coresdk.FrakContextManager.replaceUrl({
|
|
199
|
+
url: _optionalChain([location, 'optionalAccess', _9 => _9.href]),
|
|
200
|
+
context: newContext
|
|
201
|
+
});
|
|
202
|
+
},
|
|
203
|
+
[_optionalChain([location, 'optionalAccess', _10 => _10.href])]
|
|
204
|
+
);
|
|
205
|
+
return {
|
|
206
|
+
frakContext,
|
|
207
|
+
updateContext
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
// src/hook/helper/useReferralInteraction.ts
|
|
212
|
+
function useReferralInteraction({
|
|
213
|
+
productId,
|
|
214
|
+
modalConfig,
|
|
215
|
+
options
|
|
216
|
+
} = {}) {
|
|
217
|
+
const client = useFrakClient();
|
|
218
|
+
const { frakContext } = useFrakContext();
|
|
219
|
+
const { data: walletStatus } = useWalletStatus();
|
|
220
|
+
const {
|
|
221
|
+
data: referralState,
|
|
222
|
+
error,
|
|
223
|
+
status
|
|
224
|
+
} = _reactquery.useQuery.call(void 0, {
|
|
225
|
+
gcTime: 0,
|
|
226
|
+
staleTime: 0,
|
|
227
|
+
queryKey: [
|
|
228
|
+
"frak-sdk",
|
|
229
|
+
"auto-referral-interaction",
|
|
230
|
+
_nullishCoalesce(_optionalChain([frakContext, 'optionalAccess', _11 => _11.r]), () => ( "no-referrer")),
|
|
231
|
+
_nullishCoalesce(_optionalChain([walletStatus, 'optionalAccess', _12 => _12.key]), () => ( "no-wallet-status")),
|
|
232
|
+
_nullishCoalesce(productId, () => ( "no-product-id"))
|
|
233
|
+
],
|
|
234
|
+
queryFn: () => {
|
|
235
|
+
if (!client) {
|
|
236
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
237
|
+
}
|
|
238
|
+
return _actions.processReferral.call(void 0, client, {
|
|
239
|
+
walletStatus,
|
|
240
|
+
frakContext,
|
|
241
|
+
modalConfig,
|
|
242
|
+
productId,
|
|
243
|
+
options
|
|
244
|
+
});
|
|
245
|
+
},
|
|
246
|
+
enabled: !!walletStatus
|
|
247
|
+
});
|
|
248
|
+
return _react.useMemo.call(void 0, () => {
|
|
249
|
+
if (status === "pending") return "processing";
|
|
250
|
+
if (status === "error") return error;
|
|
251
|
+
return referralState || "idle";
|
|
252
|
+
}, [referralState, status, error]);
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// src/hook/useSendInteraction.ts
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
function useSendInteraction({
|
|
262
|
+
mutations
|
|
263
|
+
} = {}) {
|
|
264
|
+
const client = useFrakClient();
|
|
265
|
+
return _reactquery.useMutation.call(void 0, {
|
|
266
|
+
...mutations,
|
|
267
|
+
mutationKey: ["frak-sdk", "send-interaction"],
|
|
268
|
+
mutationFn: async (params) => {
|
|
269
|
+
if (!client) {
|
|
270
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
271
|
+
}
|
|
272
|
+
return _actions.sendInteraction.call(void 0, client, params);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// src/hook/useDisplayModal.ts
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
function useDisplayModal({
|
|
284
|
+
mutations
|
|
285
|
+
} = {}) {
|
|
286
|
+
const client = useFrakClient();
|
|
287
|
+
return _reactquery.useMutation.call(void 0, {
|
|
288
|
+
...mutations,
|
|
289
|
+
mutationKey: ["frak-sdk", "display-modal"],
|
|
290
|
+
mutationFn: async (args) => {
|
|
291
|
+
if (!client) {
|
|
292
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
293
|
+
}
|
|
294
|
+
return _actions.displayModal.call(void 0, client, args);
|
|
295
|
+
}
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/hook/useOpenSso.ts
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
function useOpenSso({ mutations } = {}) {
|
|
306
|
+
const client = useFrakClient();
|
|
307
|
+
return _reactquery.useMutation.call(void 0, {
|
|
308
|
+
...mutations,
|
|
309
|
+
mutationKey: ["frak-sdk", "open-sso"],
|
|
310
|
+
mutationFn: async (params) => {
|
|
311
|
+
if (!client) {
|
|
312
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
313
|
+
}
|
|
314
|
+
return _actions.openSso.call(void 0, client, params);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// src/hook/useGetProductInformation.ts
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
function useGetProductInformation({
|
|
326
|
+
query
|
|
327
|
+
} = {}) {
|
|
328
|
+
const client = useFrakClient();
|
|
329
|
+
return _reactquery.useQuery.call(void 0, {
|
|
330
|
+
...query,
|
|
331
|
+
queryKey: ["frak-sdk", "get-product-information"],
|
|
332
|
+
queryFn: async () => {
|
|
333
|
+
if (!client) {
|
|
334
|
+
throw new (0, _coresdk.ClientNotFound)();
|
|
335
|
+
}
|
|
336
|
+
return _actions.getProductInformation.call(void 0, client);
|
|
337
|
+
}
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// src/provider/FrakIFrameClientProvider.ts
|
|
342
|
+
var FrakIFrameClientContext = _react.createContext.call(void 0,
|
|
343
|
+
void 0
|
|
344
|
+
);
|
|
345
|
+
function FrakIFrameClientProvider({
|
|
346
|
+
style,
|
|
347
|
+
children
|
|
348
|
+
}) {
|
|
349
|
+
const config = useFrakConfig();
|
|
350
|
+
const [client, setClient] = _react.useState.call(void 0, void 0);
|
|
351
|
+
const iFrame = _react.createElement.call(void 0, "iframe", {
|
|
352
|
+
..._coresdk.baseIframeProps,
|
|
353
|
+
src: `${config.walletUrl}/listener`,
|
|
354
|
+
style: _nullishCoalesce(style, () => ( _coresdk.baseIframeProps.style)),
|
|
355
|
+
ref: (iframe) => {
|
|
356
|
+
if (!iframe || client) {
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
setClient(
|
|
360
|
+
_coresdk.createIFrameFrakClient.call(void 0, {
|
|
361
|
+
iframe,
|
|
362
|
+
config
|
|
363
|
+
})
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
const providerComponent = _react.createElement.call(void 0,
|
|
368
|
+
FrakIFrameClientContext.Provider,
|
|
369
|
+
{ value: client },
|
|
370
|
+
children
|
|
371
|
+
);
|
|
372
|
+
return _react.createElement.call(void 0, _react.Fragment, null, iFrame, providerComponent);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
exports.FrakConfigContext = FrakConfigContext; exports.FrakConfigProvider = FrakConfigProvider; exports.FrakIFrameClientContext = FrakIFrameClientContext; exports.FrakIFrameClientProvider = FrakIFrameClientProvider; exports.useDisplayModal = useDisplayModal; exports.useFrakClient = useFrakClient; exports.useFrakConfig = useFrakConfig; exports.useGetProductInformation = useGetProductInformation; exports.useOpenSso = useOpenSso; exports.useReferralInteraction = useReferralInteraction; exports.useSendInteraction = useSendInteraction; exports.useSendTransactionAction = useSendTransactionAction; exports.useSiweAuthenticate = useSiweAuthenticate; exports.useWalletStatus = useWalletStatus;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { PropsWithChildren, CSSProperties, ReactNode } from 'react';
|
|
3
|
+
import * as _frak_labs_core_sdk from '@frak-labs/core-sdk';
|
|
4
|
+
import { FrakWalletSdkConfig, FrakClient, WalletStatusReturnType, SendTransactionReturnType, FrakRpcError, SiweAuthenticateReturnType, DisplayModalParamsType, ModalStepTypes, SendInteractionReturnType, SendInteractionParamsType, ModalRpcStepsResultType, OpenSsoParamsType, GetProductInformationReturnType } from '@frak-labs/core-sdk';
|
|
5
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
6
|
+
import { UseMutationOptions, UseQueryOptions } from '@tanstack/react-query';
|
|
7
|
+
import { SendTransactionParams, SiweAuthenticateModalParams, ProcessReferralOptions } from '@frak-labs/core-sdk/actions';
|
|
8
|
+
import { Hex } from 'viem';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The context that will keep the Frak Wallet SDK configuration
|
|
12
|
+
* @ignore
|
|
13
|
+
*/
|
|
14
|
+
declare const FrakConfigContext: react.Context<FrakWalletSdkConfig | undefined>;
|
|
15
|
+
/**
|
|
16
|
+
* Props to instantiate the Frak Wallet SDK configuration provider
|
|
17
|
+
*
|
|
18
|
+
* @group provider
|
|
19
|
+
*/
|
|
20
|
+
type FrakConfigProviderProps = {
|
|
21
|
+
/**
|
|
22
|
+
* The wanted Frak configuration
|
|
23
|
+
* @see {@link @frak-labs/core-sdk!index.FrakWalletSdkConfig | FrakWalletSdkConfig}
|
|
24
|
+
*/
|
|
25
|
+
config: FrakWalletSdkConfig;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Simple config provider for the Frak Wallet SDK
|
|
29
|
+
*
|
|
30
|
+
* Should be wrapped within a {@link @tanstack/react-query!QueryClientProvider | `QueryClientProvider`}
|
|
31
|
+
*
|
|
32
|
+
* @group provider
|
|
33
|
+
*
|
|
34
|
+
* @param parameters
|
|
35
|
+
*/
|
|
36
|
+
declare function FrakConfigProvider(parameters: PropsWithChildren<FrakConfigProviderProps>): react.FunctionComponentElement<react.ProviderProps<FrakWalletSdkConfig | undefined>>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The context that will keep the Frak Wallet SDK client
|
|
40
|
+
* @ignore
|
|
41
|
+
*/
|
|
42
|
+
declare const FrakIFrameClientContext: react.Context<FrakClient | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Props to instantiate the Frak Wallet SDK configuration provider
|
|
45
|
+
*
|
|
46
|
+
* @group provider
|
|
47
|
+
*/
|
|
48
|
+
type FrakIFrameClientProps = {
|
|
49
|
+
config: FrakWalletSdkConfig;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* IFrame client provider for the Frak Wallet SDK
|
|
53
|
+
* It will automatically create the frak wallet iFrame (required for the wallet to communicate with the SDK securely), and provide it in the context
|
|
54
|
+
*
|
|
55
|
+
* @group provider
|
|
56
|
+
*
|
|
57
|
+
* @remarks
|
|
58
|
+
* This provider must be wrapped within a {@link FrakConfigProvider} to work properly
|
|
59
|
+
*
|
|
60
|
+
* @param args
|
|
61
|
+
* @param args.style - Some custom styles to apply to the iFrame
|
|
62
|
+
* @param args.children - Descedant components that will have access to the Frak Client
|
|
63
|
+
*/
|
|
64
|
+
declare function FrakIFrameClientProvider({ style, children, }: {
|
|
65
|
+
style?: CSSProperties;
|
|
66
|
+
children?: ReactNode;
|
|
67
|
+
}): react.FunctionComponentElement<{
|
|
68
|
+
children?: ReactNode | undefined;
|
|
69
|
+
}>;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Get the current Frak config
|
|
73
|
+
* @throws {FrakRpcError} if the config is not found (only if this hooks is used outside a FrakConfigProvider)
|
|
74
|
+
* @group hooks
|
|
75
|
+
*
|
|
76
|
+
* @see {@link @frak-labs/react-sdk!FrakConfigProvider | FrakConfigProvider} for the config provider
|
|
77
|
+
* @see {@link @frak-labs/core-sdk!index.FrakWalletSdkConfig | FrakWalletSdkConfig} for the config type
|
|
78
|
+
*/
|
|
79
|
+
declare function useFrakConfig(): _frak_labs_core_sdk.FrakWalletSdkConfig;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Get the current Frak client
|
|
83
|
+
*
|
|
84
|
+
* @group hooks
|
|
85
|
+
*/
|
|
86
|
+
declare function useFrakClient(): _frak_labs_core_sdk.FrakClient | undefined;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Hook that return a query helping to get the current wallet status.
|
|
90
|
+
*
|
|
91
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.watchWalletStatus | `watchWalletStatus()`} action
|
|
92
|
+
*
|
|
93
|
+
* @group hooks
|
|
94
|
+
*
|
|
95
|
+
* @returns
|
|
96
|
+
* The query hook wrapping the `watchWalletStatus()` action
|
|
97
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.WalletStatusReturnType | `WalletStatusReturnType`}
|
|
98
|
+
*
|
|
99
|
+
* @see {@link @frak-labs/core-sdk!actions.watchWalletStatus | `watchWalletStatus()`} for more info about the underlying action
|
|
100
|
+
* @see {@link @tanstack/react-query!useQuery | `useQuery()`} for more info about the useQuery response
|
|
101
|
+
*/
|
|
102
|
+
declare function useWalletStatus(): _tanstack_react_query.UseQueryResult<WalletStatusReturnType, Error>;
|
|
103
|
+
|
|
104
|
+
/** @ignore */
|
|
105
|
+
type MutationOptions$4 = Omit<UseMutationOptions<SendTransactionReturnType, FrakRpcError, SendTransactionParams>, "mutationFn" | "mutationKey">;
|
|
106
|
+
/** @inline */
|
|
107
|
+
interface UseSendTransactionParams {
|
|
108
|
+
/**
|
|
109
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
110
|
+
*/
|
|
111
|
+
mutations?: MutationOptions$4;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Hook that return a mutation helping to send a transaction
|
|
115
|
+
*
|
|
116
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.sendTransaction | `sendTransaction()`} action
|
|
117
|
+
*
|
|
118
|
+
* @param args
|
|
119
|
+
*
|
|
120
|
+
* @group hooks
|
|
121
|
+
*
|
|
122
|
+
* @returns
|
|
123
|
+
* The mutation hook wrapping the `sendTransaction()` action
|
|
124
|
+
* The `mutate` and `mutateAsync` argument is of type {@link @frak-labs/core-sdk!actions.SendTransactionParams | `SendTransactionParams`}
|
|
125
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.SendTransactionReturnType | `SendTransactionReturnType`}
|
|
126
|
+
*
|
|
127
|
+
* @see {@link @frak-labs/core-sdk!actions.sendTransaction | `sendTransaction()`} for more info about the underlying action
|
|
128
|
+
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
129
|
+
*/
|
|
130
|
+
declare function useSendTransactionAction({ mutations, }?: UseSendTransactionParams): _tanstack_react_query.UseMutationResult<SendTransactionReturnType, FrakRpcError<undefined>, SendTransactionParams, unknown>;
|
|
131
|
+
|
|
132
|
+
/** @inline */
|
|
133
|
+
type MutationOptions$3 = Omit<UseMutationOptions<SiweAuthenticateReturnType, FrakRpcError, SiweAuthenticateModalParams>, "mutationFn" | "mutationKey">;
|
|
134
|
+
/** @ignore */
|
|
135
|
+
interface UseSiweAuthenticateParams {
|
|
136
|
+
/**
|
|
137
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
138
|
+
*/
|
|
139
|
+
mutations?: MutationOptions$3;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Hook that return a mutation helping to send perform a SIWE authentication
|
|
143
|
+
*
|
|
144
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.sendTransaction | `sendTransaction()`} action
|
|
145
|
+
*
|
|
146
|
+
* @param args
|
|
147
|
+
*
|
|
148
|
+
* @group hooks
|
|
149
|
+
*
|
|
150
|
+
* @returns
|
|
151
|
+
* The mutation hook wrapping the `siweAuthenticate()` action
|
|
152
|
+
* The `mutate` and `mutateAsync` argument is of type {@link @frak-labs/core-sdk!actions.SiweAuthenticateModalParams | `SiweAuthenticateModalParams`}
|
|
153
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.SiweAuthenticateReturnType | `SiweAuthenticateReturnType`}
|
|
154
|
+
*
|
|
155
|
+
* @see {@link @frak-labs/core-sdk!actions.siweAuthenticate | `siweAuthenticate()`} for more info about the underlying action
|
|
156
|
+
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
157
|
+
*/
|
|
158
|
+
declare function useSiweAuthenticate({ mutations, }?: UseSiweAuthenticateParams): _tanstack_react_query.UseMutationResult<SiweAuthenticateReturnType, FrakRpcError<undefined>, SiweAuthenticateModalParams, unknown>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Helper hook to automatically submit a referral interaction when detected
|
|
162
|
+
*
|
|
163
|
+
* @group hooks
|
|
164
|
+
*
|
|
165
|
+
* @param args
|
|
166
|
+
* @param args.productId - The product id to interact with (if not specified will be recomputed from the current domain)
|
|
167
|
+
* @param args.modalConfig - The modal configuration to display if the user is not logged in
|
|
168
|
+
* @param args.options - Some options for the referral interaction
|
|
169
|
+
*
|
|
170
|
+
* @returns The resulting referral state, or a potential error
|
|
171
|
+
*
|
|
172
|
+
* @description This function will automatically handle the referral interaction process
|
|
173
|
+
*
|
|
174
|
+
* @see {@link @frak-labs/core-sdk!actions.processReferral | `processReferral()`} for more details on the automatic referral handling process
|
|
175
|
+
*/
|
|
176
|
+
declare function useReferralInteraction({ productId, modalConfig, options, }?: {
|
|
177
|
+
productId?: Hex;
|
|
178
|
+
modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
|
|
179
|
+
options?: ProcessReferralOptions;
|
|
180
|
+
}): Error | ("error" | "no-referrer" | "idle" | "processing" | "success" | "no-wallet" | "no-session" | "self-referral");
|
|
181
|
+
|
|
182
|
+
/** @ignore */
|
|
183
|
+
type MutationOptions$2 = Omit<UseMutationOptions<SendInteractionReturnType, FrakRpcError, SendInteractionParamsType>, "mutationFn" | "mutationKey">;
|
|
184
|
+
/** @inline */
|
|
185
|
+
interface UseSendInteractionParams$1 {
|
|
186
|
+
/**
|
|
187
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
188
|
+
*/
|
|
189
|
+
mutations?: MutationOptions$2;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Hook that return a mutation helping to send a user interaction
|
|
193
|
+
*
|
|
194
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.sendInteraction | `sendInteraction()`} action
|
|
195
|
+
*
|
|
196
|
+
* @param args
|
|
197
|
+
*
|
|
198
|
+
* @group hooks
|
|
199
|
+
*
|
|
200
|
+
* @returns
|
|
201
|
+
* The mutation hook wrapping the `sendInteraction()` action
|
|
202
|
+
* The `mutate` and `mutateAsync` argument is of type {@link @frak-labs/core-sdk!index.SendInteractionParamsType | `SendInteractionParamsType`}
|
|
203
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.SendInteractionReturnType | `SendInteractionReturnType`}
|
|
204
|
+
*
|
|
205
|
+
* @see {@link @frak-labs/core-sdk!actions.sendInteraction | `sendInteraction()`} for more info about the underlying action
|
|
206
|
+
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
207
|
+
*/
|
|
208
|
+
declare function useSendInteraction({ mutations, }?: UseSendInteractionParams$1): _tanstack_react_query.UseMutationResult<SendInteractionReturnType, FrakRpcError<undefined>, SendInteractionParamsType, unknown>;
|
|
209
|
+
|
|
210
|
+
/** @ignore */
|
|
211
|
+
type MutationOptions$1<T extends ModalStepTypes[]> = Omit<UseMutationOptions<ModalRpcStepsResultType<T>, FrakRpcError, DisplayModalParamsType<T>>, "mutationFn" | "mutationKey">;
|
|
212
|
+
/** @inline */
|
|
213
|
+
interface UseDisplayModalParams<T extends ModalStepTypes[] = ModalStepTypes[]> {
|
|
214
|
+
/**
|
|
215
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
216
|
+
*/
|
|
217
|
+
mutations?: MutationOptions$1<T>;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Hook that return a mutation helping to display a modal to the user
|
|
221
|
+
*
|
|
222
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.displayModal | `displayModal()`} action
|
|
223
|
+
*
|
|
224
|
+
* @param args
|
|
225
|
+
*
|
|
226
|
+
* @typeParam T
|
|
227
|
+
* The modal steps types to display (the result will correspond to the steps types asked in params)
|
|
228
|
+
* An array of {@link @frak-labs/core-sdk!index.ModalStepTypes | `ModalStepTypes`}
|
|
229
|
+
* If not provided, it will default to a generic array of `ModalStepTypes`
|
|
230
|
+
*
|
|
231
|
+
* @group hooks
|
|
232
|
+
*
|
|
233
|
+
* @returns
|
|
234
|
+
* The mutation hook wrapping the `displayModal()` action
|
|
235
|
+
* The `mutate` and `mutateAsync` argument is of type {@link @frak-labs/core-sdk!index.DisplayModalParamsType | `DisplayModalParamsType<T>`}, with type params `T` being the modal steps types to display
|
|
236
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.ModalRpcStepsResultType | `ModalRpcStepsResultType`}
|
|
237
|
+
*
|
|
238
|
+
* @see {@link @frak-labs/core-sdk!actions.displayModal | `displayModal()`} for more info about the underlying action
|
|
239
|
+
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
240
|
+
*/
|
|
241
|
+
declare function useDisplayModal<T extends ModalStepTypes[] = ModalStepTypes[]>({ mutations, }?: UseDisplayModalParams<T>): _tanstack_react_query.UseMutationResult<ModalRpcStepsResultType<T>, FrakRpcError<undefined>, DisplayModalParamsType<T>, unknown>;
|
|
242
|
+
|
|
243
|
+
/** @ignore */
|
|
244
|
+
type MutationOptions = Omit<UseMutationOptions<void, FrakRpcError, OpenSsoParamsType>, "mutationFn" | "mutationKey">;
|
|
245
|
+
/** @inline */
|
|
246
|
+
interface UseSendInteractionParams {
|
|
247
|
+
/**
|
|
248
|
+
* Optional mutation options, see {@link @tanstack/react-query!useMutation | `useMutation()`} for more infos
|
|
249
|
+
*/
|
|
250
|
+
mutations?: MutationOptions;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Hook that return a mutation helping to open the SSO page
|
|
254
|
+
*
|
|
255
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} action
|
|
256
|
+
*
|
|
257
|
+
* @param args
|
|
258
|
+
*
|
|
259
|
+
* @group hooks
|
|
260
|
+
*
|
|
261
|
+
* @returns
|
|
262
|
+
* The mutation hook wrapping the `openSso()` action
|
|
263
|
+
* The `mutate` and `mutateAsync` argument is of type {@link @frak-labs/core-sdk!index.OpenSsoParamsType | `OpenSsoParamsType`}
|
|
264
|
+
* The mutation doesn't output any value
|
|
265
|
+
*
|
|
266
|
+
* @see {@link @frak-labs/core-sdk!actions.openSso | `openSso()`} for more info about the underlying action
|
|
267
|
+
* @see {@link @tanstack/react-query!useMutation | `useMutation()`} for more info about the mutation options and response
|
|
268
|
+
*/
|
|
269
|
+
declare function useOpenSso({ mutations }?: UseSendInteractionParams): _tanstack_react_query.UseMutationResult<void, FrakRpcError<undefined>, OpenSsoParamsType, unknown>;
|
|
270
|
+
|
|
271
|
+
/** @ignore */
|
|
272
|
+
type QueryOptions = Omit<UseQueryOptions<GetProductInformationReturnType, FrakRpcError, undefined>, "queryKey" | "queryFn">;
|
|
273
|
+
/** @inline */
|
|
274
|
+
interface UseGetProductInformationParams {
|
|
275
|
+
/**
|
|
276
|
+
* Optional query options, see {@link @tanstack/react-query!useQuery | `useQuery()`} for more infos
|
|
277
|
+
*/
|
|
278
|
+
query?: QueryOptions;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Hook that return a query helping to get the current product information
|
|
282
|
+
*
|
|
283
|
+
* It's a {@link @tanstack/react-query!home | `tanstack`} wrapper around the {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} action
|
|
284
|
+
*
|
|
285
|
+
* @param args
|
|
286
|
+
*
|
|
287
|
+
* @group hooks
|
|
288
|
+
*
|
|
289
|
+
* @returns
|
|
290
|
+
* The query hook wrapping the `getProductInformation()` action
|
|
291
|
+
* The `data` result is a {@link @frak-labs/core-sdk!index.GetProductInformationReturnType | `GetProductInformationReturnType`}
|
|
292
|
+
*
|
|
293
|
+
* @see {@link @frak-labs/core-sdk!actions.getProductInformation | `getProductInformation()`} for more info about the underlying action
|
|
294
|
+
* @see {@link @tanstack/react-query!useQuery | `useQuery()`} for more info about the useQuery options and response
|
|
295
|
+
*/
|
|
296
|
+
declare function useGetProductInformation({ query, }?: UseGetProductInformationParams): _tanstack_react_query.UseQueryResult<undefined, FrakRpcError<undefined>>;
|
|
297
|
+
|
|
298
|
+
export { FrakConfigContext, FrakConfigProvider, type FrakConfigProviderProps, FrakIFrameClientContext, type FrakIFrameClientProps, FrakIFrameClientProvider, useDisplayModal, useFrakClient, useFrakConfig, useGetProductInformation, useOpenSso, useReferralInteraction, useSendInteraction, useSendTransactionAction, useSiweAuthenticate, useWalletStatus };
|