@frak-labs/nexus-sdk 0.0.10 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-5CFD5FM2.js +86 -0
- package/dist/chunk-BJ3CCN5P.cjs +424 -0
- package/dist/{chunk-72IEHEQX.js → chunk-GUDT2W6I.js} +32 -10
- package/dist/chunk-HXVDI2IY.js +424 -0
- package/dist/{chunk-NIFJZD3M.cjs → chunk-IQQTTKJL.cjs} +30 -8
- package/dist/chunk-S5FVCA2E.cjs +86 -0
- package/dist/client-B6_BIGc3.d.ts +357 -0
- package/dist/client-Oily5ph8.d.cts +357 -0
- package/dist/core/actions/index.cjs +2 -7
- package/dist/core/actions/index.d.cts +16 -35
- package/dist/core/actions/index.d.ts +16 -35
- package/dist/core/actions/index.js +5 -10
- package/dist/core/index.cjs +2 -4
- package/dist/core/index.d.cts +19 -19
- package/dist/core/index.d.ts +19 -19
- package/dist/core/index.js +2 -4
- package/dist/core/interactions/index.cjs +6 -2
- package/dist/core/interactions/index.d.cts +20 -6
- package/dist/core/interactions/index.d.ts +20 -6
- package/dist/core/interactions/index.js +7 -3
- package/dist/{interaction-D_CzyqRE.d.cts → interaction-D3-M3nBh.d.cts} +2 -2
- package/dist/{interaction-D_CzyqRE.d.ts → interaction-D3-M3nBh.d.ts} +2 -2
- package/dist/react/index.cjs +156 -158
- package/dist/react/index.d.cts +44 -51
- package/dist/react/index.d.ts +44 -51
- package/dist/react/index.js +162 -164
- package/dist/sendTransaction-BHqCq_9X.d.ts +30 -0
- package/dist/sendTransaction-BKKYEt8p.d.cts +30 -0
- package/package.json +8 -5
- package/dist/chunk-3T2FNW6E.cjs +0 -100
- package/dist/chunk-BPFJZRJ6.cjs +0 -152
- package/dist/chunk-HOX3RRO6.js +0 -199
- package/dist/chunk-SGLR6RFA.cjs +0 -199
- package/dist/chunk-T54VMWHQ.js +0 -100
- package/dist/chunk-TPC5PMRC.js +0 -152
- package/dist/client--U_6SK0l.d.cts +0 -339
- package/dist/client-6_BJp7Ub.d.ts +0 -339
- package/dist/watchUnlockStatus-CxnibdQx.d.cts +0 -43
- package/dist/watchUnlockStatus-g8wIxpeM.d.ts +0 -43
package/dist/react/index.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import { PropsWithChildren, CSSProperties, ReactNode } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { f as NexusWalletSdkConfig, N as NexusClient, W as WalletStatusReturnType, c as SendTransactionReturnType, a as SiweAuthenticateReturnType, D as DisplayModalParamsType, d as ModalStepTypes, e as ModalRpcStepsResultType, O as OpenSsoParamsType } from '../client-B6_BIGc3.js';
|
|
4
4
|
import * as _tanstack_react_query from '@tanstack/react-query';
|
|
5
5
|
import { UseMutationOptions } from '@tanstack/react-query';
|
|
6
6
|
import * as viem from 'viem';
|
|
7
7
|
import { Hex } from 'viem';
|
|
8
|
-
import { G as GetUnlockOptionsParams, W as WatchUnlockStatusParams } from '../watchUnlockStatus-g8wIxpeM.js';
|
|
9
8
|
import { F as FrakRpcError } from '../error-C4Zm5nQe.js';
|
|
10
|
-
import {
|
|
9
|
+
import { b as SendTransactionParams, S as SiweAuthenticateModalParams } from '../sendTransaction-BHqCq_9X.js';
|
|
10
|
+
import { S as SendInteractionParamsType, a as SendInteractionReturnType } from '../interaction-D3-M3nBh.js';
|
|
11
11
|
import 'viem/chains';
|
|
12
12
|
import 'viem/siwe';
|
|
13
13
|
|
|
@@ -18,6 +18,7 @@ declare const NexusConfigContext: react.Context<Readonly<{
|
|
|
18
18
|
walletUrl: string;
|
|
19
19
|
metadata: {
|
|
20
20
|
name: string;
|
|
21
|
+
css?: string;
|
|
21
22
|
};
|
|
22
23
|
domain: string;
|
|
23
24
|
}> | undefined>;
|
|
@@ -38,6 +39,7 @@ declare function NexusConfigProvider(parameters: PropsWithChildren<NexusConfigPr
|
|
|
38
39
|
walletUrl: string;
|
|
39
40
|
metadata: {
|
|
40
41
|
name: string;
|
|
42
|
+
css?: string;
|
|
41
43
|
};
|
|
42
44
|
domain: string;
|
|
43
45
|
}> | undefined>>;
|
|
@@ -72,6 +74,7 @@ declare function useNexusConfig(): Readonly<{
|
|
|
72
74
|
walletUrl: string;
|
|
73
75
|
metadata: {
|
|
74
76
|
name: string;
|
|
77
|
+
css?: string;
|
|
75
78
|
};
|
|
76
79
|
domain: string;
|
|
77
80
|
}>;
|
|
@@ -81,53 +84,25 @@ declare function useNexusConfig(): Readonly<{
|
|
|
81
84
|
*/
|
|
82
85
|
declare function useNexusClient(): NexusClient | undefined;
|
|
83
86
|
|
|
84
|
-
/**
|
|
85
|
-
* Hook used to get the unlock options for an article
|
|
86
|
-
*/
|
|
87
|
-
declare function useArticleUnlockOptions({ articleId, contentId, }: GetUnlockOptionsParams): _tanstack_react_query.UseQueryResult<Readonly<{
|
|
88
|
-
frkBalanceAsHex?: viem.Hex;
|
|
89
|
-
prices: {
|
|
90
|
-
index: number;
|
|
91
|
-
unlockDurationInSec: number;
|
|
92
|
-
frkAmount: viem.Hex;
|
|
93
|
-
isUserAccessible: boolean | null;
|
|
94
|
-
}[];
|
|
95
|
-
}> | undefined, Error>;
|
|
96
|
-
|
|
97
|
-
type WalletStatusQueryReturnType = WalletStatusReturnType | {
|
|
98
|
-
key: "waiting-response";
|
|
99
|
-
};
|
|
100
87
|
/**
|
|
101
88
|
* Hooks used to listen to the current wallet status
|
|
102
89
|
*/
|
|
103
|
-
declare function useWalletStatus(): _tanstack_react_query.UseQueryResult<
|
|
104
|
-
|
|
105
|
-
type ArticleUnlockStatusQueryReturnType = ArticleUnlockStatusReturnType | {
|
|
106
|
-
status: "waiting-response";
|
|
107
|
-
key: "waiting-response";
|
|
108
|
-
};
|
|
109
|
-
/**
|
|
110
|
-
* Hooks used to listen to the current article unlock status
|
|
111
|
-
*/
|
|
112
|
-
declare function useArticleUnlockStatus({ articleId, contentId, }: WatchUnlockStatusParams): _tanstack_react_query.UseQueryResult<ArticleUnlockStatusQueryReturnType | null, Error>;
|
|
90
|
+
declare function useWalletStatus(): _tanstack_react_query.UseQueryResult<WalletStatusReturnType, Error>;
|
|
113
91
|
|
|
114
|
-
type MutationOptions$
|
|
92
|
+
type MutationOptions$4 = Omit<UseMutationOptions<SendTransactionReturnType, FrakRpcError, SendTransactionParams>, "mutationFn" | "mutationKey">;
|
|
115
93
|
interface UseSendTransactionParams {
|
|
116
|
-
mutations?: MutationOptions$
|
|
94
|
+
mutations?: MutationOptions$4;
|
|
117
95
|
}
|
|
118
96
|
/**
|
|
119
97
|
* Trigger a dashboard action to the wallet
|
|
120
98
|
*/
|
|
121
99
|
declare function useSendTransactionAction({ mutations, }?: UseSendTransactionParams): _tanstack_react_query.UseMutationResult<Readonly<{
|
|
122
100
|
hash: viem.Hex;
|
|
123
|
-
}>, FrakRpcError<undefined>,
|
|
124
|
-
tx: SendTransactionTxType | SendTransactionTxType[];
|
|
125
|
-
context?: string;
|
|
126
|
-
}>, unknown>;
|
|
101
|
+
}>, FrakRpcError<undefined>, SendTransactionParams, unknown>;
|
|
127
102
|
|
|
128
|
-
type MutationOptions$
|
|
103
|
+
type MutationOptions$3 = Omit<UseMutationOptions<SiweAuthenticateReturnType, FrakRpcError, SiweAuthenticateModalParams>, "mutationFn" | "mutationKey">;
|
|
129
104
|
interface UseSiweAuthenticateParams {
|
|
130
|
-
mutations?: MutationOptions$
|
|
105
|
+
mutations?: MutationOptions$3;
|
|
131
106
|
}
|
|
132
107
|
/**
|
|
133
108
|
* Trigger a dashboard action to the wallet
|
|
@@ -135,29 +110,47 @@ interface UseSiweAuthenticateParams {
|
|
|
135
110
|
declare function useSiweAuthenticate({ mutations, }?: UseSiweAuthenticateParams): _tanstack_react_query.UseMutationResult<Readonly<{
|
|
136
111
|
signature: viem.Hex;
|
|
137
112
|
message: string;
|
|
138
|
-
}>, FrakRpcError<undefined>,
|
|
139
|
-
siwe?: Partial<SiweAuthenticationParams>;
|
|
140
|
-
context?: string;
|
|
141
|
-
}>, unknown>;
|
|
113
|
+
}>, FrakRpcError<undefined>, SiweAuthenticateModalParams, unknown>;
|
|
142
114
|
|
|
115
|
+
type ReferralState = "idle" | "processing" | "success" | "no-wallet" | "no-session" | "error" | "no-referrer" | "self-referral";
|
|
143
116
|
/**
|
|
144
|
-
* Helper hook to automatically submit a
|
|
117
|
+
* Helper hook to automatically submit a referral interaction when detected
|
|
145
118
|
* -> And automatically set the referral context in the url
|
|
146
119
|
* @param contentId
|
|
120
|
+
* @param modalConfig
|
|
147
121
|
*/
|
|
148
|
-
declare function
|
|
149
|
-
contentId
|
|
150
|
-
|
|
122
|
+
declare function useReferralInteraction({ contentId, modalConfig, }?: {
|
|
123
|
+
contentId?: Hex;
|
|
124
|
+
modalConfig?: DisplayModalParamsType<ModalStepTypes[]>;
|
|
125
|
+
}): ReferralState;
|
|
151
126
|
|
|
152
|
-
type MutationOptions = Omit<UseMutationOptions<SendInteractionReturnType, FrakRpcError, SendInteractionParamsType>, "mutationFn" | "mutationKey">;
|
|
153
|
-
interface UseSendInteractionParams {
|
|
154
|
-
mutations?: MutationOptions;
|
|
127
|
+
type MutationOptions$2 = Omit<UseMutationOptions<SendInteractionReturnType, FrakRpcError, SendInteractionParamsType>, "mutationFn" | "mutationKey">;
|
|
128
|
+
interface UseSendInteractionParams$1 {
|
|
129
|
+
mutations?: MutationOptions$2;
|
|
155
130
|
}
|
|
156
131
|
/**
|
|
157
132
|
* Send a user interaction
|
|
158
133
|
*/
|
|
159
|
-
declare function useSendInteraction({ mutations, }?: UseSendInteractionParams): _tanstack_react_query.UseMutationResult<Readonly<{
|
|
160
|
-
|
|
134
|
+
declare function useSendInteraction({ mutations, }?: UseSendInteractionParams$1): _tanstack_react_query.UseMutationResult<Readonly<{
|
|
135
|
+
delegationId: string;
|
|
161
136
|
}>, FrakRpcError<undefined>, SendInteractionParamsType, unknown>;
|
|
162
137
|
|
|
163
|
-
|
|
138
|
+
type MutationOptions$1<T extends ModalStepTypes[]> = Omit<UseMutationOptions<ModalRpcStepsResultType<T>, FrakRpcError, DisplayModalParamsType<T>>, "mutationFn" | "mutationKey">;
|
|
139
|
+
interface UseDisplayModalParams<T extends ModalStepTypes[] = ModalStepTypes[]> {
|
|
140
|
+
mutations?: MutationOptions$1<T>;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Send a user interaction
|
|
144
|
+
*/
|
|
145
|
+
declare function useDisplayModal<T extends ModalStepTypes[] = ModalStepTypes[]>({ mutations, }?: UseDisplayModalParams<T>): _tanstack_react_query.UseMutationResult<ModalRpcStepsResultType<T>, FrakRpcError<undefined>, DisplayModalParamsType<T>, unknown>;
|
|
146
|
+
|
|
147
|
+
type MutationOptions = Omit<UseMutationOptions<void, FrakRpcError, OpenSsoParamsType>, "mutationFn" | "mutationKey">;
|
|
148
|
+
interface UseSendInteractionParams {
|
|
149
|
+
mutations?: MutationOptions;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Open the SSO
|
|
153
|
+
*/
|
|
154
|
+
declare function useOpenSso({ mutations }?: UseSendInteractionParams): _tanstack_react_query.UseMutationResult<void, FrakRpcError<undefined>, OpenSsoParamsType, unknown>;
|
|
155
|
+
|
|
156
|
+
export { NexusConfigContext, NexusConfigProvider, type NexusConfigProviderProps, NexusIFrameClientContext, type NexusIFrameClientProps, NexusIFrameClientProvider, useDisplayModal, useNexusClient, useNexusConfig, useOpenSso, useReferralInteraction, useSendInteraction, useSendTransactionAction, useSiweAuthenticate, useWalletStatus };
|
package/dist/react/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createIFrameNexusClient
|
|
3
|
-
} from "../chunk-HOX3RRO6.js";
|
|
4
|
-
import {
|
|
5
|
-
getArticleUnlockOptions,
|
|
6
|
-
sendInteraction,
|
|
7
|
-
sendTransaction,
|
|
8
|
-
siweAuthenticate,
|
|
9
|
-
watchUnlockStatus,
|
|
10
|
-
watchWalletStatus
|
|
11
|
-
} from "../chunk-T54VMWHQ.js";
|
|
12
1
|
import {
|
|
13
2
|
ClientNotFound,
|
|
3
|
+
Deferred,
|
|
14
4
|
FrakRpcError,
|
|
15
5
|
RpcErrorCodes,
|
|
6
|
+
baseIframeProps,
|
|
16
7
|
compressJson,
|
|
8
|
+
createIFrameNexusClient,
|
|
17
9
|
decompressJson
|
|
18
|
-
} from "../chunk-
|
|
10
|
+
} from "../chunk-HXVDI2IY.js";
|
|
19
11
|
import {
|
|
20
|
-
|
|
21
|
-
|
|
12
|
+
displayModal,
|
|
13
|
+
openSso,
|
|
14
|
+
sendInteraction,
|
|
15
|
+
sendTransaction,
|
|
16
|
+
siweAuthenticate,
|
|
17
|
+
watchWalletStatus
|
|
18
|
+
} from "../chunk-5CFD5FM2.js";
|
|
19
|
+
import {
|
|
20
|
+
ReferralInteractionEncoder
|
|
21
|
+
} from "../chunk-GUDT2W6I.js";
|
|
22
22
|
import "../chunk-PKBMQBKP.js";
|
|
23
23
|
|
|
24
24
|
// src/react/provider/NexusConfigProvider.ts
|
|
@@ -65,36 +65,8 @@ function useNexusClient() {
|
|
|
65
65
|
return useContext2(NexusIFrameClientContext);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
// src/react/hook/useArticleUnlockOptions.ts
|
|
69
|
-
import { useQuery } from "@tanstack/react-query";
|
|
70
|
-
function useArticleUnlockOptions({
|
|
71
|
-
articleId,
|
|
72
|
-
contentId
|
|
73
|
-
}) {
|
|
74
|
-
const client = useNexusClient();
|
|
75
|
-
return useQuery({
|
|
76
|
-
queryKey: [
|
|
77
|
-
"nexus-sdk",
|
|
78
|
-
"article-unlock-options",
|
|
79
|
-
articleId ?? "no-article-id"
|
|
80
|
-
],
|
|
81
|
-
queryFn: async () => {
|
|
82
|
-
if (!client) return;
|
|
83
|
-
if (!(articleId && contentId)) {
|
|
84
|
-
throw new Error("No article id provided");
|
|
85
|
-
}
|
|
86
|
-
return await getArticleUnlockOptions(client, {
|
|
87
|
-
articleId,
|
|
88
|
-
contentId
|
|
89
|
-
});
|
|
90
|
-
},
|
|
91
|
-
enabled: !!client && !!articleId && !!contentId,
|
|
92
|
-
gcTime: 0
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
|
|
96
68
|
// src/react/hook/useWalletStatus.ts
|
|
97
|
-
import { useQuery
|
|
69
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
98
70
|
import { useCallback } from "react";
|
|
99
71
|
function useWalletStatus() {
|
|
100
72
|
const queryClient = useQueryClient();
|
|
@@ -108,75 +80,28 @@ function useWalletStatus() {
|
|
|
108
80
|
},
|
|
109
81
|
[queryClient]
|
|
110
82
|
);
|
|
111
|
-
return
|
|
83
|
+
return useQuery({
|
|
112
84
|
gcTime: 0,
|
|
113
85
|
queryKey: ["nexus-sdk", "wallet-status-listener"],
|
|
114
86
|
queryFn: async () => {
|
|
115
87
|
if (!client) {
|
|
116
|
-
|
|
88
|
+
throw new ClientNotFound();
|
|
117
89
|
}
|
|
118
|
-
|
|
119
|
-
|
|
90
|
+
const firstResult = new Deferred();
|
|
91
|
+
let hasResolved = false;
|
|
92
|
+
await watchWalletStatus(client, (status) => {
|
|
93
|
+
newStatusUpdated(status);
|
|
94
|
+
if (!hasResolved) {
|
|
95
|
+
firstResult.resolve(status);
|
|
96
|
+
hasResolved = true;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
return firstResult.promise;
|
|
120
100
|
},
|
|
121
101
|
enabled: !!client
|
|
122
102
|
});
|
|
123
103
|
}
|
|
124
104
|
|
|
125
|
-
// src/react/hook/useArticleUnlockStatus.ts
|
|
126
|
-
import { useQuery as useQuery3, useQueryClient as useQueryClient2 } from "@tanstack/react-query";
|
|
127
|
-
import { useCallback as useCallback2 } from "react";
|
|
128
|
-
function useArticleUnlockStatus({
|
|
129
|
-
articleId,
|
|
130
|
-
contentId
|
|
131
|
-
}) {
|
|
132
|
-
const queryClient = useQueryClient2();
|
|
133
|
-
const client = useNexusClient();
|
|
134
|
-
const newStatusUpdated = useCallback2(
|
|
135
|
-
(event) => {
|
|
136
|
-
queryClient.setQueryData(
|
|
137
|
-
[
|
|
138
|
-
"nexus-sdk",
|
|
139
|
-
"article-unlock-status",
|
|
140
|
-
articleId ?? "no-article-id",
|
|
141
|
-
contentId ?? "no-contentId-id"
|
|
142
|
-
],
|
|
143
|
-
event
|
|
144
|
-
);
|
|
145
|
-
},
|
|
146
|
-
[articleId, contentId, queryClient]
|
|
147
|
-
);
|
|
148
|
-
return useQuery3({
|
|
149
|
-
queryKey: [
|
|
150
|
-
"nexus-sdk",
|
|
151
|
-
"article-unlock-status",
|
|
152
|
-
articleId ?? "no-article-id",
|
|
153
|
-
contentId ?? "no-contentId-id"
|
|
154
|
-
],
|
|
155
|
-
gcTime: 0,
|
|
156
|
-
queryFn: async () => {
|
|
157
|
-
if (!client) {
|
|
158
|
-
return {
|
|
159
|
-
status: "waiting-response",
|
|
160
|
-
key: "waiting-response"
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
if (!(articleId && contentId)) {
|
|
164
|
-
return null;
|
|
165
|
-
}
|
|
166
|
-
await watchUnlockStatus(
|
|
167
|
-
client,
|
|
168
|
-
{ articleId, contentId },
|
|
169
|
-
newStatusUpdated
|
|
170
|
-
);
|
|
171
|
-
return {
|
|
172
|
-
status: "waiting-response",
|
|
173
|
-
key: "waiting-response"
|
|
174
|
-
};
|
|
175
|
-
},
|
|
176
|
-
enabled: !!client && !!articleId && !!contentId
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
|
|
180
105
|
// src/react/hook/useSendTransaction.ts
|
|
181
106
|
import { useMutation } from "@tanstack/react-query";
|
|
182
107
|
function useSendTransactionAction({
|
|
@@ -217,18 +142,36 @@ function useSiweAuthenticate({
|
|
|
217
142
|
});
|
|
218
143
|
}
|
|
219
144
|
|
|
220
|
-
// src/react/hook/helper/
|
|
221
|
-
import { useQuery as
|
|
222
|
-
import { useMemo as useMemo2 } from "react";
|
|
145
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
146
|
+
import { useQuery as useQuery3 } from "@tanstack/react-query";
|
|
147
|
+
import { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
223
148
|
import { isAddressEqual } from "viem";
|
|
224
149
|
|
|
225
|
-
// src/react/hook/
|
|
150
|
+
// src/react/hook/useDisplayModal.ts
|
|
226
151
|
import { useMutation as useMutation3 } from "@tanstack/react-query";
|
|
227
|
-
function
|
|
152
|
+
function useDisplayModal({
|
|
228
153
|
mutations
|
|
229
154
|
} = {}) {
|
|
230
155
|
const client = useNexusClient();
|
|
231
156
|
return useMutation3({
|
|
157
|
+
...mutations,
|
|
158
|
+
mutationKey: ["nexus-sdk", "display-modal"],
|
|
159
|
+
mutationFn: async (args) => {
|
|
160
|
+
if (!client) {
|
|
161
|
+
throw new ClientNotFound();
|
|
162
|
+
}
|
|
163
|
+
return displayModal(client, args);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/react/hook/useSendInteraction.ts
|
|
169
|
+
import { useMutation as useMutation4 } from "@tanstack/react-query";
|
|
170
|
+
function useSendInteraction({
|
|
171
|
+
mutations
|
|
172
|
+
} = {}) {
|
|
173
|
+
const client = useNexusClient();
|
|
174
|
+
return useMutation4({
|
|
232
175
|
...mutations,
|
|
233
176
|
mutationKey: ["nexus-sdk", "send-interaction"],
|
|
234
177
|
mutationFn: async (params) => {
|
|
@@ -241,7 +184,7 @@ function useSendInteraction({
|
|
|
241
184
|
}
|
|
242
185
|
|
|
243
186
|
// src/react/hook/utils/useNexusContext.ts
|
|
244
|
-
import { useMutation as
|
|
187
|
+
import { useMutation as useMutation5, useQuery as useQuery2 } from "@tanstack/react-query";
|
|
245
188
|
|
|
246
189
|
// src/react/hook/utils/useWindowLocation.ts
|
|
247
190
|
import { useEffect as useEffect2, useMemo, useState as useState2 } from "react";
|
|
@@ -283,7 +226,7 @@ function useWindowLocation() {
|
|
|
283
226
|
var contextKey = "nCtx";
|
|
284
227
|
function useNexusContext() {
|
|
285
228
|
const { location } = useWindowLocation();
|
|
286
|
-
const { data: nexusContext } =
|
|
229
|
+
const { data: nexusContext } = useQuery2({
|
|
287
230
|
queryKey: ["nexus-sdk", "context", location?.href ?? "no-href"],
|
|
288
231
|
queryFn: async () => {
|
|
289
232
|
if (!location?.href) return null;
|
|
@@ -293,9 +236,10 @@ function useNexusContext() {
|
|
|
293
236
|
const parsedContext = await decompressJson(nexusContext2);
|
|
294
237
|
if (!parsedContext) return null;
|
|
295
238
|
return parsedContext;
|
|
296
|
-
}
|
|
239
|
+
},
|
|
240
|
+
enabled: !!location?.href
|
|
297
241
|
});
|
|
298
|
-
const { mutate: updateContext, mutateAsync: updateContextAsync } =
|
|
242
|
+
const { mutate: updateContext, mutateAsync: updateContextAsync } = useMutation5({
|
|
299
243
|
mutationKey: ["nexus-sdk", "update-context"],
|
|
300
244
|
mutationFn: async (newContext) => {
|
|
301
245
|
if (!location || typeof window === "undefined") return;
|
|
@@ -307,47 +251,105 @@ function useNexusContext() {
|
|
|
307
251
|
window.history.replaceState(null, "", url.toString());
|
|
308
252
|
}
|
|
309
253
|
});
|
|
310
|
-
return {
|
|
254
|
+
return {
|
|
255
|
+
nexusContext,
|
|
256
|
+
updateContext,
|
|
257
|
+
updateContextAsync
|
|
258
|
+
};
|
|
311
259
|
}
|
|
312
260
|
|
|
313
|
-
// src/react/hook/helper/
|
|
314
|
-
function
|
|
261
|
+
// src/react/hook/helper/useReferralInteraction.ts
|
|
262
|
+
function useReferralInteraction({
|
|
263
|
+
contentId,
|
|
264
|
+
modalConfig
|
|
265
|
+
} = {}) {
|
|
315
266
|
const { nexusContext, updateContextAsync } = useNexusContext();
|
|
316
267
|
const { data: walletStatus } = useWalletStatus();
|
|
317
268
|
const { mutateAsync: sendInteraction2 } = useSendInteraction();
|
|
318
|
-
const
|
|
269
|
+
const ensureWalletConnected = useEnsureWalletConnected({
|
|
270
|
+
modalConfig,
|
|
271
|
+
walletStatus
|
|
272
|
+
});
|
|
273
|
+
const processReferral = useCallback2(async () => {
|
|
274
|
+
try {
|
|
275
|
+
let currentWallet = await ensureWalletConnected({
|
|
276
|
+
autoDisplay: false
|
|
277
|
+
});
|
|
278
|
+
if (!nexusContext?.r) {
|
|
279
|
+
if (currentWallet) {
|
|
280
|
+
await updateContextAsync({ r: currentWallet });
|
|
281
|
+
}
|
|
282
|
+
return "no-referrer";
|
|
283
|
+
}
|
|
284
|
+
if (!currentWallet) {
|
|
285
|
+
currentWallet = await ensureWalletConnected({
|
|
286
|
+
autoDisplay: true
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
|
|
290
|
+
return "self-referral";
|
|
291
|
+
}
|
|
292
|
+
const interaction = ReferralInteractionEncoder.referred({
|
|
293
|
+
referrer: nexusContext.r
|
|
294
|
+
});
|
|
295
|
+
await sendInteraction2({ contentId, interaction });
|
|
296
|
+
if (currentWallet) {
|
|
297
|
+
await updateContextAsync({ r: currentWallet });
|
|
298
|
+
}
|
|
299
|
+
return "success";
|
|
300
|
+
} catch (error2) {
|
|
301
|
+
return mapErrorToState(error2);
|
|
302
|
+
}
|
|
303
|
+
}, [
|
|
304
|
+
nexusContext,
|
|
305
|
+
contentId,
|
|
306
|
+
ensureWalletConnected,
|
|
307
|
+
sendInteraction2,
|
|
308
|
+
updateContextAsync
|
|
309
|
+
]);
|
|
310
|
+
const {
|
|
311
|
+
data: referralState,
|
|
312
|
+
error,
|
|
313
|
+
status
|
|
314
|
+
} = useQuery3({
|
|
319
315
|
gcTime: 0,
|
|
316
|
+
staleTime: 0,
|
|
320
317
|
queryKey: [
|
|
321
318
|
"nexus-sdk",
|
|
322
|
-
"auto-
|
|
319
|
+
"auto-referral-interaction",
|
|
323
320
|
nexusContext?.r ?? "no-referrer",
|
|
324
321
|
walletStatus?.key ?? "no-wallet-status"
|
|
325
322
|
],
|
|
326
|
-
queryFn:
|
|
327
|
-
|
|
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
|
-
}
|
|
323
|
+
queryFn: processReferral,
|
|
324
|
+
enabled: !!walletStatus
|
|
341
325
|
});
|
|
342
|
-
return
|
|
326
|
+
return useMemo2(() => {
|
|
327
|
+
if (status === "pending") return "processing";
|
|
328
|
+
if (status === "error") return mapErrorToState(error);
|
|
329
|
+
return referralState || "idle";
|
|
330
|
+
}, [referralState, status, error]);
|
|
343
331
|
}
|
|
344
|
-
function
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
status
|
|
332
|
+
function useEnsureWalletConnected({
|
|
333
|
+
modalConfig,
|
|
334
|
+
walletStatus
|
|
348
335
|
}) {
|
|
349
|
-
const
|
|
350
|
-
|
|
336
|
+
const { mutateAsync: displayModal2 } = useDisplayModal();
|
|
337
|
+
return useCallback2(
|
|
338
|
+
async ({ autoDisplay }) => {
|
|
339
|
+
if (walletStatus?.key !== "connected" || !walletStatus.interactionSession) {
|
|
340
|
+
if (!(modalConfig && autoDisplay)) {
|
|
341
|
+
return void 0;
|
|
342
|
+
}
|
|
343
|
+
const result = await displayModal2(modalConfig);
|
|
344
|
+
return result?.login?.wallet ?? void 0;
|
|
345
|
+
}
|
|
346
|
+
return walletStatus.wallet ?? void 0;
|
|
347
|
+
},
|
|
348
|
+
[walletStatus, modalConfig, displayModal2]
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
function mapErrorToState(error) {
|
|
352
|
+
if (error instanceof FrakRpcError) {
|
|
351
353
|
switch (error.code) {
|
|
352
354
|
case RpcErrorCodes.walletNotConnected:
|
|
353
355
|
return "no-wallet";
|
|
@@ -356,32 +358,30 @@ function useOutputStateMapper({
|
|
|
356
358
|
default:
|
|
357
359
|
return "error";
|
|
358
360
|
}
|
|
359
|
-
}
|
|
360
|
-
return
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
361
|
+
}
|
|
362
|
+
return "error";
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/react/hook/useOpenSso.ts
|
|
366
|
+
import { useMutation as useMutation6 } from "@tanstack/react-query";
|
|
367
|
+
function useOpenSso({ mutations } = {}) {
|
|
368
|
+
const client = useNexusClient();
|
|
369
|
+
return useMutation6({
|
|
370
|
+
...mutations,
|
|
371
|
+
mutationKey: ["nexus-sdk", "open-sso"],
|
|
372
|
+
mutationFn: async (params) => {
|
|
373
|
+
if (!client) {
|
|
374
|
+
throw new ClientNotFound();
|
|
375
|
+
}
|
|
376
|
+
return openSso(client, params);
|
|
368
377
|
}
|
|
369
|
-
}
|
|
378
|
+
});
|
|
370
379
|
}
|
|
371
380
|
|
|
372
381
|
// src/react/provider/NexusIFrameClientProvider.ts
|
|
373
382
|
var NexusIFrameClientContext = createContext2(
|
|
374
383
|
void 0
|
|
375
384
|
);
|
|
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
|
-
};
|
|
385
385
|
function NexusIFrameClientProvider({
|
|
386
386
|
style,
|
|
387
387
|
children
|
|
@@ -389,11 +389,9 @@ function NexusIFrameClientProvider({
|
|
|
389
389
|
const config = useNexusConfig();
|
|
390
390
|
const [client, setClient] = useState3(void 0);
|
|
391
391
|
const iFrame = createElement2("iframe", {
|
|
392
|
-
|
|
393
|
-
name: "nexus-wallet",
|
|
392
|
+
...baseIframeProps,
|
|
394
393
|
src: `${config.walletUrl}/listener`,
|
|
395
|
-
style: style ??
|
|
396
|
-
allow: "publickey-credentials-get *",
|
|
394
|
+
style: style ?? baseIframeProps.style,
|
|
397
395
|
ref: (iframe) => {
|
|
398
396
|
if (!iframe || client) {
|
|
399
397
|
return;
|
|
@@ -418,11 +416,11 @@ export {
|
|
|
418
416
|
NexusConfigProvider,
|
|
419
417
|
NexusIFrameClientContext,
|
|
420
418
|
NexusIFrameClientProvider,
|
|
421
|
-
|
|
422
|
-
useArticleUnlockStatus,
|
|
419
|
+
useDisplayModal,
|
|
423
420
|
useNexusClient,
|
|
424
421
|
useNexusConfig,
|
|
425
|
-
|
|
422
|
+
useOpenSso,
|
|
423
|
+
useReferralInteraction,
|
|
426
424
|
useSendInteraction,
|
|
427
425
|
useSendTransactionAction,
|
|
428
426
|
useSiweAuthenticate,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-B6_BIGc3.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
5
|
+
*/
|
|
6
|
+
type SiweAuthenticateModalParams = {
|
|
7
|
+
siwe?: Partial<SiweAuthenticationParams>;
|
|
8
|
+
metadata?: ModalRpcMetadata;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to launch a siwe authentication
|
|
12
|
+
* @param client
|
|
13
|
+
* @param siwe
|
|
14
|
+
* @param context
|
|
15
|
+
*/
|
|
16
|
+
declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
|
|
17
|
+
|
|
18
|
+
type SendTransactionParams = {
|
|
19
|
+
tx: SendTransactionModalStepType["params"]["tx"];
|
|
20
|
+
metadata?: ModalRpcMetadata;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Function used to send a user transaction
|
|
24
|
+
* @param client
|
|
25
|
+
* @param tx
|
|
26
|
+
* @param context
|
|
27
|
+
*/
|
|
28
|
+
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
|
+
|
|
30
|
+
export { type SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { S as SiweAuthenticationParams, M as ModalRpcMetadata, N as NexusClient, a as SiweAuthenticateReturnType, b as SendTransactionModalStepType, c as SendTransactionReturnType } from './client-Oily5ph8.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Partial SIWE params, since we can rebuild them from the SDK if they are empty
|
|
5
|
+
*/
|
|
6
|
+
type SiweAuthenticateModalParams = {
|
|
7
|
+
siwe?: Partial<SiweAuthenticationParams>;
|
|
8
|
+
metadata?: ModalRpcMetadata;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Function used to launch a siwe authentication
|
|
12
|
+
* @param client
|
|
13
|
+
* @param siwe
|
|
14
|
+
* @param context
|
|
15
|
+
*/
|
|
16
|
+
declare function siweAuthenticate(client: NexusClient, { siwe, metadata }: SiweAuthenticateModalParams): Promise<SiweAuthenticateReturnType>;
|
|
17
|
+
|
|
18
|
+
type SendTransactionParams = {
|
|
19
|
+
tx: SendTransactionModalStepType["params"]["tx"];
|
|
20
|
+
metadata?: ModalRpcMetadata;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Function used to send a user transaction
|
|
24
|
+
* @param client
|
|
25
|
+
* @param tx
|
|
26
|
+
* @param context
|
|
27
|
+
*/
|
|
28
|
+
declare function sendTransaction(client: NexusClient, { tx, metadata }: SendTransactionParams): Promise<SendTransactionReturnType>;
|
|
29
|
+
|
|
30
|
+
export { type SiweAuthenticateModalParams as S, sendTransaction as a, type SendTransactionParams as b, siweAuthenticate as s };
|