@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.cjs
CHANGED
|
@@ -1,13 +1,25 @@
|
|
|
1
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; }
|
|
2
2
|
|
|
3
|
-
var _chunkAYZHGMEVcjs = require('../chunk-AYZHGMEV.cjs');
|
|
4
3
|
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkV3S6RBRJcjs = require('../chunk-V3S6RBRJ.cjs');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkS5FVCA2Ecjs = require('../chunk-S5FVCA2E.cjs');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunkIQQTTKJLcjs = require('../chunk-IQQTTKJL.cjs');
|
|
22
|
+
require('../chunk-ETV4XYOV.cjs');
|
|
11
23
|
|
|
12
24
|
// src/react/provider/NexusConfigProvider.ts
|
|
13
25
|
var _react = require('react');
|
|
@@ -16,7 +28,12 @@ function NexusConfigProvider(parameters) {
|
|
|
16
28
|
const { children, config } = parameters;
|
|
17
29
|
return _react.createElement.call(void 0,
|
|
18
30
|
NexusConfigContext.Provider,
|
|
19
|
-
{
|
|
31
|
+
{
|
|
32
|
+
value: {
|
|
33
|
+
...config,
|
|
34
|
+
domain: _nullishCoalesce(_nullishCoalesce(config.domain, () => ( (typeof window !== "undefined" ? _optionalChain([window, 'optionalAccess', _ => _.location, 'optionalAccess', _2 => _2.host]) : void 0))), () => ( "not-found"))
|
|
35
|
+
}
|
|
36
|
+
},
|
|
20
37
|
children
|
|
21
38
|
);
|
|
22
39
|
}
|
|
@@ -29,13 +46,15 @@ function NexusConfigProvider(parameters) {
|
|
|
29
46
|
|
|
30
47
|
|
|
31
48
|
|
|
32
|
-
|
|
33
49
|
// src/react/hook/useNexusConfig.ts
|
|
34
50
|
|
|
35
51
|
function useNexusConfig() {
|
|
36
52
|
const config = _react.useContext.call(void 0, NexusConfigContext);
|
|
37
53
|
if (!config) {
|
|
38
|
-
throw new
|
|
54
|
+
throw new (0, _chunkV3S6RBRJcjs.FrakRpcError)(
|
|
55
|
+
_chunkV3S6RBRJcjs.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
|
|
|
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
|
-
var _reactquery = require('@tanstack/react-query');
|
|
55
|
-
function useArticleUnlockOptions({
|
|
56
|
-
articleId,
|
|
57
|
-
contentId
|
|
58
|
-
}) {
|
|
59
|
-
const client = useNexusClient();
|
|
60
|
-
return _reactquery.useQuery.call(void 0, {
|
|
61
|
-
queryKey: ["articleUnlockOptions", _nullishCoalesce(articleId, () => ( "no-article-id"))],
|
|
62
|
-
queryFn: async () => {
|
|
63
|
-
if (!(articleId && contentId)) {
|
|
64
|
-
throw new Error("No article id provided");
|
|
65
|
-
}
|
|
66
|
-
return await _chunkX4JNNWJ4cjs.getArticleUnlockOptions.call(void 0, client, {
|
|
67
|
-
articleId,
|
|
68
|
-
contentId
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
enabled: !!articleId && !!contentId,
|
|
72
|
-
gcTime: 0
|
|
73
|
-
});
|
|
65
|
+
return _react.useContext.call(void 0, NexusIFrameClientContext);
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
// src/react/hook/useWalletStatus.ts
|
|
77
|
-
|
|
69
|
+
var _reactquery = require('@tanstack/react-query');
|
|
78
70
|
|
|
79
71
|
function useWalletStatus() {
|
|
80
72
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
81
73
|
const client = useNexusClient();
|
|
82
74
|
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
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
83
|
return _reactquery.useQuery.call(void 0, {
|
|
89
84
|
gcTime: 0,
|
|
90
|
-
queryKey: ["
|
|
85
|
+
queryKey: ["nexus-sdk", "wallet-status-listener"],
|
|
91
86
|
queryFn: async () => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
87
|
+
if (!client) {
|
|
88
|
+
throw new (0, _chunkV3S6RBRJcjs.ClientNotFound)();
|
|
89
|
+
}
|
|
90
|
+
const firstResult = new (0, _chunkV3S6RBRJcjs.Deferred)();
|
|
91
|
+
let hasResolved = false;
|
|
92
|
+
await _chunkS5FVCA2Ecjs.watchWalletStatus.call(void 0, 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
|
|
95
102
|
});
|
|
96
103
|
}
|
|
97
104
|
|
|
98
|
-
// src/react/hook/
|
|
105
|
+
// src/react/hook/useSendTransaction.ts
|
|
106
|
+
|
|
107
|
+
function useSendTransactionAction({
|
|
108
|
+
mutations
|
|
109
|
+
} = {}) {
|
|
110
|
+
const client = useNexusClient();
|
|
111
|
+
return _reactquery.useMutation.call(void 0, {
|
|
112
|
+
...mutations,
|
|
113
|
+
mutationKey: ["nexus-sdk", "send-transaction"],
|
|
114
|
+
mutationFn: async (params) => {
|
|
115
|
+
if (!client) {
|
|
116
|
+
throw new (0, _chunkV3S6RBRJcjs.ClientNotFound)();
|
|
117
|
+
}
|
|
118
|
+
return _chunkS5FVCA2Ecjs.sendTransaction.call(void 0, client, params);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
99
122
|
|
|
123
|
+
// src/react/hook/useSiweAuthenticate.ts
|
|
100
124
|
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}) {
|
|
105
|
-
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
125
|
+
function useSiweAuthenticate({
|
|
126
|
+
mutations
|
|
127
|
+
} = {}) {
|
|
106
128
|
const client = useNexusClient();
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
_nullishCoalesce(contentId, () => ( "no-contentId-id"))
|
|
114
|
-
],
|
|
115
|
-
event
|
|
116
|
-
);
|
|
117
|
-
},
|
|
118
|
-
[articleId, contentId, queryClient]
|
|
119
|
-
);
|
|
120
|
-
return _reactquery.useQuery.call(void 0, {
|
|
121
|
-
queryKey: [
|
|
122
|
-
"articleUnlockStatusListener",
|
|
123
|
-
_nullishCoalesce(articleId, () => ( "no-article-id")),
|
|
124
|
-
_nullishCoalesce(contentId, () => ( "no-contentId-id"))
|
|
129
|
+
return _reactquery.useMutation.call(void 0, {
|
|
130
|
+
...mutations,
|
|
131
|
+
mutationKey: [
|
|
132
|
+
"nexus-sdk",
|
|
133
|
+
"siwe-authenticate",
|
|
134
|
+
_nullishCoalesce(_optionalChain([client, 'optionalAccess', _3 => _3.config, 'access', _4 => _4.domain]), () => ( "no-domain"))
|
|
125
135
|
],
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
return null;
|
|
136
|
+
mutationFn: async (params) => {
|
|
137
|
+
if (!client) {
|
|
138
|
+
throw new (0, _chunkV3S6RBRJcjs.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 _chunkS5FVCA2Ecjs.siweAuthenticate.call(void 0, client, params);
|
|
141
|
+
}
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
// src/react/hook/
|
|
145
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
var _viem = require('viem');
|
|
149
149
|
|
|
150
|
-
// src/react/hook/
|
|
150
|
+
// src/react/hook/useDisplayModal.ts
|
|
151
|
+
|
|
152
|
+
function useDisplayModal({
|
|
153
|
+
mutations
|
|
154
|
+
} = {}) {
|
|
155
|
+
const client = useNexusClient();
|
|
156
|
+
return _reactquery.useMutation.call(void 0, {
|
|
157
|
+
...mutations,
|
|
158
|
+
mutationKey: ["nexus-sdk", "display-modal"],
|
|
159
|
+
mutationFn: async (args) => {
|
|
160
|
+
if (!client) {
|
|
161
|
+
throw new (0, _chunkV3S6RBRJcjs.ClientNotFound)();
|
|
162
|
+
}
|
|
163
|
+
return _chunkS5FVCA2Ecjs.displayModal.call(void 0, client, args);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/react/hook/useSendInteraction.ts
|
|
169
|
+
|
|
170
|
+
function useSendInteraction({
|
|
171
|
+
mutations
|
|
172
|
+
} = {}) {
|
|
173
|
+
const client = useNexusClient();
|
|
174
|
+
return _reactquery.useMutation.call(void 0, {
|
|
175
|
+
...mutations,
|
|
176
|
+
mutationKey: ["nexus-sdk", "send-interaction"],
|
|
177
|
+
mutationFn: async (params) => {
|
|
178
|
+
if (!client) {
|
|
179
|
+
throw new (0, _chunkV3S6RBRJcjs.ClientNotFound)();
|
|
180
|
+
}
|
|
181
|
+
return _chunkS5FVCA2Ecjs.sendInteraction.call(void 0, client, params);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/react/hook/utils/useNexusContext.ts
|
|
151
187
|
|
|
152
188
|
|
|
153
|
-
// src/react/hook/
|
|
189
|
+
// src/react/hook/utils/useWindowLocation.ts
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
// src/react/hook/utils/useMounted.ts
|
|
154
193
|
|
|
155
194
|
function useMounted() {
|
|
156
195
|
const [mounted, setMounted] = _react.useState.call(void 0, 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] = _react.useState.call(void 0,
|
|
167
206
|
isMounted ? window.location : void 0
|
|
168
207
|
);
|
|
169
|
-
const [href, setHref] = _react.useState.call(void 0,
|
|
170
|
-
isMounted ? window.location.href : void 0
|
|
171
|
-
);
|
|
172
208
|
_react.useEffect.call(void 0, () => {
|
|
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 = _react.useMemo.call(void 0, () => _optionalChain([location, 'optionalAccess', _5 => _5.href]), [_optionalChain([location, 'optionalAccess', _6 => _6.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 (_optionalChain([walletStatus, 'optionalAccess', _ => _.key]) === "connected") {
|
|
208
|
-
url.searchParams.set("nexusContext", _optionalChain([walletStatus, 'optionalAccess', _2 => _2.wallet]));
|
|
209
|
-
}
|
|
210
|
-
if (_optionalChain([walletStatus, 'optionalAccess', _3 => _3.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 } = _reactquery.useQuery.call(void 0, {
|
|
230
|
+
queryKey: ["nexus-sdk", "context", _nullishCoalesce(_optionalChain([location, 'optionalAccess', _7 => _7.href]), () => ( "no-href"))],
|
|
231
|
+
queryFn: async () => {
|
|
232
|
+
if (!_optionalChain([location, 'optionalAccess', _8 => _8.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 _chunkV3S6RBRJcjs.decompressJson.call(void 0, nexusContext2);
|
|
237
|
+
if (!parsedContext) return null;
|
|
238
|
+
return parsedContext;
|
|
215
239
|
},
|
|
216
|
-
[
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
240
|
+
enabled: !!_optionalChain([location, 'optionalAccess', _9 => _9.href])
|
|
241
|
+
});
|
|
242
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = _reactquery.useMutation.call(void 0, {
|
|
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 _chunkV3S6RBRJcjs.compressJson.call(void 0, 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 = _react.useCallback.call(void 0, async () => {
|
|
274
|
+
try {
|
|
275
|
+
const currentWallet = await ensureWalletConnected();
|
|
276
|
+
if (!_optionalChain([nexusContext, 'optionalAccess', _10 => _10.r])) {
|
|
277
|
+
if (currentWallet) {
|
|
278
|
+
await updateContextAsync({ r: currentWallet });
|
|
279
|
+
}
|
|
280
|
+
return "no-referrer";
|
|
281
|
+
}
|
|
282
|
+
if (currentWallet && _viem.isAddressEqual.call(void 0, nexusContext.r, currentWallet)) {
|
|
283
|
+
return "self-referral";
|
|
284
|
+
}
|
|
285
|
+
const interaction = _chunkIQQTTKJLcjs.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
|
+
} = _reactquery.useQuery.call(void 0, {
|
|
232
308
|
gcTime: 0,
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
309
|
+
staleTime: 0,
|
|
310
|
+
queryKey: [
|
|
311
|
+
"nexus-sdk",
|
|
312
|
+
"auto-referral-interaction",
|
|
313
|
+
_nullishCoalesce(_optionalChain([nexusContext, 'optionalAccess', _11 => _11.r]), () => ( "no-referrer")),
|
|
314
|
+
_nullishCoalesce(_optionalChain([walletStatus, 'optionalAccess', _12 => _12.key]), () => ( "no-wallet-status"))
|
|
315
|
+
],
|
|
316
|
+
queryFn: processReferral,
|
|
317
|
+
enabled: !!walletStatus
|
|
318
|
+
});
|
|
319
|
+
return _react.useMemo.call(void 0, () => {
|
|
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 _react.useCallback.call(void 0, async () => {
|
|
331
|
+
if (_optionalChain([walletStatus, 'optionalAccess', _13 => _13.key]) !== "connected" || !walletStatus.interactionSession) {
|
|
332
|
+
if (!modalConfig) {
|
|
333
|
+
return void 0;
|
|
237
334
|
}
|
|
238
|
-
|
|
239
|
-
|
|
335
|
+
const result = await displayModal2(modalConfig);
|
|
336
|
+
return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _14 => _14.login, 'optionalAccess', _15 => _15.wallet]), () => ( void 0));
|
|
337
|
+
}
|
|
338
|
+
return _nullishCoalesce(walletStatus.wallet, () => ( void 0));
|
|
339
|
+
}, [walletStatus, modalConfig, displayModal2]);
|
|
340
|
+
}
|
|
341
|
+
function mapErrorToState(error) {
|
|
342
|
+
if (error instanceof _chunkV3S6RBRJcjs.FrakRpcError) {
|
|
343
|
+
switch (error.code) {
|
|
344
|
+
case _chunkV3S6RBRJcjs.RpcErrorCodes.walletNotConnected:
|
|
345
|
+
return "no-wallet";
|
|
346
|
+
case _chunkV3S6RBRJcjs.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
|
+
|
|
357
|
+
function useOpenSso({ mutations } = {}) {
|
|
358
|
+
const client = useNexusClient();
|
|
359
|
+
return _reactquery.useMutation.call(void 0, {
|
|
360
|
+
...mutations,
|
|
361
|
+
mutationKey: ["nexus-sdk", "open-sso"],
|
|
362
|
+
mutationFn: async (params) => {
|
|
363
|
+
if (!client) {
|
|
364
|
+
throw new (0, _chunkV3S6RBRJcjs.ClientNotFound)();
|
|
240
365
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
{ contentId, walletAddress: referrerAddress },
|
|
244
|
-
newStatusUpdated
|
|
245
|
-
);
|
|
246
|
-
return { key: "waiting-response" };
|
|
247
|
-
},
|
|
248
|
-
enabled: !!contentId && !!referrerAddress && _optionalChain([walletStatus, 'optionalAccess', _9 => _9.key]) !== void 0 && _optionalChain([walletStatus, 'optionalAccess', _10 => _10.key]) !== "waiting-response"
|
|
366
|
+
return _chunkS5FVCA2Ecjs.openSso.call(void 0, client, params);
|
|
367
|
+
}
|
|
249
368
|
});
|
|
250
369
|
}
|
|
251
370
|
|
|
@@ -254,34 +373,25 @@ var NexusIFrameClientContext = _react.createContext.call(void 0,
|
|
|
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 = _react.useMemo.call(void 0,
|
|
264
|
-
() => iframeElem ? _chunkAYZHGMEVcjs.createIFrameNexusClient.call(void 0, { iframe: iframeElem, config }) : void 0,
|
|
265
|
-
[iframeElem, config]
|
|
266
|
-
);
|
|
380
|
+
const [client, setClient] = _react.useState.call(void 0, void 0);
|
|
267
381
|
const iFrame = _react.createElement.call(void 0, "iframe", {
|
|
268
|
-
|
|
269
|
-
name: "nexus-wallet",
|
|
382
|
+
..._chunkV3S6RBRJcjs.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: _nullishCoalesce(style, () => ( _chunkV3S6RBRJcjs.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
|
+
_chunkV3S6RBRJcjs.createIFrameNexusClient.call(void 0, {
|
|
391
|
+
iframe,
|
|
392
|
+
config
|
|
393
|
+
})
|
|
394
|
+
);
|
|
285
395
|
}
|
|
286
396
|
});
|
|
287
397
|
const providerComponent = _react.createElement.call(void 0,
|
|
@@ -302,4 +412,7 @@ function NexusIFrameClientProvider({
|
|
|
302
412
|
|
|
303
413
|
|
|
304
414
|
|
|
305
|
-
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
exports.NexusConfigContext = NexusConfigContext; exports.NexusConfigProvider = NexusConfigProvider; exports.NexusIFrameClientContext = NexusIFrameClientContext; exports.NexusIFrameClientProvider = NexusIFrameClientProvider; exports.useDisplayModal = useDisplayModal; exports.useNexusClient = useNexusClient; exports.useNexusConfig = useNexusConfig; exports.useOpenSso = useOpenSso; exports.useReferralInteraction = useReferralInteraction; exports.useSendInteraction = useSendInteraction; exports.useSendTransactionAction = useSendTransactionAction; exports.useSiweAuthenticate = useSiweAuthenticate; exports.useWalletStatus = useWalletStatus;
|