@frak-labs/nexus-sdk 0.0.2-alpha → 0.0.4
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-4X75PGSK.cjs → chunk-2XUJYDD3.cjs} +4 -4
- package/dist/chunk-3LF3FGI6.cjs +78 -0
- package/dist/{chunk-JE64MPH2.js → chunk-5QWG35A2.js} +4 -4
- package/dist/chunk-DI2REDPX.js +78 -0
- package/dist/chunk-JXQKTLEE.cjs +171 -0
- package/dist/chunk-OXP3VK26.js +171 -0
- package/dist/{client-SCwoh_kP.d.cts → client-gnNyzrko.d.cts} +9 -7
- package/dist/{client-SCwoh_kP.d.ts → client-gnNyzrko.d.ts} +9 -7
- package/dist/core/actions/index.cjs +3 -65
- package/dist/core/actions/index.d.cts +6 -39
- package/dist/core/actions/index.d.ts +6 -39
- package/dist/core/actions/index.js +7 -69
- package/dist/core/index.cjs +22 -179
- package/dist/core/index.d.cts +7 -7
- package/dist/core/index.d.ts +7 -7
- package/dist/core/index.js +5 -162
- package/dist/react/index.cjs +169 -0
- package/dist/react/index.d.cts +99 -0
- package/dist/react/index.d.ts +99 -0
- package/dist/react/index.js +169 -0
- package/dist/watchUnlockStatus-Btjg-WTs.d.ts +38 -0
- package/dist/watchUnlockStatus-DvDS55TN.d.cts +38 -0
- package/package.json +10 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createIFrameNexusClient
|
|
3
|
+
} from "../chunk-OXP3VK26.js";
|
|
4
|
+
import {
|
|
5
|
+
getArticleUnlockOptions,
|
|
6
|
+
watchUnlockStatus,
|
|
7
|
+
watchWalletStatus
|
|
8
|
+
} from "../chunk-DI2REDPX.js";
|
|
9
|
+
import "../chunk-5QWG35A2.js";
|
|
10
|
+
|
|
11
|
+
// src/react/provider/NexusConfigProvider.ts
|
|
12
|
+
import { createContext, createElement } from "react";
|
|
13
|
+
var NexusConfigContext = createContext(void 0);
|
|
14
|
+
function NexusConfigProvider(parameters) {
|
|
15
|
+
const { children, config } = parameters;
|
|
16
|
+
return createElement(
|
|
17
|
+
NexusConfigContext.Provider,
|
|
18
|
+
{ value: config },
|
|
19
|
+
children
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/react/provider/NexusIFrameClientProvider.ts
|
|
24
|
+
import {
|
|
25
|
+
Fragment,
|
|
26
|
+
createContext as createContext2,
|
|
27
|
+
createElement as createElement2,
|
|
28
|
+
useMemo,
|
|
29
|
+
useState
|
|
30
|
+
} from "react";
|
|
31
|
+
|
|
32
|
+
// src/react/hook/useNexusConfig.ts
|
|
33
|
+
import { useContext } from "react";
|
|
34
|
+
function useNexusConfig() {
|
|
35
|
+
const config = useContext(NexusConfigContext);
|
|
36
|
+
if (!config) {
|
|
37
|
+
throw new Error("NexusConfigProvider is not found");
|
|
38
|
+
}
|
|
39
|
+
return config;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// src/react/hook/useNexusClient.ts
|
|
43
|
+
import { useContext as useContext2 } from "react";
|
|
44
|
+
function useNexusClient() {
|
|
45
|
+
const client = useContext2(NexusIFrameClientContext);
|
|
46
|
+
if (!client) {
|
|
47
|
+
throw new Error("NexusIFrameClientProvider is not found");
|
|
48
|
+
}
|
|
49
|
+
return client;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/react/hook/useArticleUnlockOptions.ts
|
|
53
|
+
import { useQuery } from "@tanstack/react-query";
|
|
54
|
+
function useArticleUnlockOptions({ articleId }) {
|
|
55
|
+
const client = useNexusClient();
|
|
56
|
+
return useQuery({
|
|
57
|
+
queryKey: ["articleUnlockOptions", articleId ?? "no-article-id"],
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
if (!articleId) {
|
|
60
|
+
throw new Error("No article id provided");
|
|
61
|
+
}
|
|
62
|
+
return await getArticleUnlockOptions(client, { articleId });
|
|
63
|
+
},
|
|
64
|
+
enabled: !!articleId
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/react/hook/useWalletStatus.ts
|
|
69
|
+
import { useQuery as useQuery2, useQueryClient } from "@tanstack/react-query";
|
|
70
|
+
import { useCallback } from "react";
|
|
71
|
+
function useWalletStatus() {
|
|
72
|
+
const queryClient = useQueryClient();
|
|
73
|
+
const client = useNexusClient();
|
|
74
|
+
const newStatusUpdated = useCallback(
|
|
75
|
+
(event) => {
|
|
76
|
+
queryClient.setQueryData(["walletStatusListener"], event);
|
|
77
|
+
},
|
|
78
|
+
[queryClient]
|
|
79
|
+
);
|
|
80
|
+
return useQuery2({
|
|
81
|
+
queryKey: ["walletStatusListener"],
|
|
82
|
+
queryFn: async () => {
|
|
83
|
+
await watchWalletStatus(client, newStatusUpdated);
|
|
84
|
+
return { key: "waiting-response" };
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/react/hook/useArticleUnlockStatus.ts
|
|
90
|
+
import { useQuery as useQuery3, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
91
|
+
import { useCallback as useCallback2 } from "react";
|
|
92
|
+
function useArticleUnlockStatus({ articleId }) {
|
|
93
|
+
const queryClient = useQueryClient2();
|
|
94
|
+
const client = useNexusClient();
|
|
95
|
+
const newStatusUpdated = useCallback2(
|
|
96
|
+
(event) => {
|
|
97
|
+
queryClient.setQueryData(
|
|
98
|
+
["articleUnlockStatusListener", articleId ?? "no-article-id"],
|
|
99
|
+
event
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
[articleId, queryClient]
|
|
103
|
+
);
|
|
104
|
+
return useQuery3({
|
|
105
|
+
queryKey: ["articleUnlockStatusListener", articleId ?? "no-article-id"],
|
|
106
|
+
queryFn: async () => {
|
|
107
|
+
await watchUnlockStatus(client, { articleId }, newStatusUpdated);
|
|
108
|
+
return {
|
|
109
|
+
status: "waiting-response",
|
|
110
|
+
key: "waiting-response"
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
enabled: !!articleId
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/react/provider/NexusIFrameClientProvider.ts
|
|
118
|
+
var NexusIFrameClientContext = createContext2(
|
|
119
|
+
void 0
|
|
120
|
+
);
|
|
121
|
+
function NexusIFrameClientProvider({
|
|
122
|
+
children
|
|
123
|
+
}) {
|
|
124
|
+
const config = useNexusConfig();
|
|
125
|
+
const [iframeElem, setIframElem] = useState(
|
|
126
|
+
void 0
|
|
127
|
+
);
|
|
128
|
+
const client = useMemo(
|
|
129
|
+
() => iframeElem ? createIFrameNexusClient({ iframe: iframeElem, config }) : void 0,
|
|
130
|
+
[iframeElem, config]
|
|
131
|
+
);
|
|
132
|
+
const iFrame = createElement2("iframe", {
|
|
133
|
+
id: "nexus-wallet",
|
|
134
|
+
name: "nexus-wallet",
|
|
135
|
+
src: `${config.walletUrl}/listener`,
|
|
136
|
+
style: {
|
|
137
|
+
width: "0",
|
|
138
|
+
height: "0",
|
|
139
|
+
border: "0",
|
|
140
|
+
position: "absolute",
|
|
141
|
+
top: "-1000px",
|
|
142
|
+
left: "-1000px"
|
|
143
|
+
},
|
|
144
|
+
ref: (iframe) => {
|
|
145
|
+
if (!iframe) {
|
|
146
|
+
setIframElem(void 0);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
setIframElem(iframe);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const providerComponent = createElement2(
|
|
153
|
+
NexusIFrameClientContext.Provider,
|
|
154
|
+
{ value: client },
|
|
155
|
+
children
|
|
156
|
+
);
|
|
157
|
+
return createElement2(Fragment, null, iFrame, providerComponent);
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
NexusConfigContext,
|
|
161
|
+
NexusConfigProvider,
|
|
162
|
+
NexusIFrameClientContext,
|
|
163
|
+
NexusIFrameClientProvider,
|
|
164
|
+
useArticleUnlockOptions,
|
|
165
|
+
useArticleUnlockStatus,
|
|
166
|
+
useNexusClient,
|
|
167
|
+
useNexusConfig,
|
|
168
|
+
useWalletStatus
|
|
169
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-gnNyzrko.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type used to get the unlock options
|
|
6
|
+
*/
|
|
7
|
+
type GetUnlockOptionsParams = {
|
|
8
|
+
articleId: Hex;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to fetch the unlock option for the given client
|
|
12
|
+
* @param client
|
|
13
|
+
* @param articleId
|
|
14
|
+
*/
|
|
15
|
+
declare function getArticleUnlockOptions(client: NexusClient, { articleId }: GetUnlockOptionsParams): Promise<Readonly<{
|
|
16
|
+
prices: {
|
|
17
|
+
index: number;
|
|
18
|
+
unlockDurationInSec: number;
|
|
19
|
+
frkAmount: `0x${string}`;
|
|
20
|
+
isUserAccessible: boolean | null;
|
|
21
|
+
}[];
|
|
22
|
+
}>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type used to get the unlock options
|
|
26
|
+
*/
|
|
27
|
+
type WatchUnlockStatusParams = {
|
|
28
|
+
articleId: Hex;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Function used to watch a current article unlock status
|
|
32
|
+
* @param client
|
|
33
|
+
* @param articleId
|
|
34
|
+
* @param callback
|
|
35
|
+
*/
|
|
36
|
+
declare function watchUnlockStatus(client: NexusClient, { articleId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
|
|
37
|
+
|
|
38
|
+
export { type GetUnlockOptionsParams as G, type WatchUnlockStatusParams as W, getArticleUnlockOptions as g, watchUnlockStatus as w };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Hex } from 'viem';
|
|
2
|
+
import { N as NexusClient, A as ArticleUnlockStatusReturnType } from './client-gnNyzrko.cjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Type used to get the unlock options
|
|
6
|
+
*/
|
|
7
|
+
type GetUnlockOptionsParams = {
|
|
8
|
+
articleId: Hex;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to fetch the unlock option for the given client
|
|
12
|
+
* @param client
|
|
13
|
+
* @param articleId
|
|
14
|
+
*/
|
|
15
|
+
declare function getArticleUnlockOptions(client: NexusClient, { articleId }: GetUnlockOptionsParams): Promise<Readonly<{
|
|
16
|
+
prices: {
|
|
17
|
+
index: number;
|
|
18
|
+
unlockDurationInSec: number;
|
|
19
|
+
frkAmount: `0x${string}`;
|
|
20
|
+
isUserAccessible: boolean | null;
|
|
21
|
+
}[];
|
|
22
|
+
}>>;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Type used to get the unlock options
|
|
26
|
+
*/
|
|
27
|
+
type WatchUnlockStatusParams = {
|
|
28
|
+
articleId: Hex;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Function used to watch a current article unlock status
|
|
32
|
+
* @param client
|
|
33
|
+
* @param articleId
|
|
34
|
+
* @param callback
|
|
35
|
+
*/
|
|
36
|
+
declare function watchUnlockStatus(client: NexusClient, { articleId }: WatchUnlockStatusParams, callback: (status: ArticleUnlockStatusReturnType) => void): Promise<void>;
|
|
37
|
+
|
|
38
|
+
export { type GetUnlockOptionsParams as G, type WatchUnlockStatusParams as W, getArticleUnlockOptions as g, watchUnlockStatus as w };
|
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.4",
|
|
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",
|
|
@@ -48,6 +48,11 @@
|
|
|
48
48
|
"types": "./dist/core/actions/index.d.ts",
|
|
49
49
|
"import": "./dist/core/actions/index.js",
|
|
50
50
|
"default": "./dist/core/actions/index.cjs"
|
|
51
|
+
},
|
|
52
|
+
"./react": {
|
|
53
|
+
"types": "./dist/react/index.d.ts",
|
|
54
|
+
"import": "./dist/react/index.js",
|
|
55
|
+
"default": "./dist/react/index.cjs"
|
|
51
56
|
}
|
|
52
57
|
},
|
|
53
58
|
"scripts": {
|
|
@@ -58,13 +63,16 @@
|
|
|
58
63
|
"build": "tsup --splitting"
|
|
59
64
|
},
|
|
60
65
|
"peerDependencies": {
|
|
61
|
-
"viem": "^2.
|
|
66
|
+
"viem": "^2.x",
|
|
67
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
68
|
+
"react": ">=18"
|
|
62
69
|
},
|
|
63
70
|
"dependencies": {
|
|
64
71
|
"async-lz-string": "^1.1.0",
|
|
65
72
|
"js-sha256": "^0.11.0"
|
|
66
73
|
},
|
|
67
74
|
"devDependencies": {
|
|
75
|
+
"@tanstack/react-query": ">=5.0.0",
|
|
68
76
|
"@types/node": "^20",
|
|
69
77
|
"tsup": "^8.0.2",
|
|
70
78
|
"typescript": "^5"
|