@frak-labs/nexus-sdk 0.0.9 → 0.0.11
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/chunk-5CFD5FM2.js +86 -0
- package/dist/chunk-7MVQQ2X6.js +381 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/chunk-GUDT2W6I.js +70 -0
- package/dist/chunk-IQQTTKJL.cjs +70 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/chunk-V3S6RBRJ.cjs +381 -0
- package/dist/client-C7u9zGwC.d.cts +332 -0
- package/dist/client-gE3fYzkD.d.ts +332 -0
- package/dist/core/actions/index.cjs +3 -3
- package/dist/core/actions/index.d.cts +21 -28
- package/dist/core/actions/index.d.ts +21 -28
- package/dist/core/actions/index.js +12 -12
- package/dist/core/index.cjs +3 -8
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -14
- package/dist/core/interactions/index.cjs +13 -0
- package/dist/core/interactions/index.d.cts +53 -0
- package/dist/core/interactions/index.d.ts +53 -0
- package/dist/core/interactions/index.js +13 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D3-M3nBh.d.cts +22 -0
- package/dist/interaction-D3-M3nBh.d.ts +22 -0
- package/dist/react/index.cjs +279 -166
- package/dist/react/index.d.cts +80 -37
- package/dist/react/index.d.ts +80 -37
- package/dist/react/index.js +291 -178
- package/dist/sendTransaction-BZW627cT.d.cts +30 -0
- package/dist/sendTransaction-DpJTfGJc.d.ts +30 -0
- package/package.json +16 -7
- package/dist/chunk-AYZHGMEV.cjs +0 -171
- package/dist/chunk-PDR3CF3P.js +0 -86
- package/dist/chunk-SZUN32YC.js +0 -171
- package/dist/chunk-VK7GPKK4.js +0 -169
- package/dist/chunk-X4JNNWJ4.cjs +0 -86
- package/dist/chunk-ZOLP2FJZ.cjs +0 -169
- package/dist/client-BwzXSgqQ.d.cts +0 -278
- package/dist/client-BwzXSgqQ.d.ts +0 -278
- package/dist/watchUnlockStatus-DXClCYH9.d.cts +0 -43
- package/dist/watchUnlockStatus-WJxoDliF.d.ts +0 -43
package/dist/react/index.js
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
ClientNotFound,
|
|
3
|
+
Deferred,
|
|
4
|
+
FrakRpcError,
|
|
5
|
+
RpcErrorCodes,
|
|
6
|
+
baseIframeProps,
|
|
7
|
+
compressJson,
|
|
8
|
+
createIFrameNexusClient,
|
|
9
|
+
decompressJson
|
|
10
|
+
} from "../chunk-7MVQQ2X6.js";
|
|
4
11
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
12
|
+
displayModal,
|
|
13
|
+
openSso,
|
|
14
|
+
sendInteraction,
|
|
15
|
+
sendTransaction,
|
|
16
|
+
siweAuthenticate,
|
|
8
17
|
watchWalletStatus
|
|
9
|
-
} from "../chunk-
|
|
10
|
-
import
|
|
18
|
+
} from "../chunk-5CFD5FM2.js";
|
|
19
|
+
import {
|
|
20
|
+
ReferralInteractionEncoder
|
|
21
|
+
} from "../chunk-GUDT2W6I.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
|
-
{
|
|
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
|
-
|
|
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
|
|
54
|
+
throw new FrakRpcError(
|
|
55
|
+
RpcErrorCodes.configError,
|
|
56
|
+
"Nexus config not found"
|
|
57
|
+
);
|
|
39
58
|
}
|
|
40
59
|
return config;
|
|
41
60
|
}
|
|
@@ -43,114 +62,134 @@ function useNexusConfig() {
|
|
|
43
62
|
// src/react/hook/useNexusClient.ts
|
|
44
63
|
import { useContext as useContext2 } from "react";
|
|
45
64
|
function useNexusClient() {
|
|
46
|
-
|
|
47
|
-
if (!client) {
|
|
48
|
-
throw new Error("NexusIFrameClientProvider is not found");
|
|
49
|
-
}
|
|
50
|
-
return client;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// src/react/hook/useArticleUnlockOptions.ts
|
|
54
|
-
import { useQuery } from "@tanstack/react-query";
|
|
55
|
-
function useArticleUnlockOptions({
|
|
56
|
-
articleId,
|
|
57
|
-
contentId
|
|
58
|
-
}) {
|
|
59
|
-
const client = useNexusClient();
|
|
60
|
-
return useQuery({
|
|
61
|
-
queryKey: ["articleUnlockOptions", articleId ?? "no-article-id"],
|
|
62
|
-
queryFn: async () => {
|
|
63
|
-
if (!(articleId && contentId)) {
|
|
64
|
-
throw new Error("No article id provided");
|
|
65
|
-
}
|
|
66
|
-
return await getArticleUnlockOptions(client, {
|
|
67
|
-
articleId,
|
|
68
|
-
contentId
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
enabled: !!articleId && !!contentId,
|
|
72
|
-
gcTime: 0
|
|
73
|
-
});
|
|
65
|
+
return useContext2(NexusIFrameClientContext);
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
// src/react/hook/useWalletStatus.ts
|
|
77
|
-
import { useQuery
|
|
69
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
78
70
|
import { useCallback } from "react";
|
|
79
71
|
function useWalletStatus() {
|
|
80
72
|
const queryClient = useQueryClient();
|
|
81
73
|
const client = useNexusClient();
|
|
82
74
|
const newStatusUpdated = useCallback(
|
|
83
75
|
(event) => {
|
|
84
|
-
queryClient.setQueryData(
|
|
76
|
+
queryClient.setQueryData(
|
|
77
|
+
["nexus-sdk", "wallet-status-listener"],
|
|
78
|
+
event
|
|
79
|
+
);
|
|
85
80
|
},
|
|
86
81
|
[queryClient]
|
|
87
82
|
);
|
|
88
|
-
return
|
|
83
|
+
return useQuery({
|
|
89
84
|
gcTime: 0,
|
|
90
|
-
queryKey: ["
|
|
85
|
+
queryKey: ["nexus-sdk", "wallet-status-listener"],
|
|
91
86
|
queryFn: async () => {
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
if (!client) {
|
|
88
|
+
throw new ClientNotFound();
|
|
89
|
+
}
|
|
90
|
+
const firstResult = new Deferred();
|
|
91
|
+
let hasResolved = false;
|
|
92
|
+
await watchWalletStatus(client, (status) => {
|
|
93
|
+
newStatusUpdated(status);
|
|
94
|
+
if (!hasResolved) {
|
|
95
|
+
firstResult.resolve(status);
|
|
96
|
+
hasResolved = true;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return firstResult.promise;
|
|
100
|
+
},
|
|
101
|
+
enabled: !!client
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/react/hook/useSendTransaction.ts
|
|
106
|
+
import { useMutation } from "@tanstack/react-query";
|
|
107
|
+
function useSendTransactionAction({
|
|
108
|
+
mutations
|
|
109
|
+
} = {}) {
|
|
110
|
+
const client = useNexusClient();
|
|
111
|
+
return useMutation({
|
|
112
|
+
...mutations,
|
|
113
|
+
mutationKey: ["nexus-sdk", "send-transaction"],
|
|
114
|
+
mutationFn: async (params) => {
|
|
115
|
+
if (!client) {
|
|
116
|
+
throw new ClientNotFound();
|
|
117
|
+
}
|
|
118
|
+
return sendTransaction(client, params);
|
|
94
119
|
}
|
|
95
120
|
});
|
|
96
121
|
}
|
|
97
122
|
|
|
98
|
-
// src/react/hook/
|
|
99
|
-
import {
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
contentId
|
|
104
|
-
}) {
|
|
105
|
-
const queryClient = useQueryClient2();
|
|
123
|
+
// src/react/hook/useSiweAuthenticate.ts
|
|
124
|
+
import { useMutation as useMutation2 } from "@tanstack/react-query";
|
|
125
|
+
function useSiweAuthenticate({
|
|
126
|
+
mutations
|
|
127
|
+
} = {}) {
|
|
106
128
|
const client = useNexusClient();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
contentId ?? "no-contentId-id"
|
|
114
|
-
],
|
|
115
|
-
event
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
[articleId, contentId, queryClient]
|
|
119
|
-
);
|
|
120
|
-
return useQuery3({
|
|
121
|
-
queryKey: [
|
|
122
|
-
"articleUnlockStatusListener",
|
|
123
|
-
articleId ?? "no-article-id",
|
|
124
|
-
contentId ?? "no-contentId-id"
|
|
129
|
+
return useMutation2({
|
|
130
|
+
...mutations,
|
|
131
|
+
mutationKey: [
|
|
132
|
+
"nexus-sdk",
|
|
133
|
+
"siwe-authenticate",
|
|
134
|
+
client?.config.domain ?? "no-domain"
|
|
125
135
|
],
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return null;
|
|
136
|
+
mutationFn: async (params) => {
|
|
137
|
+
if (!client) {
|
|
138
|
+
throw new ClientNotFound();
|
|
130
139
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
{ articleId, contentId },
|
|
134
|
-
newStatusUpdated
|
|
135
|
-
);
|
|
136
|
-
return {
|
|
137
|
-
status: "waiting-response",
|
|
138
|
-
key: "waiting-response"
|
|
139
|
-
};
|
|
140
|
-
},
|
|
141
|
-
enabled: !!articleId && !!contentId
|
|
140
|
+
return siweAuthenticate(client, params);
|
|
141
|
+
}
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
// src/react/hook/
|
|
146
|
-
import { useQuery as
|
|
147
|
-
import { useCallback as
|
|
145
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
146
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
147
|
+
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
148
148
|
import { isAddressEqual } from "viem";
|
|
149
149
|
|
|
150
|
-
// src/react/hook/
|
|
151
|
-
import {
|
|
150
|
+
// src/react/hook/useDisplayModal.ts
|
|
151
|
+
import { useMutation as useMutation3 } from "@tanstack/react-query";
|
|
152
|
+
function useDisplayModal({
|
|
153
|
+
mutations
|
|
154
|
+
} = {}) {
|
|
155
|
+
const client = useNexusClient();
|
|
156
|
+
return useMutation3({
|
|
157
|
+
...mutations,
|
|
158
|
+
mutationKey: ["nexus-sdk", "display-modal"],
|
|
159
|
+
mutationFn: async (args) => {
|
|
160
|
+
if (!client) {
|
|
161
|
+
throw new ClientNotFound();
|
|
162
|
+
}
|
|
163
|
+
return displayModal(client, args);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/react/hook/useSendInteraction.ts
|
|
169
|
+
import { useMutation as useMutation4 } from "@tanstack/react-query";
|
|
170
|
+
function useSendInteraction({
|
|
171
|
+
mutations
|
|
172
|
+
} = {}) {
|
|
173
|
+
const client = useNexusClient();
|
|
174
|
+
return useMutation4({
|
|
175
|
+
...mutations,
|
|
176
|
+
mutationKey: ["nexus-sdk", "send-interaction"],
|
|
177
|
+
mutationFn: async (params) => {
|
|
178
|
+
if (!client) {
|
|
179
|
+
throw new ClientNotFound();
|
|
180
|
+
}
|
|
181
|
+
return sendInteraction(client, params);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/react/hook/utils/useNexusContext.ts
|
|
187
|
+
import { useMutation as useMutation5, useQuery as useQuery2 } from "@tanstack/react-query";
|
|
152
188
|
|
|
153
|
-
// src/react/hook/
|
|
189
|
+
// src/react/hook/utils/useWindowLocation.ts
|
|
190
|
+
import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
191
|
+
|
|
192
|
+
// src/react/hook/utils/useMounted.ts
|
|
154
193
|
import { useEffect, useState } from "react";
|
|
155
194
|
function useMounted() {
|
|
156
195
|
const [mounted, setMounted] = useState(false);
|
|
@@ -160,22 +199,17 @@ function useMounted() {
|
|
|
160
199
|
return mounted;
|
|
161
200
|
}
|
|
162
201
|
|
|
163
|
-
// src/react/hook/useWindowLocation.ts
|
|
164
|
-
|
|
202
|
+
// src/react/hook/utils/useWindowLocation.ts
|
|
203
|
+
function useWindowLocation() {
|
|
165
204
|
const isMounted = useMounted();
|
|
166
205
|
const [location, setLocation] = useState2(
|
|
167
206
|
isMounted ? window.location : void 0
|
|
168
207
|
);
|
|
169
|
-
const [href, setHref] = useState2(
|
|
170
|
-
isMounted ? window.location.href : void 0
|
|
171
|
-
);
|
|
172
208
|
useEffect2(() => {
|
|
173
|
-
if (!isMounted)
|
|
174
|
-
|
|
175
|
-
const setWindowLocation = () => {
|
|
209
|
+
if (!isMounted) return;
|
|
210
|
+
function setWindowLocation() {
|
|
176
211
|
setLocation(window.location);
|
|
177
|
-
|
|
178
|
-
};
|
|
212
|
+
}
|
|
179
213
|
if (!location) {
|
|
180
214
|
setWindowLocation();
|
|
181
215
|
}
|
|
@@ -184,68 +218,153 @@ var useWindowLocation = () => {
|
|
|
184
218
|
window.removeEventListener("popstate", setWindowLocation);
|
|
185
219
|
};
|
|
186
220
|
}, [isMounted, location]);
|
|
221
|
+
const href = useMemo(() => location?.href, [location?.href]);
|
|
187
222
|
return { location, href };
|
|
188
|
-
}
|
|
223
|
+
}
|
|
189
224
|
|
|
190
|
-
// src/react/hook/
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
const
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
);
|
|
203
|
-
|
|
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
|
-
}
|
|
225
|
+
// src/react/hook/utils/useNexusContext.ts
|
|
226
|
+
var contextKey = "nCtx";
|
|
227
|
+
function useNexusContext() {
|
|
228
|
+
const { location } = useWindowLocation();
|
|
229
|
+
const { data: nexusContext } = useQuery2({
|
|
230
|
+
queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
|
|
231
|
+
queryFn: async () => {
|
|
232
|
+
if (!location?.href) return null;
|
|
233
|
+
const url = new URL(location.href);
|
|
234
|
+
const nexusContext2 = url.searchParams.get(contextKey);
|
|
235
|
+
if (!nexusContext2) return null;
|
|
236
|
+
const parsedContext = await decompressJson(nexusContext2);
|
|
237
|
+
if (!parsedContext) return null;
|
|
238
|
+
return parsedContext;
|
|
215
239
|
},
|
|
216
|
-
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
240
|
+
enabled: !!location?.href
|
|
241
|
+
});
|
|
242
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation5({
|
|
243
|
+
mutationKey: ["nexus-sdk", "update-context"],
|
|
244
|
+
mutationFn: async (newContext) => {
|
|
245
|
+
if (!location || typeof window === "undefined") return;
|
|
246
|
+
const fullNewContext = nexusContext ? { ...nexusContext, ...newContext } : newContext;
|
|
247
|
+
const compressedContext = await compressJson(fullNewContext);
|
|
248
|
+
if (!compressedContext) return;
|
|
249
|
+
const url = new URL(location.href);
|
|
250
|
+
url.searchParams.set(contextKey, compressedContext);
|
|
225
251
|
window.history.replaceState(null, "", url.toString());
|
|
226
252
|
}
|
|
227
|
-
|
|
228
|
-
|
|
253
|
+
});
|
|
254
|
+
return {
|
|
255
|
+
nexusContext,
|
|
256
|
+
updateContext,
|
|
257
|
+
updateContextAsync
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
262
|
+
function useReferralInteraction({
|
|
263
|
+
contentId,
|
|
264
|
+
modalConfig
|
|
265
|
+
} = {}) {
|
|
266
|
+
const { nexusContext, updateContextAsync } = useNexusContext();
|
|
267
|
+
const { data: walletStatus } = useWalletStatus();
|
|
268
|
+
const { mutateAsync: sendInteraction2 } = useSendInteraction();
|
|
269
|
+
const ensureWalletConnected = useEnsureWalletConnected({
|
|
270
|
+
modalConfig,
|
|
271
|
+
walletStatus
|
|
272
|
+
});
|
|
273
|
+
const processReferral = useCallback2(async () => {
|
|
274
|
+
try {
|
|
275
|
+
const currentWallet = await ensureWalletConnected();
|
|
276
|
+
if (!nexusContext?.r) {
|
|
277
|
+
if (currentWallet) {
|
|
278
|
+
await updateContextAsync({ r: currentWallet });
|
|
279
|
+
}
|
|
280
|
+
return "no-referrer";
|
|
281
|
+
}
|
|
282
|
+
if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
|
|
283
|
+
return "self-referral";
|
|
284
|
+
}
|
|
285
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
286
|
+
referrer: nexusContext.r
|
|
287
|
+
});
|
|
288
|
+
await sendInteraction2({ contentId, interaction });
|
|
289
|
+
if (currentWallet) {
|
|
290
|
+
await updateContextAsync({ r: currentWallet });
|
|
291
|
+
}
|
|
292
|
+
return "success";
|
|
293
|
+
} catch (error2) {
|
|
294
|
+
return mapErrorToState(error2);
|
|
229
295
|
}
|
|
230
|
-
}, [
|
|
231
|
-
|
|
296
|
+
}, [
|
|
297
|
+
nexusContext,
|
|
298
|
+
contentId,
|
|
299
|
+
ensureWalletConnected,
|
|
300
|
+
sendInteraction2,
|
|
301
|
+
updateContextAsync
|
|
302
|
+
]);
|
|
303
|
+
const {
|
|
304
|
+
data: referralState,
|
|
305
|
+
error,
|
|
306
|
+
status
|
|
307
|
+
} = useQuery3({
|
|
232
308
|
gcTime: 0,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
309
|
+
staleTime: 0,
|
|
310
|
+
queryKey: [
|
|
311
|
+
"nexus-sdk",
|
|
312
|
+
"auto-referral-interaction",
|
|
313
|
+
nexusContext?.r ?? "no-referrer",
|
|
314
|
+
walletStatus?.key ?? "no-wallet-status"
|
|
315
|
+
],
|
|
316
|
+
queryFn: processReferral,
|
|
317
|
+
enabled: !!walletStatus
|
|
318
|
+
});
|
|
319
|
+
return useMemo2(() => {
|
|
320
|
+
if (status === "pending") return "processing";
|
|
321
|
+
if (status === "error") return mapErrorToState(error);
|
|
322
|
+
return referralState || "idle";
|
|
323
|
+
}, [referralState, status, error]);
|
|
324
|
+
}
|
|
325
|
+
function useEnsureWalletConnected({
|
|
326
|
+
modalConfig,
|
|
327
|
+
walletStatus
|
|
328
|
+
}) {
|
|
329
|
+
const { mutateAsync: displayModal2 } = useDisplayModal();
|
|
330
|
+
return useCallback2(async () => {
|
|
331
|
+
if (walletStatus?.key !== "connected" || !walletStatus.interactionSession) {
|
|
332
|
+
if (!modalConfig) {
|
|
333
|
+
return void 0;
|
|
237
334
|
}
|
|
238
|
-
|
|
239
|
-
|
|
335
|
+
const result = await displayModal2(modalConfig);
|
|
336
|
+
return result?.login?.wallet ?? void 0;
|
|
337
|
+
}
|
|
338
|
+
return walletStatus.wallet ?? void 0;
|
|
339
|
+
}, [walletStatus, modalConfig, displayModal2]);
|
|
340
|
+
}
|
|
341
|
+
function mapErrorToState(error) {
|
|
342
|
+
if (error instanceof FrakRpcError) {
|
|
343
|
+
switch (error.code) {
|
|
344
|
+
case RpcErrorCodes.walletNotConnected:
|
|
345
|
+
return "no-wallet";
|
|
346
|
+
case RpcErrorCodes.noInteractionSession:
|
|
347
|
+
return "no-session";
|
|
348
|
+
default:
|
|
349
|
+
return "error";
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
return "error";
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// src/react/hook/useOpenSso.ts
|
|
356
|
+
import { useMutation as useMutation6 } from "@tanstack/react-query";
|
|
357
|
+
function useOpenSso({ mutations } = {}) {
|
|
358
|
+
const client = useNexusClient();
|
|
359
|
+
return useMutation6({
|
|
360
|
+
...mutations,
|
|
361
|
+
mutationKey: ["nexus-sdk", "open-sso"],
|
|
362
|
+
mutationFn: async (params) => {
|
|
363
|
+
if (!client) {
|
|
364
|
+
throw new ClientNotFound();
|
|
240
365
|
}
|
|
241
|
-
|
|
242
|
-
|
|
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"
|
|
366
|
+
return openSso(client, params);
|
|
367
|
+
}
|
|
249
368
|
});
|
|
250
369
|
}
|
|
251
370
|
|
|
@@ -254,34 +373,25 @@ var NexusIFrameClientContext = createContext2(
|
|
|
254
373
|
void 0
|
|
255
374
|
);
|
|
256
375
|
function NexusIFrameClientProvider({
|
|
376
|
+
style,
|
|
257
377
|
children
|
|
258
378
|
}) {
|
|
259
379
|
const config = useNexusConfig();
|
|
260
|
-
const [
|
|
261
|
-
void 0
|
|
262
|
-
);
|
|
263
|
-
const client = useMemo(
|
|
264
|
-
() => iframeElem ? createIFrameNexusClient({ iframe: iframeElem, config }) : void 0,
|
|
265
|
-
[iframeElem, config]
|
|
266
|
-
);
|
|
380
|
+
const [client, setClient] = useState3(void 0);
|
|
267
381
|
const iFrame = createElement2("iframe", {
|
|
268
|
-
|
|
269
|
-
name: "nexus-wallet",
|
|
382
|
+
...baseIframeProps,
|
|
270
383
|
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
|
-
},
|
|
384
|
+
style: style ?? baseIframeProps.style,
|
|
279
385
|
ref: (iframe) => {
|
|
280
|
-
if (!iframe) {
|
|
281
|
-
setIframeElem(void 0);
|
|
386
|
+
if (!iframe || client) {
|
|
282
387
|
return;
|
|
283
388
|
}
|
|
284
|
-
|
|
389
|
+
setClient(
|
|
390
|
+
createIFrameNexusClient({
|
|
391
|
+
iframe,
|
|
392
|
+
config
|
|
393
|
+
})
|
|
394
|
+
);
|
|
285
395
|
}
|
|
286
396
|
});
|
|
287
397
|
const providerComponent = createElement2(
|
|
@@ -296,10 +406,13 @@ export {
|
|
|
296
406
|
NexusConfigProvider,
|
|
297
407
|
NexusIFrameClientContext,
|
|
298
408
|
NexusIFrameClientProvider,
|
|
299
|
-
|
|
300
|
-
useArticleUnlockStatus,
|
|
409
|
+
useDisplayModal,
|
|
301
410
|
useNexusClient,
|
|
302
411
|
useNexusConfig,
|
|
303
|
-
|
|
412
|
+
useOpenSso,
|
|
413
|
+
useReferralInteraction,
|
|
414
|
+
useSendInteraction,
|
|
415
|
+
useSendTransactionAction,
|
|
416
|
+
useSiweAuthenticate,
|
|
304
417
|
useWalletStatus
|
|
305
418
|
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-C7u9zGwC.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
5
|
+
*/
|
|
6
|
+
type SiweAuthenticateModalParams = {
|
|
7
|
+
siwe?: Partial<SiweAuthenticationParams>;
|
|
8
|
+
metadata?: ModalRpcMetadata;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to launch a siwe authentication
|
|
12
|
+
* @param client
|
|
13
|
+
* @param siwe
|
|
14
|
+
* @param context
|
|
15
|
+
*/
|
|
16
|
+
declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
|
|
17
|
+
|
|
18
|
+
type SendTransactionParams = {
|
|
19
|
+
tx: SendTransactionModalStepType["params"]["tx"];
|
|
20
|
+
metadata?: ModalRpcMetadata;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Function used to send a user transaction
|
|
24
|
+
* @param client
|
|
25
|
+
* @param tx
|
|
26
|
+
* @param context
|
|
27
|
+
*/
|
|
28
|
+
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
|
+
|
|
30
|
+
export { type SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-gE3fYzkD.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
5
|
+
*/
|
|
6
|
+
type SiweAuthenticateModalParams = {
|
|
7
|
+
siwe?: Partial<SiweAuthenticationParams>;
|
|
8
|
+
metadata?: ModalRpcMetadata;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to launch a siwe authentication
|
|
12
|
+
* @param client
|
|
13
|
+
* @param siwe
|
|
14
|
+
* @param context
|
|
15
|
+
*/
|
|
16
|
+
declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
|
|
17
|
+
|
|
18
|
+
type SendTransactionParams = {
|
|
19
|
+
tx: SendTransactionModalStepType["params"]["tx"];
|
|
20
|
+
metadata?: ModalRpcMetadata;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Function used to send a user transaction
|
|
24
|
+
* @param client
|
|
25
|
+
* @param tx
|
|
26
|
+
* @param context
|
|
27
|
+
*/
|
|
28
|
+
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
|
+
|
|
30
|
+
export { type SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|