@frak-labs/nexus-sdk 0.0.8 → 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.
- package/dist/chunk-3T2FNW6E.cjs +100 -0
- package/dist/chunk-72IEHEQX.js +48 -0
- package/dist/chunk-BPFJZRJ6.cjs +152 -0
- package/dist/chunk-ETV4XYOV.cjs +7 -0
- package/dist/{chunk-OXP3VK26.js → chunk-HOX3RRO6.js} +58 -30
- package/dist/chunk-NIFJZD3M.cjs +48 -0
- package/dist/chunk-PKBMQBKP.js +7 -0
- package/dist/{chunk-JXQKTLEE.cjs → chunk-SGLR6RFA.cjs} +59 -31
- package/dist/chunk-T54VMWHQ.js +100 -0
- package/dist/chunk-TPC5PMRC.js +152 -0
- package/dist/{client-MgLVRfPw.d.cts → client--U_6SK0l.d.cts} +101 -12
- package/dist/{client-MgLVRfPw.d.ts → client-6_BJp7Ub.d.ts} +101 -12
- package/dist/core/actions/index.cjs +10 -3
- package/dist/core/actions/index.d.cts +31 -3
- package/dist/core/actions/index.d.ts +31 -3
- package/dist/core/actions/index.js +9 -2
- package/dist/core/index.cjs +4 -7
- package/dist/core/index.d.cts +8 -35
- package/dist/core/index.d.ts +8 -35
- package/dist/core/index.js +9 -12
- package/dist/core/interactions/index.cjs +9 -0
- package/dist/core/interactions/index.d.cts +39 -0
- package/dist/core/interactions/index.d.ts +39 -0
- package/dist/core/interactions/index.js +9 -0
- package/dist/error-C4Zm5nQe.d.cts +27 -0
- package/dist/error-C4Zm5nQe.d.ts +27 -0
- package/dist/interaction-D_CzyqRE.d.cts +22 -0
- package/dist/interaction-D_CzyqRE.d.ts +22 -0
- package/dist/react/index.cjs +276 -42
- package/dist/react/index.d.cts +72 -12
- package/dist/react/index.d.ts +72 -12
- package/dist/react/index.js +272 -38
- package/dist/{watchUnlockStatus-DQYfUj46.d.ts → watchUnlockStatus-CxnibdQx.d.cts} +3 -3
- package/dist/{watchUnlockStatus-DqWkImYK.d.cts → watchUnlockStatus-g8wIxpeM.d.ts} +3 -3
- package/package.json +11 -5
- package/dist/chunk-2XUJYDD3.cjs +0 -160
- package/dist/chunk-4VFMYMTH.js +0 -74
- package/dist/chunk-5QWG35A2.js +0 -160
- package/dist/chunk-6V4UCVTD.cjs +0 -74
package/dist/react/index.d.ts
CHANGED
|
@@ -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 } from '../client-
|
|
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 {
|
|
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?:
|
|
88
|
+
frkBalanceAsHex?: viem.Hex;
|
|
78
89
|
prices: {
|
|
79
90
|
index: number;
|
|
80
91
|
unlockDurationInSec: number;
|
|
81
|
-
frkAmount:
|
|
92
|
+
frkAmount: viem.Hex;
|
|
82
93
|
isUserAccessible: boolean | null;
|
|
83
94
|
}[];
|
|
84
|
-
}
|
|
95
|
+
}> | undefined, Error>;
|
|
85
96
|
|
|
86
97
|
type WalletStatusQueryReturnType = WalletStatusReturnType | {
|
|
87
98
|
key: "waiting-response";
|
|
@@ -100,4 +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
|
-
|
|
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
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Send a user interaction
|
|
158
|
+
*/
|
|
159
|
+
declare function useSendInteraction({ mutations, }?: UseSendInteractionParams): _tanstack_react_query.UseMutationResult<Readonly<{
|
|
160
|
+
hash: viem.Hex;
|
|
161
|
+
}>, FrakRpcError<undefined>, SendInteractionParamsType, unknown>;
|
|
162
|
+
|
|
163
|
+
export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, usePressReferralInteraction, useSendInteraction, useSendTransactionAction, useSiweAuthenticate, useWalletStatus };
|
package/dist/react/index.js
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createIFrameNexusClient
|
|
3
|
-
} from "../chunk-
|
|
3
|
+
} from "../chunk-HOX3RRO6.js";
|
|
4
4
|
import {
|
|
5
5
|
getArticleUnlockOptions,
|
|
6
|
+
sendInteraction,
|
|
7
|
+
sendTransaction,
|
|
8
|
+
siweAuthenticate,
|
|
6
9
|
watchUnlockStatus,
|
|
7
10
|
watchWalletStatus
|
|
8
|
-
} from "../chunk-
|
|
9
|
-
import
|
|
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";
|
|
10
23
|
|
|
11
24
|
// src/react/provider/NexusConfigProvider.ts
|
|
12
25
|
import { createContext, createElement } from "react";
|
|
@@ -15,7 +28,12 @@ function NexusConfigProvider(parameters) {
|
|
|
15
28
|
const { children, config } = parameters;
|
|
16
29
|
return createElement(
|
|
17
30
|
NexusConfigContext.Provider,
|
|
18
|
-
{
|
|
31
|
+
{
|
|
32
|
+
value: {
|
|
33
|
+
...config,
|
|
34
|
+
domain: config.domain ?? (typeof window !== "undefined" ? window?.location?.host : void 0) ?? "not-found"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
19
37
|
children
|
|
20
38
|
);
|
|
21
39
|
}
|
|
@@ -25,8 +43,7 @@ import {
|
|
|
25
43
|
Fragment,
|
|
26
44
|
createContext as createContext2,
|
|
27
45
|
createElement as createElement2,
|
|
28
|
-
|
|
29
|
-
useState
|
|
46
|
+
useState as useState3
|
|
30
47
|
} from "react";
|
|
31
48
|
|
|
32
49
|
// src/react/hook/useNexusConfig.ts
|
|
@@ -34,7 +51,10 @@ import { useContext } from "react";
|
|
|
34
51
|
function useNexusConfig() {
|
|
35
52
|
const config = useContext(NexusConfigContext);
|
|
36
53
|
if (!config) {
|
|
37
|
-
throw new
|
|
54
|
+
throw new FrakRpcError(
|
|
55
|
+
RpcErrorCodes.configError,
|
|
56
|
+
"Nexus config not found"
|
|
57
|
+
);
|
|
38
58
|
}
|
|
39
59
|
return config;
|
|
40
60
|
}
|
|
@@ -42,11 +62,7 @@ function useNexusConfig() {
|
|
|
42
62
|
// src/react/hook/useNexusClient.ts
|
|
43
63
|
import { useContext as useContext2 } from "react";
|
|
44
64
|
function useNexusClient() {
|
|
45
|
-
|
|
46
|
-
if (!client) {
|
|
47
|
-
throw new Error("NexusIFrameClientProvider is not found");
|
|
48
|
-
}
|
|
49
|
-
return client;
|
|
65
|
+
return useContext2(NexusIFrameClientContext);
|
|
50
66
|
}
|
|
51
67
|
|
|
52
68
|
// src/react/hook/useArticleUnlockOptions.ts
|
|
@@ -57,8 +73,13 @@ function useArticleUnlockOptions({
|
|
|
57
73
|
}) {
|
|
58
74
|
const client = useNexusClient();
|
|
59
75
|
return useQuery({
|
|
60
|
-
queryKey: [
|
|
76
|
+
queryKey: [
|
|
77
|
+
"nexus-sdk",
|
|
78
|
+
"article-unlock-options",
|
|
79
|
+
articleId ?? "no-article-id"
|
|
80
|
+
],
|
|
61
81
|
queryFn: async () => {
|
|
82
|
+
if (!client) return;
|
|
62
83
|
if (!(articleId && contentId)) {
|
|
63
84
|
throw new Error("No article id provided");
|
|
64
85
|
}
|
|
@@ -67,7 +88,7 @@ function useArticleUnlockOptions({
|
|
|
67
88
|
contentId
|
|
68
89
|
});
|
|
69
90
|
},
|
|
70
|
-
enabled: !!articleId && !!contentId,
|
|
91
|
+
enabled: !!client && !!articleId && !!contentId,
|
|
71
92
|
gcTime: 0
|
|
72
93
|
});
|
|
73
94
|
}
|
|
@@ -80,17 +101,24 @@ function useWalletStatus() {
|
|
|
80
101
|
const client = useNexusClient();
|
|
81
102
|
const newStatusUpdated = useCallback(
|
|
82
103
|
(event) => {
|
|
83
|
-
queryClient.setQueryData(
|
|
104
|
+
queryClient.setQueryData(
|
|
105
|
+
["nexus-sdk", "wallet-status-listener"],
|
|
106
|
+
event
|
|
107
|
+
);
|
|
84
108
|
},
|
|
85
109
|
[queryClient]
|
|
86
110
|
);
|
|
87
111
|
return useQuery2({
|
|
88
112
|
gcTime: 0,
|
|
89
|
-
queryKey: ["
|
|
113
|
+
queryKey: ["nexus-sdk", "wallet-status-listener"],
|
|
90
114
|
queryFn: async () => {
|
|
115
|
+
if (!client) {
|
|
116
|
+
return { key: "waiting-response" };
|
|
117
|
+
}
|
|
91
118
|
await watchWalletStatus(client, newStatusUpdated);
|
|
92
119
|
return { key: "waiting-response" };
|
|
93
|
-
}
|
|
120
|
+
},
|
|
121
|
+
enabled: !!client
|
|
94
122
|
});
|
|
95
123
|
}
|
|
96
124
|
|
|
@@ -107,7 +135,8 @@ function useArticleUnlockStatus({
|
|
|
107
135
|
(event) => {
|
|
108
136
|
queryClient.setQueryData(
|
|
109
137
|
[
|
|
110
|
-
"
|
|
138
|
+
"nexus-sdk",
|
|
139
|
+
"article-unlock-status",
|
|
111
140
|
articleId ?? "no-article-id",
|
|
112
141
|
contentId ?? "no-contentId-id"
|
|
113
142
|
],
|
|
@@ -118,12 +147,19 @@ function useArticleUnlockStatus({
|
|
|
118
147
|
);
|
|
119
148
|
return useQuery3({
|
|
120
149
|
queryKey: [
|
|
121
|
-
"
|
|
150
|
+
"nexus-sdk",
|
|
151
|
+
"article-unlock-status",
|
|
122
152
|
articleId ?? "no-article-id",
|
|
123
153
|
contentId ?? "no-contentId-id"
|
|
124
154
|
],
|
|
125
155
|
gcTime: 0,
|
|
126
156
|
queryFn: async () => {
|
|
157
|
+
if (!client) {
|
|
158
|
+
return {
|
|
159
|
+
status: "waiting-response",
|
|
160
|
+
key: "waiting-response"
|
|
161
|
+
};
|
|
162
|
+
}
|
|
127
163
|
if (!(articleId && contentId)) {
|
|
128
164
|
return null;
|
|
129
165
|
}
|
|
@@ -137,43 +173,237 @@ function useArticleUnlockStatus({
|
|
|
137
173
|
key: "waiting-response"
|
|
138
174
|
};
|
|
139
175
|
},
|
|
140
|
-
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
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
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
|
+
}
|
|
141
217
|
});
|
|
142
218
|
}
|
|
143
219
|
|
|
220
|
+
// src/react/hook/helper/usePressReferralInteraction.ts
|
|
221
|
+
import { useQuery as useQuery5 } from "@tanstack/react-query";
|
|
222
|
+
import { useMemo as useMemo2 } from "react";
|
|
223
|
+
import { isAddressEqual } from "viem";
|
|
224
|
+
|
|
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";
|
|
245
|
+
|
|
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
|
|
250
|
+
import { useEffect, useState } from "react";
|
|
251
|
+
function useMounted() {
|
|
252
|
+
const [mounted, setMounted] = useState(false);
|
|
253
|
+
useEffect(() => {
|
|
254
|
+
setMounted(true);
|
|
255
|
+
}, []);
|
|
256
|
+
return mounted;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// src/react/hook/utils/useWindowLocation.ts
|
|
260
|
+
function useWindowLocation() {
|
|
261
|
+
const isMounted = useMounted();
|
|
262
|
+
const [location, setLocation] = useState2(
|
|
263
|
+
isMounted ? window.location : void 0
|
|
264
|
+
);
|
|
265
|
+
useEffect2(() => {
|
|
266
|
+
if (!isMounted) return;
|
|
267
|
+
function setWindowLocation() {
|
|
268
|
+
setLocation(window.location);
|
|
269
|
+
}
|
|
270
|
+
if (!location) {
|
|
271
|
+
setWindowLocation();
|
|
272
|
+
}
|
|
273
|
+
window.addEventListener("popstate", setWindowLocation);
|
|
274
|
+
return () => {
|
|
275
|
+
window.removeEventListener("popstate", setWindowLocation);
|
|
276
|
+
};
|
|
277
|
+
}, [isMounted, location]);
|
|
278
|
+
const href = useMemo(() => location?.href, [location?.href]);
|
|
279
|
+
return { location, href };
|
|
280
|
+
}
|
|
281
|
+
|
|
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;
|
|
296
|
+
}
|
|
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());
|
|
308
|
+
}
|
|
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({
|
|
319
|
+
gcTime: 0,
|
|
320
|
+
queryKey: [
|
|
321
|
+
"nexus-sdk",
|
|
322
|
+
"auto-press-referral-interaction",
|
|
323
|
+
nexusContext?.r ?? "no-referrer",
|
|
324
|
+
walletStatus?.key ?? "no-wallet-status"
|
|
325
|
+
],
|
|
326
|
+
queryFn: async () => {
|
|
327
|
+
if (!nexusContext && walletStatus?.key === "connected") {
|
|
328
|
+
await updateContextAsync({ r: walletStatus.wallet });
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
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
|
+
}
|
|
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]);
|
|
370
|
+
}
|
|
371
|
+
|
|
144
372
|
// src/react/provider/NexusIFrameClientProvider.ts
|
|
145
373
|
var NexusIFrameClientContext = createContext2(
|
|
146
374
|
void 0
|
|
147
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
|
+
};
|
|
148
385
|
function NexusIFrameClientProvider({
|
|
386
|
+
style,
|
|
149
387
|
children
|
|
150
388
|
}) {
|
|
151
389
|
const config = useNexusConfig();
|
|
152
|
-
const [
|
|
153
|
-
void 0
|
|
154
|
-
);
|
|
155
|
-
const client = useMemo(
|
|
156
|
-
() => iframeElem ? createIFrameNexusClient({ iframe: iframeElem, config }) : void 0,
|
|
157
|
-
[iframeElem, config]
|
|
158
|
-
);
|
|
390
|
+
const [client, setClient] = useState3(void 0);
|
|
159
391
|
const iFrame = createElement2("iframe", {
|
|
160
392
|
id: "nexus-wallet",
|
|
161
393
|
name: "nexus-wallet",
|
|
162
394
|
src: `${config.walletUrl}/listener`,
|
|
163
|
-
style:
|
|
164
|
-
|
|
165
|
-
height: "0",
|
|
166
|
-
border: "0",
|
|
167
|
-
position: "absolute",
|
|
168
|
-
top: "-1000px",
|
|
169
|
-
left: "-1000px"
|
|
170
|
-
},
|
|
395
|
+
style: style ?? defaultIframeStyle,
|
|
396
|
+
allow: "publickey-credentials-get *",
|
|
171
397
|
ref: (iframe) => {
|
|
172
|
-
if (!iframe) {
|
|
173
|
-
setIframeElem(void 0);
|
|
398
|
+
if (!iframe || client) {
|
|
174
399
|
return;
|
|
175
400
|
}
|
|
176
|
-
|
|
401
|
+
setClient(
|
|
402
|
+
createIFrameNexusClient({
|
|
403
|
+
iframe,
|
|
404
|
+
config
|
|
405
|
+
})
|
|
406
|
+
);
|
|
177
407
|
}
|
|
178
408
|
});
|
|
179
409
|
const providerComponent = createElement2(
|
|
@@ -192,5 +422,9 @@ export {
|
|
|
192
422
|
useArticleUnlockStatus,
|
|
193
423
|
useNexusClient,
|
|
194
424
|
useNexusConfig,
|
|
425
|
+
usePressReferralInteraction,
|
|
426
|
+
useSendInteraction,
|
|
427
|
+
useSendTransactionAction,
|
|
428
|
+
useSiweAuthenticate,
|
|
195
429
|
useWalletStatus
|
|
196
430
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
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--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?:
|
|
18
|
+
frkBalanceAsHex?: Hex;
|
|
19
19
|
prices: {
|
|
20
20
|
index: number;
|
|
21
21
|
unlockDurationInSec: number;
|
|
22
|
-
frkAmount:
|
|
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-
|
|
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?:
|
|
18
|
+
frkBalanceAsHex?: Hex;
|
|
19
19
|
prices: {
|
|
20
20
|
index: number;
|
|
21
21
|
unlockDurationInSec: number;
|
|
22
|
-
frkAmount:
|
|
22
|
+
frkAmount: Hex;
|
|
23
23
|
isUserAccessible: boolean | null;
|
|
24
24
|
}[];
|
|
25
25
|
}>>;
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"url": "https://twitter.com/QNivelais"
|
|
12
12
|
}
|
|
13
13
|
],
|
|
14
|
-
"version": "0.0.
|
|
14
|
+
"version": "0.0.10",
|
|
15
15
|
"description": "Nexus Wallet client SDK, helping any person to interact with the Frak wallet, and require the unlock of a premium article within the Frak ecosystem.",
|
|
16
16
|
"repository": "https://github.com/frak-id/wallet",
|
|
17
17
|
"homepage": "https://docs.frak.id/wallet-sdk",
|
|
@@ -49,6 +49,11 @@
|
|
|
49
49
|
"import": "./dist/core/actions/index.js",
|
|
50
50
|
"default": "./dist/core/actions/index.cjs"
|
|
51
51
|
},
|
|
52
|
+
"./interactions": {
|
|
53
|
+
"types": "./dist/core/interactions/index.d.ts",
|
|
54
|
+
"import": "./dist/core/interactions/index.js",
|
|
55
|
+
"default": "./dist/core/interactions/index.cjs"
|
|
56
|
+
},
|
|
52
57
|
"./react": {
|
|
53
58
|
"types": "./dist/react/index.d.ts",
|
|
54
59
|
"import": "./dist/react/index.js",
|
|
@@ -58,9 +63,10 @@
|
|
|
58
63
|
"scripts": {
|
|
59
64
|
"lint": "biome lint .",
|
|
60
65
|
"format:check": "biome check .",
|
|
61
|
-
"format": "biome check --
|
|
66
|
+
"format": "biome check --write .",
|
|
62
67
|
"clean": "rimraf dist",
|
|
63
|
-
"build": "tsup --splitting"
|
|
68
|
+
"build": "tsup --splitting",
|
|
69
|
+
"build:watch": "tsup --watch --splitting --format esm"
|
|
64
70
|
},
|
|
65
71
|
"peerDependencies": {
|
|
66
72
|
"viem": "^2.x",
|
|
@@ -72,9 +78,9 @@
|
|
|
72
78
|
"js-sha256": "^0.11.0"
|
|
73
79
|
},
|
|
74
80
|
"devDependencies": {
|
|
75
|
-
"@tanstack/react-query": ">=5.
|
|
81
|
+
"@tanstack/react-query": ">=5.49.2",
|
|
76
82
|
"@types/node": "^20",
|
|
77
|
-
"tsup": "^8.0
|
|
83
|
+
"tsup": "^8.1.0",
|
|
78
84
|
"typescript": "^5"
|
|
79
85
|
}
|
|
80
86
|
}
|