@getpara/react-sdk-lite 2.0.0-dev.7 → 2.1.0

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 (172) hide show
  1. package/dist/cli/cli.mjs +26 -1
  2. package/dist/modal/ParaModal.js +16 -10
  3. package/dist/modal/components/Account/Account.js +42 -4
  4. package/dist/modal/components/Account/AccountHeader.js +13 -16
  5. package/dist/modal/components/Account/AccountProfile.d.ts +1 -1
  6. package/dist/modal/components/Account/AccountProfile.js +82 -210
  7. package/dist/modal/components/Account/AccountProfileEntry.d.ts +12 -0
  8. package/dist/modal/components/Account/AccountProfileEntry.js +228 -0
  9. package/dist/modal/components/Account/AccountProfileLinkOptions.js +15 -4
  10. package/dist/modal/components/Account/AccountSend/AccountSendAsset.d.ts +1 -0
  11. package/dist/modal/components/Account/AccountSend/AccountSendAsset.js +94 -0
  12. package/dist/modal/components/Account/AccountSend/AccountSendForm.d.ts +1 -0
  13. package/dist/modal/components/Account/AccountSend/AccountSendForm.js +343 -0
  14. package/dist/modal/components/Account/AccountSend/AccountSendNetwork.d.ts +1 -0
  15. package/dist/modal/components/Account/AccountSend/AccountSendNetwork.js +53 -0
  16. package/dist/modal/components/Account/AccountSend/AccountSendNoAssets.d.ts +1 -0
  17. package/dist/modal/components/Account/AccountSend/AccountSendNoAssets.js +56 -0
  18. package/dist/modal/components/Account/AccountSend/AssetNetwork.d.ts +5 -0
  19. package/dist/modal/components/Account/AccountSend/AssetNetwork.js +36 -0
  20. package/dist/modal/components/Account/AccountSend/context.d.ts +38 -0
  21. package/dist/modal/components/Account/AccountSend/context.js +418 -0
  22. package/dist/modal/components/Account/AccountSend/index.d.ts +4 -0
  23. package/dist/modal/components/Account/AccountSend/index.js +67 -0
  24. package/dist/modal/components/Account/AccountWallet.d.ts +1 -0
  25. package/dist/modal/components/Account/AccountWallet.js +134 -0
  26. package/dist/modal/components/{WalletSelect/WalletSelect.d.ts → Account/AccountWalletSelect.d.ts} +1 -1
  27. package/dist/modal/components/{WalletSelect/WalletSelect.js → Account/AccountWalletSelect.js} +20 -6
  28. package/dist/modal/components/AddFunds/AddFunds.js +3 -2
  29. package/dist/modal/components/AddFunds/AddFundsAsset.js +7 -6
  30. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +5 -5
  31. package/dist/modal/components/AddFunds/AddFundsProvider.js +1 -2
  32. package/dist/modal/components/AddFunds/AddFundsSettings.js +13 -54
  33. package/dist/modal/components/AddFunds/common.d.ts +0 -14
  34. package/dist/modal/components/AddFunds/common.js +1 -8
  35. package/dist/modal/components/AuthInput/AuthInput.js +2 -2
  36. package/dist/modal/components/AwaitingAccountStep/AwaitingAccountStep.js +3 -2
  37. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +8 -33
  38. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +5 -2
  39. package/dist/modal/components/Body/Body.js +81 -48
  40. package/dist/modal/components/ChainSwitch/ChainSwitch.js +8 -5
  41. package/dist/modal/components/Controls/ChainSelect.js +1 -2
  42. package/dist/modal/components/Controls/Controls.js +3 -1
  43. package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.d.ts +5 -1
  44. package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.js +48 -19
  45. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +5 -2
  46. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +63 -33
  47. package/dist/modal/components/ExternalWallets/ExternalWallets.d.ts +3 -1
  48. package/dist/modal/components/ExternalWallets/ExternalWallets.js +22 -12
  49. package/dist/modal/components/Footer/Footer.js +4 -5
  50. package/dist/modal/components/Header/Header.js +1 -2
  51. package/dist/modal/components/Header/hooks/useStepTitle.js +53 -38
  52. package/dist/modal/components/Hero/Hero.js +5 -3
  53. package/dist/modal/components/IFrameStep/IFrameStep.js +13 -12
  54. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +4 -1
  55. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +6 -5
  56. package/dist/modal/components/OAuth/TelegramOAuthStep.js +6 -5
  57. package/dist/modal/components/OnRampComponents/AddingFunds.js +1 -1
  58. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +1 -2
  59. package/dist/modal/components/QuantityInput.d.ts +9 -0
  60. package/dist/modal/components/QuantityInput.js +91 -0
  61. package/dist/modal/components/SearchableButtonList.d.ts +34 -0
  62. package/dist/modal/components/SearchableButtonList.js +223 -0
  63. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +4 -1
  64. package/dist/modal/components/SwitchWalletsStep/SwitchWalletsStep.d.ts +1 -0
  65. package/dist/modal/components/SwitchWalletsStep/SwitchWalletsStep.js +10 -0
  66. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +13 -2
  67. package/dist/modal/components/Waiting/Waiting.d.ts +1 -1
  68. package/dist/modal/components/Waiting/Waiting.js +7 -2
  69. package/dist/modal/components/WalletCard/WalletCard.js +2 -3
  70. package/dist/modal/components/WalletSelectOld/WalletSelectOld.d.ts +7 -1
  71. package/dist/modal/components/WalletSelectOld/WalletSelectOld.js +33 -12
  72. package/dist/modal/components/common.d.ts +8 -10
  73. package/dist/modal/components/common.js +16 -36
  74. package/dist/modal/hooks/index.d.ts +4 -0
  75. package/dist/modal/hooks/index.js +5 -0
  76. package/dist/modal/hooks/useDebounce.d.ts +4 -0
  77. package/dist/modal/hooks/useDebounce.js +16 -0
  78. package/dist/modal/hooks/useFarcasterLogin.js +8 -1
  79. package/dist/modal/hooks/useTelegramLogin.js +4 -0
  80. package/dist/modal/index.d.ts +1 -1
  81. package/dist/modal/index.js +1 -1
  82. package/dist/modal/stores/modal/actions.js +9 -2
  83. package/dist/modal/stores/modal/useModalStore.d.ts +9 -1
  84. package/dist/modal/stores/modal/useModalStore.js +6 -2
  85. package/dist/modal/types/modalProps.d.ts +5 -1
  86. package/dist/modal/utils/authInputHelpers.js +1 -1
  87. package/dist/modal/utils/countryCodes.js +50 -1
  88. package/dist/modal/utils/getWalletDisplayName.js +1 -1
  89. package/dist/modal/utils/openPopup.d.ts +1 -1
  90. package/dist/modal/utils/openPopup.js +6 -2
  91. package/dist/modal/utils/renderTextWithLinks.d.ts +2 -0
  92. package/dist/modal/utils/renderTextWithLinks.js +34 -0
  93. package/dist/modal/utils/steps.d.ts +24 -3
  94. package/dist/modal/utils/steps.js +51 -5
  95. package/dist/modal/utils/stringFormatters.d.ts +2 -3
  96. package/dist/modal/utils/stringFormatters.js +11 -7
  97. package/dist/modal/utils/validatePortalOrigin.d.ts +2 -0
  98. package/dist/modal/utils/validatePortalOrigin.js +15 -0
  99. package/dist/provider/ParaProviderMin.js +13 -5
  100. package/dist/provider/actions/getEmbeddedAccount.d.ts +3 -2
  101. package/dist/provider/actions/getEmbeddedAccount.js +13 -4
  102. package/dist/provider/actions/index.d.ts +11 -9
  103. package/dist/provider/actions/index.js +4 -0
  104. package/dist/provider/components/CosmosWalletWrapper.js +3 -3
  105. package/dist/provider/components/EvmWalletWrapper.js +3 -3
  106. package/dist/provider/components/ExternalWalletWrapper.js +7 -1
  107. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +3 -1
  108. package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +3 -1
  109. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +3 -1
  110. package/dist/provider/hooks/mutations/index.d.ts +2 -0
  111. package/dist/provider/hooks/mutations/index.js +4 -0
  112. package/dist/provider/hooks/mutations/useAddAuthMethod.d.ts +42 -0
  113. package/dist/provider/hooks/mutations/useAddAuthMethod.js +57 -0
  114. package/dist/provider/hooks/mutations/useClaimPregenWallets.d.ts +2 -2
  115. package/dist/provider/hooks/mutations/useCreateGuestWallets.d.ts +2 -2
  116. package/dist/provider/hooks/mutations/useCreatePregenWallet.d.ts +5 -5
  117. package/dist/provider/hooks/mutations/useCreatePregenWalletPerType.d.ts +2 -2
  118. package/dist/provider/hooks/mutations/useCreateWallet.d.ts +2 -2
  119. package/dist/provider/hooks/mutations/useCreateWalletPerType.d.ts +2 -2
  120. package/dist/provider/hooks/mutations/useEnable2fa.d.ts +2 -2
  121. package/dist/provider/hooks/mutations/useExportPrivateKey.d.ts +15 -0
  122. package/dist/provider/hooks/mutations/useExportPrivateKey.js +32 -0
  123. package/dist/provider/hooks/mutations/useHasPregenWallet.d.ts +2 -2
  124. package/dist/provider/hooks/mutations/useIssueJwt.d.ts +2 -2
  125. package/dist/provider/hooks/mutations/useKeepSessionAlive.d.ts +2 -2
  126. package/dist/provider/hooks/mutations/useLoginExternalWallet.d.ts +8 -2
  127. package/dist/provider/hooks/mutations/useLogout.d.ts +2 -2
  128. package/dist/provider/hooks/mutations/useResendVerificationCode.d.ts +2 -2
  129. package/dist/provider/hooks/mutations/useSetup2fa.d.ts +2 -2
  130. package/dist/provider/hooks/mutations/useSignMessage.d.ts +2 -2
  131. package/dist/provider/hooks/mutations/useSignTransaction.d.ts +2 -2
  132. package/dist/provider/hooks/mutations/useSignUpOrLogIn.d.ts +2 -2
  133. package/dist/provider/hooks/mutations/useSwitchWallets.d.ts +57 -0
  134. package/dist/provider/hooks/mutations/useSwitchWallets.js +30 -0
  135. package/dist/provider/hooks/mutations/useUpdatePregenWalletIdentifier.d.ts +2 -2
  136. package/dist/provider/hooks/mutations/useVerify2fa.d.ts +2 -2
  137. package/dist/provider/hooks/mutations/useVerifyExternalWallet.d.ts +18 -27
  138. package/dist/provider/hooks/mutations/useVerifyFarcaster.d.ts +5 -5
  139. package/dist/provider/hooks/mutations/useVerifyNewAccount.d.ts +14 -11
  140. package/dist/provider/hooks/mutations/useVerifyOAuth.d.ts +2 -2
  141. package/dist/provider/hooks/mutations/useVerifyTelegram.d.ts +5 -5
  142. package/dist/provider/hooks/mutations/useWaitForLogin.d.ts +2 -2
  143. package/dist/provider/hooks/mutations/useWaitForSignup.d.ts +2 -2
  144. package/dist/provider/hooks/mutations/useWaitForWalletCreation.d.ts +2 -2
  145. package/dist/provider/hooks/queries/index.d.ts +1 -0
  146. package/dist/provider/hooks/queries/index.js +2 -0
  147. package/dist/provider/hooks/queries/useAccount.js +58 -24
  148. package/dist/provider/hooks/queries/useLinkedAccounts.js +4 -2
  149. package/dist/provider/hooks/queries/useProfileBalance.d.ts +29 -0
  150. package/dist/provider/hooks/queries/useProfileBalance.js +65 -0
  151. package/dist/provider/hooks/utils/useAssetInfo.d.ts +3 -0
  152. package/dist/provider/hooks/utils/useAssetInfo.js +21 -0
  153. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +1 -1
  154. package/dist/provider/hooks/utils/useEventListeners.js +22 -5
  155. package/dist/provider/hooks/utils/useModal.js +3 -3
  156. package/dist/provider/hooks/utils/useWalletState.d.ts +2 -1
  157. package/dist/provider/hooks/utils/useWalletState.js +2 -1
  158. package/dist/provider/providers/AccountLinkProvider.js +18 -11
  159. package/dist/provider/providers/AssetsProvider.d.ts +14 -0
  160. package/dist/provider/providers/AssetsProvider.js +68 -0
  161. package/dist/provider/providers/AuthProvider.d.ts +4 -0
  162. package/dist/provider/providers/AuthProvider.js +187 -43
  163. package/dist/provider/providers/ExternalWalletProvider.d.ts +19 -5
  164. package/dist/provider/providers/ExternalWalletProvider.js +363 -44
  165. package/dist/provider/stores/getters.d.ts +2 -2
  166. package/dist/provider/stores/slices/modal.js +4 -1
  167. package/dist/provider/stores/types.d.ts +6 -3
  168. package/package.json +8 -8
  169. package/dist/modal/constants/constants.d.ts +0 -35
  170. package/dist/modal/constants/constants.js +0 -148
  171. package/dist/modal/utils/routeMobileExternalWallet.d.ts +0 -1
  172. package/dist/modal/utils/routeMobileExternalWallet.js +0 -31
@@ -5,7 +5,8 @@ import { TWalletType } from '@getpara/web-sdk';
5
5
  export declare const useWalletState: () => {
6
6
  selectedWallet: {
7
7
  id: string | undefined;
8
- type: "EVM" | "SOLANA" | "COSMOS" | undefined;
8
+ type: "SOLANA" | "COSMOS" | "EVM" | undefined;
9
+ address: string | undefined;
9
10
  };
10
11
  setSelectedWallet: ({ id, type }: {
11
12
  id?: string;
@@ -37,7 +37,8 @@ const useWalletState = () => {
37
37
  return {
38
38
  selectedWallet: {
39
39
  id: selectedWalletId,
40
- type: selectedWalletType
40
+ type: selectedWalletType,
41
+ address: selectedWalletId ? client == null ? void 0 : client.getDisplayAddress(selectedWalletId, { addressType: selectedWalletType }) : void 0
41
42
  },
42
43
  setSelectedWallet,
43
44
  updateSelectedWallet
@@ -70,10 +70,9 @@ const AccountLinkProvider = ({ children }) => {
70
70
  var _a, _b, _c;
71
71
  const para = useInternalClient();
72
72
  const queryClient = useQueryClient();
73
- const account = useAccount();
73
+ const { embedded } = useAccount();
74
74
  const { data: coreAccountLinkInProgress } = useAccountLinkInProgress();
75
75
  const {
76
- wallet: connectedWallet,
77
76
  wallets,
78
77
  signMessage,
79
78
  isSigningMessage,
@@ -113,8 +112,7 @@ const AccountLinkProvider = ({ children }) => {
113
112
  status: statusVerifyExternalWalletLink,
114
113
  reset: resetVerifyExternalWalletLink
115
114
  } = useVerifyExternalWalletLink();
116
- const { embedded } = account;
117
- const isEnabled = (embedded == null ? void 0 : embedded.isConnected) || !(embedded == null ? void 0 : embedded.isGuestMode) && (!((_a = para.authInfo) == null ? void 0 : _a.externalWallet) || includeWalletVerification || externalWalletsWithFullAuth.includes((_c = (_b = para.authInfo) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.providerId));
115
+ const isEnabled = !(embedded == null ? void 0 : embedded.isGuestMode) && (embedded == null ? void 0 : embedded.isConnected) && (!((_a = para.authInfo) == null ? void 0 : _a.externalWallet) || includeWalletVerification || externalWalletsWithFullAuth === "ALL" || externalWalletsWithFullAuth.includes((_c = (_b = para.authInfo) == null ? void 0 : _b.externalWallet) == null ? void 0 : _c.providerId));
118
116
  const [accountLinkInProgress, setAccountLinkInProgress] = useState(
119
117
  coreAccountLinkInProgress || void 0
120
118
  );
@@ -152,9 +150,6 @@ const AccountLinkProvider = ({ children }) => {
152
150
  }
153
151
  const providerId = supportedWalletId != null ? supportedWalletId : args.externalWallet.provider;
154
152
  const type = args.externalWallet.type;
155
- if (providerId === (connectedWallet == null ? void 0 : connectedWallet.id)) {
156
- throw new Error(`Cannot link the currently connected external wallet: ${providerId}`);
157
- }
158
153
  setAccountLinkInProgress({
159
154
  type: "EXTERNAL_WALLET",
160
155
  pendingWalletProvider: providerId,
@@ -164,7 +159,7 @@ const AccountLinkProvider = ({ children }) => {
164
159
  if (!linkWallet) {
165
160
  throw new Error(`wallet not installed: ${providerId}`);
166
161
  }
167
- openModal({ step: !type ? ModalStep.EX_WALLET_NETWORK_SELECT : ModalStep.ACCOUNT_PROFILE_ADD });
162
+ openModal({ step: !type ? ModalStep.LINK_EX_WALLET_NETWORK_SELECT : ModalStep.ACCOUNT_PROFILE_ADD });
168
163
  if (!type) {
169
164
  return;
170
165
  }
@@ -193,7 +188,7 @@ const AccountLinkProvider = ({ children }) => {
193
188
  setLinkAccountError(e.message);
194
189
  } finally {
195
190
  if (linkWallet.type === "EVM" || linkWallet.type === "SOLANA") {
196
- yield disconnectBase(providerId, linkWallet.type);
191
+ yield disconnectBase(providerId, linkWallet.type, { disconnectType: "ACCOUNT_LINKING" });
197
192
  }
198
193
  }
199
194
  }
@@ -316,15 +311,27 @@ const AccountLinkProvider = ({ children }) => {
316
311
  break;
317
312
  }
318
313
  };
319
- const onAccountLinkVerified = (updatedAccounts) => {
314
+ const onAccountLinkVerified = (updatedAccounts) => __async(void 0, null, function* () {
320
315
  queryClient.invalidateQueries({ queryKey: [LINKED_ACCOUNTS_BASE_KEY] });
321
316
  queryClient.setQueryData(["getLinkedAccounts"], () => updatedAccounts);
317
+ if ((accountLinkInProgress == null ? void 0 : accountLinkInProgress.type) === "EXTERNAL_WALLET" && accountLinkInProgress.externalWallet) {
318
+ try {
319
+ yield disconnectBase(
320
+ accountLinkInProgress.externalWallet.providerId,
321
+ accountLinkInProgress.externalWallet.type,
322
+ { disconnectType: "ACCOUNT_LINKING" }
323
+ );
324
+ } catch (e) {
325
+ }
326
+ }
322
327
  setTimeout(() => {
323
328
  setStep(ModalStep.ACCOUNT_PROFILE);
329
+ setAccountLinkInProgress(void 0);
324
330
  }, 2e3);
325
- };
331
+ });
326
332
  const onAccountLinkError = (e) => {
327
333
  setLinkAccountError(e instanceof Error ? e.message : e);
334
+ setAccountLinkInProgress(void 0);
328
335
  };
329
336
  const unlinkAccount = (linkedAccount) => {
330
337
  setUnlinkingAccount(linkedAccount);
@@ -0,0 +1,14 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { AssetMetadataIndexed, ProfileBalance } from '@getpara/web-sdk';
3
+ type Value = {
4
+ displayCurrency: 'USD';
5
+ profileBalance: ProfileBalance | null;
6
+ profileBalanceIsPending: boolean;
7
+ assetMetadata: AssetMetadataIndexed | null;
8
+ assetMetadataIsPending: boolean;
9
+ totalBalance: string | undefined;
10
+ };
11
+ export declare const AssetsContext: import("react").Context<Value>;
12
+ export declare function AssetsProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
13
+ export declare const useAssets: () => Value;
14
+ export {};
@@ -0,0 +1,68 @@
1
+ "use client";
2
+ import "../../chunk-MMUBH76A.js";
3
+ import { jsx } from "react/jsx-runtime";
4
+ import { createContext, useContext, useMemo } from "react";
5
+ import { formatCurrency, formatAssetQuantity } from "@getpara/web-sdk";
6
+ import { useAssetInfo } from "../hooks/utils/useAssetInfo.js";
7
+ import { useStore } from "../stores/useStore.js";
8
+ import { useProfileBalance } from "../hooks/queries/index.js";
9
+ const AssetsContext = createContext({
10
+ displayCurrency: "USD",
11
+ profileBalance: null,
12
+ profileBalanceIsPending: true,
13
+ assetMetadata: null,
14
+ assetMetadataIsPending: true,
15
+ totalBalance: void 0
16
+ });
17
+ function AssetsProvider({ children }) {
18
+ const balancesConfig = useStore((state) => {
19
+ var _a;
20
+ return (_a = state.modalConfig) == null ? void 0 : _a.balances;
21
+ });
22
+ const { data: profileBalance, isPending: profileBalanceIsPending } = useProfileBalance();
23
+ const { data: assetMetadata, isPending: assetMetadataIsPending } = useAssetInfo();
24
+ const totalBalance = useMemo(() => {
25
+ switch (true) {
26
+ case !balancesConfig:
27
+ case (balancesConfig == null ? void 0 : balancesConfig.displayType) === "AGGREGATED":
28
+ if (!(profileBalance == null ? void 0 : profileBalance.value)) {
29
+ return void 0;
30
+ }
31
+ return formatCurrency(profileBalance.value);
32
+ default: {
33
+ if (!profileBalance) {
34
+ return void 0;
35
+ }
36
+ const assetQuantity = profileBalance.wallets.reduce((acc, wallet) => {
37
+ const asset = wallet.assets.find((a) => {
38
+ var _a;
39
+ return ((_a = a.metadata) == null ? void 0 : _a.symbol) === balancesConfig.asset.symbol;
40
+ });
41
+ if (!asset) {
42
+ return acc;
43
+ }
44
+ return acc + asset.quantity;
45
+ }, 0);
46
+ return formatAssetQuantity({ quantity: assetQuantity, symbol: balancesConfig.asset.symbol });
47
+ }
48
+ }
49
+ }, [balancesConfig, profileBalance]);
50
+ const value = useMemo(
51
+ () => ({
52
+ displayCurrency: "USD",
53
+ profileBalance: profileBalance || null,
54
+ profileBalanceIsPending,
55
+ assetMetadata: assetMetadata || null,
56
+ assetMetadataIsPending,
57
+ totalBalance
58
+ }),
59
+ [profileBalance, totalBalance, profileBalanceIsPending, assetMetadata, assetMetadataIsPending]
60
+ );
61
+ return /* @__PURE__ */ jsx(AssetsContext.Provider, { value, children });
62
+ }
63
+ const useAssets = () => useContext(AssetsContext);
64
+ export {
65
+ AssetsContext,
66
+ AssetsProvider,
67
+ useAssets
68
+ };
@@ -23,6 +23,10 @@ type Value = {
23
23
  createGuestWallets: () => void;
24
24
  isCreateGuestWalletsPending: boolean;
25
25
  logout: () => void;
26
+ switchWallets: (authMethod?: string) => void;
27
+ switchWalletsUrl: string | undefined;
28
+ setSwitchWalletsUrl: (_: string) => void;
29
+ isSwitchWalletsPending: boolean;
26
30
  biometricHints?: BiometricHints;
27
31
  };
28
32
  type Props = PropsWithChildren<{
@@ -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 } 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 {
@@ -20,22 +20,24 @@ import {
20
20
  useVerifyTelegram,
21
21
  useSetup2fa,
22
22
  useLogout,
23
- useCreateGuestWallets
23
+ useCreateGuestWallets,
24
+ useWalletState
24
25
  } from "../index.js";
26
+ import { useSwitchWallets } from "../hooks/mutations/useSwitchWallets.js";
25
27
  import { DEFAULTS } from "../../modal/constants/defaults.js";
26
28
  import { openPopup } from "../../modal/utils/openPopup.js";
27
29
  import {
28
30
  AuthMethod,
29
31
  entityToWallet,
30
- getPortalBaseURL
32
+ isMobile
31
33
  } from "@getpara/web-sdk";
32
34
  import { useInternalClient } from "../../provider/hooks/utils/useInternalClient.js";
33
35
  import { useGoBack } from "../../modal/hooks/useGoBack.js";
34
36
  import { isExternalWallet } from "@getpara/user-management-client";
35
- import { routeMobileExternalWallet } from "../../modal/utils/routeMobileExternalWallet.js";
36
37
  import { useStore } from "../stores/useStore.js";
37
38
  import { useFormattedBiometricHints } from "../hooks/utils/useFormattedBiometricHints.js";
38
39
  import { useQueryClient } from "@tanstack/react-query";
40
+ import { validatePortalOrigin } from "../../modal/utils/validatePortalOrigin.js";
39
41
  const AuthContext = createContext({
40
42
  signUpOrLogIn: () => {
41
43
  },
@@ -65,7 +67,13 @@ const AuthContext = createContext({
65
67
  },
66
68
  isCreateGuestWalletsPending: false,
67
69
  logout: () => {
68
- }
70
+ },
71
+ switchWallets: () => {
72
+ },
73
+ switchWalletsUrl: void 0,
74
+ setSwitchWalletsUrl: () => {
75
+ },
76
+ isSwitchWalletsPending: false
69
77
  });
70
78
  function AuthProvider({
71
79
  children,
@@ -111,10 +119,15 @@ function AuthProvider({
111
119
  const { waitForLogin: mutateWaitForLogin } = useWaitForLogin();
112
120
  const { waitForSignup: mutateWaitForSignup } = useWaitForSignup();
113
121
  const { waitForWalletCreationAsync: mutateAsyncWaitForWalletCreation } = useWaitForWalletCreation();
122
+ const { switchWallets: mutateSwitchWallets, isPending: mutateIsSwitchWalletsPending } = useSwitchWallets();
114
123
  const { setup2fa: mutateSetup2fa, isPending: isSetup2faPending } = useSetup2fa();
115
124
  const { createGuestWallets: mutateCreateGuestWallets, isPending: isCreateGuestWalletsPending } = useCreateGuestWallets();
116
125
  const { logout: mutateLogout } = useLogout();
126
+ const { updateSelectedWallet } = useWalletState();
117
127
  const { data: biometricHints } = useFormattedBiometricHints();
128
+ const [switchWalletsUrl, setSwitchWalletsUrl] = useState(void 0);
129
+ const [isSwitchWalletsPending, setIsSwitchWalletsPending] = useState(mutateIsSwitchWalletsPending);
130
+ const messageHandlerRef = useRef(null);
118
131
  const goBackIfPopupClosedOnSteps = (steps) => {
119
132
  var _a;
120
133
  if (((_a = refs.popupWindow.current) == null ? void 0 : _a.closed) && (!refs.currentStep.current || steps.includes(refs.currentStep.current))) {
@@ -127,11 +140,12 @@ function AuthProvider({
127
140
  return !!stepNow && !steps.includes(stepNow);
128
141
  };
129
142
  const setupListener = () => {
130
- window.addEventListener("message", function handleMessage(event) {
143
+ if (messageHandlerRef.current) {
144
+ window.removeEventListener("message", messageHandlerRef.current);
145
+ }
146
+ const handleMessage = (event) => {
131
147
  var _a;
132
- const portalBase = getPortalBaseURL(para.ctx);
133
- const portalLocalBase = getPortalBaseURL(para.ctx, true);
134
- if (!event.origin.startsWith(portalBase) && !event.origin.startsWith(portalLocalBase)) {
148
+ if (!validatePortalOrigin(event, para.ctx)) {
135
149
  return;
136
150
  }
137
151
  if (((_a = event.data) == null ? void 0 : _a.type) === "CLOSE_WINDOW") {
@@ -139,11 +153,16 @@ function AuthProvider({
139
153
  setAuthStepRoute();
140
154
  setIFrameUrl();
141
155
  setIsIFrameReady(false);
142
- setStep(ModalStep.AWAITING_ACCOUNT);
156
+ if (refs.currentStep.current !== ModalStep.LOGIN_DONE && refs.currentStep.current !== ModalStep.AWAITING_ACCOUNT) {
157
+ setStep(ModalStep.AWAITING_ACCOUNT);
158
+ }
143
159
  }
144
160
  window.removeEventListener("message", handleMessage);
161
+ messageHandlerRef.current = null;
145
162
  }
146
- });
163
+ };
164
+ messageHandlerRef.current = handleMessage;
165
+ window.addEventListener("message", handleMessage);
147
166
  };
148
167
  const pollSignup = () => {
149
168
  if (typeof window !== "undefined") {
@@ -170,7 +189,9 @@ function AuthProvider({
170
189
  onSuccess: () => {
171
190
  if (para.isNoWalletConfig) {
172
191
  onLoginComplete({
173
- on2faSetupOrError: () => setStep(ModalStep.LOGIN_DONE),
192
+ on2faSetupOrError: () => {
193
+ setStep(ModalStep.LOGIN_DONE);
194
+ },
174
195
  on2faNotSetup: () => setStep(ModalStep.SETUP_2FA)
175
196
  });
176
197
  } else {
@@ -203,12 +224,14 @@ function AuthProvider({
203
224
  if (refs.currentStep.current !== ModalStep.AWAITING_BIOMETRIC_CREATION) {
204
225
  setStep(ModalStep.AWAITING_BIOMETRIC_CREATION);
205
226
  }
206
- refs.popupWindow.current = openPopup({
207
- url: authState.passkeyUrl,
208
- target: "ParaPasskey",
209
- type: "CREATE_PASSKEY",
210
- current: refs.popupWindow.current
211
- });
227
+ if (typeof window !== "undefined") {
228
+ refs.popupWindow.current = openPopup({
229
+ url: authState.passkeyUrl,
230
+ target: "ParaPasskey",
231
+ type: "CREATE_PASSKEY",
232
+ current: refs.popupWindow.current
233
+ });
234
+ }
212
235
  break;
213
236
  case AuthMethod.PASSWORD:
214
237
  setupListener();
@@ -237,7 +260,7 @@ function AuthProvider({
237
260
  const presentVerifyUi = useCallback(
238
261
  (method, authState) => {
239
262
  switch (method) {
240
- case AuthMethod.SLO:
263
+ case AuthMethod.BASIC_LOGIN:
241
264
  setupListener();
242
265
  if (isIFrameReady) {
243
266
  setStep(ModalStep.OTP);
@@ -252,13 +275,14 @@ function AuthProvider({
252
275
  [isIFrameReady]
253
276
  );
254
277
  const login = (authState) => {
255
- if (authState.isWalletSelectionNeeded || authState.passkeyUrl) {
256
- setStep(ModalStep.BIOMETRIC_LOGIN);
257
- } else {
278
+ const hasPasskey = !!authState.passkeyUrl;
279
+ if (!hasPasskey) {
258
280
  setupListener();
259
281
  setIFrameUrl(authState.passwordUrl || authState.pinUrl);
260
282
  setIsIFrameReady(false);
261
283
  setStep(ModalStep.EMBEDDED_PASSWORD_LOGIN);
284
+ } else {
285
+ setStep(ModalStep.BIOMETRIC_LOGIN);
262
286
  }
263
287
  pollLogin();
264
288
  };
@@ -277,14 +301,17 @@ function AuthProvider({
277
301
  ModalStep.AWAITING_ACCOUNT,
278
302
  ModalStep.OTP,
279
303
  ModalStep.FARCASTER_OAUTH,
280
- ModalStep.TELEGRAM_OAUTH
304
+ ModalStep.TELEGRAM_OAUTH,
305
+ ModalStep.AWAITING_OAUTH,
306
+ ModalStep.SWITCH_WALLETS
281
307
  ]),
282
308
  onPoll: () => {
283
309
  goBackIfPopupClosedOnSteps([
284
310
  ModalStep.AWAITING_BIOMETRIC_LOGIN,
285
311
  ModalStep.AWAITING_PASSWORD_LOGIN,
286
312
  ModalStep.EMBEDDED_PASSWORD_LOGIN,
287
- ModalStep.OTP
313
+ ModalStep.OTP,
314
+ ModalStep.SWITCH_WALLETS
288
315
  ]);
289
316
  }
290
317
  },
@@ -326,23 +353,49 @@ function AuthProvider({
326
353
  loginOverride();
327
354
  return;
328
355
  }
329
- refs.popupWindow.current = openPopup({
330
- url: isPIN ? authState.pinUrl : isPassword ? authState.passwordUrl : authState.passkeyUrl,
331
- target: isPIN ? "ParaPIN" : isPassword ? "ParaPassword" : "ParaPasskey",
332
- type: isPIN ? "LOGIN_PASSWORD" : isPassword ? "LOGIN_PASSWORD" : "LOGIN_PASSKEY",
333
- current: refs.popupWindow.current
334
- });
356
+ if (typeof window !== "undefined") {
357
+ refs.popupWindow.current = openPopup({
358
+ url: isPIN ? authState.pinUrl : isPassword ? authState.passwordUrl : authState.passkeyUrl,
359
+ target: isPIN ? "ParaPIN" : isPassword ? "ParaPassword" : "ParaPasskey",
360
+ type: isPIN ? "LOGIN_PASSWORD" : isPassword ? "LOGIN_PASSWORD" : "LOGIN_PASSKEY",
361
+ current: refs.popupWindow.current
362
+ });
363
+ }
335
364
  setStep(isPassword || isPIN ? ModalStep.AWAITING_PASSWORD_LOGIN : ModalStep.AWAITING_BIOMETRIC_LOGIN);
336
365
  },
337
366
  [loginState, biometricHints]
338
367
  );
339
368
  const onNewAuthState = (authState) => __async(this, null, function* () {
340
- refs.popupWindow.current = null;
369
+ var _a, _b, _c;
341
370
  setAuthState(authState);
342
371
  switch (authState.stage) {
343
372
  case "verify":
344
- if (isExternalWallet(authState.auth) && authState.signatureVerificationMessage) {
345
- setStep(ModalStep.EXTERNAL_WALLET_VERIFICATION);
373
+ if (isExternalWallet(authState.auth)) {
374
+ if (authState.loginUrl && ((_a = authState.externalWallet) == null ? void 0 : _a.withFullParaAuth)) {
375
+ let isBasicLogin = false;
376
+ if (authState.nextStage === "login") {
377
+ isBasicLogin = authState.loginAuthMethods.includes(AuthMethod.BASIC_LOGIN);
378
+ } else {
379
+ isBasicLogin = authState.signupAuthMethods.includes(AuthMethod.BASIC_LOGIN);
380
+ }
381
+ if (authState.nextStage === "login") {
382
+ setFlow("login");
383
+ isBasicLogin && pollLogin();
384
+ } else {
385
+ setFlow("signup");
386
+ isBasicLogin && pollSignup();
387
+ }
388
+ if (!isMobile() && refs.popupWindow.current) {
389
+ refs.popupWindow.current.location.href = authState.loginUrl;
390
+ setStep(ModalStep.AWAITING_ACCOUNT);
391
+ } else {
392
+ setIFrameUrl(authState.loginUrl);
393
+ setStep(ModalStep.OTP);
394
+ setupListener();
395
+ }
396
+ } else {
397
+ setStep(ModalStep.EXTERNAL_WALLET_VERIFICATION);
398
+ }
346
399
  } else {
347
400
  if (authState.nextStage === "login") {
348
401
  setFlow("login");
@@ -354,7 +407,7 @@ function AuthProvider({
354
407
  if (authState.loginUrl) {
355
408
  setIFrameUrl(authState.loginUrl);
356
409
  setIsIFrameReady(false);
357
- presentVerifyUi(AuthMethod.SLO, authState);
410
+ presentVerifyUi(AuthMethod.BASIC_LOGIN, authState);
358
411
  } else {
359
412
  setStep(ModalStep.VERIFICATIONS);
360
413
  }
@@ -383,12 +436,14 @@ function AuthProvider({
383
436
  }
384
437
  break;
385
438
  case "done":
386
- if (authState.isNewUser) {
387
- pollSignup();
388
- setFlow("signup");
389
- } else {
390
- pollLogin();
391
- setFlow("login");
439
+ if (!((_b = authState.externalWallet) == null ? void 0 : _b.withFullParaAuth) && !((_c = authState.externalWallet) == null ? void 0 : _c.withVerification)) {
440
+ if (authState.isNewUser) {
441
+ pollSignup();
442
+ setFlow("signup");
443
+ } else {
444
+ pollLogin();
445
+ setFlow("login");
446
+ }
392
447
  }
393
448
  if (!authState.isWalletSelectionNeeded) {
394
449
  setStep(ModalStep.AWAITING_ACCOUNT);
@@ -448,7 +503,7 @@ function AuthProvider({
448
503
  isCanceled: () => refs.currentStep.current !== ModalStep.FARCASTER_OAUTH,
449
504
  onConnectUri: (connectUri) => {
450
505
  setFarcasterConnectUri(connectUri);
451
- routeMobileExternalWallet(connectUri);
506
+ openMobileUrl(connectUri);
452
507
  },
453
508
  useShortUrls: true,
454
509
  serverAuthState
@@ -556,6 +611,75 @@ function AuthProvider({
556
611
  const logout = () => {
557
612
  mutateLogout();
558
613
  };
614
+ const switchWallets = () => {
615
+ if (!switchWalletsUrl) {
616
+ return;
617
+ }
618
+ setIsSwitchWalletsPending(true);
619
+ try {
620
+ setStep(ModalStep.SWITCH_WALLETS);
621
+ refs.popupWindow.current = openPopup({
622
+ url: switchWalletsUrl,
623
+ target: "ParaSwitchWallets",
624
+ type: "SWITCH_WALLETS",
625
+ current: refs.popupWindow.current
626
+ });
627
+ pollSwitchWallets();
628
+ } catch (error) {
629
+ console.error("Failed to open wallet switching popup:", error);
630
+ }
631
+ };
632
+ const pollSwitchWallets = () => {
633
+ if (typeof window !== "undefined") {
634
+ refs.poll.current = {
635
+ action: "login",
636
+ timeout: window == null ? void 0 : window.setTimeout(() => __async(this, null, function* () {
637
+ mutateSwitchWallets(
638
+ {
639
+ isCanceled: () => {
640
+ var _a, _b;
641
+ const exitedSteps = cancelIfExitedSteps([ModalStep.SWITCH_WALLETS, ModalStep.SWITCH_WALLETS_IFRAME]);
642
+ const popupClosed = (_b = (_a = refs.popupWindow.current) == null ? void 0 : _a.closed) != null ? _b : false;
643
+ const isCanceled = exitedSteps || popupClosed;
644
+ if (isCanceled) {
645
+ if (popupClosed && (refs.currentStep.current === ModalStep.SWITCH_WALLETS || refs.currentStep.current === ModalStep.SWITCH_WALLETS_IFRAME)) {
646
+ goBack();
647
+ }
648
+ }
649
+ return isCanceled;
650
+ },
651
+ onPoll: () => {
652
+ if (refs.currentStep.current === ModalStep.SWITCH_WALLETS || refs.currentStep.current === ModalStep.SWITCH_WALLETS_IFRAME) {
653
+ goBackIfPopupClosedOnSteps([ModalStep.SWITCH_WALLETS, ModalStep.SWITCH_WALLETS_IFRAME]);
654
+ }
655
+ }
656
+ },
657
+ {
658
+ onSuccess: () => {
659
+ updateSelectedWallet();
660
+ setTimeout(() => {
661
+ setStep(ModalStep.ACCOUNT_PROFILE);
662
+ refs.popupWindow.current = null;
663
+ }, 500);
664
+ },
665
+ onError: () => {
666
+ if (refs.currentStep.current === ModalStep.SWITCH_WALLETS) {
667
+ goBack();
668
+ }
669
+ },
670
+ onSettled: () => {
671
+ var _a;
672
+ setIsSwitchWalletsPending(false);
673
+ window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
674
+ refs.poll.current = null;
675
+ refs.popupWindow.current = null;
676
+ }
677
+ }
678
+ );
679
+ }), DEFAULTS.LOGGIN_POLLING_DELAY_MS)
680
+ };
681
+ }
682
+ };
559
683
  const isPasswordIFrameLoading = !!iFrameUrl && iFrameUrl === (signupState == null ? void 0 : signupState.passwordUrl) && !isIFrameReady;
560
684
  const value = useMemo(
561
685
  () => ({
@@ -576,6 +700,10 @@ function AuthProvider({
576
700
  createGuestWallets,
577
701
  isCreateGuestWalletsPending,
578
702
  logout,
703
+ switchWallets,
704
+ switchWalletsUrl,
705
+ setSwitchWalletsUrl,
706
+ isSwitchWalletsPending,
579
707
  biometricHints: biometricHints || void 0,
580
708
  verifyFarcasterStatus
581
709
  }),
@@ -598,16 +726,26 @@ function AuthProvider({
598
726
  createGuestWallets,
599
727
  isCreateGuestWalletsPending,
600
728
  logout,
729
+ switchWallets,
730
+ switchWalletsUrl,
731
+ setSwitchWalletsUrl,
732
+ isSwitchWalletsPending,
601
733
  biometricHints,
602
734
  verifyFarcasterStatus
603
735
  ]
604
736
  );
605
737
  useEffect(() => {
738
+ let timerId;
606
739
  if (!!authStepRoute && refs.currentStep.current !== authStepRoute) {
607
- setTimeout(() => {
740
+ timerId = setTimeout(() => {
608
741
  setStep(authStepRoute);
609
742
  }, 200);
610
743
  }
744
+ return () => {
745
+ if (timerId) {
746
+ clearTimeout(timerId);
747
+ }
748
+ };
611
749
  }, [authStepRoute]);
612
750
  useEffect(() => {
613
751
  refs.currentStep.current = currentStep;
@@ -617,10 +755,16 @@ function AuthProvider({
617
755
  setStep(ModalStep.ACCOUNT_MAIN);
618
756
  }
619
757
  }, [isCreateGuestWalletsPending]);
758
+ useEffect(() => {
759
+ setIsSwitchWalletsPending((prev) => !!prev ? mutateIsSwitchWalletsPending : prev);
760
+ }, [mutateIsSwitchWalletsPending]);
620
761
  useEffect(() => {
621
762
  return () => {
622
763
  var _a;
623
764
  window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
765
+ if (messageHandlerRef.current) {
766
+ window.removeEventListener("message", messageHandlerRef.current);
767
+ }
624
768
  };
625
769
  }, []);
626
770
  return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
@@ -1,6 +1,6 @@
1
1
  import { PropsWithChildren } from 'react';
2
2
  import { TWalletType } from '@getpara/web-sdk';
3
- import { BalanceManagement, ChainManagement, CommonWallet, ExternalWalletContextType } from '@getpara/react-common';
3
+ import { BalanceManagement, ChainManagement, CommonWallet, DisconnectBaseOptions, ExternalWalletContextType, MutationStatus } from '@getpara/react-common';
4
4
  import { ExternalWalletInfo, VerifyExternalWalletParams } from '@getpara/web-sdk';
5
5
  import { CosmosSignResult } from '@getpara/cosmos-wallet-connectors';
6
6
  export declare const useWalletDisplayHelpers: (wallet: CommonWallet | undefined) => {
@@ -23,6 +23,7 @@ export declare const defaultExternalWallet: {
23
23
  username: undefined;
24
24
  avatar: undefined;
25
25
  connectExternalWallet: () => Promise<void>;
26
+ addAdditionalExternalWallet: () => Promise<void>;
26
27
  disconnectExternalWallet: () => Promise<void>;
27
28
  switchChain: () => Promise<void>;
28
29
  setChainIdSwitchingTo: () => void;
@@ -32,11 +33,14 @@ export declare const defaultExternalWallet: {
32
33
  isSigningMessage: boolean;
33
34
  getWalletBalance: () => Promise<undefined>;
34
35
  requestInfo: (_: string) => Promise<ExternalWalletInfo>;
35
- disconnectBase: (_: string, __: TWalletType) => Promise<void>;
36
+ disconnectBase: (_: string, __: TWalletType, ___?: DisconnectBaseOptions) => Promise<void>;
36
37
  connectFarcasterMiniApp: () => Promise<void>;
37
38
  verificationStage: undefined;
39
+ evmDisconnectStatus: string;
40
+ solanaDisconnectStatus: string;
41
+ cosmosDisconnectStatus: string;
38
42
  };
39
- type Value = Omit<ExternalWalletContextType<CosmosSignResult>, 'disconnect' | 'signVerificationMessage' | 'requestInfo' | 'disconnectBase'> & ChainManagement<string, void> & BalanceManagement & {
43
+ type Value = Omit<ExternalWalletContextType<CosmosSignResult>, 'disconnect' | 'disconnectStatus' | 'signVerificationMessage' | 'requestInfo' | 'disconnectBase'> & ChainManagement<string, void> & BalanceManagement & {
40
44
  wallet?: CommonWallet;
41
45
  qrUri?: string;
42
46
  chainIdSwitchingTo?: string;
@@ -47,16 +51,26 @@ type Value = Omit<ExternalWalletContextType<CosmosSignResult>, 'disconnect' | 's
47
51
  };
48
52
  username?: string;
49
53
  avatar?: string;
50
- 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>;
61
+ addAdditionalExternalWallet: (wallet: CommonWallet) => Promise<void>;
51
62
  disconnectExternalWallet: () => Promise<void>;
52
63
  setChainIdSwitchingTo: (chainId?: string) => void;
53
64
  connectEmbeddedToExternalConnectors: () => Promise<void>;
54
65
  isSigningMessage: boolean;
55
66
  verifyWalletSignature: () => Promise<VerifyExternalWalletParams | undefined>;
56
67
  requestInfo: (_: string, __: TWalletType) => Promise<ExternalWalletInfo>;
57
- disconnectBase: (_: string, __: TWalletType) => Promise<void>;
68
+ disconnectBase: (_: string, __: TWalletType, ___?: DisconnectBaseOptions) => Promise<void>;
58
69
  connectFarcasterMiniApp: () => Promise<void>;
59
70
  verificationStage?: 'verifying' | 'switchingChain';
71
+ evmDisconnectStatus: MutationStatus;
72
+ solanaDisconnectStatus: MutationStatus;
73
+ cosmosDisconnectStatus: MutationStatus;
60
74
  };
61
75
  export declare const ExternalWalletContext: import("react").Context<Value>;
62
76
  export declare function ExternalWalletProvider({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;