@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
@@ -5,17 +5,22 @@ import {
5
5
  __spreadValues
6
6
  } from "../../chunk-MMUBH76A.js";
7
7
  import { jsx } from "react/jsx-runtime";
8
- import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
8
+ import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
9
9
  import { isMobile, truncateAddress } from "@getpara/web-sdk";
10
10
  import { useInternalClient } from "../hooks/utils/useInternalClient.js";
11
11
  import { useStore } from "../stores/useStore.js";
12
- import { ModalStep } from "../../modal/index.js";
12
+ import { ModalStep, openPopup } from "../../modal/index.js";
13
13
  import { useModalStore } from "../../modal/stores/index.js";
14
14
  import { useAccount, useModal, useParaStatus, useVerifyExternalWallet, useWalletState } from "../hooks/index.js";
15
+ import {
16
+ openMobileUrl
17
+ } from "@getpara/react-common";
15
18
  import { ParaEvent, dispatchEvent } from "@getpara/web-sdk";
16
19
  import { useAuthActions } from "./AuthProvider.js";
17
20
  import { IS_FULLY_LOGGED_IN_BASE_KEY } from "../hooks/queries/useIsFullyLoggedIn.js";
18
21
  import { useQueryClient } from "@tanstack/react-query";
22
+ import { useGoBack } from "../../modal/hooks/useGoBack.js";
23
+ import { validatePortalOrigin } from "../../modal/utils/validatePortalOrigin.js";
19
24
  const useWalletDisplayHelpers = (wallet) => {
20
25
  const isUsingMobileConnector = useModalStore((state) => state.isUsingMobileConnector);
21
26
  return {
@@ -125,9 +130,11 @@ function ExternalWalletProvider({ children }) {
125
130
  const { onNewAuthState } = useAuthActions();
126
131
  const { verifyExternalWalletAsync } = useVerifyExternalWallet();
127
132
  const queryClient = useQueryClient();
133
+ const goBack = useGoBack();
128
134
  const [qrUri, setQrUri] = useState();
129
135
  const [chainIdSwitchingTo, setChainIdSwitchingTo] = useState();
130
136
  const [isSigningMessage, setIsSigningMessage] = useState(false);
137
+ const popupCloseIntervalRef = useRef(null);
131
138
  const allWallets = [...evmWallets, ...solanaWallets, ...cosmosWallets];
132
139
  let wallets = allWallets.filter(
133
140
  (w) => (w.internalId !== "FARCASTER" || (para == null ? void 0 : para.isFarcasterMiniApp)) && externalWallets.includes(w.internalId)
@@ -142,20 +149,25 @@ function ExternalWalletProvider({ children }) {
142
149
  () => wallets.find((w) => w.id === (selectedExternalWallet == null ? void 0 : selectedExternalWallet.id) && w.type === (selectedExternalWallet == null ? void 0 : selectedExternalWallet.type)),
143
150
  [wallets, selectedExternalWallet]
144
151
  );
145
- const updateQrUri = () => __async(this, null, function* () {
146
- var _a;
147
- const uri = yield (_a = wallet == null ? void 0 : wallet.getQrUri) == null ? void 0 : _a.call(wallet);
148
- setQrUri(uri);
149
- });
150
- useEffect(() => {
151
- if (wallet) {
152
- if (!qrUri) {
153
- updateQrUri();
154
- }
155
- } else if (qrUri) {
156
- setQrUri(void 0);
152
+ const [walletConnectCleanup, setWalletConnectCleanup] = useState(null);
153
+ const listenForWalletConnectUri = () => {
154
+ setQrUri(void 0);
155
+ if (walletConnectCleanup) {
156
+ walletConnectCleanup();
157
157
  }
158
- }, [wallet]);
158
+ const callback = (event) => {
159
+ openMobileUrl(event.detail);
160
+ setQrUri(event.detail);
161
+ cleanup();
162
+ setWalletConnectCleanup(null);
163
+ };
164
+ const cleanup = () => {
165
+ window.removeEventListener("PARA_WALLETCONNECT_URI_READY", callback);
166
+ };
167
+ window.addEventListener("PARA_WALLETCONNECT_URI_READY", callback);
168
+ setWalletConnectCleanup(() => cleanup);
169
+ return cleanup;
170
+ };
159
171
  const isWithFullAuth = (wallet2) => {
160
172
  if (connectionOnly) {
161
173
  return false;
@@ -351,7 +363,10 @@ function ExternalWalletProvider({ children }) {
351
363
  return verifyExternalWalletParams;
352
364
  }), [cosmosSignVerificationMessage, evmSignVerificationMessage, solanaSignVerificationMessage, wallet]);
353
365
  const signMessage = useCallback(
354
- (_0) => __async(this, [_0], function* ({ message, externalWallet: _externalWallet }) {
366
+ (_0) => __async(this, [_0], function* ({
367
+ message,
368
+ externalWallet: _externalWallet
369
+ }) {
355
370
  var _a;
356
371
  setExternalWalletError();
357
372
  setIsSigningMessage(true);
@@ -362,14 +377,16 @@ function ExternalWalletProvider({ children }) {
362
377
  switch (walletType) {
363
378
  case "COSMOS":
364
379
  {
365
- const { address, signature, error, cosmosPublicKeyHex, cosmosSigner } = yield cosmosSignMessage({
366
- message,
367
- externalWallet
368
- });
380
+ const { address, signature, error, cosmosPublicKeyHex, cosmosSigner, addressBech32 } = yield cosmosSignMessage(
381
+ {
382
+ message,
383
+ externalWallet
384
+ }
385
+ );
369
386
  if (error) {
370
387
  throw new Error(error);
371
388
  } else if (signature && address) {
372
- response = { address, signature, cosmosPublicKeyHex, cosmosSigner };
389
+ response = { address, signature, cosmosPublicKeyHex, cosmosSigner, addressBech32 };
373
390
  }
374
391
  }
375
392
  break;
@@ -407,6 +424,7 @@ function ExternalWalletProvider({ children }) {
407
424
  );
408
425
  const addAdditionalExternalWallet = useCallback(
409
426
  (wallet2) => __async(this, null, function* () {
427
+ setExternalWalletError();
410
428
  try {
411
429
  const walletInfo = yield requestInfo(wallet2.id, wallet2.type);
412
430
  const walletAddress = wallet2.type === "COSMOS" && walletInfo.addressBech32 ? walletInfo.addressBech32 : walletInfo.address;
@@ -470,8 +488,199 @@ function ExternalWalletProvider({ children }) {
470
488
  }),
471
489
  [para, connectionOnly, includeWalletVerification, setStep, setExternalWalletError]
472
490
  );
491
+ const setupExternalWalletVerificationStatusListener = (wallet2) => {
492
+ typeof window !== "undefined" && window.addEventListener("message", function handleMessage(event) {
493
+ return __async(this, null, function* () {
494
+ var _a, _b, _c, _d;
495
+ if (!validatePortalOrigin(event, para.ctx)) {
496
+ return;
497
+ }
498
+ if (((_a = event.data) == null ? void 0 : _a.type) === "EW_VERIFY_SUCCESS") {
499
+ clearPopupWindowCloseListener();
500
+ const serverAuthState = (_b = event.data) == null ? void 0 : _b.serverAuthState;
501
+ if (serverAuthState && ((_c = serverAuthState.externalWallet) == null ? void 0 : _c.withFullParaAuth)) {
502
+ const authState = yield para.verifyExternalWallet({ serverAuthState });
503
+ yield onNewAuthState(authState);
504
+ } else {
505
+ setStep(ModalStep.LOGIN_DONE);
506
+ }
507
+ window.removeEventListener("message", handleMessage);
508
+ }
509
+ if (((_d = event.data) == null ? void 0 : _d.type) === "EW_VERIFY_RETRY") {
510
+ yield handleTriggerSignMessage(wallet2, event.data.message);
511
+ window.removeEventListener("message", handleMessage);
512
+ }
513
+ });
514
+ });
515
+ };
516
+ const handlePostMessage = (message) => {
517
+ var _a;
518
+ if (refs.popupWindow.current) {
519
+ refs.popupWindow.current.postMessage(message, "*");
520
+ } else if (refs.iFrame.current) {
521
+ (_a = refs.iFrame.current.contentWindow) == null ? void 0 : _a.postMessage(message, "*");
522
+ }
523
+ };
524
+ const handleTriggerSignMessage = (wallet2, message) => __async(this, null, function* () {
525
+ setupExternalWalletVerificationStatusListener(wallet2);
526
+ try {
527
+ const { address, signature, cosmosPublicKeyHex, cosmosSigner, addressBech32 } = yield signMessage({
528
+ message,
529
+ externalWallet: wallet2
530
+ });
531
+ const paraWallet = Object.values(para.externalWallets)[0];
532
+ const walletType = paraWallet == null ? void 0 : paraWallet.type;
533
+ let verifyExternalWalletParams;
534
+ const withVerification = includeWalletVerification;
535
+ const isConnectionOnly = connectionOnly;
536
+ const withFullParaAuth = (paraWallet == null ? void 0 : paraWallet.name) ? isWithFullAuth(paraWallet) : false;
537
+ const defaultWalletInfo = {
538
+ withVerification,
539
+ isConnectionOnly,
540
+ withFullParaAuth,
541
+ provider: paraWallet.name,
542
+ providerId: paraWallet.externalProviderId,
543
+ isExternal: true
544
+ };
545
+ switch (walletType) {
546
+ case "COSMOS":
547
+ {
548
+ verifyExternalWalletParams = {
549
+ externalWallet: __spreadValues({
550
+ partnerId: para.partnerId,
551
+ type: "COSMOS",
552
+ address,
553
+ addressBech32
554
+ }, defaultWalletInfo),
555
+ signedMessage: signature,
556
+ cosmosPublicKeyHex,
557
+ cosmosSigner
558
+ };
559
+ }
560
+ break;
561
+ case "EVM":
562
+ {
563
+ verifyExternalWalletParams = {
564
+ externalWallet: __spreadValues({
565
+ partnerId: para.partnerId,
566
+ type: "EVM",
567
+ address
568
+ }, defaultWalletInfo),
569
+ signedMessage: signature
570
+ };
571
+ }
572
+ break;
573
+ case "SOLANA":
574
+ {
575
+ verifyExternalWalletParams = {
576
+ externalWallet: __spreadValues({
577
+ partnerId: para.partnerId,
578
+ type: "SOLANA",
579
+ address
580
+ }, defaultWalletInfo),
581
+ signedMessage: signature
582
+ };
583
+ }
584
+ break;
585
+ default:
586
+ break;
587
+ }
588
+ if (!(verifyExternalWalletParams == null ? void 0 : verifyExternalWalletParams.externalWallet) || !(verifyExternalWalletParams == null ? void 0 : verifyExternalWalletParams.signedMessage)) {
589
+ console.error("No signature or address found on the verifyWalletSignature response.");
590
+ handlePostMessage({ type: "EW_SIGN_MESSAGE_ERROR", error: "Signature verification failed." });
591
+ return;
592
+ }
593
+ handlePostMessage({ type: "EW_SIGN_MESSAGE_SUCCESS", verifyExternalWalletParams });
594
+ } catch (error) {
595
+ handlePostMessage({ type: "EW_SIGN_MESSAGE_ERROR", error: error.message || "Error signing message" });
596
+ }
597
+ });
598
+ const setupExternalWalletVerificationTriggerListener = (wallet2) => {
599
+ if (!wallet2) {
600
+ return;
601
+ }
602
+ typeof window !== "undefined" && window.addEventListener("message", function handleMessage(event) {
603
+ return __async(this, null, function* () {
604
+ var _a;
605
+ if (!validatePortalOrigin(event, para.ctx)) {
606
+ return;
607
+ }
608
+ if (((_a = event.data) == null ? void 0 : _a.type) === "EW_TRIGGER_SIGN_MESSAGE") {
609
+ yield handleTriggerSignMessage(wallet2, event.data.message);
610
+ window.removeEventListener("message", handleMessage);
611
+ }
612
+ });
613
+ });
614
+ };
615
+ const setupPopupWindowCloseListener = () => {
616
+ const popup = refs.popupWindow.current;
617
+ if (!popup) return;
618
+ if (popupCloseIntervalRef.current) {
619
+ clearInterval(popupCloseIntervalRef.current);
620
+ }
621
+ popupCloseIntervalRef.current = setInterval(() => {
622
+ if (popup.closed) {
623
+ if (popupCloseIntervalRef.current) {
624
+ clearInterval(popupCloseIntervalRef.current);
625
+ popupCloseIntervalRef.current = null;
626
+ }
627
+ goBack();
628
+ disconnectExternalWallet();
629
+ }
630
+ }, 500);
631
+ };
632
+ const clearPopupWindowCloseListener = () => {
633
+ if (popupCloseIntervalRef.current) {
634
+ clearInterval(popupCloseIntervalRef.current);
635
+ popupCloseIntervalRef.current = null;
636
+ refs.popupWindow.current = null;
637
+ }
638
+ };
639
+ const handlePostConnectRetry = () => {
640
+ handlePostMessage({ type: "EW_CONNECT_RETRY" });
641
+ };
642
+ const handlePostConnectError = (error) => {
643
+ handlePostMessage({ type: "EW_CONNECT_ERROR", error });
644
+ };
645
+ const handleConnectRetryMessage = (wallet2) => (event) => __async(this, null, function* () {
646
+ var _a;
647
+ if (!validatePortalOrigin(event, para.ctx)) {
648
+ return;
649
+ }
650
+ if (((_a = event.data) == null ? void 0 : _a.type) === "EW_CONNECT_RETRY") {
651
+ clearExternalWalletConnectionRetryListener(wallet2);
652
+ yield connectExternalWallet({ wallet: wallet2, isMobileConnect: wallet2.isMobile, isRetryConnection: true });
653
+ }
654
+ });
655
+ const setupExternalWalletConnectionRetryListener = (wallet2) => {
656
+ typeof window !== "undefined" && window.addEventListener("message", handleConnectRetryMessage(wallet2));
657
+ };
658
+ const clearExternalWalletConnectionRetryListener = (wallet2) => {
659
+ window.removeEventListener("message", handleConnectRetryMessage(wallet2));
660
+ };
473
661
  const connectExternalWallet = useCallback(
474
- (wallet2, isMobileConnect, isManualWalletConnect, isResetAfterManualWalletConnect) => __async(this, null, function* () {
662
+ (_0) => __async(this, [_0], function* ({
663
+ wallet: wallet2,
664
+ isManualWalletConnect,
665
+ isMobileConnect,
666
+ isResetAfterManualWalletConnect,
667
+ isRetryConnection
668
+ }) {
669
+ if (isRetryConnection) {
670
+ clearExternalWalletConnectionRetryListener(wallet2);
671
+ handlePostConnectRetry();
672
+ }
673
+ if (!isMobile() && isWithFullAuth(wallet2)) {
674
+ const popupUrl = yield para.constructPortalUrl("connectExternalWallet");
675
+ if (typeof window !== void 0) {
676
+ refs.popupWindow.current = openPopup({
677
+ url: popupUrl,
678
+ type: "LOGIN_EXTERNAL_WALLET",
679
+ target: "ParaExternalWallet"
680
+ });
681
+ }
682
+ setupPopupWindowCloseListener();
683
+ }
475
684
  if (isExternalWalletConnecting && isManualWalletConnect) {
476
685
  yield evmDisconnect();
477
686
  yield solanaDisconnect();
@@ -479,23 +688,27 @@ function ExternalWalletProvider({ children }) {
479
688
  setQrUri(void 0);
480
689
  setIsExternalWalletConnecting(false);
481
690
  }
482
- if (isResetAfterManualWalletConnect || isManualWalletConnect || !isExternalWalletConnecting) {
691
+ if (isResetAfterManualWalletConnect || isManualWalletConnect || isMobileConnect || !isExternalWalletConnecting) {
483
692
  setExternalWalletError();
484
693
  setIsExternalWalletConnecting(true);
485
694
  setIsUsingMobileConnector(isMobileConnect);
695
+ listenForWalletConnectUri();
486
696
  const { address, error, authState } = yield isMobileConnect ? wallet2.connectMobile(isManualWalletConnect, connectionOnly) : wallet2.connect(connectionOnly);
487
697
  if (error) {
488
698
  setExternalWalletError([error]);
489
699
  setIsUsingMobileConnector();
700
+ handlePostConnectError(error);
490
701
  if (isManualWalletConnect && error === "Connection request rejected") {
491
702
  setExternalWalletError();
492
- yield connectExternalWallet(wallet2, false, false, true);
493
- yield updateQrUri();
703
+ yield connectExternalWallet({ wallet: wallet2, isResetAfterManualWalletConnect: true });
494
704
  return;
495
705
  }
706
+ setupExternalWalletConnectionRetryListener(wallet2);
496
707
  } else if (address) {
497
708
  if (!!authState && (isWithFullAuth(wallet2) || includeWalletVerification)) {
709
+ clearExternalWalletConnectionRetryListener(wallet2);
498
710
  onNewAuthState(authState);
711
+ setupExternalWalletVerificationTriggerListener(authState.externalWallet);
499
712
  } else {
500
713
  setStep(ModalStep.LOGIN_DONE);
501
714
  }
@@ -521,7 +734,7 @@ function ExternalWalletProvider({ children }) {
521
734
  isConnectionOnly: true
522
735
  });
523
736
  } else {
524
- yield connectExternalWallet(evmWallet, false, true);
737
+ yield connectExternalWallet({ wallet: evmWallet, isManualWalletConnect: true });
525
738
  }
526
739
  }
527
740
  if (solanaWallet && (solanaFarcasterStatus == null ? void 0 : solanaFarcasterStatus.isPresent)) {
@@ -535,7 +748,7 @@ function ExternalWalletProvider({ children }) {
535
748
  isConnectionOnly: true
536
749
  });
537
750
  } else {
538
- yield connectExternalWallet(solanaWallet, false, true);
751
+ yield connectExternalWallet({ wallet: solanaWallet, isManualWalletConnect: true });
539
752
  }
540
753
  }
541
754
  if (loginWallets.length > 0) {
@@ -547,6 +760,7 @@ function ExternalWalletProvider({ children }) {
547
760
  }
548
761
  });
549
762
  const requestInfo = (providerId, type) => __async(this, null, function* () {
763
+ listenForWalletConnectUri();
550
764
  switch (type) {
551
765
  case "EVM": {
552
766
  const externalWallet = yield evmRequestInfo(providerId);
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@getpara/react-sdk-lite",
3
- "version": "2.0.0-alpha.67",
3
+ "version": "2.0.0-alpha.69",
4
4
  "bin": {
5
5
  "setup-para": "dist/cli/cli.mjs"
6
6
  },
7
7
  "dependencies": {
8
- "@getpara/react-common": "2.0.0-alpha.67",
9
- "@getpara/react-components": "2.0.0-alpha.67",
10
- "@getpara/web-sdk": "2.0.0-alpha.67",
8
+ "@getpara/react-common": "2.0.0-alpha.69",
9
+ "@getpara/react-components": "2.0.0-alpha.69",
10
+ "@getpara/web-sdk": "2.0.0-alpha.69",
11
11
  "date-fns": "^3.6.0",
12
12
  "framer-motion": "^11.3.31",
13
13
  "libphonenumber-js": "^1.11.7",
@@ -16,9 +16,9 @@
16
16
  "zustand-sync-tabs": "^0.2.2"
17
17
  },
18
18
  "devDependencies": {
19
- "@getpara/cosmos-wallet-connectors": "2.0.0-alpha.67",
20
- "@getpara/evm-wallet-connectors": "2.0.0-alpha.67",
21
- "@getpara/solana-wallet-connectors": "2.0.0-alpha.67",
19
+ "@getpara/cosmos-wallet-connectors": "2.0.0-alpha.69",
20
+ "@getpara/evm-wallet-connectors": "2.0.0-alpha.69",
21
+ "@getpara/solana-wallet-connectors": "2.0.0-alpha.69",
22
22
  "@tanstack/react-query": "^5.74.0",
23
23
  "@testing-library/dom": "^10.4.0",
24
24
  "@testing-library/react": "^16.3.0",
@@ -38,7 +38,7 @@
38
38
  "package.json",
39
39
  "styles.css"
40
40
  ],
41
- "gitHead": "0266cc49e978575fed0b12c9bb0c832651e140eb",
41
+ "gitHead": "956310e0ff58cc8e2736625d221245ab68304855",
42
42
  "main": "dist/index.js",
43
43
  "peerDependencies": {
44
44
  "@tanstack/react-query": ">=5.0.0",
@@ -1 +0,0 @@
1
- export declare const routeMobileExternalWallet: (qrUri?: string) => void;
@@ -1,31 +0,0 @@
1
- "use client";
2
- import "../../chunk-MMUBH76A.js";
3
- import { isAndroid, isMobile, isTelegram } from "@getpara/web-sdk";
4
- const routeMobileExternalWallet = (qrUri) => {
5
- if (typeof window === "undefined") {
6
- return;
7
- }
8
- if (isMobile()) {
9
- if (!qrUri) return;
10
- if (!isTelegram() && qrUri.startsWith("http")) {
11
- const link = document.createElement("a");
12
- link.href = qrUri;
13
- link.target = "_blank";
14
- link.rel = "noreferrer noopener";
15
- link.click();
16
- } else {
17
- if (isTelegram()) {
18
- let href = qrUri;
19
- if (isAndroid()) {
20
- href = encodeURI(qrUri);
21
- }
22
- window.open(href, "_blank", "noreferrer noopener");
23
- } else {
24
- window.location.href = qrUri;
25
- }
26
- }
27
- }
28
- };
29
- export {
30
- routeMobileExternalWallet
31
- };