@frak-labs/nexus-sdk 0.0.3-alpha → 0.0.6
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-N4N55SQ6.cjs → chunk-2XUJYDD3.cjs} +2 -2
- package/dist/chunk-3LF3FGI6.cjs +78 -0
- package/dist/{chunk-6ZFDRVV6.js → chunk-5QWG35A2.js} +2 -2
- package/dist/chunk-DI2REDPX.js +78 -0
- package/dist/chunk-JXQKTLEE.cjs +171 -0
- package/dist/chunk-OXP3VK26.js +171 -0
- package/dist/{client-CkvisXxD.d.cts → client-DWLJ8zR-.d.cts} +10 -7
- package/dist/{client-CkvisXxD.d.ts → client-DWLJ8zR-.d.ts} +10 -7
- package/dist/core/actions/index.cjs +3 -65
- package/dist/core/actions/index.d.cts +4 -37
- package/dist/core/actions/index.d.ts +4 -37
- package/dist/core/actions/index.js +7 -69
- package/dist/core/index.cjs +22 -179
- package/dist/core/index.d.cts +3 -3
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +4 -161
- 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--7dFtOJr.d.ts +38 -0
- package/dist/watchUnlockStatus-B4kRztOM.d.cts +38 -0
- package/package.json +10 -2
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkJXQKTLEEcjs = require('../chunk-JXQKTLEE.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunk3LF3FGI6cjs = require('../chunk-3LF3FGI6.cjs');
|
|
9
|
+
require('../chunk-2XUJYDD3.cjs');
|
|
10
|
+
|
|
11
|
+
// src/react/provider/NexusConfigProvider.ts
|
|
12
|
+
var _react = require('react');
|
|
13
|
+
var NexusConfigContext = _react.createContext.call(void 0, void 0);
|
|
14
|
+
function NexusConfigProvider(parameters) {
|
|
15
|
+
const { children, config } = parameters;
|
|
16
|
+
return _react.createElement.call(void 0,
|
|
17
|
+
NexusConfigContext.Provider,
|
|
18
|
+
{ value: config },
|
|
19
|
+
children
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// src/react/provider/NexusIFrameClientProvider.ts
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// src/react/hook/useNexusConfig.ts
|
|
33
|
+
|
|
34
|
+
function useNexusConfig() {
|
|
35
|
+
const config = _react.useContext.call(void 0, 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
|
+
|
|
44
|
+
function useNexusClient() {
|
|
45
|
+
const client = _react.useContext.call(void 0, 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
|
+
var _reactquery = require('@tanstack/react-query');
|
|
54
|
+
function useArticleUnlockOptions({ articleId }) {
|
|
55
|
+
const client = useNexusClient();
|
|
56
|
+
return _reactquery.useQuery.call(void 0, {
|
|
57
|
+
queryKey: ["articleUnlockOptions", _nullishCoalesce(articleId, () => ( "no-article-id"))],
|
|
58
|
+
queryFn: async () => {
|
|
59
|
+
if (!articleId) {
|
|
60
|
+
throw new Error("No article id provided");
|
|
61
|
+
}
|
|
62
|
+
return await _chunk3LF3FGI6cjs.getArticleUnlockOptions.call(void 0, client, { articleId });
|
|
63
|
+
},
|
|
64
|
+
enabled: !!articleId
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// src/react/hook/useWalletStatus.ts
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
function useWalletStatus() {
|
|
72
|
+
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
73
|
+
const client = useNexusClient();
|
|
74
|
+
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
75
|
+
(event) => {
|
|
76
|
+
queryClient.setQueryData(["walletStatusListener"], event);
|
|
77
|
+
},
|
|
78
|
+
[queryClient]
|
|
79
|
+
);
|
|
80
|
+
return _reactquery.useQuery.call(void 0, {
|
|
81
|
+
queryKey: ["walletStatusListener"],
|
|
82
|
+
queryFn: async () => {
|
|
83
|
+
await _chunk3LF3FGI6cjs.watchWalletStatus.call(void 0, client, newStatusUpdated);
|
|
84
|
+
return { key: "waiting-response" };
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// src/react/hook/useArticleUnlockStatus.ts
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
function useArticleUnlockStatus({ articleId }) {
|
|
93
|
+
const queryClient = _reactquery.useQueryClient.call(void 0, );
|
|
94
|
+
const client = useNexusClient();
|
|
95
|
+
const newStatusUpdated = _react.useCallback.call(void 0,
|
|
96
|
+
(event) => {
|
|
97
|
+
queryClient.setQueryData(
|
|
98
|
+
["articleUnlockStatusListener", _nullishCoalesce(articleId, () => ( "no-article-id"))],
|
|
99
|
+
event
|
|
100
|
+
);
|
|
101
|
+
},
|
|
102
|
+
[articleId, queryClient]
|
|
103
|
+
);
|
|
104
|
+
return _reactquery.useQuery.call(void 0, {
|
|
105
|
+
queryKey: ["articleUnlockStatusListener", _nullishCoalesce(articleId, () => ( "no-article-id"))],
|
|
106
|
+
queryFn: async () => {
|
|
107
|
+
await _chunk3LF3FGI6cjs.watchUnlockStatus.call(void 0, 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 = _react.createContext.call(void 0,
|
|
119
|
+
void 0
|
|
120
|
+
);
|
|
121
|
+
function NexusIFrameClientProvider({
|
|
122
|
+
children
|
|
123
|
+
}) {
|
|
124
|
+
const config = useNexusConfig();
|
|
125
|
+
const [iframeElem, setIframeElem] = _react.useState.call(void 0,
|
|
126
|
+
void 0
|
|
127
|
+
);
|
|
128
|
+
const client = _react.useMemo.call(void 0,
|
|
129
|
+
() => iframeElem ? _chunkJXQKTLEEcjs.createIFrameNexusClient.call(void 0, { iframe: iframeElem, config }) : void 0,
|
|
130
|
+
[iframeElem, config]
|
|
131
|
+
);
|
|
132
|
+
const iFrame = _react.createElement.call(void 0, "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
|
+
setIframeElem(void 0);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
setIframeElem(iframe);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
const providerComponent = _react.createElement.call(void 0,
|
|
153
|
+
NexusIFrameClientContext.Provider,
|
|
154
|
+
{ value: client },
|
|
155
|
+
children
|
|
156
|
+
);
|
|
157
|
+
return _react.createElement.call(void 0, _react.Fragment, null, iFrame, providerComponent);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
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.useWalletStatus = useWalletStatus;
|
|
@@ -0,0 +1,99 @@
|
|
|
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-DWLJ8zR-.cjs';
|
|
4
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
|
+
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-B4kRztOM.cjs';
|
|
6
|
+
import 'viem';
|
|
7
|
+
import 'viem/chains';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The context that will keep the Nexus Wallet SDK configuration
|
|
11
|
+
*/
|
|
12
|
+
declare const NexusConfigContext: react.Context<Readonly<{
|
|
13
|
+
walletUrl: string;
|
|
14
|
+
contentId: `0x${string}`;
|
|
15
|
+
contentTitle: string;
|
|
16
|
+
}> | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
19
|
+
*/
|
|
20
|
+
type NexusConfigProviderProps = {
|
|
21
|
+
config: NexusWalletSdkConfig;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Simple config provider for the Nexus Wallet SDK
|
|
25
|
+
* @param parameters
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigProviderProps>): react.FunctionComponentElement<react.ProviderProps<Readonly<{
|
|
29
|
+
walletUrl: string;
|
|
30
|
+
contentId: `0x${string}`;
|
|
31
|
+
contentTitle: string;
|
|
32
|
+
}> | undefined>>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The context that will keep the Nexus Wallet SDK client
|
|
36
|
+
*/
|
|
37
|
+
declare const NexusIFrameClientContext: react.Context<NexusClient | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
40
|
+
*/
|
|
41
|
+
type NexusIFrameClientProps = {
|
|
42
|
+
config: NexusWalletSdkConfig;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* IFrame client provider for the Nexus Wallet SDK
|
|
46
|
+
* - Automatically set the config provider
|
|
47
|
+
* @param parameters
|
|
48
|
+
* @constructor
|
|
49
|
+
*/
|
|
50
|
+
declare function NexusIFrameClientProvider({ children, }: {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
}): react.FunctionComponentElement<{
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Use the current nexus config
|
|
58
|
+
*/
|
|
59
|
+
declare function useNexusConfig(): Readonly<{
|
|
60
|
+
walletUrl: string;
|
|
61
|
+
contentId: `0x${string}`;
|
|
62
|
+
contentTitle: string;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Use the current nexus iframe client
|
|
67
|
+
*/
|
|
68
|
+
declare function useNexusClient(): NexusClient;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Hook used to get the unlock options for an article
|
|
72
|
+
*/
|
|
73
|
+
declare function useArticleUnlockOptions({ articleId }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
74
|
+
prices: {
|
|
75
|
+
index: number;
|
|
76
|
+
unlockDurationInSec: number;
|
|
77
|
+
frkAmount: `0x${string}`;
|
|
78
|
+
isUserAccessible: boolean | null;
|
|
79
|
+
}[];
|
|
80
|
+
}>, Error>;
|
|
81
|
+
|
|
82
|
+
type WalletStatusQueryReturnType = WalletStatusReturnType | {
|
|
83
|
+
key: "waiting-response";
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Hooks used to listen to the current wallet status
|
|
87
|
+
*/
|
|
88
|
+
declare function useWalletStatus(): _tanstack_react_query.UseQueryResult<WalletStatusQueryReturnType, Error>;
|
|
89
|
+
|
|
90
|
+
type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
|
|
91
|
+
status: "waiting-response";
|
|
92
|
+
key: "waiting-response";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Hooks used to listen to the current article unlock status
|
|
96
|
+
*/
|
|
97
|
+
declare function useArticleUnlockStatus({ articleId }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType, Error>;
|
|
98
|
+
|
|
99
|
+
export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, useWalletStatus };
|
|
@@ -0,0 +1,99 @@
|
|
|
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-DWLJ8zR-.js';
|
|
4
|
+
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
|
+
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus--7dFtOJr.js';
|
|
6
|
+
import 'viem';
|
|
7
|
+
import 'viem/chains';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The context that will keep the Nexus Wallet SDK configuration
|
|
11
|
+
*/
|
|
12
|
+
declare const NexusConfigContext: react.Context<Readonly<{
|
|
13
|
+
walletUrl: string;
|
|
14
|
+
contentId: `0x${string}`;
|
|
15
|
+
contentTitle: string;
|
|
16
|
+
}> | undefined>;
|
|
17
|
+
/**
|
|
18
|
+
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
19
|
+
*/
|
|
20
|
+
type NexusConfigProviderProps = {
|
|
21
|
+
config: NexusWalletSdkConfig;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Simple config provider for the Nexus Wallet SDK
|
|
25
|
+
* @param parameters
|
|
26
|
+
* @constructor
|
|
27
|
+
*/
|
|
28
|
+
declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigProviderProps>): react.FunctionComponentElement<react.ProviderProps<Readonly<{
|
|
29
|
+
walletUrl: string;
|
|
30
|
+
contentId: `0x${string}`;
|
|
31
|
+
contentTitle: string;
|
|
32
|
+
}> | undefined>>;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* The context that will keep the Nexus Wallet SDK client
|
|
36
|
+
*/
|
|
37
|
+
declare const NexusIFrameClientContext: react.Context<NexusClient | undefined>;
|
|
38
|
+
/**
|
|
39
|
+
* Props to instantiate the Nexus Wallet SDK configuration provider
|
|
40
|
+
*/
|
|
41
|
+
type NexusIFrameClientProps = {
|
|
42
|
+
config: NexusWalletSdkConfig;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* IFrame client provider for the Nexus Wallet SDK
|
|
46
|
+
* - Automatically set the config provider
|
|
47
|
+
* @param parameters
|
|
48
|
+
* @constructor
|
|
49
|
+
*/
|
|
50
|
+
declare function NexusIFrameClientProvider({ children, }: {
|
|
51
|
+
children?: ReactNode;
|
|
52
|
+
}): react.FunctionComponentElement<{
|
|
53
|
+
children?: ReactNode;
|
|
54
|
+
}>;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Use the current nexus config
|
|
58
|
+
*/
|
|
59
|
+
declare function useNexusConfig(): Readonly<{
|
|
60
|
+
walletUrl: string;
|
|
61
|
+
contentId: `0x${string}`;
|
|
62
|
+
contentTitle: string;
|
|
63
|
+
}>;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Use the current nexus iframe client
|
|
67
|
+
*/
|
|
68
|
+
declare function useNexusClient(): NexusClient;
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Hook used to get the unlock options for an article
|
|
72
|
+
*/
|
|
73
|
+
declare function useArticleUnlockOptions({ articleId }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
74
|
+
prices: {
|
|
75
|
+
index: number;
|
|
76
|
+
unlockDurationInSec: number;
|
|
77
|
+
frkAmount: `0x${string}`;
|
|
78
|
+
isUserAccessible: boolean | null;
|
|
79
|
+
}[];
|
|
80
|
+
}>, Error>;
|
|
81
|
+
|
|
82
|
+
type WalletStatusQueryReturnType = WalletStatusReturnType | {
|
|
83
|
+
key: "waiting-response";
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* Hooks used to listen to the current wallet status
|
|
87
|
+
*/
|
|
88
|
+
declare function useWalletStatus(): _tanstack_react_query.UseQueryResult<WalletStatusQueryReturnType, Error>;
|
|
89
|
+
|
|
90
|
+
type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
|
|
91
|
+
status: "waiting-response";
|
|
92
|
+
key: "waiting-response";
|
|
93
|
+
};
|
|
94
|
+
/**
|
|
95
|
+
* Hooks used to listen to the current article unlock status
|
|
96
|
+
*/
|
|
97
|
+
declare function useArticleUnlockStatus({ articleId }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType, Error>;
|
|
98
|
+
|
|
99
|
+
export { type ArticleUnlockStatusQueryReturnType, NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, type WalletStatusQueryReturnType, useArticleUnlockOptions, useArticleUnlockStatus, useNexusClient, useNexusConfig, useWalletStatus };
|
|
@@ -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, setIframeElem] = 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
|
+
setIframeElem(void 0);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
setIframeElem(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-DWLJ8zR-.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-DWLJ8zR-.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.6",
|
|
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.28.6",
|
|
68
76
|
"@types/node": "^20",
|
|
69
77
|
"tsup": "^8.0.2",
|
|
70
78
|
"typescript": "^5"
|