@getpara/react-sdk 1.12.0 → 2.0.0-alpha.5

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 (241) hide show
  1. package/dist/cli/cli.mjs +35 -0
  2. package/dist/index.d.ts +1 -0
  3. package/dist/index.js +5 -0
  4. package/dist/modal/ParaModal.js +211 -313
  5. package/dist/modal/components/Account/Account.js +66 -12
  6. package/dist/modal/components/AddFunds/AddFunds.js +5 -6
  7. package/dist/modal/components/AddFunds/AddFundsAsset.js +15 -13
  8. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +16 -10
  9. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +2 -2
  10. package/dist/modal/components/AddFunds/AddFundsContext.js +20 -14
  11. package/dist/modal/components/AddFunds/AddFundsDone.js +10 -4
  12. package/dist/modal/components/AddFunds/AddFundsProvider.js +11 -7
  13. package/dist/modal/components/AddFunds/AddFundsReceive.js +17 -13
  14. package/dist/modal/components/AddFunds/AddFundsSettings.js +10 -6
  15. package/dist/modal/components/AddFunds/common.d.ts +1 -1
  16. package/dist/modal/components/AuthInput/AuthInput.d.ts +1 -1
  17. package/dist/modal/components/AuthInput/AuthInput.js +70 -91
  18. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.d.ts +4 -4
  19. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +4 -4
  20. package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +4 -3
  21. package/dist/modal/components/AuthMainStep/AuthMainStep.js +20 -7
  22. package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +4 -3
  23. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +54 -10
  24. package/dist/modal/components/AuthOptions/AuthOptions.d.ts +4 -3
  25. package/dist/modal/components/AuthOptions/AuthOptions.js +42 -8
  26. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +5 -1
  27. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +9 -4
  28. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.d.ts +1 -3
  29. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +25 -17
  30. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.d.ts +1 -1
  31. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +34 -72
  32. package/dist/modal/components/Body/Body.d.ts +4 -3
  33. package/dist/modal/components/Body/Body.js +27 -10
  34. package/dist/modal/components/ChainSwitch/ChainSwitch.d.ts +1 -1
  35. package/dist/modal/components/ChainSwitch/ChainSwitch.js +5 -4
  36. package/dist/modal/components/Controls/Controls.js +5 -2
  37. package/dist/modal/components/Controls/Selects.d.ts +1 -1
  38. package/dist/modal/components/Controls/Selects.js +30 -25
  39. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +1 -1
  40. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +10 -6
  41. package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +7 -69
  42. package/dist/modal/components/ExternalWallets/ExternalWallets.js +7 -6
  43. package/dist/modal/components/Footer/Footer.d.ts +1 -1
  44. package/dist/modal/components/Footer/Footer.js +6 -4
  45. package/dist/modal/components/Header/hooks/useStepTitle.js +7 -3
  46. package/dist/modal/components/Hero/Hero.js +5 -5
  47. package/dist/modal/components/IFrameStep/IFrameStep.js +8 -4
  48. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +7 -4
  49. package/dist/modal/components/ModalContent/ModalContent.js +14 -243
  50. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +3 -57
  51. package/dist/modal/components/OAuth/OAuth.d.ts +2 -2
  52. package/dist/modal/components/OAuth/OAuth.js +11 -85
  53. package/dist/modal/components/OAuth/TelegramOAuthStep.js +11 -60
  54. package/dist/modal/components/OnRampComponents/AddingFunds.js +1 -1
  55. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +10 -4
  56. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +23 -32
  57. package/dist/modal/components/StripeComponents/StripeComponents.js +1 -1
  58. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +5 -2
  59. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +44 -60
  60. package/dist/modal/components/WalletCard/WalletCard.d.ts +5 -5
  61. package/dist/modal/components/WalletCard/WalletCard.js +8 -7
  62. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +33 -12
  63. package/dist/modal/components/common.d.ts +5 -5
  64. package/dist/modal/components/common.js +10 -4
  65. package/dist/modal/constants/constants.d.ts +1 -1
  66. package/dist/modal/constants/oAuthLogos.d.ts +3 -3
  67. package/dist/modal/hooks/useGoBack.js +6 -5
  68. package/dist/modal/index.d.ts +0 -3
  69. package/dist/modal/index.js +1 -5
  70. package/dist/modal/stores/index.d.ts +0 -2
  71. package/dist/modal/stores/index.js +0 -2
  72. package/dist/modal/stores/modal/actions.js +69 -16
  73. package/dist/modal/stores/modal/useModalStore.d.ts +26 -22
  74. package/dist/modal/stores/modal/useModalStore.js +9 -13
  75. package/dist/modal/types/commonTypes.d.ts +0 -52
  76. package/dist/modal/types/modalProps.d.ts +8 -32
  77. package/dist/modal/utils/authInputHelpers.d.ts +7 -0
  78. package/dist/modal/utils/authInputHelpers.js +38 -0
  79. package/dist/modal/utils/authLayoutHelpers.d.ts +2 -2
  80. package/dist/modal/{components/AuthInput → utils}/countryCodes.js +6 -3
  81. package/dist/modal/utils/getTileButtonFlex.d.ts +1 -1
  82. package/dist/modal/utils/isPasskeySupported.d.ts +1 -0
  83. package/dist/modal/utils/isPasskeySupported.js +15 -0
  84. package/dist/modal/utils/openPopup.d.ts +2 -2
  85. package/dist/modal/utils/openPopup.js +2 -2
  86. package/dist/modal/utils/steps.d.ts +6 -0
  87. package/dist/modal/utils/steps.js +15 -0
  88. package/dist/provider/ParaProvider.d.ts +3 -1
  89. package/dist/provider/ParaProvider.js +69 -8
  90. package/dist/provider/actions/getAccount.d.ts +26 -8
  91. package/dist/provider/actions/getAccount.js +42 -14
  92. package/dist/provider/actions/getWallet.d.ts +3 -3
  93. package/dist/provider/actions/index.d.ts +27 -0
  94. package/dist/provider/actions/index.js +59 -0
  95. package/dist/provider/actions/utils.d.ts +3 -0
  96. package/dist/provider/actions/utils.js +15 -0
  97. package/dist/provider/components/CosmosWalletWrapper.d.ts +11 -0
  98. package/dist/provider/components/CosmosWalletWrapper.js +34 -0
  99. package/dist/provider/components/EvmWalletWrapper.d.ts +12 -0
  100. package/dist/provider/components/EvmWalletWrapper.js +34 -0
  101. package/dist/provider/components/ExternalWalletWrapper.d.ts +8 -0
  102. package/dist/provider/components/ExternalWalletWrapper.js +139 -0
  103. package/dist/provider/components/SolanaWalletWrapper.d.ts +9 -0
  104. package/dist/provider/components/SolanaWalletWrapper.js +36 -0
  105. package/dist/provider/external/getParaCosmosConnector.d.ts +7 -0
  106. package/dist/provider/external/getParaCosmosConnector.js +22 -0
  107. package/dist/provider/external/getParaEvmConnector.d.ts +7 -0
  108. package/dist/provider/external/getParaEvmConnector.js +22 -0
  109. package/dist/provider/external/getParaSolanaConnector.d.ts +7 -0
  110. package/dist/provider/external/getParaSolanaConnector.js +22 -0
  111. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.d.ts +12 -0
  112. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +18 -0
  113. package/dist/provider/external/stubs/EvmExternalWalletContextStub.d.ts +3 -0
  114. package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +21 -0
  115. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.d.ts +8 -0
  116. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +14 -0
  117. package/dist/provider/hooks/mutations/index.d.ts +26 -11
  118. package/dist/provider/hooks/mutations/index.js +52 -17
  119. package/dist/provider/hooks/mutations/utils.d.ts +4 -0
  120. package/dist/provider/hooks/mutations/utils.js +22 -0
  121. package/dist/provider/hooks/queries/useAccount.d.ts +1 -7
  122. package/dist/provider/hooks/queries/useWallet.d.ts +1 -1
  123. package/dist/provider/hooks/queries/useWalletBalance.d.ts +1 -2
  124. package/dist/provider/hooks/queries/useWalletBalance.js +40 -11
  125. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +5 -5
  126. package/dist/provider/hooks/utils/useEventListeners.d.ts +1 -1
  127. package/dist/provider/hooks/utils/useEventListeners.js +98 -56
  128. package/dist/provider/hooks/utils/useWalletState.d.ts +5 -4
  129. package/dist/provider/hooks/utils/useWalletState.js +24 -9
  130. package/dist/provider/index.d.ts +1 -0
  131. package/dist/provider/index.js +1 -0
  132. package/dist/provider/providers/AuthProvider.d.ts +35 -0
  133. package/dist/provider/providers/AuthProvider.js +498 -0
  134. package/dist/provider/providers/CosmosExternalWalletProvider.d.ts +7 -0
  135. package/dist/provider/providers/CosmosExternalWalletProvider.js +66 -0
  136. package/dist/provider/providers/EvmExternalWalletProvider.d.ts +7 -0
  137. package/dist/provider/providers/EvmExternalWalletProvider.js +74 -0
  138. package/dist/provider/providers/ExternalWalletProvider.d.ts +76 -0
  139. package/dist/{modal/providers/ExternalWalletContext.js → provider/providers/ExternalWalletProvider.js} +146 -112
  140. package/dist/provider/providers/SolanaExternalWalletProvider.d.ts +7 -0
  141. package/dist/provider/providers/SolanaExternalWalletProvider.js +66 -0
  142. package/dist/provider/stores/getters.d.ts +3 -3
  143. package/dist/provider/stores/setters.d.ts +1 -0
  144. package/dist/provider/stores/setters.js +7 -0
  145. package/dist/provider/stores/slices/config.d.ts +3 -0
  146. package/dist/provider/stores/slices/config.js +9 -0
  147. package/dist/provider/stores/slices/externalWallets.d.ts +3 -0
  148. package/dist/provider/stores/slices/externalWallets.js +40 -0
  149. package/dist/provider/stores/slices/index.d.ts +1 -0
  150. package/dist/provider/stores/slices/index.js +1 -0
  151. package/dist/provider/stores/slices/modal.js +11 -4
  152. package/dist/provider/stores/types.d.ts +50 -4
  153. package/dist/provider/stores/useStore.js +4 -3
  154. package/dist/provider/types/externalWalletProviders.d.ts +12 -0
  155. package/dist/provider/types/externalWalletProviders.js +1 -0
  156. package/dist/provider/types/provider.d.ts +126 -17
  157. package/dist/provider/types/utils.d.ts +16 -0
  158. package/dist/provider/utils/constants.js +3 -4
  159. package/dist/provider/utils/paraConfigTypeGuards.d.ts +7 -0
  160. package/dist/provider/utils/paraConfigTypeGuards.js +13 -0
  161. package/dist/provider/utils/renameMutations.d.ts +3 -0
  162. package/dist/provider/utils/renameMutations.js +5 -3
  163. package/package.json +20 -8
  164. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.d.ts +0 -8
  165. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +0 -124
  166. package/dist/modal/hooks/useActiveWallet.d.ts +0 -1
  167. package/dist/modal/hooks/useActiveWallet.js +0 -15
  168. package/dist/modal/hooks/useCreateAccount.d.ts +0 -6
  169. package/dist/modal/hooks/useCreateAccount.js +0 -77
  170. package/dist/modal/hooks/useEmbeddedExternalConnection.d.ts +0 -1
  171. package/dist/modal/hooks/useEmbeddedExternalConnection.js +0 -54
  172. package/dist/modal/hooks/useSetLoginURLs.d.ts +0 -8
  173. package/dist/modal/hooks/useSetLoginURLs.js +0 -49
  174. package/dist/modal/hooks/useWalletBalance.d.ts +0 -4
  175. package/dist/modal/hooks/useWalletBalance.js +0 -49
  176. package/dist/modal/providers/CosmosExternalWalletContextStub.d.ts +0 -42
  177. package/dist/modal/providers/CosmosExternalWalletContextStub.js +0 -38
  178. package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +0 -46
  179. package/dist/modal/providers/EvmExternalWalletContextStub.js +0 -55
  180. package/dist/modal/providers/ExternalWalletContext.d.ts +0 -92
  181. package/dist/modal/providers/SolanaExternalWalletContextStub.d.ts +0 -32
  182. package/dist/modal/providers/SolanaExternalWalletContextStub.js +0 -32
  183. package/dist/modal/stores/externalWalletProvider/actions.d.ts +0 -3
  184. package/dist/modal/stores/externalWalletProvider/actions.js +0 -10
  185. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.d.ts +0 -22
  186. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +0 -21
  187. package/dist/modal/stores/theme/actions.d.ts +0 -3
  188. package/dist/modal/stores/theme/actions.js +0 -28
  189. package/dist/modal/stores/theme/useThemeStore.d.ts +0 -20
  190. package/dist/modal/stores/theme/useThemeStore.js +0 -21
  191. package/dist/modal/stores/userInfo/actions.d.ts +0 -3
  192. package/dist/modal/stores/userInfo/actions.js +0 -30
  193. package/dist/modal/stores/userInfo/useUserInfoStore.d.ts +0 -19
  194. package/dist/modal/stores/userInfo/useUserInfoStore.js +0 -17
  195. package/dist/provider/actions/checkIfUserExists.d.ts +0 -9
  196. package/dist/provider/actions/checkIfUserExists.js +0 -21
  197. package/dist/provider/actions/createGuestWallets.d.ts +0 -2
  198. package/dist/provider/actions/createGuestWallets.js +0 -13
  199. package/dist/provider/actions/createUser.d.ts +0 -12
  200. package/dist/provider/actions/createUser.js +0 -26
  201. package/dist/provider/actions/getWalletBalance.d.ts +0 -2
  202. package/dist/provider/actions/getWalletBalance.js +0 -14
  203. package/dist/provider/actions/initiateLogin.d.ts +0 -4
  204. package/dist/provider/actions/initiateLogin.js +0 -20
  205. package/dist/provider/actions/keepSessionAlive.d.ts +0 -2
  206. package/dist/provider/actions/keepSessionAlive.js +0 -20
  207. package/dist/provider/actions/logout.d.ts +0 -2
  208. package/dist/provider/actions/logout.js +0 -17
  209. package/dist/provider/actions/signMessage.d.ts +0 -8
  210. package/dist/provider/actions/signMessage.js +0 -20
  211. package/dist/provider/actions/signTransaction.d.ts +0 -8
  212. package/dist/provider/actions/signTransaction.js +0 -20
  213. package/dist/provider/actions/waitForAccountCreation.d.ts +0 -2
  214. package/dist/provider/actions/waitForAccountCreation.js +0 -21
  215. package/dist/provider/actions/waitForLoginAndSetup.d.ts +0 -6
  216. package/dist/provider/actions/waitForLoginAndSetup.js +0 -24
  217. package/dist/provider/actions/waitForPasskeyAndCreateWallet.d.ts +0 -2
  218. package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +0 -21
  219. package/dist/provider/hooks/mutations/useCheckIfUserExists.d.ts +0 -13
  220. package/dist/provider/hooks/mutations/useCheckIfUserExists.js +0 -23
  221. package/dist/provider/hooks/mutations/useCreateGuestWallets.d.ts +0 -15
  222. package/dist/provider/hooks/mutations/useCreateGuestWallets.js +0 -23
  223. package/dist/provider/hooks/mutations/useCreateUser.d.ts +0 -13
  224. package/dist/provider/hooks/mutations/useCreateUser.js +0 -20
  225. package/dist/provider/hooks/mutations/useInitiateLogin.d.ts +0 -14
  226. package/dist/provider/hooks/mutations/useInitiateLogin.js +0 -23
  227. package/dist/provider/hooks/mutations/useKeepSessionAlive.d.ts +0 -12
  228. package/dist/provider/hooks/mutations/useKeepSessionAlive.js +0 -20
  229. package/dist/provider/hooks/mutations/useLogout.d.ts +0 -12
  230. package/dist/provider/hooks/mutations/useLogout.js +0 -30
  231. package/dist/provider/hooks/mutations/useSignMessage.d.ts +0 -15
  232. package/dist/provider/hooks/mutations/useSignMessage.js +0 -39
  233. package/dist/provider/hooks/mutations/useSignTransaction.d.ts +0 -14
  234. package/dist/provider/hooks/mutations/useSignTransaction.js +0 -39
  235. package/dist/provider/hooks/mutations/useWaitForAccountCreation.d.ts +0 -12
  236. package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +0 -30
  237. package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.d.ts +0 -14
  238. package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +0 -30
  239. package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.d.ts +0 -13
  240. package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +0 -30
  241. /package/dist/modal/{components/AuthInput → utils}/countryCodes.d.ts +0 -0
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env node
2
+ import * as fs from 'node:fs/promises';
3
+ import * as path from 'node:path';
4
+ import { createRequire } from 'module';
5
+ const require = createRequire(import.meta.url);
6
+
7
+ const PACKAGES_TO_STUB = [
8
+ '@getpara/evm-wallet-connectors',
9
+ '@getpara/cosmos-wallet-connectors',
10
+ '@getpara/solana-wallet-connectors',
11
+ ];
12
+
13
+ const checkForPackages = async () => {
14
+ const pathToParaPackages = require.resolve('@getpara/react-sdk');
15
+
16
+ const pathToNodeModules = path.resolve(pathToParaPackages, '../../node_modules');
17
+
18
+ for (let i = 0; i < PACKAGES_TO_STUB.length; i++) {
19
+ const packageName = PACKAGES_TO_STUB[i];
20
+ try {
21
+ await import(packageName);
22
+ } catch (err) {
23
+ if (err.code === 'ERR_MODULE_NOT_FOUND') {
24
+ const packageJsonContent = { name: packageName, main: './index.js' };
25
+ await fs.mkdir(path.join(pathToNodeModules, packageName), { recursive: true });
26
+ await fs.writeFile(path.join(pathToNodeModules, packageName, 'index.js'), '//STUB');
27
+ await fs.writeFile(path.join(pathToNodeModules, packageName, 'package.json'), JSON.stringify(packageJsonContent), {
28
+ encoding: 'utf-8',
29
+ });
30
+ }
31
+ }
32
+ }
33
+ };
34
+
35
+ await checkForPackages();
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './modal/index.js';
2
2
  export * from './provider/index.js';
3
3
  export * from '@getpara/web-sdk';
4
+ export { ExternalWallet, EvmWallet, SolanaWallet, CosmosWallet } from '@getpara/react-common';
4
5
  export type { Theme } from '@getpara/react-components';
5
6
  import ParaWeb from '@getpara/web-sdk';
6
7
  export default ParaWeb;
package/dist/index.js CHANGED
@@ -3,8 +3,13 @@ import "./chunk-MMUBH76A.js";
3
3
  export * from "./modal/index.js";
4
4
  export * from "./provider/index.js";
5
5
  export * from "@getpara/web-sdk";
6
+ import { ExternalWallet, EvmWallet, SolanaWallet, CosmosWallet } from "@getpara/react-common";
6
7
  import ParaWeb from "@getpara/web-sdk";
7
8
  var src_default = ParaWeb;
8
9
  export {
10
+ CosmosWallet,
11
+ EvmWallet,
12
+ ExternalWallet,
13
+ SolanaWallet,
9
14
  src_default as default
10
15
  };
@@ -8,345 +8,243 @@ import { jsx } from "react/jsx-runtime";
8
8
  import { CpslAuthModal, defineCustomElements, generateTheme } from "@getpara/react-components";
9
9
  import { ModalContent } from "./components/index.js";
10
10
  import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
11
- import { useModalStore, useUserInfoStore, useThemeStore } from "./stores/index.js";
11
+ import { useModalStore } from "./stores/index.js";
12
12
  import { ModalStep, RESET_TO_ACCOUNT_STEPS, RESET_TO_AUTH_STEPS } from "./utils/steps.js";
13
13
  import { AuthLayout } from "./types/modalProps.js";
14
14
  import { DEFAULTS } from "./constants/defaults.js";
15
15
  import { useGoBack } from "./hooks/useGoBack.js";
16
- import { isPasskeySupported, ParaEvent } from "@getpara/web-sdk";
17
- import { ExternalWalletsWrapper } from "./components/ExternalWalletsWrapper/ExternalWalletsWrapper.js";
18
16
  import styled from "styled-components";
19
17
  import { hasEmbeddedAuth, hasExternalWallet } from "./utils/authLayoutHelpers.js";
20
18
  import { useModal, useWalletState } from "../provider/index.js";
21
- import { useStore } from "../provider/stores/useStore.js";
22
- import { getExternalWalletDisplayName } from "@getpara/react-common";
23
19
  import { useInternalClient } from "../provider/hooks/utils/useInternalClient.js";
24
- import { useExternalWalletProviderStore } from "./stores/externalWalletProvider/useExternalWalletProviderStore.js";
20
+ import { useExternalWallets } from "../provider/providers/ExternalWalletProvider.js";
21
+ import { useStore } from "../provider/stores/useStore.js";
22
+ import parsePhoneNumberFromString from "libphonenumber-js";
23
+ import { useAuthActions } from "../provider/providers/AuthProvider.js";
24
+ import { validateAuth } from "./utils/authInputHelpers.js";
25
25
  defineCustomElements();
26
- const ParaModal = forwardRef(
27
- (_a, ref) => {
28
- var _b = _a, { para, isOpen, externalWalletsWithParaAuth, rpcUrl: rpcUrlFromProps } = _b, rest = __objRest(_b, ["para", "isOpen", "externalWalletsWithParaAuth", "rpcUrl"]);
29
- const [isInitialized, setIsInitialized] = useState(false);
30
- const setClient = useStore((state) => state.setClient);
31
- const client = useStore((state) => state.client);
32
- const rpcUrl = useStore((state) => state.rpcUrl);
33
- const setRpcUrl = useStore((state) => state.setRpcUrl);
34
- const { closeModal, openModal } = useModal();
35
- const updateExternalWalletProviderState = useExternalWalletProviderStore((state) => state.updateState);
36
- useEffect(() => {
37
- updateExternalWalletProviderState({ fullAuthWallets: externalWalletsWithParaAuth });
38
- }, [externalWalletsWithParaAuth]);
39
- useEffect(() => {
40
- if (!client) {
41
- setClient(para);
42
- }
43
- setIsInitialized(true);
44
- }, []);
45
- useEffect(() => {
46
- if (rpcUrl !== rpcUrlFromProps) {
47
- setRpcUrl(rpcUrlFromProps);
26
+ const ParaModal = forwardRef((props, ref) => {
27
+ const storedModalConfig = useStore((state) => state.modalConfig);
28
+ const modalContentRef = useRef(null);
29
+ const currentStep = useModalStore((state) => state.step);
30
+ const setAuthState = useModalStore((state) => state.setAuthState);
31
+ const setOnModalStepChange = useModalStore((state) => state.setOnModalStepChange);
32
+ const setStep = useModalStore((state) => state.setStep);
33
+ const hasPreviousStep = useModalStore((state) => state.hasPreviousStep());
34
+ const setFlow = useModalStore((state) => state.setFlow);
35
+ const setIsFullyLoggedIn = useModalStore((state) => state.setIsFullyLoggedIn);
36
+ const goBack = useGoBack();
37
+ const setAuthLayout = useModalStore((state) => state.setAuthLayout);
38
+ const storedAuthLayout = useModalStore((state) => state.authLayout);
39
+ const resetModalState = useModalStore((state) => state.resetState);
40
+ const setRecoveryShare = useModalStore((state) => state.setRecoveryShare);
41
+ const { disconnectExternalWallet } = useExternalWallets();
42
+ const { isOpen: storedIsOpen, closeModal } = useModal();
43
+ const para = useInternalClient();
44
+ const { setSelectedWallet, updateSelectedWallet } = useWalletState();
45
+ const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
46
+ const { signUpOrLogIn, isCreateGuestWalletsPending } = useAuthActions();
47
+ const [isModalMounted, setIsModalMounted] = useState(false);
48
+ const [isInit, setIsInit] = useState(false);
49
+ const externalWallets = useStore((state) => state.externalWallets);
50
+ const _a = __spreadValues(__spreadValues({}, storedModalConfig), props), {
51
+ isOpen: configIsOpen,
52
+ theme,
53
+ disableEmailLogin = false,
54
+ disablePhoneLogin = false,
55
+ isGuestModeEnabled = false,
56
+ oAuthMethods = ["GOOGLE", "TWITTER"],
57
+ bareModal = false,
58
+ className,
59
+ currentStepOverride,
60
+ authLayout = [AuthLayout.AUTH_FULL, AuthLayout.EXTERNAL_FULL],
61
+ embeddedModal,
62
+ onModalStepChange,
63
+ onClose,
64
+ defaultAuthIdentifier
65
+ } = _a, rest = __objRest(_a, [
66
+ "isOpen",
67
+ "theme",
68
+ "disableEmailLogin",
69
+ "disablePhoneLogin",
70
+ "isGuestModeEnabled",
71
+ "oAuthMethods",
72
+ "bareModal",
73
+ "className",
74
+ "currentStepOverride",
75
+ "authLayout",
76
+ "embeddedModal",
77
+ "onModalStepChange",
78
+ "onClose",
79
+ "defaultAuthIdentifier"
80
+ ]);
81
+ const isOpen = configIsOpen != null ? configIsOpen : storedIsOpen;
82
+ useImperativeHandle(ref, () => {
83
+ return {
84
+ goBack() {
85
+ goBack();
86
+ },
87
+ canGoBack() {
88
+ return hasPreviousStep;
89
+ },
90
+ currentStep() {
91
+ return currentStep;
92
+ },
93
+ handleModalClose() {
94
+ var _a2;
95
+ (_a2 = modalContentRef == null ? void 0 : modalContentRef.current) == null ? void 0 : _a2.handleModalClose();
48
96
  }
49
- }, [rpcUrlFromProps]);
50
- useEffect(() => {
51
- if (!isOpen) {
52
- closeModal();
53
- }
54
- if (isOpen) {
55
- openModal();
56
- }
57
- }, [isOpen]);
58
- if (!isInitialized) {
59
- return null;
60
- }
61
- return /* @__PURE__ */ jsx(ParaModalInner, __spreadValues({ ref, para, externalWalletsWithParaAuth }, rest));
62
- }
63
- );
64
- const ParaModalInner = forwardRef(
65
- (_c, ref) => {
66
- var _d = _c, {
67
- theme,
68
- appName,
69
- logo,
70
- disableEmailLogin = false,
71
- disablePhoneLogin = false,
72
- oAuthMethods,
73
- bareModal = false,
74
- className,
75
- currentStepOverride,
76
- externalWallets,
77
- authLayout = [AuthLayout.AUTH_FULL, AuthLayout.EXTERNAL_FULL],
78
- embeddedModal,
79
- onModalStepChange,
80
- hideWallets = false,
81
- onClose,
82
- externalWalletsWithParaAuth
83
- } = _d, rest = __objRest(_d, [
84
- "theme",
85
- "appName",
86
- "logo",
87
- "disableEmailLogin",
88
- "disablePhoneLogin",
89
- "oAuthMethods",
90
- "bareModal",
91
- "className",
92
- "currentStepOverride",
93
- "externalWallets",
94
- "authLayout",
95
- "embeddedModal",
96
- "onModalStepChange",
97
- "hideWallets",
98
- "onClose",
99
- "externalWalletsWithParaAuth"
100
- ]);
101
- const modalContentRef = useRef(null);
102
- const updateThemeState = useThemeStore((state) => state.updateState);
103
- const refs = useModalStore((state) => state.refs);
104
- const setWebAuthURLForLogin = useModalStore((state) => state.setWebAuthURLForLogin);
105
- const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
106
- const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
107
- const currentStep = useModalStore((state) => state.step);
108
- const setOnModalStepChange = useModalStore((state) => state.setOnModalStepChange);
109
- const setStep = useModalStore((state) => state.setStep);
110
- const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
111
- const hasPreviousStep = useModalStore((state) => state.hasPreviousStep());
112
- const setFlow = useModalStore((state) => state.setFlow);
113
- const setIsFullyLoggedIn = useModalStore((state) => state.setIsFullyLoggedIn);
114
- const goBack = useGoBack();
115
- const setAuthLayout = useThemeStore((state) => state.setAuthLayout);
116
- const storedAuthLayout = useThemeStore((state) => state.authLayout);
117
- const resetModalState = useModalStore((state) => state.resetState);
118
- const resetUserInfoState = useUserInfoStore((state) => state.resetState);
119
- const setRecoveryShare = useUserInfoStore((state) => state.setRecoveryShare);
120
- const { isOpen, closeModal } = useModal();
121
- const para = useInternalClient();
122
- const { selectedWallet, setSelectedWallet } = useWalletState();
123
- const setIsPasskeySupported = useModalStore((state) => state.setIsPasskeySupported);
124
- const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
125
- const [isModalMounted, setIsModalMounted] = useState(false);
126
- const [isInit, setIsInit] = useState(false);
127
- const [ready, setIsReady] = useState(false);
128
- useImperativeHandle(ref, () => {
129
- return {
130
- goBack() {
131
- goBack();
132
- },
133
- canGoBack() {
134
- return hasPreviousStep;
135
- },
136
- currentStep() {
137
- return currentStep;
138
- },
139
- handleModalClose() {
140
- var _a;
141
- (_a = modalContentRef == null ? void 0 : modalContentRef.current) == null ? void 0 : _a.handleModalClose();
142
- }
143
- };
144
- }, [hasPreviousStep, currentStep]);
145
- const initModal = () => __async(void 0, null, function* () {
146
- const isAccount = yield para.isFullyLoggedIn();
147
- setIsPasskeySupported(yield isPasskeySupported());
148
- if (currentStepOverride) {
97
+ };
98
+ }, [hasPreviousStep, currentStep]);
99
+ const initModal = (shouldAutoLogin) => __async(void 0, null, function* () {
100
+ var _a2;
101
+ const isAccount = yield para.isFullyLoggedIn(), isGuest = isAccount && para.isGuestMode || isCreateGuestWalletsPending;
102
+ switch (true) {
103
+ case !!currentStepOverride:
149
104
  setStep(ModalStep[currentStepOverride.toUpperCase()]);
150
- } else if (isAccount) {
105
+ break;
106
+ case isGuest:
107
+ setFlow("guest");
108
+ setStep(isCreateGuestWalletsPending ? ModalStep.AWAITING_GUEST_WALLET_CREATION : ModalStep.ACCOUNT_MAIN);
109
+ setIsFullyLoggedIn(true);
110
+ break;
111
+ case isAccount:
151
112
  setFlow("account");
152
113
  setStep(ModalStep.ACCOUNT_MAIN);
153
114
  setIsFullyLoggedIn(true);
154
- } else {
115
+ break;
116
+ default:
155
117
  if (currentStep !== ModalStep.AUTH_MAIN && currentStep !== ModalStep.SECRET) {
156
- setStep(ModalStep.AUTH_MAIN);
157
- setFlow();
158
- setWebAuthURLForLogin();
159
- setWebAuthURLForCreate();
160
- setBiometricLocationHints();
118
+ setFlow(void 0);
119
+ setStep(para.isTelegram ? ModalStep.TELEGRAM_OAUTH : ModalStep.AUTH_MAIN);
120
+ setAuthState();
161
121
  setAuthStepRoute();
162
122
  }
123
+ yield disconnectExternalWallet();
163
124
  setSelectedWallet({ id: void 0, type: void 0 });
164
125
  setIsFullyLoggedIn(false);
165
- }
166
- switch (true) {
167
- case para.isEmail:
168
- setAuthInfo({ email: para.getEmail() });
169
- break;
170
- case para.isPhone:
171
- {
172
- const { phone, countryCode } = para.getPhone();
173
- setAuthInfo({ phone, countryCode });
126
+ if (shouldAutoLogin) {
127
+ if (defaultAuthIdentifier && ((_a2 = para.authInfo) == null ? void 0 : _a2.identifier) !== defaultAuthIdentifier) {
128
+ const number = parsePhoneNumberFromString(defaultAuthIdentifier);
129
+ try {
130
+ const auth = validateAuth(
131
+ number ? number.nationalNumber : defaultAuthIdentifier,
132
+ (number == null ? void 0 : number.countryCallingCode) ? `+${number == null ? void 0 : number.countryCallingCode}` : void 0,
133
+ number ? "phone" : "email"
134
+ );
135
+ para.setAuth(number ? { phone: defaultAuthIdentifier } : { email: defaultAuthIdentifier });
136
+ signUpOrLogIn(auth);
137
+ } catch (err) {
138
+ console.error("invalid user identifier:", err.message);
139
+ }
174
140
  }
175
- break;
176
- case para.isFarcaster:
177
- setAuthInfo({ farcasterUsername: para.getFarcasterUsername() });
178
- break;
179
- case para.isTelegram:
180
- setAuthInfo({ telegramUserId: para.telegramUserId });
181
- if (!isAccount) {
182
- setStep(ModalStep.TELEGRAM_OAUTH);
183
- }
184
- break;
185
- case para.isExternalWalletAuth:
186
- const externalWallets2 = Object.values(para.externalWallets);
187
- const externalWalletWithFullAuth = externalWallets2.find((w) => w.isExternalWithParaAuth);
188
- setAuthInfo({
189
- displayName: getExternalWalletDisplayName({
190
- address: externalWalletWithFullAuth.address,
191
- type: externalWalletWithFullAuth.type
192
- }),
193
- externalWalletAddress: externalWalletWithFullAuth.address
194
- });
195
- break;
196
- }
197
- setIsInit(true);
198
- });
199
- useEffect(() => {
200
- let _authLayout = authLayout;
201
- if (!(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout)) {
202
- _authLayout = _authLayout.filter((l) => !l.includes("EXTERNAL"));
203
- }
204
- if (disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout)) {
205
- _authLayout = _authLayout.filter((l) => !l.includes("AUTH"));
206
- }
207
- if (JSON.stringify(storedAuthLayout) !== JSON.stringify(_authLayout)) {
208
- setAuthLayout(_authLayout);
209
- }
210
- }, [disableEmailLogin, disablePhoneLogin, oAuthMethods, externalWallets, authLayout]);
211
- useEffect(() => {
212
- setOnModalStepChange(onModalStepChange);
213
- }, [onModalStepChange]);
214
- useEffect(() => {
215
- var _a;
216
- updateThemeState({
217
- logo,
218
- appName,
219
- oAuthLogoVariant: (_a = theme == null ? void 0 : theme.oAuthLogoVariant) != null ? _a : "default",
220
- bareModal,
221
- embeddedModal,
222
- hideWallets
223
- });
224
- }, [logo, appName, theme == null ? void 0 : theme.oAuthLogoVariant, bareModal, embeddedModal, hideWallets]);
225
- useEffect(() => {
226
- if (theme) {
227
- generateTheme(theme);
228
- updateThemeState({ isDark: theme.mode === "dark", theme });
229
- }
230
- }, [theme]);
231
- useEffect(() => {
232
- if (para) {
233
- initModal();
234
- if (bareModal) {
235
- setIsModalMounted(true);
236
- }
237
- } else {
238
- console.error("A Para instance must be provided.");
239
- }
240
- }, []);
241
- useEffect(() => {
242
- if (isOpen && para) {
243
- initModal();
244
- }
245
- }, [isOpen]);
246
- const updateActiveWallet = () => {
247
- if (!(selectedWallet == null ? void 0 : selectedWallet.id) || !para.findWallet(selectedWallet == null ? void 0 : selectedWallet.id)) {
248
- const defaultWallet = para.findWallet(void 0, void 0, { forbidPregen: true });
249
- setSelectedWallet({ id: defaultWallet == null ? void 0 : defaultWallet.id, type: defaultWallet == null ? void 0 : defaultWallet.type });
250
- }
251
- };
252
- useEffect(() => {
253
- updateActiveWallet();
254
- }, [para]);
255
- useEffect(() => {
256
- const closePopupWindow = () => {
257
- var _a;
258
- (_a = refs.popupWindow.current) == null ? void 0 : _a.close();
259
- };
260
- if (typeof window !== "undefined") {
261
- window.addEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
262
- window.addEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
263
- window.addEventListener("beforeunload", closePopupWindow);
264
- }
265
- setIsReady(true);
266
- return () => {
267
- if (typeof window !== "undefined") {
268
- window.removeEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
269
- window.removeEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
270
- window.removeEventListener("beforeunload", closePopupWindow);
271
141
  }
272
- };
273
- }, []);
274
- const handleClose = () => {
275
- closeModal();
276
- onClose == null ? void 0 : onClose();
277
- };
278
- const handleModalEntering = () => {
279
- setIsModalMounted(true);
280
- };
281
- const handleModalExited = () => __async(void 0, null, function* () {
282
- if (!bareModal) {
283
- setIsModalMounted(false);
284
- }
285
- if (RESET_TO_AUTH_STEPS.includes(currentStep)) {
286
- resetModalState();
287
- resetUserInfoState();
288
- setRecoveryShare(null);
289
- } else if (RESET_TO_ACCOUNT_STEPS.includes(currentStep)) {
290
- setStep(ModalStep.LOGIN_DONE);
291
- }
292
- if (para) {
293
- yield initModal();
294
- para.exitLoops();
295
- }
296
- if (!bareModal) {
297
- setIsInit(false);
298
- }
299
- });
300
- if (!ready) {
301
- return null;
142
+ break;
302
143
  }
303
- if (!para) {
304
- console.error("A Para instance is required.");
305
- return null;
144
+ setIsInit(true);
145
+ });
146
+ useEffect(() => {
147
+ let _authLayout = authLayout;
148
+ if (!(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout)) {
149
+ _authLayout = _authLayout.filter((l) => !l.includes("EXTERNAL"));
306
150
  }
307
- if (!(storedAuthLayout == null ? void 0 : storedAuthLayout.length)) {
308
- const hasExternalWalletError = !(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout);
309
- const hasEmbeddedWalletError = disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout);
310
- if (hasExternalWalletError || hasEmbeddedWalletError) {
311
- if (hasExternalWalletError) {
312
- console.error("At least one external wallet must be provided if external wallet auth is enabled.");
313
- }
314
- if (hasEmbeddedWalletError) {
315
- console.error(
316
- "At least one login method (email, phone or OAuth) must be provided if embedded wallet auth is enabled."
317
- );
318
- }
319
- } else {
320
- console.error("At least one auth layout selection is required.");
321
- }
322
- return null;
151
+ if (disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout)) {
152
+ _authLayout = _authLayout.filter((l) => !l.includes("AUTH"));
153
+ }
154
+ if (JSON.stringify(storedAuthLayout) !== JSON.stringify(_authLayout)) {
155
+ setAuthLayout(_authLayout);
156
+ }
157
+ }, [disableEmailLogin, disablePhoneLogin, oAuthMethods, externalWallets, authLayout, storedAuthLayout]);
158
+ useEffect(() => {
159
+ if (theme) {
160
+ generateTheme(theme);
323
161
  }
324
- return /* @__PURE__ */ jsx(ExternalWalletsWrapper, { wallets: externalWallets, externalWalletsWithFullAuth: externalWalletsWithParaAuth, children: /* @__PURE__ */ jsx(
325
- StyledAuthModal,
326
- {
327
- enterTransitionDuration: DEFAULTS.ANIMATION_DURATION,
328
- exitTransitionDuration: DEFAULTS.ANIMATION_DURATION,
329
- open: isOpen,
330
- onCpslModalExited: handleModalExited,
331
- onCpslModalEntering: handleModalEntering,
332
- onCpslModalRequestClose: handleClose,
333
- noOverlay: bareModal,
334
- className,
335
- "data-testid": "modal",
336
- $embeddedModal: embeddedModal,
337
- children: isModalMounted && (isInit && embeddedModal || !embeddedModal) && /* @__PURE__ */ jsx(
338
- ModalContent,
339
- __spreadValues({
340
- oAuthMethods,
341
- disableEmailLogin,
342
- disablePhoneLogin,
343
- onClose: handleClose
344
- }, rest)
345
- )
162
+ }, [theme]);
163
+ useEffect(() => {
164
+ setOnModalStepChange(onModalStepChange);
165
+ }, [onModalStepChange]);
166
+ useEffect(() => {
167
+ if (para) {
168
+ initModal();
169
+ } else {
170
+ console.error("A Para instance must be provided.");
171
+ }
172
+ }, []);
173
+ useEffect(() => {
174
+ if (isOpen && para) {
175
+ initModal(true);
176
+ }
177
+ }, [isOpen]);
178
+ useEffect(() => {
179
+ updateSelectedWallet();
180
+ }, [para]);
181
+ const handleClose = () => {
182
+ closeModal();
183
+ onClose == null ? void 0 : onClose();
184
+ };
185
+ const handleModalEntering = () => {
186
+ setIsModalMounted(true);
187
+ };
188
+ const handleModalExited = () => __async(void 0, null, function* () {
189
+ setIsModalMounted(false);
190
+ if (RESET_TO_AUTH_STEPS.includes(currentStep)) {
191
+ resetModalState();
192
+ setRecoveryShare(null);
193
+ } else if (RESET_TO_ACCOUNT_STEPS.includes(currentStep)) {
194
+ setStep(ModalStep.LOGIN_DONE);
195
+ }
196
+ if (para) {
197
+ yield initModal();
198
+ }
199
+ setIsInit(false);
200
+ });
201
+ if (!para) {
202
+ console.error("A Para instance is required.");
203
+ return null;
204
+ }
205
+ if (!(storedAuthLayout == null ? void 0 : storedAuthLayout.length)) {
206
+ const hasExternalWalletError = !(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout);
207
+ const hasEmbeddedWalletError = disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout);
208
+ if (hasExternalWalletError || hasEmbeddedWalletError) {
209
+ if (hasExternalWalletError) {
210
+ console.error("At least one external wallet must be provided if external wallet auth is enabled.");
211
+ }
212
+ if (hasEmbeddedWalletError) {
213
+ console.error(
214
+ "At least one login method (email, phone or OAuth) must be provided if embedded wallet auth is enabled."
215
+ );
346
216
  }
347
- ) });
217
+ } else {
218
+ console.error("At least one auth layout selection is required.");
219
+ }
220
+ return null;
348
221
  }
349
- );
222
+ return /* @__PURE__ */ jsx(
223
+ StyledAuthModal,
224
+ {
225
+ enterTransitionDuration: DEFAULTS.ANIMATION_DURATION,
226
+ exitTransitionDuration: DEFAULTS.ANIMATION_DURATION,
227
+ open: isOpen,
228
+ onCpslModalExited: handleModalExited,
229
+ onCpslModalEntering: handleModalEntering,
230
+ onCpslModalRequestClose: handleClose,
231
+ noOverlay: bareModal,
232
+ className,
233
+ "data-testid": "modal",
234
+ $embeddedModal: !!embeddedModal,
235
+ children: isModalMounted && ((embeddedModal || bareModal) && isInit || !embeddedModal && !bareModal) && /* @__PURE__ */ jsx(
236
+ ModalContent,
237
+ __spreadValues({
238
+ oAuthMethods,
239
+ disableEmailLogin,
240
+ disablePhoneLogin,
241
+ isGuestModeEnabled,
242
+ onClose: handleClose
243
+ }, rest)
244
+ )
245
+ }
246
+ );
247
+ });
350
248
  const StyledAuthModal = styled(CpslAuthModal)`
351
249
  ${({ $embeddedModal }) => $embeddedModal && `
352
250
  &::part(modal-body-card) {