@frak-labs/nexus-sdk 0.0.7 → 0.0.9
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/README.md +7 -6
- package/dist/{chunk-JXQKTLEE.cjs → chunk-AYZHGMEV.cjs} +14 -14
- package/dist/{chunk-DI2REDPX.js → chunk-PDR3CF3P.js} +19 -11
- package/dist/{chunk-OXP3VK26.js → chunk-SZUN32YC.js} +1 -1
- package/dist/{chunk-5QWG35A2.js → chunk-VK7GPKK4.js} +9 -0
- package/dist/{chunk-3LF3FGI6.cjs → chunk-X4JNNWJ4.cjs} +23 -15
- package/dist/{chunk-2XUJYDD3.cjs → chunk-ZOLP2FJZ.cjs} +9 -0
- package/dist/{client-DWLJ8zR-.d.ts → client-BwzXSgqQ.d.cts} +32 -3
- package/dist/{client-DWLJ8zR-.d.cts → client-BwzXSgqQ.d.ts} +32 -3
- package/dist/core/actions/index.cjs +5 -3
- package/dist/core/actions/index.d.cts +21 -5
- package/dist/core/actions/index.d.ts +21 -5
- package/dist/core/actions/index.js +4 -2
- package/dist/core/index.cjs +3 -3
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +2 -2
- package/dist/react/index.cjs +148 -18
- package/dist/react/index.d.cts +25 -11
- package/dist/react/index.d.ts +25 -11
- package/dist/react/index.js +146 -16
- package/dist/{watchUnlockStatus-B4kRztOM.d.cts → watchUnlockStatus-DXClCYH9.d.cts} +8 -3
- package/dist/{watchUnlockStatus--7dFtOJr.d.ts → watchUnlockStatus-WJxoDliF.d.ts} +8 -3
- package/package.json +2 -2
package/dist/react/index.cjs
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
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
|
|
3
|
+
var _chunkAYZHGMEVcjs = require('../chunk-AYZHGMEV.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
require('../chunk-
|
|
8
|
+
|
|
9
|
+
var _chunkX4JNNWJ4cjs = require('../chunk-X4JNNWJ4.cjs');
|
|
10
|
+
require('../chunk-ZOLP2FJZ.cjs');
|
|
10
11
|
|
|
11
12
|
// src/react/provider/NexusConfigProvider.ts
|
|
12
13
|
var _react = require('react');
|
|
@@ -51,17 +52,23 @@ function useNexusClient() {
|
|
|
51
52
|
|
|
52
53
|
// src/react/hook/useArticleUnlockOptions.ts
|
|
53
54
|
var _reactquery = require('@tanstack/react-query');
|
|
54
|
-
function useArticleUnlockOptions({
|
|
55
|
+
function useArticleUnlockOptions({
|
|
56
|
+
articleId,
|
|
57
|
+
contentId
|
|
58
|
+
}) {
|
|
55
59
|
const client = useNexusClient();
|
|
56
60
|
return _reactquery.useQuery.call(void 0, {
|
|
57
61
|
queryKey: ["articleUnlockOptions", _nullishCoalesce(articleId, () => ( "no-article-id"))],
|
|
58
62
|
queryFn: async () => {
|
|
59
|
-
if (!articleId) {
|
|
63
|
+
if (!(articleId && contentId)) {
|
|
60
64
|
throw new Error("No article id provided");
|
|
61
65
|
}
|
|
62
|
-
return await
|
|
66
|
+
return await _chunkX4JNNWJ4cjs.getArticleUnlockOptions.call(void 0, client, {
|
|
67
|
+
articleId,
|
|
68
|
+
contentId
|
|
69
|
+
});
|
|
63
70
|
},
|
|
64
|
-
enabled: !!articleId,
|
|
71
|
+
enabled: !!articleId && !!contentId,
|
|
65
72
|
gcTime: 0
|
|
66
73
|
});
|
|
67
74
|
}
|
|
@@ -82,7 +89,7 @@ function useWalletStatus() {
|
|
|
82
89
|
gcTime: 0,
|
|
83
90
|
queryKey: ["walletStatusListener"],
|
|
84
91
|
queryFn: async () => {
|
|
85
|
-
await
|
|
92
|
+
await _chunkX4JNNWJ4cjs.watchWalletStatus.call(void 0, client, newStatusUpdated);
|
|
86
93
|
return { key: "waiting-response" };
|
|
87
94
|
}
|
|
88
95
|
});
|
|
@@ -91,32 +98,154 @@ function useWalletStatus() {
|
|
|
91
98
|
// src/react/hook/useArticleUnlockStatus.ts
|
|
92
99
|
|
|
93
100
|
|
|
94
|
-
function useArticleUnlockStatus({
|
|
101
|
+
function useArticleUnlockStatus({
|
|
102
|
+
articleId,
|
|
103
|
+
contentId
|
|
104
|
+
}) {
|
|
95
105
|
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
96
106
|
const client = useNexusClient();
|
|
97
107
|
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
98
108
|
(event) => {
|
|
99
109
|
queryClient.setQueryData(
|
|
100
|
-
[
|
|
110
|
+
[
|
|
111
|
+
"articleUnlockStatusListener",
|
|
112
|
+
_nullishCoalesce(articleId, () => ( "no-article-id")),
|
|
113
|
+
_nullishCoalesce(contentId, () => ( "no-contentId-id"))
|
|
114
|
+
],
|
|
101
115
|
event
|
|
102
116
|
);
|
|
103
117
|
},
|
|
104
|
-
[articleId, queryClient]
|
|
118
|
+
[articleId, contentId, queryClient]
|
|
105
119
|
);
|
|
106
120
|
return _reactquery.useQuery.call(void 0, {
|
|
107
|
-
queryKey: [
|
|
121
|
+
queryKey: [
|
|
122
|
+
"articleUnlockStatusListener",
|
|
123
|
+
_nullishCoalesce(articleId, () => ( "no-article-id")),
|
|
124
|
+
_nullishCoalesce(contentId, () => ( "no-contentId-id"))
|
|
125
|
+
],
|
|
108
126
|
gcTime: 0,
|
|
109
127
|
queryFn: async () => {
|
|
110
|
-
if (!articleId) {
|
|
128
|
+
if (!(articleId && contentId)) {
|
|
111
129
|
return null;
|
|
112
130
|
}
|
|
113
|
-
await
|
|
131
|
+
await _chunkX4JNNWJ4cjs.watchUnlockStatus.call(void 0,
|
|
132
|
+
client,
|
|
133
|
+
{ articleId, contentId },
|
|
134
|
+
newStatusUpdated
|
|
135
|
+
);
|
|
114
136
|
return {
|
|
115
137
|
status: "waiting-response",
|
|
116
138
|
key: "waiting-response"
|
|
117
139
|
};
|
|
118
140
|
},
|
|
119
|
-
enabled: !!articleId
|
|
141
|
+
enabled: !!articleId && !!contentId
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/react/hook/useNexusReferral.ts
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
var _viem = require('viem');
|
|
149
|
+
|
|
150
|
+
// src/react/hook/useWindowLocation.ts
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
// src/react/hook/useMounted.ts
|
|
154
|
+
|
|
155
|
+
function useMounted() {
|
|
156
|
+
const [mounted, setMounted] = _react.useState.call(void 0, false);
|
|
157
|
+
_react.useEffect.call(void 0, () => {
|
|
158
|
+
setMounted(true);
|
|
159
|
+
}, []);
|
|
160
|
+
return mounted;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/react/hook/useWindowLocation.ts
|
|
164
|
+
var useWindowLocation = () => {
|
|
165
|
+
const isMounted = useMounted();
|
|
166
|
+
const [location, setLocation] = _react.useState.call(void 0,
|
|
167
|
+
isMounted ? window.location : void 0
|
|
168
|
+
);
|
|
169
|
+
const [href, setHref] = _react.useState.call(void 0,
|
|
170
|
+
isMounted ? window.location.href : void 0
|
|
171
|
+
);
|
|
172
|
+
_react.useEffect.call(void 0, () => {
|
|
173
|
+
if (!isMounted)
|
|
174
|
+
return;
|
|
175
|
+
const setWindowLocation = () => {
|
|
176
|
+
setLocation(window.location);
|
|
177
|
+
setHref(window.location.href);
|
|
178
|
+
};
|
|
179
|
+
if (!location) {
|
|
180
|
+
setWindowLocation();
|
|
181
|
+
}
|
|
182
|
+
window.addEventListener("popstate", setWindowLocation);
|
|
183
|
+
return () => {
|
|
184
|
+
window.removeEventListener("popstate", setWindowLocation);
|
|
185
|
+
};
|
|
186
|
+
}, [isMounted, location]);
|
|
187
|
+
return { location, href };
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/react/hook/useNexusReferral.ts
|
|
191
|
+
function useNexusReferral({ contentId }) {
|
|
192
|
+
const { href } = useWindowLocation();
|
|
193
|
+
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
194
|
+
const client = useNexusClient();
|
|
195
|
+
const { data: walletStatus } = useWalletStatus();
|
|
196
|
+
const [referrerAddress, setReferrerAddress] = _react.useState.call(void 0, );
|
|
197
|
+
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
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 (_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
|
+
}
|
|
215
|
+
},
|
|
216
|
+
[queryClient, href, walletStatus]
|
|
217
|
+
);
|
|
218
|
+
_react.useEffect.call(void 0, () => {
|
|
219
|
+
if (!href)
|
|
220
|
+
return;
|
|
221
|
+
const url = new URL(href);
|
|
222
|
+
const context = url.searchParams.get("nexusContext");
|
|
223
|
+
if (!context && _optionalChain([walletStatus, 'optionalAccess', _4 => _4.key]) === "connected") {
|
|
224
|
+
url.searchParams.set("nexusContext", _optionalChain([walletStatus, 'optionalAccess', _5 => _5.wallet]));
|
|
225
|
+
window.history.replaceState(null, "", url.toString());
|
|
226
|
+
}
|
|
227
|
+
if (context) {
|
|
228
|
+
setReferrerAddress(context);
|
|
229
|
+
}
|
|
230
|
+
}, [href, walletStatus]);
|
|
231
|
+
return _reactquery.useQuery.call(void 0, {
|
|
232
|
+
gcTime: 0,
|
|
233
|
+
queryKey: ["setUserReferredQueryReturnTypeListener"],
|
|
234
|
+
queryFn: async () => {
|
|
235
|
+
if (!(contentId && referrerAddress)) {
|
|
236
|
+
return { key: "no-referrer" };
|
|
237
|
+
}
|
|
238
|
+
if (_optionalChain([walletStatus, 'optionalAccess', _6 => _6.key]) === "connected" && _optionalChain([walletStatus, 'optionalAccess', _7 => _7.wallet]) && _viem.isAddressEqual.call(void 0, _optionalChain([walletStatus, 'optionalAccess', _8 => _8.wallet]), referrerAddress)) {
|
|
239
|
+
return { key: "same-wallet" };
|
|
240
|
+
}
|
|
241
|
+
await _chunkX4JNNWJ4cjs.setUserReferred.call(void 0,
|
|
242
|
+
client,
|
|
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"
|
|
120
249
|
});
|
|
121
250
|
}
|
|
122
251
|
|
|
@@ -132,7 +261,7 @@ function NexusIFrameClientProvider({
|
|
|
132
261
|
void 0
|
|
133
262
|
);
|
|
134
263
|
const client = _react.useMemo.call(void 0,
|
|
135
|
-
() => iframeElem ?
|
|
264
|
+
() => iframeElem ? _chunkAYZHGMEVcjs.createIFrameNexusClient.call(void 0, { iframe: iframeElem, config }) : void 0,
|
|
136
265
|
[iframeElem, config]
|
|
137
266
|
);
|
|
138
267
|
const iFrame = _react.createElement.call(void 0, "iframe", {
|
|
@@ -172,4 +301,5 @@ function NexusIFrameClientProvider({
|
|
|
172
301
|
|
|
173
302
|
|
|
174
303
|
|
|
175
|
-
|
|
304
|
+
|
|
305
|
+
exports.NexusConfigContext = NexusConfigContext; exports.NexusConfigProvider = NexusConfigProvider; exports.NexusIFrameClientContext = NexusIFrameClientContext; exports.NexusIFrameClientProvider = NexusIFrameClientProvider; exports.useArticleUnlockOptions = useArticleUnlockOptions; exports.useArticleUnlockStatus = useArticleUnlockStatus; exports.useNexusClient = useNexusClient; exports.useNexusConfig = useNexusConfig; exports.useNexusReferral = useNexusReferral; exports.useWalletStatus = useWalletStatus;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
-
import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType } from '../client-
|
|
3
|
+
import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType, e as SetUserReferredParams, c as SetUserReferredReturnType } from '../client-BwzXSgqQ.cjs';
|
|
4
4
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
|
-
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-
|
|
5
|
+
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-DXClCYH9.cjs';
|
|
6
6
|
import 'viem';
|
|
7
7
|
import 'viem/chains';
|
|
8
8
|
|
|
@@ -11,8 +11,9 @@ import 'viem/chains';
|
|
|
11
11
|
*/
|
|
12
12
|
declare const NexusConfigContext: react.Context<Readonly<{
|
|
13
13
|
walletUrl: string;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
metadata: {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
16
17
|
}> | undefined>;
|
|
17
18
|
/**
|
|
18
19
|
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
@@ -27,8 +28,9 @@ type NexusConfigProviderProps = {
|
|
|
27
28
|
*/
|
|
28
29
|
declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigProviderProps>): react.FunctionComponentElement<react.ProviderProps<Readonly<{
|
|
29
30
|
walletUrl: string;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
metadata: {
|
|
32
|
+
name: string;
|
|
33
|
+
};
|
|
32
34
|
}> | undefined>>;
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -58,8 +60,9 @@ declare function NexusIFrameClientProvider({ children, }: {
|
|
|
58
60
|
*/
|
|
59
61
|
declare function useNexusConfig(): Readonly<{
|
|
60
62
|
walletUrl: string;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
metadata: {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
63
66
|
}>;
|
|
64
67
|
|
|
65
68
|
/**
|
|
@@ -70,7 +73,8 @@ declare function useNexusClient(): NexusClient;
|
|
|
70
73
|
/**
|
|
71
74
|
* Hook used to get the unlock options for an article
|
|
72
75
|
*/
|
|
73
|
-
declare function useArticleUnlockOptions({ articleId }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
76
|
+
declare function useArticleUnlockOptions({ articleId, contentId, }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
77
|
+
frkBalanceAsHex?: `0x${string}` | undefined;
|
|
74
78
|
prices: {
|
|
75
79
|
index: number;
|
|
76
80
|
unlockDurationInSec: number;
|
|
@@ -94,6 +98,16 @@ type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
|
|
|
94
98
|
/**
|
|
95
99
|
* Hooks used to listen to the current article unlock status
|
|
96
100
|
*/
|
|
97
|
-
declare function useArticleUnlockStatus({ articleId }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
|
|
101
|
+
declare function useArticleUnlockStatus({ articleId, contentId, }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
|
|
98
102
|
|
|
99
|
-
|
|
103
|
+
type SetUserReferredQueryReturnType = SetUserReferredReturnType | {
|
|
104
|
+
key: "waiting-response";
|
|
105
|
+
} | {
|
|
106
|
+
key: "no-referrer";
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Use the current nexus referral
|
|
110
|
+
*/
|
|
111
|
+
declare function useNexusReferral({ contentId }: SetUserReferredParams): _tanstack_react_query.UseQueryResult<SetUserReferredQueryReturnType, Error>;
|
|
112
|
+
|
|
113
|
+
export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, useNexusReferral, useWalletStatus };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { PropsWithChildren, ReactNode } from 'react';
|
|
3
|
-
import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType } from '../client-
|
|
3
|
+
import { a as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, A as ArticleUnlockStatusReturnType, e as SetUserReferredParams, c as SetUserReferredReturnType } from '../client-BwzXSgqQ.js';
|
|
4
4
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
|
-
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus
|
|
5
|
+
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-WJxoDliF.js';
|
|
6
6
|
import 'viem';
|
|
7
7
|
import 'viem/chains';
|
|
8
8
|
|
|
@@ -11,8 +11,9 @@ import 'viem/chains';
|
|
|
11
11
|
*/
|
|
12
12
|
declare const NexusConfigContext: react.Context<Readonly<{
|
|
13
13
|
walletUrl: string;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
metadata: {
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
16
17
|
}> | undefined>;
|
|
17
18
|
/**
|
|
18
19
|
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
@@ -27,8 +28,9 @@ type NexusConfigProviderProps = {
|
|
|
27
28
|
*/
|
|
28
29
|
declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigProviderProps>): react.FunctionComponentElement<react.ProviderProps<Readonly<{
|
|
29
30
|
walletUrl: string;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
metadata: {
|
|
32
|
+
name: string;
|
|
33
|
+
};
|
|
32
34
|
}> | undefined>>;
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -58,8 +60,9 @@ declare function NexusIFrameClientProvider({ children, }: {
|
|
|
58
60
|
*/
|
|
59
61
|
declare function useNexusConfig(): Readonly<{
|
|
60
62
|
walletUrl: string;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
metadata: {
|
|
64
|
+
name: string;
|
|
65
|
+
};
|
|
63
66
|
}>;
|
|
64
67
|
|
|
65
68
|
/**
|
|
@@ -70,7 +73,8 @@ declare function useNexusClient(): NexusClient;
|
|
|
70
73
|
/**
|
|
71
74
|
* Hook used to get the unlock options for an article
|
|
72
75
|
*/
|
|
73
|
-
declare function useArticleUnlockOptions({ articleId }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
76
|
+
declare function useArticleUnlockOptions({ articleId, contentId, }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
77
|
+
frkBalanceAsHex?: `0x${string}` | undefined;
|
|
74
78
|
prices: {
|
|
75
79
|
index: number;
|
|
76
80
|
unlockDurationInSec: number;
|
|
@@ -94,6 +98,16 @@ type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
|
|
|
94
98
|
/**
|
|
95
99
|
* Hooks used to listen to the current article unlock status
|
|
96
100
|
*/
|
|
97
|
-
declare function useArticleUnlockStatus({ articleId }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
|
|
101
|
+
declare function useArticleUnlockStatus({ articleId, contentId, }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
|
|
98
102
|
|
|
99
|
-
|
|
103
|
+
type SetUserReferredQueryReturnType = SetUserReferredReturnType | {
|
|
104
|
+
key: "waiting-response";
|
|
105
|
+
} | {
|
|
106
|
+
key: "no-referrer";
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Use the current nexus referral
|
|
110
|
+
*/
|
|
111
|
+
declare function useNexusReferral({ contentId }: SetUserReferredParams): _tanstack_react_query.UseQueryResult<SetUserReferredQueryReturnType, Error>;
|
|
112
|
+
|
|
113
|
+
export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, useNexusReferral, useWalletStatus };
|
package/dist/react/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createIFrameNexusClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-SZUN32YC.js";
|
|
4
4
|
import {
|
|
5
5
|
getArticleUnlockOptions,
|
|
6
|
+
setUserReferred,
|
|
6
7
|
watchUnlockStatus,
|
|
7
8
|
watchWalletStatus
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-PDR3CF3P.js";
|
|
10
|
+
import "../chunk-VK7GPKK4.js";
|
|
10
11
|
|
|
11
12
|
// src/react/provider/NexusConfigProvider.ts
|
|
12
13
|
import { createContext, createElement } from "react";
|
|
@@ -26,7 +27,7 @@ import {
|
|
|
26
27
|
createContext as createContext2,
|
|
27
28
|
createElement as createElement2,
|
|
28
29
|
useMemo,
|
|
29
|
-
useState
|
|
30
|
+
useState as useState4
|
|
30
31
|
} from "react";
|
|
31
32
|
|
|
32
33
|
// src/react/hook/useNexusConfig.ts
|
|
@@ -51,17 +52,23 @@ function useNexusClient() {
|
|
|
51
52
|
|
|
52
53
|
// src/react/hook/useArticleUnlockOptions.ts
|
|
53
54
|
import { useQuery } from "@tanstack/react-query";
|
|
54
|
-
function useArticleUnlockOptions({
|
|
55
|
+
function useArticleUnlockOptions({
|
|
56
|
+
articleId,
|
|
57
|
+
contentId
|
|
58
|
+
}) {
|
|
55
59
|
const client = useNexusClient();
|
|
56
60
|
return useQuery({
|
|
57
61
|
queryKey: ["articleUnlockOptions", articleId ?? "no-article-id"],
|
|
58
62
|
queryFn: async () => {
|
|
59
|
-
if (!articleId) {
|
|
63
|
+
if (!(articleId && contentId)) {
|
|
60
64
|
throw new Error("No article id provided");
|
|
61
65
|
}
|
|
62
|
-
return await getArticleUnlockOptions(client, {
|
|
66
|
+
return await getArticleUnlockOptions(client, {
|
|
67
|
+
articleId,
|
|
68
|
+
contentId
|
|
69
|
+
});
|
|
63
70
|
},
|
|
64
|
-
enabled: !!articleId,
|
|
71
|
+
enabled: !!articleId && !!contentId,
|
|
65
72
|
gcTime: 0
|
|
66
73
|
});
|
|
67
74
|
}
|
|
@@ -91,32 +98,154 @@ function useWalletStatus() {
|
|
|
91
98
|
// src/react/hook/useArticleUnlockStatus.ts
|
|
92
99
|
import { useQuery as useQuery3, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
93
100
|
import { useCallback as useCallback2 } from "react";
|
|
94
|
-
function useArticleUnlockStatus({
|
|
101
|
+
function useArticleUnlockStatus({
|
|
102
|
+
articleId,
|
|
103
|
+
contentId
|
|
104
|
+
}) {
|
|
95
105
|
const queryClient = useQueryClient2();
|
|
96
106
|
const client = useNexusClient();
|
|
97
107
|
const newStatusUpdated = useCallback2(
|
|
98
108
|
(event) => {
|
|
99
109
|
queryClient.setQueryData(
|
|
100
|
-
[
|
|
110
|
+
[
|
|
111
|
+
"articleUnlockStatusListener",
|
|
112
|
+
articleId ?? "no-article-id",
|
|
113
|
+
contentId ?? "no-contentId-id"
|
|
114
|
+
],
|
|
101
115
|
event
|
|
102
116
|
);
|
|
103
117
|
},
|
|
104
|
-
[articleId, queryClient]
|
|
118
|
+
[articleId, contentId, queryClient]
|
|
105
119
|
);
|
|
106
120
|
return useQuery3({
|
|
107
|
-
queryKey: [
|
|
121
|
+
queryKey: [
|
|
122
|
+
"articleUnlockStatusListener",
|
|
123
|
+
articleId ?? "no-article-id",
|
|
124
|
+
contentId ?? "no-contentId-id"
|
|
125
|
+
],
|
|
108
126
|
gcTime: 0,
|
|
109
127
|
queryFn: async () => {
|
|
110
|
-
if (!articleId) {
|
|
128
|
+
if (!(articleId && contentId)) {
|
|
111
129
|
return null;
|
|
112
130
|
}
|
|
113
|
-
await watchUnlockStatus(
|
|
131
|
+
await watchUnlockStatus(
|
|
132
|
+
client,
|
|
133
|
+
{ articleId, contentId },
|
|
134
|
+
newStatusUpdated
|
|
135
|
+
);
|
|
114
136
|
return {
|
|
115
137
|
status: "waiting-response",
|
|
116
138
|
key: "waiting-response"
|
|
117
139
|
};
|
|
118
140
|
},
|
|
119
|
-
enabled: !!articleId
|
|
141
|
+
enabled: !!articleId && !!contentId
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
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";
|
|
148
|
+
import { isAddressEqual } from "viem";
|
|
149
|
+
|
|
150
|
+
// src/react/hook/useWindowLocation.ts
|
|
151
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
152
|
+
|
|
153
|
+
// src/react/hook/useMounted.ts
|
|
154
|
+
import { useEffect, useState } from "react";
|
|
155
|
+
function useMounted() {
|
|
156
|
+
const [mounted, setMounted] = useState(false);
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
setMounted(true);
|
|
159
|
+
}, []);
|
|
160
|
+
return mounted;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// src/react/hook/useWindowLocation.ts
|
|
164
|
+
var useWindowLocation = () => {
|
|
165
|
+
const isMounted = useMounted();
|
|
166
|
+
const [location, setLocation] = useState2(
|
|
167
|
+
isMounted ? window.location : void 0
|
|
168
|
+
);
|
|
169
|
+
const [href, setHref] = useState2(
|
|
170
|
+
isMounted ? window.location.href : void 0
|
|
171
|
+
);
|
|
172
|
+
useEffect2(() => {
|
|
173
|
+
if (!isMounted)
|
|
174
|
+
return;
|
|
175
|
+
const setWindowLocation = () => {
|
|
176
|
+
setLocation(window.location);
|
|
177
|
+
setHref(window.location.href);
|
|
178
|
+
};
|
|
179
|
+
if (!location) {
|
|
180
|
+
setWindowLocation();
|
|
181
|
+
}
|
|
182
|
+
window.addEventListener("popstate", setWindowLocation);
|
|
183
|
+
return () => {
|
|
184
|
+
window.removeEventListener("popstate", setWindowLocation);
|
|
185
|
+
};
|
|
186
|
+
}, [isMounted, location]);
|
|
187
|
+
return { location, href };
|
|
188
|
+
};
|
|
189
|
+
|
|
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());
|
|
226
|
+
}
|
|
227
|
+
if (context) {
|
|
228
|
+
setReferrerAddress(context);
|
|
229
|
+
}
|
|
230
|
+
}, [href, walletStatus]);
|
|
231
|
+
return useQuery4({
|
|
232
|
+
gcTime: 0,
|
|
233
|
+
queryKey: ["setUserReferredQueryReturnTypeListener"],
|
|
234
|
+
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" };
|
|
240
|
+
}
|
|
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"
|
|
120
249
|
});
|
|
121
250
|
}
|
|
122
251
|
|
|
@@ -128,7 +257,7 @@ function NexusIFrameClientProvider({
|
|
|
128
257
|
children
|
|
129
258
|
}) {
|
|
130
259
|
const config = useNexusConfig();
|
|
131
|
-
const [iframeElem, setIframeElem] =
|
|
260
|
+
const [iframeElem, setIframeElem] = useState4(
|
|
132
261
|
void 0
|
|
133
262
|
);
|
|
134
263
|
const client = useMemo(
|
|
@@ -171,5 +300,6 @@ export {
|
|
|
171
300
|
useArticleUnlockStatus,
|
|
172
301
|
useNexusClient,
|
|
173
302
|
useNexusConfig,
|
|
303
|
+
useNexusReferral,
|
|
174
304
|
useWalletStatus
|
|
175
305
|
};
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { Hex } from 'viem';
|
|
2
|
-
import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-
|
|
2
|
+
import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-BwzXSgqQ.cjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Type used to get the unlock options
|
|
6
6
|
*/
|
|
7
7
|
type GetUnlockOptionsParams = {
|
|
8
8
|
articleId: Hex;
|
|
9
|
+
contentId: Hex;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* Function used to fetch the unlock option for the given client
|
|
12
13
|
* @param client
|
|
13
14
|
* @param articleId
|
|
15
|
+
* @param contentId
|
|
14
16
|
*/
|
|
15
|
-
declare function getArticleUnlockOptions(client: NexusClient, { articleId }: GetUnlockOptionsParams): Promise<Readonly<{
|
|
17
|
+
declare function getArticleUnlockOptions(client: NexusClient, { articleId, contentId }: GetUnlockOptionsParams): Promise<Readonly<{
|
|
18
|
+
frkBalanceAsHex?: `0x${string}` | undefined;
|
|
16
19
|
prices: {
|
|
17
20
|
index: number;
|
|
18
21
|
unlockDurationInSec: number;
|
|
@@ -26,13 +29,15 @@ declare function getArticleUnlockOptions(client: NexusClient, { articleId }: Get
|
|
|
26
29
|
*/
|
|
27
30
|
type WatchUnlockStatusParams = {
|
|
28
31
|
articleId: Hex;
|
|
32
|
+
contentId: Hex;
|
|
29
33
|
};
|
|
30
34
|
/**
|
|
31
35
|
* Function used to watch a current article unlock status
|
|
32
36
|
* @param client
|
|
33
37
|
* @param articleId
|
|
38
|
+
* @param contentId
|
|
34
39
|
* @param callback
|
|
35
40
|
*/
|
|
36
|
-
declare function watchUnlockStatus(client: NexusClient, { articleId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
|
|
41
|
+
declare function watchUnlockStatus(client: NexusClient, { articleId, contentId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
|
|
37
42
|
|
|
38
43
|
export { type GetUnlockOptionsParams as G, type WatchUnlockStatusParams as W, getArticleUnlockOptions as g, watchUnlockStatus as w };
|