@frak-labs/nexus-sdk 0.0.9 → 0.0.10

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.
Files changed (39) hide show
  1. package/dist/chunk-3T2FNW6E.cjs +100 -0
  2. package/dist/chunk-72IEHEQX.js +48 -0
  3. package/dist/chunk-BPFJZRJ6.cjs +152 -0
  4. package/dist/chunk-ETV4XYOV.cjs +7 -0
  5. package/dist/{chunk-SZUN32YC.js → chunk-HOX3RRO6.js} +58 -30
  6. package/dist/chunk-NIFJZD3M.cjs +48 -0
  7. package/dist/chunk-PKBMQBKP.js +7 -0
  8. package/dist/{chunk-AYZHGMEV.cjs → chunk-SGLR6RFA.cjs} +59 -31
  9. package/dist/chunk-T54VMWHQ.js +100 -0
  10. package/dist/chunk-TPC5PMRC.js +152 -0
  11. package/dist/{client-BwzXSgqQ.d.ts → client--U_6SK0l.d.cts} +91 -30
  12. package/dist/{client-BwzXSgqQ.d.cts → client-6_BJp7Ub.d.ts} +91 -30
  13. package/dist/core/actions/index.cjs +8 -3
  14. package/dist/core/actions/index.d.cts +25 -13
  15. package/dist/core/actions/index.d.ts +25 -13
  16. package/dist/core/actions/index.js +9 -4
  17. package/dist/core/index.cjs +4 -7
  18. package/dist/core/index.d.cts +8 -35
  19. package/dist/core/index.d.ts +8 -35
  20. package/dist/core/index.js +9 -12
  21. package/dist/core/interactions/index.cjs +9 -0
  22. package/dist/core/interactions/index.d.cts +39 -0
  23. package/dist/core/interactions/index.d.ts +39 -0
  24. package/dist/core/interactions/index.js +9 -0
  25. package/dist/error-C4Zm5nQe.d.cts +27 -0
  26. package/dist/error-C4Zm5nQe.d.ts +27 -0
  27. package/dist/interaction-D_CzyqRE.d.cts +22 -0
  28. package/dist/interaction-D_CzyqRE.d.ts +22 -0
  29. package/dist/react/index.cjs +234 -109
  30. package/dist/react/index.d.cts +69 -19
  31. package/dist/react/index.d.ts +69 -19
  32. package/dist/react/index.js +236 -111
  33. package/dist/{watchUnlockStatus-WJxoDliF.d.ts → watchUnlockStatus-CxnibdQx.d.cts} +3 -3
  34. package/dist/{watchUnlockStatus-DXClCYH9.d.cts → watchUnlockStatus-g8wIxpeM.d.ts} +3 -3
  35. package/package.json +11 -5
  36. package/dist/chunk-PDR3CF3P.js +0 -86
  37. package/dist/chunk-VK7GPKK4.js +0 -169
  38. package/dist/chunk-X4JNNWJ4.cjs +0 -86
  39. package/dist/chunk-ZOLP2FJZ.cjs +0 -169
@@ -1,10 +1,15 @@
1
1
  import * as react from 'react';
2
- import { PropsWithChildren, ReactNode } from 'react';
3
- import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType, e as SetUserReferredParams, c as SetUserReferredReturnType } from '../client-BwzXSgqQ.js';
2
+ import { PropsWithChildren, CSSProperties, ReactNode } from 'react';
3
+ import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType, e as SendTransactionTxType, d as SendTransactionReturnType, c as SendTransactionActionParamsType, h as SiweAuthenticationParams, f as SiweAuthenticateReturnType, g as SiweAuthenticateActionParamsType } from '../client-6_BJp7Ub.js';
4
4
  import * as _tanstack_react_query from '@tanstack/react-query';
5
- import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-WJxoDliF.js';
6
- import 'viem';
5
+ import { UseMutationOptions } from '@tanstack/react-query';
6
+ import * as viem from 'viem';
7
+ import { Hex } from 'viem';
8
+ import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-g8wIxpeM.js';
9
+ import { F as FrakRpcError } from '../error-C4Zm5nQe.js';
10
+ import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-D_CzyqRE.js';
7
11
  import 'viem/chains';
12
+ import 'viem/siwe';
8
13
 
9
14
  /**
10
15
  * The context that will keep the Nexus Wallet SDK configuration
@@ -14,12 +19,15 @@ declare const NexusConfigContext: react.Context<Readonly<{
14
19
  metadata: {
15
20
  name: string;
16
21
  };
22
+ domain: string;
17
23
  }> | undefined>;
18
24
  /**
19
25
  * Props to instantiate the Nexus Wallet SDK configuration provider
20
26
  */
21
27
  type NexusConfigProviderProps = {
22
- config: NexusWalletSdkConfig;
28
+ config: Omit<NexusWalletSdkConfig, "domain"> & {
29
+ domain?: string;
30
+ };
23
31
  };
24
32
  /**
25
33
  * Simple config provider for the Nexus Wallet SDK
@@ -31,6 +39,7 @@ declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigPr
31
39
  metadata: {
32
40
  name: string;
33
41
  };
42
+ domain: string;
34
43
  }> | undefined>>;
35
44
 
36
45
  /**
@@ -49,10 +58,11 @@ type NexusIFrameClientProps = {
49
58
  * @param parameters
50
59
  * @constructor
51
60
  */
52
- declare function NexusIFrameClientProvider({ children, }: {
61
+ declare function NexusIFrameClientProvider({ style, children, }: {
62
+ style?: CSSProperties;
53
63
  children?: ReactNode;
54
64
  }): react.FunctionComponentElement<{
55
- children?: ReactNode;
65
+ children?: ReactNode | undefined;
56
66
  }>;
57
67
 
58
68
  /**
@@ -63,25 +73,26 @@ declare function useNexusConfig(): Readonly<{
63
73
  metadata: {
64
74
  name: string;
65
75
  };
76
+ domain: string;
66
77
  }>;
67
78
 
68
79
  /**
69
80
  * Use the current nexus iframe client
70
81
  */
71
- declare function useNexusClient(): NexusClient;
82
+ declare function useNexusClient(): NexusClient | undefined;
72
83
 
73
84
  /**
74
85
  * Hook used to get the unlock options for an article
75
86
  */
76
87
  declare function useArticleUnlockOptions({ articleId, contentId, }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
77
- frkBalanceAsHex?: `0x${string}` | undefined;
88
+ frkBalanceAsHex?: viem.Hex;
78
89
  prices: {
79
90
  index: number;
80
91
  unlockDurationInSec: number;
81
- frkAmount: `0x${string}`;
92
+ frkAmount: viem.Hex;
82
93
  isUserAccessible: boolean | null;
83
94
  }[];
84
- }>, Error>;
95
+ }> | undefined, Error>;
85
96
 
86
97
  type WalletStatusQueryReturnType = WalletStatusReturnType | {
87
98
  key: "waiting-response";
@@ -100,14 +111,53 @@ type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
100
111
  */
101
112
  declare function useArticleUnlockStatus({ articleId, contentId, }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
102
113
 
103
- type SetUserReferredQueryReturnType = SetUserReferredReturnType | {
104
- key: "waiting-response";
105
- } | {
106
- key: "no-referrer";
107
- };
114
+ type MutationOptions$2 = Omit<UseMutationOptions<SendTransactionReturnType, FrakRpcError, SendTransactionActionParamsType>, "mutationFn" | "mutationKey">;
115
+ interface UseSendTransactionParams {
116
+ mutations?: MutationOptions$2;
117
+ }
118
+ /**
119
+ * Trigger a dashboard action to the wallet
120
+ */
121
+ declare function useSendTransactionAction({ mutations, }?: UseSendTransactionParams): _tanstack_react_query.UseMutationResult<Readonly<{
122
+ hash: viem.Hex;
123
+ }>, FrakRpcError<undefined>, Readonly<{
124
+ tx: SendTransactionTxType | SendTransactionTxType[];
125
+ context?: string;
126
+ }>, unknown>;
127
+
128
+ type MutationOptions$1 = Omit<UseMutationOptions<SiweAuthenticateReturnType, FrakRpcError, SiweAuthenticateActionParamsType>, "mutationFn" | "mutationKey">;
129
+ interface UseSiweAuthenticateParams {
130
+ mutations?: MutationOptions$1;
131
+ }
132
+ /**
133
+ * Trigger a dashboard action to the wallet
134
+ */
135
+ declare function useSiweAuthenticate({ mutations, }?: UseSiweAuthenticateParams): _tanstack_react_query.UseMutationResult<Readonly<{
136
+ signature: viem.Hex;
137
+ message: string;
138
+ }>, FrakRpcError<undefined>, Readonly<{
139
+ siwe?: Partial<SiweAuthenticationParams>;
140
+ context?: string;
141
+ }>, unknown>;
142
+
143
+ /**
144
+ * Helper hook to automatically submit a press referral interaction when detected
145
+ * -> And automatically set the referral context in the url
146
+ * @param contentId
147
+ */
148
+ declare function usePressReferralInteraction({ contentId }: {
149
+ contentId: Hex;
150
+ }): "error" | "loading" | "no-referral" | "referred" | "no-wallet" | "no-session";
151
+
152
+ type MutationOptions = Omit<UseMutationOptions<SendInteractionReturnType, FrakRpcError, SendInteractionParamsType>, "mutationFn" | "mutationKey">;
153
+ interface UseSendInteractionParams {
154
+ mutations?: MutationOptions;
155
+ }
108
156
  /**
109
- * Use the current nexus referral
157
+ * Send a user interaction
110
158
  */
111
- declare function useNexusReferral({ contentId }: SetUserReferredParams): _tanstack_react_query.UseQueryResult<SetUserReferredQueryReturnType, Error>;
159
+ declare function useSendInteraction({ mutations, }?: UseSendInteractionParams): _tanstack_react_query.UseMutationResult<Readonly<{
160
+ hash: viem.Hex;
161
+ }>, FrakRpcError<undefined>, SendInteractionParamsType, unknown>;
112
162
 
113
- export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, useNexusReferral, useWalletStatus };
163
+ export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, usePressReferralInteraction, useSendInteraction, useSendTransactionAction, useSiweAuthenticate, useWalletStatus };
@@ -1,13 +1,25 @@
1
1
  import {
2
2
  createIFrameNexusClient
3
- } from "../chunk-SZUN32YC.js";
3
+ } from "../chunk-HOX3RRO6.js";
4
4
  import {
5
5
  getArticleUnlockOptions,
6
- setUserReferred,
6
+ sendInteraction,
7
+ sendTransaction,
8
+ siweAuthenticate,
7
9
  watchUnlockStatus,
8
10
  watchWalletStatus
9
- } from "../chunk-PDR3CF3P.js";
10
- import "../chunk-VK7GPKK4.js";
11
+ } from "../chunk-T54VMWHQ.js";
12
+ import {
13
+ ClientNotFound,
14
+ FrakRpcError,
15
+ RpcErrorCodes,
16
+ compressJson,
17
+ decompressJson
18
+ } from "../chunk-TPC5PMRC.js";
19
+ import {
20
+ PressInteractionEncoder
21
+ } from "../chunk-72IEHEQX.js";
22
+ import "../chunk-PKBMQBKP.js";
11
23
 
12
24
  // src/react/provider/NexusConfigProvider.ts
13
25
  import { createContext, createElement } from "react";
@@ -16,7 +28,12 @@ function NexusConfigProvider(parameters) {
16
28
  const { children, config } = parameters;
17
29
  return createElement(
18
30
  NexusConfigContext.Provider,
19
- { value: config },
31
+ {
32
+ value: {
33
+ ...config,
34
+ domain: config.domain ?? (typeof window !== "undefined" ? window?.location?.host : void 0) ?? "not-found"
35
+ }
36
+ },
20
37
  children
21
38
  );
22
39
  }
@@ -26,8 +43,7 @@ import {
26
43
  Fragment,
27
44
  createContext as createContext2,
28
45
  createElement as createElement2,
29
- useMemo,
30
- useState as useState4
46
+ useState as useState3
31
47
  } from "react";
32
48
 
33
49
  // src/react/hook/useNexusConfig.ts
@@ -35,7 +51,10 @@ import { useContext } from "react";
35
51
  function useNexusConfig() {
36
52
  const config = useContext(NexusConfigContext);
37
53
  if (!config) {
38
- throw new Error("NexusConfigProvider is not found");
54
+ throw new FrakRpcError(
55
+ RpcErrorCodes.configError,
56
+ "Nexus config not found"
57
+ );
39
58
  }
40
59
  return config;
41
60
  }
@@ -43,11 +62,7 @@ function useNexusConfig() {
43
62
  // src/react/hook/useNexusClient.ts
44
63
  import { useContext as useContext2 } from "react";
45
64
  function useNexusClient() {
46
- const client = useContext2(NexusIFrameClientContext);
47
- if (!client) {
48
- throw new Error("NexusIFrameClientProvider is not found");
49
- }
50
- return client;
65
+ return useContext2(NexusIFrameClientContext);
51
66
  }
52
67
 
53
68
  // src/react/hook/useArticleUnlockOptions.ts
@@ -58,8 +73,13 @@ function useArticleUnlockOptions({
58
73
  }) {
59
74
  const client = useNexusClient();
60
75
  return useQuery({
61
- queryKey: ["articleUnlockOptions", articleId ?? "no-article-id"],
76
+ queryKey: [
77
+ "nexus-sdk",
78
+ "article-unlock-options",
79
+ articleId ?? "no-article-id"
80
+ ],
62
81
  queryFn: async () => {
82
+ if (!client) return;
63
83
  if (!(articleId && contentId)) {
64
84
  throw new Error("No article id provided");
65
85
  }
@@ -68,7 +88,7 @@ function useArticleUnlockOptions({
68
88
  contentId
69
89
  });
70
90
  },
71
- enabled: !!articleId && !!contentId,
91
+ enabled: !!client && !!articleId && !!contentId,
72
92
  gcTime: 0
73
93
  });
74
94
  }
@@ -81,17 +101,24 @@ function useWalletStatus() {
81
101
  const client = useNexusClient();
82
102
  const newStatusUpdated = useCallback(
83
103
  (event) => {
84
- queryClient.setQueryData(["walletStatusListener"], event);
104
+ queryClient.setQueryData(
105
+ ["nexus-sdk", "wallet-status-listener"],
106
+ event
107
+ );
85
108
  },
86
109
  [queryClient]
87
110
  );
88
111
  return useQuery2({
89
112
  gcTime: 0,
90
- queryKey: ["walletStatusListener"],
113
+ queryKey: ["nexus-sdk", "wallet-status-listener"],
91
114
  queryFn: async () => {
115
+ if (!client) {
116
+ return { key: "waiting-response" };
117
+ }
92
118
  await watchWalletStatus(client, newStatusUpdated);
93
119
  return { key: "waiting-response" };
94
- }
120
+ },
121
+ enabled: !!client
95
122
  });
96
123
  }
97
124
 
@@ -108,7 +135,8 @@ function useArticleUnlockStatus({
108
135
  (event) => {
109
136
  queryClient.setQueryData(
110
137
  [
111
- "articleUnlockStatusListener",
138
+ "nexus-sdk",
139
+ "article-unlock-status",
112
140
  articleId ?? "no-article-id",
113
141
  contentId ?? "no-contentId-id"
114
142
  ],
@@ -119,12 +147,19 @@ function useArticleUnlockStatus({
119
147
  );
120
148
  return useQuery3({
121
149
  queryKey: [
122
- "articleUnlockStatusListener",
150
+ "nexus-sdk",
151
+ "article-unlock-status",
123
152
  articleId ?? "no-article-id",
124
153
  contentId ?? "no-contentId-id"
125
154
  ],
126
155
  gcTime: 0,
127
156
  queryFn: async () => {
157
+ if (!client) {
158
+ return {
159
+ status: "waiting-response",
160
+ key: "waiting-response"
161
+ };
162
+ }
128
163
  if (!(articleId && contentId)) {
129
164
  return null;
130
165
  }
@@ -138,19 +173,80 @@ function useArticleUnlockStatus({
138
173
  key: "waiting-response"
139
174
  };
140
175
  },
141
- enabled: !!articleId && !!contentId
176
+ enabled: !!client && !!articleId && !!contentId
177
+ });
178
+ }
179
+
180
+ // src/react/hook/useSendTransaction.ts
181
+ import { useMutation } from "@tanstack/react-query";
182
+ function useSendTransactionAction({
183
+ mutations
184
+ } = {}) {
185
+ const client = useNexusClient();
186
+ return useMutation({
187
+ ...mutations,
188
+ mutationKey: ["nexus-sdk", "send-transaction"],
189
+ mutationFn: async (params) => {
190
+ if (!client) {
191
+ throw new ClientNotFound();
192
+ }
193
+ return sendTransaction(client, params);
194
+ }
142
195
  });
143
196
  }
144
197
 
145
- // src/react/hook/useNexusReferral.ts
146
- import { useQuery as useQuery4, useQueryClient as useQueryClient3 } from "@tanstack/react-query";
147
- import { useCallback as useCallback3, useEffect as useEffect3, useState as useState3 } from "react";
198
+ // src/react/hook/useSiweAuthenticate.ts
199
+ import { useMutation as useMutation2 } from "@tanstack/react-query";
200
+ function useSiweAuthenticate({
201
+ mutations
202
+ } = {}) {
203
+ const client = useNexusClient();
204
+ return useMutation2({
205
+ ...mutations,
206
+ mutationKey: [
207
+ "nexus-sdk",
208
+ "siwe-authenticate",
209
+ client?.config.domain ?? "no-domain"
210
+ ],
211
+ mutationFn: async (params) => {
212
+ if (!client) {
213
+ throw new ClientNotFound();
214
+ }
215
+ return siweAuthenticate(client, params);
216
+ }
217
+ });
218
+ }
219
+
220
+ // src/react/hook/helper/usePressReferralInteraction.ts
221
+ import { useQuery as useQuery5 } from "@tanstack/react-query";
222
+ import { useMemo as useMemo2 } from "react";
148
223
  import { isAddressEqual } from "viem";
149
224
 
150
- // src/react/hook/useWindowLocation.ts
151
- import { useEffect as useEffect2, useState as useState2 } from "react";
225
+ // src/react/hook/useSendInteraction.ts
226
+ import { useMutation as useMutation3 } from "@tanstack/react-query";
227
+ function useSendInteraction({
228
+ mutations
229
+ } = {}) {
230
+ const client = useNexusClient();
231
+ return useMutation3({
232
+ ...mutations,
233
+ mutationKey: ["nexus-sdk", "send-interaction"],
234
+ mutationFn: async (params) => {
235
+ if (!client) {
236
+ throw new ClientNotFound();
237
+ }
238
+ return sendInteraction(client, params);
239
+ }
240
+ });
241
+ }
242
+
243
+ // src/react/hook/utils/useNexusContext.ts
244
+ import { useMutation as useMutation4, useQuery as useQuery4 } from "@tanstack/react-query";
152
245
 
153
- // src/react/hook/useMounted.ts
246
+ // src/react/hook/utils/useWindowLocation.ts
247
+ import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
248
+
249
+ // src/react/hook/utils/useMounted.ts
154
250
  import { useEffect, useState } from "react";
155
251
  function useMounted() {
156
252
  const [mounted, setMounted] = useState(false);
@@ -160,22 +256,17 @@ function useMounted() {
160
256
  return mounted;
161
257
  }
162
258
 
163
- // src/react/hook/useWindowLocation.ts
164
- var useWindowLocation = () => {
259
+ // src/react/hook/utils/useWindowLocation.ts
260
+ function useWindowLocation() {
165
261
  const isMounted = useMounted();
166
262
  const [location, setLocation] = useState2(
167
263
  isMounted ? window.location : void 0
168
264
  );
169
- const [href, setHref] = useState2(
170
- isMounted ? window.location.href : void 0
171
- );
172
265
  useEffect2(() => {
173
- if (!isMounted)
174
- return;
175
- const setWindowLocation = () => {
266
+ if (!isMounted) return;
267
+ function setWindowLocation() {
176
268
  setLocation(window.location);
177
- setHref(window.location.href);
178
- };
269
+ }
179
270
  if (!location) {
180
271
  setWindowLocation();
181
272
  }
@@ -184,104 +275,135 @@ var useWindowLocation = () => {
184
275
  window.removeEventListener("popstate", setWindowLocation);
185
276
  };
186
277
  }, [isMounted, location]);
278
+ const href = useMemo(() => location?.href, [location?.href]);
187
279
  return { location, href };
188
- };
280
+ }
189
281
 
190
- // src/react/hook/useNexusReferral.ts
191
- function useNexusReferral({ contentId }) {
192
- const { href } = useWindowLocation();
193
- const queryClient = useQueryClient3();
194
- const client = useNexusClient();
195
- const { data: walletStatus } = useWalletStatus();
196
- const [referrerAddress, setReferrerAddress] = useState3();
197
- const newStatusUpdated = useCallback3(
198
- (event) => {
199
- queryClient.setQueryData(
200
- ["setUserReferredQueryReturnTypeListener"],
201
- event
202
- );
203
- if (event.key === "referred-successful" || event.key === "referred-history") {
204
- if (!href)
205
- return;
206
- const url = new URL(href);
207
- if (walletStatus?.key === "connected") {
208
- url.searchParams.set("nexusContext", walletStatus?.wallet);
209
- }
210
- if (walletStatus?.key === "not-connected") {
211
- url.searchParams.delete("nexusContext");
212
- }
213
- window.history.replaceState(null, "", url.toString());
214
- }
215
- },
216
- [queryClient, href, walletStatus]
217
- );
218
- useEffect3(() => {
219
- if (!href)
220
- return;
221
- const url = new URL(href);
222
- const context = url.searchParams.get("nexusContext");
223
- if (!context && walletStatus?.key === "connected") {
224
- url.searchParams.set("nexusContext", walletStatus?.wallet);
225
- window.history.replaceState(null, "", url.toString());
282
+ // src/react/hook/utils/useNexusContext.ts
283
+ var contextKey = "nCtx";
284
+ function useNexusContext() {
285
+ const { location } = useWindowLocation();
286
+ const { data: nexusContext } = useQuery4({
287
+ queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
288
+ queryFn: async () => {
289
+ if (!location?.href) return null;
290
+ const url = new URL(location.href);
291
+ const nexusContext2 = url.searchParams.get(contextKey);
292
+ if (!nexusContext2) return null;
293
+ const parsedContext = await decompressJson(nexusContext2);
294
+ if (!parsedContext) return null;
295
+ return parsedContext;
226
296
  }
227
- if (context) {
228
- setReferrerAddress(context);
297
+ });
298
+ const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation4({
299
+ mutationKey: ["nexus-sdk", "update-context"],
300
+ mutationFn: async (newContext) => {
301
+ if (!location || typeof window === "undefined") return;
302
+ const fullNewContext = nexusContext ? { ...nexusContext, ...newContext } : newContext;
303
+ const compressedContext = await compressJson(fullNewContext);
304
+ if (!compressedContext) return;
305
+ const url = new URL(location.href);
306
+ url.searchParams.set(contextKey, compressedContext);
307
+ window.history.replaceState(null, "", url.toString());
229
308
  }
230
- }, [href, walletStatus]);
231
- return useQuery4({
309
+ });
310
+ return { nexusContext, updateContext, updateContextAsync };
311
+ }
312
+
313
+ // src/react/hook/helper/usePressReferralInteraction.ts
314
+ function usePressReferralInteraction({ contentId }) {
315
+ const { nexusContext, updateContextAsync } = useNexusContext();
316
+ const { data: walletStatus } = useWalletStatus();
317
+ const { mutateAsync: sendInteraction2 } = useSendInteraction();
318
+ const { data, error, status } = useQuery5({
232
319
  gcTime: 0,
233
- queryKey: ["setUserReferredQueryReturnTypeListener"],
320
+ queryKey: [
321
+ "nexus-sdk",
322
+ "auto-press-referral-interaction",
323
+ nexusContext?.r ?? "no-referrer",
324
+ walletStatus?.key ?? "no-wallet-status"
325
+ ],
234
326
  queryFn: async () => {
235
- if (!(contentId && referrerAddress)) {
236
- return { key: "no-referrer" };
237
- }
238
- if (walletStatus?.key === "connected" && walletStatus?.wallet && isAddressEqual(walletStatus?.wallet, referrerAddress)) {
239
- return { key: "same-wallet" };
327
+ if (!nexusContext && walletStatus?.key === "connected") {
328
+ await updateContextAsync({ r: walletStatus.wallet });
329
+ return null;
240
330
  }
241
- await setUserReferred(
242
- client,
243
- { contentId, walletAddress: referrerAddress },
244
- newStatusUpdated
245
- );
246
- return { key: "waiting-response" };
247
- },
248
- enabled: !!contentId && !!referrerAddress && walletStatus?.key !== void 0 && walletStatus?.key !== "waiting-response"
331
+ if (!nexusContext || walletStatus?.key !== "connected") return null;
332
+ if (isAddressEqual(nexusContext.r, walletStatus.wallet))
333
+ return null;
334
+ const interaction = PressInteractionEncoder.referred({
335
+ referrer: nexusContext.r
336
+ });
337
+ await sendInteraction2({ contentId, interaction });
338
+ await updateContextAsync({ r: walletStatus.wallet });
339
+ return { referrer: nexusContext.r };
340
+ }
249
341
  });
342
+ return useOutputStateMapper({ data, error, status });
343
+ }
344
+ function useOutputStateMapper({
345
+ data,
346
+ error,
347
+ status
348
+ }) {
349
+ const errorState = useMemo2(() => {
350
+ if (!(error instanceof FrakRpcError)) return null;
351
+ switch (error.code) {
352
+ case RpcErrorCodes.walletNotConnected:
353
+ return "no-wallet";
354
+ case RpcErrorCodes.noInteractionSession:
355
+ return "no-session";
356
+ default:
357
+ return "error";
358
+ }
359
+ }, [error]);
360
+ return useMemo2(() => {
361
+ switch (status) {
362
+ case "pending":
363
+ return "loading";
364
+ case "success":
365
+ return data === null ? "no-referral" : "referred";
366
+ case "error":
367
+ return errorState ?? "error";
368
+ }
369
+ }, [data, errorState, status]);
250
370
  }
251
371
 
252
372
  // src/react/provider/NexusIFrameClientProvider.ts
253
373
  var NexusIFrameClientContext = createContext2(
254
374
  void 0
255
375
  );
376
+ var defaultIframeStyle = {
377
+ width: "0",
378
+ height: "0",
379
+ border: "0",
380
+ position: "absolute",
381
+ zIndex: 1e3,
382
+ top: "-1000px",
383
+ left: "-1000px"
384
+ };
256
385
  function NexusIFrameClientProvider({
386
+ style,
257
387
  children
258
388
  }) {
259
389
  const config = useNexusConfig();
260
- const [iframeElem, setIframeElem] = useState4(
261
- void 0
262
- );
263
- const client = useMemo(
264
- () => iframeElem ? createIFrameNexusClient({ iframe: iframeElem, config }) : void 0,
265
- [iframeElem, config]
266
- );
390
+ const [client, setClient] = useState3(void 0);
267
391
  const iFrame = createElement2("iframe", {
268
392
  id: "nexus-wallet",
269
393
  name: "nexus-wallet",
270
394
  src: `${config.walletUrl}/listener`,
271
- style: {
272
- width: "0",
273
- height: "0",
274
- border: "0",
275
- position: "absolute",
276
- top: "-1000px",
277
- left: "-1000px"
278
- },
395
+ style: style ?? defaultIframeStyle,
396
+ allow: "publickey-credentials-get *",
279
397
  ref: (iframe) => {
280
- if (!iframe) {
281
- setIframeElem(void 0);
398
+ if (!iframe || client) {
282
399
  return;
283
400
  }
284
- setIframeElem(iframe);
401
+ setClient(
402
+ createIFrameNexusClient({
403
+ iframe,
404
+ config
405
+ })
406
+ );
285
407
  }
286
408
  });
287
409
  const providerComponent = createElement2(
@@ -300,6 +422,9 @@ export {
300
422
  useArticleUnlockStatus,
301
423
  useNexusClient,
302
424
  useNexusConfig,
303
- useNexusReferral,
425
+ usePressReferralInteraction,
426
+ useSendInteraction,
427
+ useSendTransactionAction,
428
+ useSiweAuthenticate,
304
429
  useWalletStatus
305
430
  };
@@ -1,5 +1,5 @@
1
1
  import { Hex } from 'viem';
2
- import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-BwzXSgqQ.js';
2
+ import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client--U_6SK0l.cjs';
3
3
 
4
4
  /**
5
5
  * Type used to get the unlock options
@@ -15,11 +15,11 @@ type GetUnlockOptionsParams = {
15
15
  * @param contentId
16
16
  */
17
17
  declare function getArticleUnlockOptions(client: NexusClient, { articleId, contentId }: GetUnlockOptionsParams): Promise<Readonly<{
18
- frkBalanceAsHex?: `0x${string}` | undefined;
18
+ frkBalanceAsHex?: Hex;
19
19
  prices: {
20
20
  index: number;
21
21
  unlockDurationInSec: number;
22
- frkAmount: `0x${string}`;
22
+ frkAmount: Hex;
23
23
  isUserAccessible: boolean | null;
24
24
  }[];
25
25
  }>>;
@@ -1,5 +1,5 @@
1
1
  import { Hex } from 'viem';
2
- import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-BwzXSgqQ.cjs';
2
+ import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-6_BJp7Ub.js';
3
3
 
4
4
  /**
5
5
  * Type used to get the unlock options
@@ -15,11 +15,11 @@ type GetUnlockOptionsParams = {
15
15
  * @param contentId
16
16
  */
17
17
  declare function getArticleUnlockOptions(client: NexusClient, { articleId, contentId }: GetUnlockOptionsParams): Promise<Readonly<{
18
- frkBalanceAsHex?: `0x${string}` | undefined;
18
+ frkBalanceAsHex?: Hex;
19
19
  prices: {
20
20
  index: number;
21
21
  unlockDurationInSec: number;
22
- frkAmount: `0x${string}`;
22
+ frkAmount: Hex;
23
23
  isUserAccessible: boolean | null;
24
24
  }[];
25
25
  }>>;