@getpara/react-sdk-lite 2.0.0-alpha.67 → 2.0.0-alpha.69

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.
Files changed (29) hide show
  1. package/dist/modal/components/Account/AccountWalletSelect.js +15 -2
  2. package/dist/modal/components/ChainSwitch/ChainSwitch.js +8 -3
  3. package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.js +2 -2
  4. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +2 -1
  5. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +36 -29
  6. package/dist/modal/components/ExternalWallets/ExternalWallets.js +2 -2
  7. package/dist/modal/components/IFrameStep/IFrameStep.js +8 -6
  8. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +6 -5
  9. package/dist/modal/components/OAuth/TelegramOAuthStep.js +6 -5
  10. package/dist/modal/components/WalletSelectOld/WalletSelectOld.js +17 -4
  11. package/dist/modal/hooks/useFarcasterLogin.js +8 -1
  12. package/dist/modal/hooks/useTelegramLogin.js +4 -0
  13. package/dist/modal/stores/modal/useModalStore.d.ts +1 -0
  14. package/dist/modal/stores/modal/useModalStore.js +2 -1
  15. package/dist/modal/utils/openPopup.d.ts +1 -1
  16. package/dist/modal/utils/openPopup.js +3 -1
  17. package/dist/modal/utils/stringFormatters.js +10 -1
  18. package/dist/modal/utils/validatePortalOrigin.d.ts +2 -0
  19. package/dist/modal/utils/validatePortalOrigin.js +14 -0
  20. package/dist/provider/hooks/mutations/useAddAuthMethod.d.ts +3 -3
  21. package/dist/provider/hooks/mutations/useLoginExternalWallet.d.ts +6 -0
  22. package/dist/provider/hooks/mutations/useVerifyExternalWallet.d.ts +16 -28
  23. package/dist/provider/hooks/utils/useEventListeners.js +2 -0
  24. package/dist/provider/providers/AuthProvider.js +76 -35
  25. package/dist/provider/providers/ExternalWalletProvider.d.ts +7 -1
  26. package/dist/provider/providers/ExternalWalletProvider.js +241 -27
  27. package/package.json +8 -8
  28. package/dist/modal/utils/routeMobileExternalWallet.d.ts +0 -1
  29. package/dist/modal/utils/routeMobileExternalWallet.js +0 -31
@@ -17,17 +17,13 @@ export declare const VERIFY_EXTERNAL_WALLET_KEY = "VERIFY_EXTERNAL_WALLET";
17
17
  export declare const useVerifyExternalWallet: () => {
18
18
  status: "idle" | "pending" | "error" | "success";
19
19
  error: Error | null;
20
- data: Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin> | undefined;
20
+ data: Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin | import("@getpara/core-sdk/dist/types/types/methods.js").AuthStateDone> | undefined;
21
21
  isSuccess: boolean;
22
- variables: {
23
- portalTheme?: import("@getpara/web-sdk").Theme | undefined;
24
- useShortUrls?: boolean | undefined;
25
- externalWallet: import("@getpara/web-sdk").ExternalWalletInfo;
26
- signedMessage: string;
27
- cosmosPublicKeyHex?: string | undefined;
28
- cosmosSigner?: string | undefined;
29
- sessionLookupId?: string | undefined;
30
- } | undefined;
22
+ variables: Compute<(import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & {
23
+ serverAuthState: import("@getpara/shared").ServerAuthStateSignup | import("@getpara/shared").ServerAuthStateLogin | import("@getpara/shared").ServerAuthStateDone;
24
+ }) | (import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & import("@getpara/web-sdk").VerifyExternalWalletParams & {
25
+ serverAuthState?: undefined;
26
+ })> | undefined;
31
27
  isError: boolean;
32
28
  isIdle: boolean;
33
29
  isPending: boolean;
@@ -37,22 +33,14 @@ export declare const useVerifyExternalWallet: () => {
37
33
  failureReason: Error | null;
38
34
  isPaused: boolean;
39
35
  submittedAt: number;
40
- verifyExternalWallet: import("@tanstack/react-query").UseMutateFunction<Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin>, Error, {
41
- portalTheme?: import("@getpara/web-sdk").Theme | undefined;
42
- useShortUrls?: boolean | undefined;
43
- externalWallet: import("@getpara/web-sdk").ExternalWalletInfo;
44
- signedMessage: string;
45
- cosmosPublicKeyHex?: string | undefined;
46
- cosmosSigner?: string | undefined;
47
- sessionLookupId?: string | undefined;
48
- }, unknown>;
49
- verifyExternalWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin>, Error, {
50
- portalTheme?: import("@getpara/web-sdk").Theme | undefined;
51
- useShortUrls?: boolean | undefined;
52
- externalWallet: import("@getpara/web-sdk").ExternalWalletInfo;
53
- signedMessage: string;
54
- cosmosPublicKeyHex?: string | undefined;
55
- cosmosSigner?: string | undefined;
56
- sessionLookupId?: string | undefined;
57
- }, unknown>;
36
+ verifyExternalWallet: import("@tanstack/react-query").UseMutateFunction<Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin | import("@getpara/core-sdk/dist/types/types/methods.js").AuthStateDone>, Error, Compute<(import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & {
37
+ serverAuthState: import("@getpara/shared").ServerAuthStateSignup | import("@getpara/shared").ServerAuthStateLogin | import("@getpara/shared").ServerAuthStateDone;
38
+ }) | (import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & import("@getpara/web-sdk").VerifyExternalWalletParams & {
39
+ serverAuthState?: undefined;
40
+ })>, unknown>;
41
+ verifyExternalWalletAsync: import("@tanstack/react-query").UseMutateAsyncFunction<Compute<import("@getpara/web-sdk").AuthStateSignup | import("@getpara/web-sdk").AuthStateLogin | import("@getpara/core-sdk/dist/types/types/methods.js").AuthStateDone>, Error, Compute<(import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & {
42
+ serverAuthState: import("@getpara/shared").ServerAuthStateSignup | import("@getpara/shared").ServerAuthStateLogin | import("@getpara/shared").ServerAuthStateDone;
43
+ }) | (import("@getpara/core-sdk/dist/types/types/methods.js").WithCustomTheme & import("@getpara/core-sdk/dist/types/types/methods.js").WithUseShortUrls & import("@getpara/web-sdk").VerifyExternalWalletParams & {
44
+ serverAuthState?: undefined;
45
+ })>, unknown>;
58
46
  };
@@ -123,6 +123,7 @@ const useEventListeners = ({
123
123
  });
124
124
  }, [queryClient, refs.balancesInvalidationTime]);
125
125
  useEffect(() => {
126
+ if (typeof window === "undefined") return;
126
127
  window.addEventListener(ParaEvent.LOGIN_EVENT, loginListener);
127
128
  window.addEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
128
129
  window.addEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
@@ -136,6 +137,7 @@ const useEventListeners = ({
136
137
  window.addEventListener(ParaEvent.GUEST_WALLETS_CREATED, guestWalletsCreatedListener);
137
138
  window.addEventListener(ParaEvent.ASSET_TRANSFERRED, assetTransferListener);
138
139
  return () => {
140
+ if (typeof window === "undefined") return;
139
141
  window.removeEventListener(ParaEvent.LOGIN_EVENT, loginListener);
140
142
  window.removeEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
141
143
  window.removeEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
@@ -5,8 +5,8 @@ import {
5
5
  __spreadValues
6
6
  } from "../../chunk-MMUBH76A.js";
7
7
  import { jsx } from "react/jsx-runtime";
8
- import { useUserAgent } from "@getpara/react-common";
9
- import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
8
+ import { openMobileUrl, useUserAgent } from "@getpara/react-common";
9
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
10
10
  import { useModalStore } from "../../modal/stores/index.js";
11
11
  import { ModalStep } from "../../modal/utils/steps.js";
12
12
  import {
@@ -29,15 +29,15 @@ import { openPopup } from "../../modal/utils/openPopup.js";
29
29
  import {
30
30
  AuthMethod,
31
31
  entityToWallet,
32
- getPortalBaseURL
32
+ isMobile
33
33
  } from "@getpara/web-sdk";
34
34
  import { useInternalClient } from "../../provider/hooks/utils/useInternalClient.js";
35
35
  import { useGoBack } from "../../modal/hooks/useGoBack.js";
36
36
  import { isExternalWallet } from "@getpara/user-management-client";
37
- import { routeMobileExternalWallet } from "../../modal/utils/routeMobileExternalWallet.js";
38
37
  import { useStore } from "../stores/useStore.js";
39
38
  import { useFormattedBiometricHints } from "../hooks/utils/useFormattedBiometricHints.js";
40
39
  import { useQueryClient } from "@tanstack/react-query";
40
+ import { validatePortalOrigin } from "../../modal/utils/validatePortalOrigin.js";
41
41
  const AuthContext = createContext({
42
42
  signUpOrLogIn: () => {
43
43
  },
@@ -127,6 +127,7 @@ function AuthProvider({
127
127
  const { data: biometricHints } = useFormattedBiometricHints();
128
128
  const [switchWalletsUrl, setSwitchWalletsUrl] = useState(void 0);
129
129
  const [isSwitchWalletsPending, setIsSwitchWalletsPending] = useState(mutateIsSwitchWalletsPending);
130
+ const messageHandlerRef = useRef(null);
130
131
  const goBackIfPopupClosedOnSteps = (steps) => {
131
132
  var _a;
132
133
  if (((_a = refs.popupWindow.current) == null ? void 0 : _a.closed) && (!refs.currentStep.current || steps.includes(refs.currentStep.current))) {
@@ -139,11 +140,12 @@ function AuthProvider({
139
140
  return !!stepNow && !steps.includes(stepNow);
140
141
  };
141
142
  const setupListener = () => {
142
- window.addEventListener("message", function handleMessage(event) {
143
+ if (messageHandlerRef.current) {
144
+ window.removeEventListener("message", messageHandlerRef.current);
145
+ }
146
+ const handleMessage = (event) => {
143
147
  var _a;
144
- const portalBase = getPortalBaseURL(para.ctx);
145
- const portalLocalBase = getPortalBaseURL(para.ctx, true);
146
- if (!event.origin.startsWith(portalBase) && !event.origin.startsWith(portalLocalBase)) {
148
+ if (!validatePortalOrigin(event, para.ctx)) {
147
149
  return;
148
150
  }
149
151
  if (((_a = event.data) == null ? void 0 : _a.type) === "CLOSE_WINDOW") {
@@ -151,11 +153,16 @@ function AuthProvider({
151
153
  setAuthStepRoute();
152
154
  setIFrameUrl();
153
155
  setIsIFrameReady(false);
154
- setStep(ModalStep.AWAITING_ACCOUNT);
156
+ if (refs.currentStep.current !== ModalStep.LOGIN_DONE && refs.currentStep.current !== ModalStep.AWAITING_ACCOUNT) {
157
+ setStep(ModalStep.AWAITING_ACCOUNT);
158
+ }
155
159
  }
156
160
  window.removeEventListener("message", handleMessage);
161
+ messageHandlerRef.current = null;
157
162
  }
158
- });
163
+ };
164
+ messageHandlerRef.current = handleMessage;
165
+ window.addEventListener("message", handleMessage);
159
166
  };
160
167
  const pollSignup = () => {
161
168
  if (typeof window !== "undefined") {
@@ -215,12 +222,14 @@ function AuthProvider({
215
222
  if (refs.currentStep.current !== ModalStep.AWAITING_BIOMETRIC_CREATION) {
216
223
  setStep(ModalStep.AWAITING_BIOMETRIC_CREATION);
217
224
  }
218
- refs.popupWindow.current = openPopup({
219
- url: authState.passkeyUrl,
220
- target: "ParaPasskey",
221
- type: "CREATE_PASSKEY",
222
- current: refs.popupWindow.current
223
- });
225
+ if (typeof window !== "undefined") {
226
+ refs.popupWindow.current = openPopup({
227
+ url: authState.passkeyUrl,
228
+ target: "ParaPasskey",
229
+ type: "CREATE_PASSKEY",
230
+ current: refs.popupWindow.current
231
+ });
232
+ }
224
233
  break;
225
234
  case AuthMethod.PASSWORD:
226
235
  setupListener();
@@ -264,13 +273,14 @@ function AuthProvider({
264
273
  [isIFrameReady]
265
274
  );
266
275
  const login = (authState) => {
267
- if (authState.isWalletSelectionNeeded || authState.passkeyUrl) {
268
- setStep(ModalStep.BIOMETRIC_LOGIN);
269
- } else {
276
+ const hasPasskey = !!authState.passkeyUrl;
277
+ if (!hasPasskey) {
270
278
  setupListener();
271
279
  setIFrameUrl(authState.passwordUrl || authState.pinUrl);
272
280
  setIsIFrameReady(false);
273
281
  setStep(ModalStep.EMBEDDED_PASSWORD_LOGIN);
282
+ } else {
283
+ setStep(ModalStep.BIOMETRIC_LOGIN);
274
284
  }
275
285
  pollLogin();
276
286
  };
@@ -341,23 +351,49 @@ function AuthProvider({
341
351
  loginOverride();
342
352
  return;
343
353
  }
344
- refs.popupWindow.current = openPopup({
345
- url: isPIN ? authState.pinUrl : isPassword ? authState.passwordUrl : authState.passkeyUrl,
346
- target: isPIN ? "ParaPIN" : isPassword ? "ParaPassword" : "ParaPasskey",
347
- type: isPIN ? "LOGIN_PASSWORD" : isPassword ? "LOGIN_PASSWORD" : "LOGIN_PASSKEY",
348
- current: refs.popupWindow.current
349
- });
354
+ if (typeof window !== "undefined") {
355
+ refs.popupWindow.current = openPopup({
356
+ url: isPIN ? authState.pinUrl : isPassword ? authState.passwordUrl : authState.passkeyUrl,
357
+ target: isPIN ? "ParaPIN" : isPassword ? "ParaPassword" : "ParaPasskey",
358
+ type: isPIN ? "LOGIN_PASSWORD" : isPassword ? "LOGIN_PASSWORD" : "LOGIN_PASSKEY",
359
+ current: refs.popupWindow.current
360
+ });
361
+ }
350
362
  setStep(isPassword || isPIN ? ModalStep.AWAITING_PASSWORD_LOGIN : ModalStep.AWAITING_BIOMETRIC_LOGIN);
351
363
  },
352
364
  [loginState, biometricHints]
353
365
  );
354
366
  const onNewAuthState = (authState) => __async(this, null, function* () {
355
- refs.popupWindow.current = null;
367
+ var _a, _b, _c;
356
368
  setAuthState(authState);
357
369
  switch (authState.stage) {
358
370
  case "verify":
359
- if (isExternalWallet(authState.auth) && authState.signatureVerificationMessage) {
360
- setStep(ModalStep.EXTERNAL_WALLET_VERIFICATION);
371
+ if (isExternalWallet(authState.auth)) {
372
+ if (authState.loginUrl && ((_a = authState.externalWallet) == null ? void 0 : _a.withFullParaAuth)) {
373
+ let isBasicLogin = false;
374
+ if (authState.nextStage === "login") {
375
+ isBasicLogin = authState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
376
+ } else {
377
+ isBasicLogin = authState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
378
+ }
379
+ if (authState.nextStage === "login") {
380
+ setFlow("login");
381
+ isBasicLogin && pollLogin();
382
+ } else {
383
+ setFlow("signup");
384
+ isBasicLogin && pollSignup();
385
+ }
386
+ if (!isMobile() && refs.popupWindow.current) {
387
+ refs.popupWindow.current.location.href = authState.loginUrl;
388
+ setStep(ModalStep.AWAITING_ACCOUNT);
389
+ } else {
390
+ setIFrameUrl(authState.loginUrl);
391
+ setStep(ModalStep.OTP);
392
+ setupListener();
393
+ }
394
+ } else {
395
+ setStep(ModalStep.EXTERNAL_WALLET_VERIFICATION);
396
+ }
361
397
  } else {
362
398
  if (authState.nextStage === "login") {
363
399
  setFlow("login");
@@ -398,12 +434,14 @@ function AuthProvider({
398
434
  }
399
435
  break;
400
436
  case "done":
401
- if (authState.isNewUser) {
402
- pollSignup();
403
- setFlow("signup");
404
- } else {
405
- pollLogin();
406
- setFlow("login");
437
+ if (!((_b = authState.externalWallet) == null ? void 0 : _b.withFullParaAuth) && !((_c = authState.externalWallet) == null ? void 0 : _c.withVerification)) {
438
+ if (authState.isNewUser) {
439
+ pollSignup();
440
+ setFlow("signup");
441
+ } else {
442
+ pollLogin();
443
+ setFlow("login");
444
+ }
407
445
  }
408
446
  if (!authState.isWalletSelectionNeeded) {
409
447
  setStep(ModalStep.AWAITING_ACCOUNT);
@@ -463,7 +501,7 @@ function AuthProvider({
463
501
  isCanceled: () => refs.currentStep.current !== ModalStep.FARCASTER_OAUTH,
464
502
  onConnectUri: (connectUri) => {
465
503
  setFarcasterConnectUri(connectUri);
466
- routeMobileExternalWallet(connectUri);
504
+ openMobileUrl(connectUri);
467
505
  },
468
506
  useShortUrls: true,
469
507
  serverAuthState
@@ -722,6 +760,9 @@ function AuthProvider({
722
760
  return () => {
723
761
  var _a;
724
762
  window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
763
+ if (messageHandlerRef.current) {
764
+ window.removeEventListener("message", messageHandlerRef.current);
765
+ }
725
766
  };
726
767
  }, []);
727
768
  return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
@@ -51,7 +51,13 @@ type Value = Omit<ExternalWalletContextType<CosmosSignResult>, 'disconnect' | 'd
51
51
  };
52
52
  username?: string;
53
53
  avatar?: string;
54
- connectExternalWallet: (wallet: CommonWallet, isMobile?: boolean, isManualWalletConnect?: boolean) => Promise<void>;
54
+ connectExternalWallet: (_: {
55
+ wallet: CommonWallet;
56
+ isMobile?: boolean;
57
+ isManualWalletConnect?: boolean;
58
+ isResetAfterManualWalletConnect?: boolean;
59
+ isRetryConnection?: boolean;
60
+ }) => Promise<void>;
55
61
  addAdditionalExternalWallet: (wallet: CommonWallet) => Promise<void>;
56
62
  disconnectExternalWallet: () => Promise<void>;
57
63
  setChainIdSwitchingTo: (chainId?: string) => void;