@frak-labs/nexus-sdk 0.0.12 → 0.0.13

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.
@@ -212,9 +212,11 @@ function createIFrameLifecycleManager({
212
212
  const isConnectedDeferred = new Deferred();
213
213
  const handler = async (messageEvent) => {
214
214
  switch (messageEvent.iframeLifecycle) {
215
+ // Resolve the isConnected promise
215
216
  case "connected":
216
217
  isConnectedDeferred.resolve(true);
217
218
  break;
219
+ // Perform a nexus backup
218
220
  case "do-backup":
219
221
  if (messageEvent.data.backup) {
220
222
  localStorage.setItem(BACKUP_KEY, messageEvent.data.backup);
@@ -222,6 +224,7 @@ function createIFrameLifecycleManager({
222
224
  localStorage.removeItem(BACKUP_KEY);
223
225
  }
224
226
  break;
227
+ // Change iframe visibility
225
228
  case "show":
226
229
  case "hide":
227
230
  changeIframeVisibility({
@@ -212,9 +212,11 @@ function createIFrameLifecycleManager({
212
212
  const isConnectedDeferred = new Deferred();
213
213
  const handler = async (messageEvent) => {
214
214
  switch (messageEvent.iframeLifecycle) {
215
+ // Resolve the isConnected promise
215
216
  case "connected":
216
217
  isConnectedDeferred.resolve(true);
217
218
  break;
219
+ // Perform a nexus backup
218
220
  case "do-backup":
219
221
  if (messageEvent.data.backup) {
220
222
  localStorage.setItem(BACKUP_KEY, messageEvent.data.backup);
@@ -222,6 +224,7 @@ function createIFrameLifecycleManager({
222
224
  localStorage.removeItem(BACKUP_KEY);
223
225
  }
224
226
  break;
227
+ // Change iframe visibility
225
228
  case "show":
226
229
  case "hide":
227
230
  changeIframeVisibility({
@@ -5,7 +5,7 @@
5
5
 
6
6
 
7
7
 
8
- var _chunkBJ3CCN5Pcjs = require('../chunk-BJ3CCN5P.cjs');
8
+ var _chunk2SGRLI7Tcjs = require('../chunk-2SGRLI7T.cjs');
9
9
  require('../chunk-ETV4XYOV.cjs');
10
10
 
11
11
 
@@ -14,4 +14,4 @@ require('../chunk-ETV4XYOV.cjs');
14
14
 
15
15
 
16
16
 
17
- exports.FrakRpcError = _chunkBJ3CCN5Pcjs.FrakRpcError; exports.RpcErrorCodes = _chunkBJ3CCN5Pcjs.RpcErrorCodes; exports.createIFrameNexusClient = _chunkBJ3CCN5Pcjs.createIFrameNexusClient; exports.createIframe = _chunkBJ3CCN5Pcjs.createIframe; exports.decompressDataAndCheckHash = _chunkBJ3CCN5Pcjs.decompressDataAndCheckHash; exports.hashAndCompressData = _chunkBJ3CCN5Pcjs.hashAndCompressData;
17
+ exports.FrakRpcError = _chunk2SGRLI7Tcjs.FrakRpcError; exports.RpcErrorCodes = _chunk2SGRLI7Tcjs.RpcErrorCodes; exports.createIFrameNexusClient = _chunk2SGRLI7Tcjs.createIFrameNexusClient; exports.createIframe = _chunk2SGRLI7Tcjs.createIframe; exports.decompressDataAndCheckHash = _chunk2SGRLI7Tcjs.decompressDataAndCheckHash; exports.hashAndCompressData = _chunk2SGRLI7Tcjs.hashAndCompressData;
@@ -5,7 +5,7 @@ import {
5
5
  createIframe,
6
6
  decompressDataAndCheckHash,
7
7
  hashAndCompressData
8
- } from "../chunk-HXVDI2IY.js";
8
+ } from "../chunk-FF32LTPI.js";
9
9
  import "../chunk-PKBMQBKP.js";
10
10
  export {
11
11
  FrakRpcError,
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _chunkBJ3CCN5Pcjs = require('../chunk-BJ3CCN5P.cjs');
10
+ var _chunk2SGRLI7Tcjs = require('../chunk-2SGRLI7T.cjs');
11
11
 
12
12
 
13
13
 
@@ -51,8 +51,8 @@ function NexusConfigProvider(parameters) {
51
51
  function useNexusConfig() {
52
52
  const config = _react.useContext.call(void 0, NexusConfigContext);
53
53
  if (!config) {
54
- throw new (0, _chunkBJ3CCN5Pcjs.FrakRpcError)(
55
- _chunkBJ3CCN5Pcjs.RpcErrorCodes.configError,
54
+ throw new (0, _chunk2SGRLI7Tcjs.FrakRpcError)(
55
+ _chunk2SGRLI7Tcjs.RpcErrorCodes.configError,
56
56
  "Nexus config not found"
57
57
  );
58
58
  }
@@ -85,9 +85,9 @@ function useWalletStatus() {
85
85
  queryKey: ["nexus-sdk", "wallet-status-listener"],
86
86
  queryFn: async () => {
87
87
  if (!client) {
88
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
88
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
89
89
  }
90
- const firstResult = new (0, _chunkBJ3CCN5Pcjs.Deferred)();
90
+ const firstResult = new (0, _chunk2SGRLI7Tcjs.Deferred)();
91
91
  let hasResolved = false;
92
92
  await _chunkS5FVCA2Ecjs.watchWalletStatus.call(void 0, client, (status) => {
93
93
  newStatusUpdated(status);
@@ -113,7 +113,7 @@ function useSendTransactionAction({
113
113
  mutationKey: ["nexus-sdk", "send-transaction"],
114
114
  mutationFn: async (params) => {
115
115
  if (!client) {
116
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
116
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
117
117
  }
118
118
  return _chunkS5FVCA2Ecjs.sendTransaction.call(void 0, client, params);
119
119
  }
@@ -135,7 +135,7 @@ function useSiweAuthenticate({
135
135
  ],
136
136
  mutationFn: async (params) => {
137
137
  if (!client) {
138
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
138
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
139
139
  }
140
140
  return _chunkS5FVCA2Ecjs.siweAuthenticate.call(void 0, client, params);
141
141
  }
@@ -158,7 +158,7 @@ function useDisplayModal({
158
158
  mutationKey: ["nexus-sdk", "display-modal"],
159
159
  mutationFn: async (args) => {
160
160
  if (!client) {
161
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
161
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
162
162
  }
163
163
  return _chunkS5FVCA2Ecjs.displayModal.call(void 0, client, args);
164
164
  }
@@ -176,7 +176,7 @@ function useSendInteraction({
176
176
  mutationKey: ["nexus-sdk", "send-interaction"],
177
177
  mutationFn: async (params) => {
178
178
  if (!client) {
179
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
179
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
180
180
  }
181
181
  return _chunkS5FVCA2Ecjs.sendInteraction.call(void 0, client, params);
182
182
  }
@@ -233,7 +233,7 @@ function useNexusContext() {
233
233
  const url = new URL(location.href);
234
234
  const nexusContext2 = url.searchParams.get(contextKey);
235
235
  if (!nexusContext2) return null;
236
- const parsedContext = await _chunkBJ3CCN5Pcjs.decompressJson.call(void 0, nexusContext2);
236
+ const parsedContext = await _chunk2SGRLI7Tcjs.decompressJson.call(void 0, nexusContext2);
237
237
  if (!parsedContext) return null;
238
238
  return parsedContext;
239
239
  },
@@ -244,7 +244,7 @@ function useNexusContext() {
244
244
  mutationFn: async (newContext) => {
245
245
  if (!location || typeof window === "undefined") return;
246
246
  const fullNewContext = nexusContext ? { ...nexusContext, ...newContext } : newContext;
247
- const compressedContext = await _chunkBJ3CCN5Pcjs.compressJson.call(void 0, fullNewContext);
247
+ const compressedContext = await _chunk2SGRLI7Tcjs.compressJson.call(void 0, fullNewContext);
248
248
  if (!compressedContext) return;
249
249
  const url = new URL(location.href);
250
250
  url.searchParams.set(contextKey, compressedContext);
@@ -272,19 +272,15 @@ function useReferralInteraction({
272
272
  });
273
273
  const processReferral = _react.useCallback.call(void 0, async () => {
274
274
  try {
275
- let currentWallet = await ensureWalletConnected({
276
- autoDisplay: false
277
- });
278
- if (!_optionalChain([nexusContext, 'optionalAccess', _10 => _10.r])) {
275
+ let currentWallet = _optionalChain([walletStatus, 'optionalAccess', _10 => _10.key]) === "connected" ? walletStatus.wallet : void 0;
276
+ if (!_optionalChain([nexusContext, 'optionalAccess', _11 => _11.r])) {
279
277
  if (currentWallet) {
280
278
  await updateContextAsync({ r: currentWallet });
281
279
  }
282
280
  return "no-referrer";
283
281
  }
284
282
  if (!currentWallet) {
285
- currentWallet = await ensureWalletConnected({
286
- autoDisplay: true
287
- });
283
+ currentWallet = await ensureWalletConnected();
288
284
  }
289
285
  if (currentWallet && _viem.isAddressEqual.call(void 0, nexusContext.r, currentWallet)) {
290
286
  return "self-referral";
@@ -305,7 +301,8 @@ function useReferralInteraction({
305
301
  contentId,
306
302
  ensureWalletConnected,
307
303
  sendInteraction2,
308
- updateContextAsync
304
+ updateContextAsync,
305
+ walletStatus
309
306
  ]);
310
307
  const {
311
308
  data: referralState,
@@ -317,8 +314,8 @@ function useReferralInteraction({
317
314
  queryKey: [
318
315
  "nexus-sdk",
319
316
  "auto-referral-interaction",
320
- _nullishCoalesce(_optionalChain([nexusContext, 'optionalAccess', _11 => _11.r]), () => ( "no-referrer")),
321
- _nullishCoalesce(_optionalChain([walletStatus, 'optionalAccess', _12 => _12.key]), () => ( "no-wallet-status"))
317
+ _nullishCoalesce(_optionalChain([nexusContext, 'optionalAccess', _12 => _12.r]), () => ( "no-referrer")),
318
+ _nullishCoalesce(_optionalChain([walletStatus, 'optionalAccess', _13 => _13.key]), () => ( "no-wallet-status"))
322
319
  ],
323
320
  queryFn: processReferral,
324
321
  enabled: !!walletStatus
@@ -334,26 +331,23 @@ function useEnsureWalletConnected({
334
331
  walletStatus
335
332
  }) {
336
333
  const { mutateAsync: displayModal2 } = useDisplayModal();
337
- return _react.useCallback.call(void 0,
338
- async ({ autoDisplay }) => {
339
- if (_optionalChain([walletStatus, 'optionalAccess', _13 => _13.key]) !== "connected" || !walletStatus.interactionSession) {
340
- if (!(modalConfig && autoDisplay)) {
341
- return void 0;
342
- }
343
- const result = await displayModal2(modalConfig);
344
- return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _14 => _14.login, 'optionalAccess', _15 => _15.wallet]), () => ( void 0));
334
+ return _react.useCallback.call(void 0, async () => {
335
+ if (_optionalChain([walletStatus, 'optionalAccess', _14 => _14.key]) !== "connected" || !walletStatus.interactionSession) {
336
+ if (!modalConfig) {
337
+ return void 0;
345
338
  }
346
- return _nullishCoalesce(walletStatus.wallet, () => ( void 0));
347
- },
348
- [walletStatus, modalConfig, displayModal2]
349
- );
339
+ const result = await displayModal2(modalConfig);
340
+ return _nullishCoalesce(_optionalChain([result, 'optionalAccess', _15 => _15.login, 'optionalAccess', _16 => _16.wallet]), () => ( void 0));
341
+ }
342
+ return _nullishCoalesce(walletStatus.wallet, () => ( void 0));
343
+ }, [walletStatus, modalConfig, displayModal2]);
350
344
  }
351
345
  function mapErrorToState(error) {
352
- if (error instanceof _chunkBJ3CCN5Pcjs.FrakRpcError) {
346
+ if (error instanceof _chunk2SGRLI7Tcjs.FrakRpcError) {
353
347
  switch (error.code) {
354
- case _chunkBJ3CCN5Pcjs.RpcErrorCodes.walletNotConnected:
348
+ case _chunk2SGRLI7Tcjs.RpcErrorCodes.walletNotConnected:
355
349
  return "no-wallet";
356
- case _chunkBJ3CCN5Pcjs.RpcErrorCodes.noInteractionSession:
350
+ case _chunk2SGRLI7Tcjs.RpcErrorCodes.noInteractionSession:
357
351
  return "no-session";
358
352
  default:
359
353
  return "error";
@@ -371,7 +365,7 @@ function useOpenSso({ mutations } = {}) {
371
365
  mutationKey: ["nexus-sdk", "open-sso"],
372
366
  mutationFn: async (params) => {
373
367
  if (!client) {
374
- throw new (0, _chunkBJ3CCN5Pcjs.ClientNotFound)();
368
+ throw new (0, _chunk2SGRLI7Tcjs.ClientNotFound)();
375
369
  }
376
370
  return _chunkS5FVCA2Ecjs.openSso.call(void 0, client, params);
377
371
  }
@@ -389,15 +383,15 @@ function NexusIFrameClientProvider({
389
383
  const config = useNexusConfig();
390
384
  const [client, setClient] = _react.useState.call(void 0, void 0);
391
385
  const iFrame = _react.createElement.call(void 0, "iframe", {
392
- ..._chunkBJ3CCN5Pcjs.baseIframeProps,
386
+ ..._chunk2SGRLI7Tcjs.baseIframeProps,
393
387
  src: `${config.walletUrl}/listener`,
394
- style: _nullishCoalesce(style, () => ( _chunkBJ3CCN5Pcjs.baseIframeProps.style)),
388
+ style: _nullishCoalesce(style, () => ( _chunk2SGRLI7Tcjs.baseIframeProps.style)),
395
389
  ref: (iframe) => {
396
390
  if (!iframe || client) {
397
391
  return;
398
392
  }
399
393
  setClient(
400
- _chunkBJ3CCN5Pcjs.createIFrameNexusClient.call(void 0, {
394
+ _chunk2SGRLI7Tcjs.createIFrameNexusClient.call(void 0, {
401
395
  iframe,
402
396
  config
403
397
  })
@@ -7,7 +7,7 @@ import {
7
7
  compressJson,
8
8
  createIFrameNexusClient,
9
9
  decompressJson
10
- } from "../chunk-HXVDI2IY.js";
10
+ } from "../chunk-FF32LTPI.js";
11
11
  import {
12
12
  displayModal,
13
13
  openSso,
@@ -272,9 +272,7 @@ function useReferralInteraction({
272
272
  });
273
273
  const processReferral = useCallback2(async () => {
274
274
  try {
275
- let currentWallet = await ensureWalletConnected({
276
- autoDisplay: false
277
- });
275
+ let currentWallet = walletStatus?.key === "connected" ? walletStatus.wallet : void 0;
278
276
  if (!nexusContext?.r) {
279
277
  if (currentWallet) {
280
278
  await updateContextAsync({ r: currentWallet });
@@ -282,9 +280,7 @@ function useReferralInteraction({
282
280
  return "no-referrer";
283
281
  }
284
282
  if (!currentWallet) {
285
- currentWallet = await ensureWalletConnected({
286
- autoDisplay: true
287
- });
283
+ currentWallet = await ensureWalletConnected();
288
284
  }
289
285
  if (currentWallet && isAddressEqual(nexusContext.r, currentWallet)) {
290
286
  return "self-referral";
@@ -305,7 +301,8 @@ function useReferralInteraction({
305
301
  contentId,
306
302
  ensureWalletConnected,
307
303
  sendInteraction2,
308
- updateContextAsync
304
+ updateContextAsync,
305
+ walletStatus
309
306
  ]);
310
307
  const {
311
308
  data: referralState,
@@ -334,19 +331,16 @@ function useEnsureWalletConnected({
334
331
  walletStatus
335
332
  }) {
336
333
  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;
334
+ return useCallback2(async () => {
335
+ if (walletStatus?.key !== "connected" || !walletStatus.interactionSession) {
336
+ if (!modalConfig) {
337
+ return void 0;
345
338
  }
346
- return walletStatus.wallet ?? void 0;
347
- },
348
- [walletStatus, modalConfig, displayModal2]
349
- );
339
+ const result = await displayModal2(modalConfig);
340
+ return result?.login?.wallet ?? void 0;
341
+ }
342
+ return walletStatus.wallet ?? void 0;
343
+ }, [walletStatus, modalConfig, displayModal2]);
350
344
  }
351
345
  function mapErrorToState(error) {
352
346
  if (error instanceof FrakRpcError) {
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.12",
14
+ "version": "0.0.13",
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": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -81,9 +81,9 @@
81
81
  "js-sha256": "^0.11.0"
82
82
  },
83
83
  "devDependencies": {
84
- "@tanstack/react-query": ">=5.51.15",
84
+ "@tanstack/react-query": ">=5.52.2",
85
85
  "@types/node": "^22",
86
- "tsup": "^8.2.3",
86
+ "tsup": "^8.2.4",
87
87
  "typescript": "^5"
88
88
  }
89
89
  }