@frak-labs/react-sdk 0.0.6 → 0.0.8

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/index.js CHANGED
@@ -1,389 +1 @@
1
- // src/provider/FrakConfigProvider.ts
2
- import { createContext, createElement } from "react";
3
- var FrakConfigContext = createContext(
4
- void 0
5
- );
6
- function FrakConfigProvider(parameters) {
7
- const { children, config } = parameters;
8
- return createElement(
9
- FrakConfigContext.Provider,
10
- {
11
- value: {
12
- ...config,
13
- walletUrl: config.walletUrl ?? "https://wallet.frak.id",
14
- domain: config.domain ?? (typeof window !== "undefined" ? window?.location?.host : void 0) ?? "not-found"
15
- }
16
- },
17
- children
18
- );
19
- }
20
-
21
- // src/provider/FrakIFrameClientProvider.ts
22
- import {
23
- baseIframeProps,
24
- createIFrameFrakClient
25
- } from "@frak-labs/core-sdk";
26
- import {
27
- Fragment,
28
- createContext as createContext2,
29
- createElement as createElement2,
30
- useState as useState3
31
- } from "react";
32
-
33
- // src/hook/useFrakConfig.ts
34
- import { FrakRpcError, RpcErrorCodes } from "@frak-labs/core-sdk";
35
- import { useContext } from "react";
36
- function useFrakConfig() {
37
- const config = useContext(FrakConfigContext);
38
- if (!config) {
39
- throw new FrakRpcError(
40
- RpcErrorCodes.configError,
41
- "Frak config not found"
42
- );
43
- }
44
- return config;
45
- }
46
-
47
- // src/hook/useFrakClient.ts
48
- import { useContext as useContext2 } from "react";
49
- function useFrakClient() {
50
- return useContext2(FrakIFrameClientContext);
51
- }
52
-
53
- // src/hook/useWalletStatus.ts
54
- import {
55
- ClientNotFound
56
- } from "@frak-labs/core-sdk";
57
- import { watchWalletStatus } from "@frak-labs/core-sdk/actions";
58
- import { useQuery, useQueryClient } from "@tanstack/react-query";
59
- import { useCallback } from "react";
60
- function useWalletStatus() {
61
- const queryClient = useQueryClient();
62
- const client = useFrakClient();
63
- const newStatusUpdated = useCallback(
64
- (event) => {
65
- queryClient.setQueryData(
66
- ["frak-sdk", "wallet-status-listener"],
67
- event
68
- );
69
- },
70
- [queryClient]
71
- );
72
- return useQuery({
73
- gcTime: 0,
74
- staleTime: 0,
75
- queryKey: ["frak-sdk", "wallet-status-listener"],
76
- queryFn: async () => {
77
- if (!client) {
78
- throw new ClientNotFound();
79
- }
80
- return watchWalletStatus(client, newStatusUpdated);
81
- },
82
- enabled: !!client
83
- });
84
- }
85
-
86
- // src/hook/useSendTransaction.ts
87
- import {
88
- ClientNotFound as ClientNotFound2
89
- } from "@frak-labs/core-sdk";
90
- import {
91
- sendTransaction
92
- } from "@frak-labs/core-sdk/actions";
93
- import { useMutation } from "@tanstack/react-query";
94
- function useSendTransactionAction({
95
- mutations
96
- } = {}) {
97
- const client = useFrakClient();
98
- return useMutation({
99
- ...mutations,
100
- mutationKey: ["frak-sdk", "send-transaction"],
101
- mutationFn: async (params) => {
102
- if (!client) {
103
- throw new ClientNotFound2();
104
- }
105
- return sendTransaction(client, params);
106
- }
107
- });
108
- }
109
-
110
- // src/hook/useSiweAuthenticate.ts
111
- import {
112
- ClientNotFound as ClientNotFound3
113
- } from "@frak-labs/core-sdk";
114
- import {
115
- siweAuthenticate
116
- } from "@frak-labs/core-sdk/actions";
117
- import { useMutation as useMutation2 } from "@tanstack/react-query";
118
- function useSiweAuthenticate({
119
- mutations
120
- } = {}) {
121
- const client = useFrakClient();
122
- return useMutation2({
123
- ...mutations,
124
- mutationKey: [
125
- "frak-sdk",
126
- "siwe-authenticate",
127
- client?.config.domain ?? "no-domain"
128
- ],
129
- mutationFn: async (params) => {
130
- if (!client) {
131
- throw new ClientNotFound3();
132
- }
133
- return siweAuthenticate(client, params);
134
- }
135
- });
136
- }
137
-
138
- // src/hook/helper/useReferralInteraction.ts
139
- import {
140
- ClientNotFound as ClientNotFound4
141
- } from "@frak-labs/core-sdk";
142
- import {
143
- processReferral
144
- } from "@frak-labs/core-sdk/actions";
145
- import { useQuery as useQuery2 } from "@tanstack/react-query";
146
- import { useMemo as useMemo3 } from "react";
147
-
148
- // src/hook/utils/useFrakContext.ts
149
- import { FrakContextManager } from "@frak-labs/core-sdk";
150
- import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
151
-
152
- // src/hook/utils/useWindowLocation.ts
153
- import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
154
-
155
- // src/hook/utils/useMounted.ts
156
- import { useEffect, useState } from "react";
157
- function useMounted() {
158
- const [mounted, setMounted] = useState(false);
159
- useEffect(() => {
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] = useState2(
169
- isMounted ? window.location : void 0
170
- );
171
- useEffect2(() => {
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 = useMemo(() => location?.href, [location?.href]);
185
- return { location, href };
186
- }
187
-
188
- // src/hook/utils/useFrakContext.ts
189
- function useFrakContext() {
190
- const { location } = useWindowLocation();
191
- const frakContext = useMemo2(() => {
192
- if (!location?.href) return null;
193
- return FrakContextManager.parse({ url: location.href });
194
- }, [location?.href]);
195
- const updateContext = useCallback2(
196
- (newContext) => {
197
- console.log("Updating context", { newContext });
198
- FrakContextManager.replaceUrl({
199
- url: location?.href,
200
- context: newContext
201
- });
202
- },
203
- [location?.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
- } = useQuery2({
225
- gcTime: 0,
226
- staleTime: 0,
227
- queryKey: [
228
- "frak-sdk",
229
- "auto-referral-interaction",
230
- frakContext?.r ?? "no-referrer",
231
- walletStatus?.key ?? "no-wallet-status",
232
- productId ?? "no-product-id"
233
- ],
234
- queryFn: () => {
235
- if (!client) {
236
- throw new ClientNotFound4();
237
- }
238
- return processReferral(client, {
239
- walletStatus,
240
- frakContext,
241
- modalConfig,
242
- productId,
243
- options
244
- });
245
- },
246
- enabled: !!walletStatus
247
- });
248
- return useMemo3(() => {
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
- import {
257
- ClientNotFound as ClientNotFound5
258
- } from "@frak-labs/core-sdk";
259
- import { sendInteraction } from "@frak-labs/core-sdk/actions";
260
- import { useMutation as useMutation3 } from "@tanstack/react-query";
261
- function useSendInteraction({
262
- mutations
263
- } = {}) {
264
- const client = useFrakClient();
265
- return useMutation3({
266
- ...mutations,
267
- mutationKey: ["frak-sdk", "send-interaction"],
268
- mutationFn: async (params) => {
269
- if (!client) {
270
- throw new ClientNotFound5();
271
- }
272
- return sendInteraction(client, params);
273
- }
274
- });
275
- }
276
-
277
- // src/hook/useDisplayModal.ts
278
- import {
279
- ClientNotFound as ClientNotFound6
280
- } from "@frak-labs/core-sdk";
281
- import { displayModal } from "@frak-labs/core-sdk/actions";
282
- import { useMutation as useMutation4 } from "@tanstack/react-query";
283
- function useDisplayModal({
284
- mutations
285
- } = {}) {
286
- const client = useFrakClient();
287
- return useMutation4({
288
- ...mutations,
289
- mutationKey: ["frak-sdk", "display-modal"],
290
- mutationFn: async (args) => {
291
- if (!client) {
292
- throw new ClientNotFound6();
293
- }
294
- return displayModal(client, args);
295
- }
296
- });
297
- }
298
-
299
- // src/hook/useOpenSso.ts
300
- import {
301
- ClientNotFound as ClientNotFound7
302
- } from "@frak-labs/core-sdk";
303
- import { openSso } from "@frak-labs/core-sdk/actions";
304
- import { useMutation as useMutation5 } from "@tanstack/react-query";
305
- function useOpenSso({ mutations } = {}) {
306
- const client = useFrakClient();
307
- return useMutation5({
308
- ...mutations,
309
- mutationKey: ["frak-sdk", "open-sso"],
310
- mutationFn: async (params) => {
311
- if (!client) {
312
- throw new ClientNotFound7();
313
- }
314
- return openSso(client, params);
315
- }
316
- });
317
- }
318
-
319
- // src/hook/useGetProductInformation.ts
320
- import {
321
- ClientNotFound as ClientNotFound8
322
- } from "@frak-labs/core-sdk";
323
- import { getProductInformation } from "@frak-labs/core-sdk/actions";
324
- import { useQuery as useQuery3 } from "@tanstack/react-query";
325
- function useGetProductInformation({
326
- query
327
- } = {}) {
328
- const client = useFrakClient();
329
- return useQuery3({
330
- ...query,
331
- queryKey: ["frak-sdk", "get-product-information"],
332
- queryFn: async () => {
333
- if (!client) {
334
- throw new ClientNotFound8();
335
- }
336
- return getProductInformation(client);
337
- }
338
- });
339
- }
340
-
341
- // src/provider/FrakIFrameClientProvider.ts
342
- var FrakIFrameClientContext = createContext2(
343
- void 0
344
- );
345
- function FrakIFrameClientProvider({
346
- style,
347
- children
348
- }) {
349
- const config = useFrakConfig();
350
- const [client, setClient] = useState3(void 0);
351
- const iFrame = createElement2("iframe", {
352
- ...baseIframeProps,
353
- src: `${config.walletUrl}/listener`,
354
- style: style ?? baseIframeProps.style,
355
- ref: (iframe) => {
356
- if (!iframe || client) {
357
- return;
358
- }
359
- setClient(
360
- createIFrameFrakClient({
361
- iframe,
362
- config
363
- })
364
- );
365
- }
366
- });
367
- const providerComponent = createElement2(
368
- FrakIFrameClientContext.Provider,
369
- { value: client },
370
- children
371
- );
372
- return createElement2(Fragment, null, iFrame, providerComponent);
373
- }
374
- export {
375
- FrakConfigContext,
376
- FrakConfigProvider,
377
- FrakIFrameClientContext,
378
- FrakIFrameClientProvider,
379
- useDisplayModal,
380
- useFrakClient,
381
- useFrakConfig,
382
- useGetProductInformation,
383
- useOpenSso,
384
- useReferralInteraction,
385
- useSendInteraction,
386
- useSendTransactionAction,
387
- useSiweAuthenticate,
388
- useWalletStatus
389
- };
1
+ import*as e from"react";import*as t from"@frak-labs/core-sdk";import*as n from"@frak-labs/core-sdk/actions";import*as r from"@tanstack/react-query";let o=(0,e.createContext)(void 0);function a(t){let{children:n,config:r}=t;return(0,e.createElement)(o.Provider,{value:{...r,walletUrl:r.walletUrl??"https://wallet.frak.id",domain:r.domain??("undefined"!=typeof window?window?.location?.host:void 0)??"not-found"}},n)}function u(){let n=(0,e.useContext)(o);if(!n)throw new t.FrakRpcError(t.RpcErrorCodes.configError,"Frak config not found");return n}let i=(0,e.createContext)(void 0);function s({style:n,children:r}){let o=u(),[a,s]=(0,e.useState)(void 0),l=(0,e.createElement)("iframe",{...t.baseIframeProps,src:`${o.walletUrl}/listener`,style:n??t.baseIframeProps.style,ref:e=>{e&&!a&&s((0,t.createIFrameFrakClient)({iframe:e,config:o}))}}),f=(0,e.createElement)(i.Provider,{value:a},r);return(0,e.createElement)(e.Fragment,null,l,f)}function l(){return(0,e.useContext)(i)}function f({mutations:e}={}){let o=l();return(0,r.useMutation)({...e,mutationKey:["frak-sdk","display-modal"],mutationFn:async e=>{if(!o)throw new t.ClientNotFound;return(0,n.displayModal)(o,e)}})}function c({mutations:e}={}){let o=l();return(0,r.useMutation)({...e,mutationKey:["frak-sdk","send-transaction"],mutationFn:async e=>{if(!o)throw new t.ClientNotFound;return(0,n.sendTransaction)(o,e)}})}function d(){let o=(0,r.useQueryClient)(),a=l(),u=(0,e.useCallback)(e=>{o.setQueryData(["frak-sdk","wallet-status-listener"],e)},[o]);return(0,r.useQuery)({gcTime:0,staleTime:0,queryKey:["frak-sdk","wallet-status-listener"],queryFn:async()=>{if(!a)throw new t.ClientNotFound;return(0,n.watchWalletStatus)(a,u)},enabled:!!a})}function m({productId:o,modalConfig:a,options:u}={}){let i=l(),{frakContext:s}=function(){let{location:n}=function(){let t=function(){let[t,n]=(0,e.useState)(!1);return(0,e.useEffect)(()=>{n(!0)},[]),t}(),[n,r]=(0,e.useState)(t?window.location:void 0);(0,e.useEffect)(()=>{if(t)return n||e(),window.addEventListener("popstate",e),()=>{window.removeEventListener("popstate",e)};function e(){r(window.location)}},[t,n]);let o=(0,e.useMemo)(()=>n?.href,[n?.href]);return{location:n,href:o}}();return{frakContext:(0,e.useMemo)(()=>n?.href?t.FrakContextManager.parse({url:n.href}):null,[n?.href]),updateContext:(0,e.useCallback)(e=>{console.log("Updating context",{newContext:e}),t.FrakContextManager.replaceUrl({url:n?.href,context:e})},[n?.href])}}(),{data:f}=d(),{data:c,error:w,status:k}=(0,r.useQuery)({gcTime:0,staleTime:0,queryKey:["frak-sdk","auto-referral-interaction",s?.r??"no-referrer",f?.key??"no-wallet-status",o??"no-product-id"],queryFn:()=>{if(!i)throw new t.ClientNotFound;return(0,n.processReferral)(i,{walletStatus:f,frakContext:s,modalConfig:a,productId:o,options:u})},enabled:!!f});return(0,e.useMemo)(()=>"pending"===k?"processing":"error"===k?w:c||"idle",[c,k,w])}function w({query:e}={}){let o=l();return(0,r.useQuery)({...e,queryKey:["frak-sdk","get-product-information"],queryFn:async()=>{if(!o)throw new t.ClientNotFound;return(0,n.getProductInformation)(o)}})}function k({mutations:e}={}){let o=l();return(0,r.useMutation)({...e,mutationKey:["frak-sdk","siwe-authenticate",o?.config.domain??"no-domain"],mutationFn:async e=>{if(!o)throw new t.ClientNotFound;return(0,n.siweAuthenticate)(o,e)}})}function y({mutations:e}={}){let o=l();return(0,r.useMutation)({...e,mutationKey:["frak-sdk","open-sso"],mutationFn:async e=>{if(!o)throw new t.ClientNotFound;return(0,n.openSso)(o,e)}})}function F({mutations:e}={}){let o=l();return(0,r.useMutation)({...e,mutationKey:["frak-sdk","send-interaction"],mutationFn:async e=>{if(!o)throw new t.ClientNotFound;return(0,n.sendInteraction)(o,e)}})}export{o as FrakConfigContext,a as FrakConfigProvider,i as FrakIFrameClientContext,s as FrakIFrameClientProvider,f as useDisplayModal,l as useFrakClient,u as useFrakConfig,w as useGetProductInformation,y as useOpenSso,m as useReferralInteraction,F as useSendInteraction,c as useSendTransactionAction,k as useSiweAuthenticate,d as useWalletStatus};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.6",
14
+ "version": "0.0.8",
15
15
  "description": "React SDK of the Frak wallet, low level library to interact directly with the frak ecosystem.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -54,15 +54,15 @@
54
54
  "format:check": "biome check .",
55
55
  "format": "biome check --write .",
56
56
  "clean": "rimraf dist",
57
- "build": "tsup && bun run check-exports",
58
- "build:watch": "tsup --watch",
57
+ "build": "rslib build && bun run check-exports",
58
+ "build:watch": "rslib build --watch",
59
59
  "check-exports": "attw --pack .",
60
60
  "typecheck": "tsc --noEmit",
61
61
  "prepublish": "bun run lint && bun run build",
62
- "publish": "bun publish"
62
+ "publish": "echo 'Publishing react...'"
63
63
  },
64
64
  "dependencies": {
65
- "@frak-labs/core-sdk": "0.0.6"
65
+ "@frak-labs/core-sdk": "0.0.7"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "viem": "^2.x",
@@ -71,10 +71,10 @@
71
71
  },
72
72
  "devDependencies": {
73
73
  "@arethetypeswrong/cli": "^0.17.3",
74
+ "@microsoft/api-extractor": "^7.50.1",
75
+ "@rsbuild/plugin-react": "^1.1.1",
76
+ "@rslib/core": "^0.5.2",
74
77
  "@types/node": "^22",
75
- "browserslist": "^4.24.4",
76
- "browserslist-to-esbuild": "^2.1.1",
77
- "tsup": "^8.3.6",
78
78
  "typescript": "^5"
79
79
  },
80
80
  "browserslist": [