@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
@@ -1,66 +1,12 @@
1
1
  "use client";
2
- import {
3
- __async
4
- } from "../../../chunk-MMUBH76A.js";
2
+ import "../../../chunk-MMUBH76A.js";
5
3
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- import { useEffect } from "react";
7
4
  import { CpslButton, CpslIcon, CpslQrCode, CpslSpinner, CpslText } from "@getpara/react-components";
8
5
  import { CenteredText, Heading, InnerStepContainer, QRContainer, StepContainer } from "../common.js";
9
- import { useModalStore, useThemeStore, useUserInfoStore } from "../../stores/index.js";
10
- import { ModalStep } from "../../utils/steps.js";
11
- import { AuthMethod, isMobile } from "@getpara/web-sdk";
12
- import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
13
- import { useSetLoginURLs } from "../../hooks/useSetLoginURLs.js";
6
+ import { useModalStore } from "../../stores/index.js";
7
+ import { isMobile } from "@getpara/web-sdk";
14
8
  const FarcasterOAuthStep = () => {
15
- const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
16
- const setStep = useModalStore((state) => state.setStep);
17
- const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
18
- const setIFrameUrl = useModalStore((state) => state.setIFrameUrl);
19
- const setIsIFrameReady = useModalStore((state) => state.setIsIFrameReady);
20
- const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
21
- const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
22
- const para = useInternalClient();
23
- const setFlow = useModalStore((state) => state.setFlow);
24
9
  const farcasterConnectUri = useModalStore((state) => state.farcasterConnectUri);
25
- const setFarcasterConnectUri = useModalStore((state) => state.setFarcasterConnectUri);
26
- const theme = useThemeStore((state) => state.theme);
27
- const setLoginURLs = useSetLoginURLs();
28
- useEffect(() => {
29
- if (farcasterConnectUri) {
30
- const pollStatus = () => __async(void 0, null, function* () {
31
- const { userExists, username, pfpUrl } = yield para.waitForFarcasterStatus();
32
- setAuthInfo({ farcasterUsername: username, pfpUrl });
33
- if (userExists) {
34
- const supportedAuthMethods = yield para.initiateUserLoginV2({ farcasterUsername: username });
35
- if (supportedAuthMethods.size > 0) {
36
- const biometricLocationHints = supportedAuthMethods.has(AuthMethod.PASSKEY) ? yield para.getUserBiometricLocationHints() : [];
37
- yield setLoginURLs({ supportedAuthMethods, authType: "farcaster", displayName: username, pfpUrl });
38
- setFlow("login");
39
- setStep(ModalStep.BIOMETRIC_LOGIN);
40
- setBiometricLocationHints(biometricLocationHints);
41
- return;
42
- }
43
- }
44
- const supportedCreateAuthMethods = yield para.getSupportedCreateAuthMethods();
45
- setIsIFrameReady(false);
46
- setFlow("signUp");
47
- const supportsPasskey = supportedCreateAuthMethods.has(AuthMethod.PASSKEY);
48
- if (supportsPasskey) {
49
- setWebAuthURLForCreate(yield para.shortenLoginLink(yield para.getSetUpBiometricsURL({ authType: "farcaster" })));
50
- setStep(ModalStep.BIOMETRIC_CREATION);
51
- }
52
- if (supportedCreateAuthMethods.has(AuthMethod.PASSWORD)) {
53
- setIFrameUrl(yield para.shortenLoginLink(yield para.getSetupPasswordURL({ authType: "farcaster", theme })));
54
- setAuthStepRoute(supportsPasskey ? ModalStep.BIOMETRIC_CREATION : ModalStep.PASSWORD_CREATION);
55
- }
56
- return;
57
- });
58
- pollStatus();
59
- return () => {
60
- setFarcasterConnectUri(void 0);
61
- };
62
- }
63
- }, [farcasterConnectUri]);
64
10
  return /* @__PURE__ */ jsx(StepContainer, { $wide: true, children: isMobile() ? /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
65
11
  /* @__PURE__ */ jsx(CpslText, { weight: "medium", color: "secondary", children: `Don\u2019t have Farcaster` }),
66
12
  /* @__PURE__ */ jsxs(CpslButton, { as: "a", href: "https://link.warpcast.com/download-qr", target: "_blank", variant: "secondary", children: [
@@ -1,6 +1,6 @@
1
- import { OAuthMethod } from '@getpara/web-sdk';
1
+ import { TOAuthMethod } from '@getpara/web-sdk';
2
2
  interface OAuthProps {
3
- methods: OAuthMethod[];
3
+ methods: TOAuthMethod[];
4
4
  }
5
5
  export declare const OAuth: ({ methods }: OAuthProps) => import("react/jsx-runtime").JSX.Element;
6
6
  export {};
@@ -3,50 +3,21 @@ import {
3
3
  __async
4
4
  } from "../../../chunk-MMUBH76A.js";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { AuthMethod, OAuthMethod } from "@getpara/web-sdk";
7
6
  import { styled } from "styled-components";
8
- import { useModalStore, useUserInfoStore } from "../../stores/index.js";
7
+ import { useModalStore } from "../../stores/index.js";
9
8
  import { ModalStep } from "../../utils/steps.js";
10
- import { openPopup } from "../../utils/openPopup.js";
11
- import { useThemeStore } from "../../stores/theme/useThemeStore.js";
12
9
  import { getTileButtonFlex } from "../../utils/getTileButtonFlex.js";
13
10
  import { StyledCpslTileButton } from "../common.js";
14
11
  import { brandedOAuthLogos, oAuthLogos } from "../../constants/oAuthLogos.js";
15
- import { useEffect } from "react";
16
- import { routeMobileExternalWallet } from "../../utils/routeMobileExternalWallet.js";
17
- import { useGoBack } from "../../hooks/useGoBack.js";
18
- import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
19
- import { useSetLoginURLs } from "../../hooks/useSetLoginURLs.js";
12
+ import { useStore } from "../../../provider/stores/useStore.js";
13
+ import { useAuthActions } from "../../../provider/providers/AuthProvider.js";
20
14
  const HAS_MORE_LENGTH = 3;
21
15
  const OAuth = ({ methods }) => {
22
- const goBack = useGoBack();
23
- const oAuthLogoVariant = useThemeStore((state) => state.oAuthLogoVariant);
24
- const isDark = useThemeStore((state) => state.isDark);
25
- const para = useInternalClient();
26
- const refs = useModalStore((state) => state.refs);
27
- const setFlow = useModalStore((state) => state.setFlow);
16
+ const oAuthLogoVariant = useStore((state) => state.oAuthLogoVariant);
17
+ const isDark = useStore((state) => state.isDarkTheme);
28
18
  const setStep = useModalStore((state) => state.setStep);
29
- const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
30
- const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
31
- const setFarcasterConnectUri = useModalStore((state) => state.setFarcasterConnectUri);
32
- const farcasterConnectUri = useModalStore((state) => state.farcasterConnectUri);
33
- const showAll = useModalStore((state) => state.step === ModalStep.AUTH_MORE);
34
- const setIFrameUrl = useModalStore((state) => state.setIFrameUrl);
35
- const setIsIFrameReady = useModalStore((state) => state.setIsIFrameReady);
36
- const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
37
- const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
38
- const theme = useThemeStore((state) => state.theme);
39
- const setLoginURLs = useSetLoginURLs();
40
- useEffect(() => {
41
- const initializeFarcaster = () => __async(void 0, null, function* () {
42
- if (!methods.includes(OAuthMethod.FARCASTER)) {
43
- return;
44
- }
45
- const connectUri = yield para.getFarcasterConnectURL();
46
- setFarcasterConnectUri(connectUri);
47
- });
48
- initializeFarcaster();
49
- }, []);
19
+ const showAll = useModalStore((state) => state.step === ModalStep.AUTH_MORE || state.step === ModalStep.AUTH_GUEST_SIGNUP);
20
+ const { verifyFarcaster, verifyOAuth } = useAuthActions();
50
21
  const hasMore = methods.length > HAS_MORE_LENGTH;
51
22
  const methodsToShow = showAll || !hasMore ? methods : methods.slice(0, HAS_MORE_LENGTH - 1);
52
23
  const handleShowAll = () => {
@@ -54,59 +25,14 @@ const OAuth = ({ methods }) => {
54
25
  };
55
26
  const handleMethodClick = (method) => () => __async(void 0, null, function* () {
56
27
  switch (method) {
57
- case OAuthMethod.FARCASTER:
58
- if (!farcasterConnectUri) {
59
- return;
60
- }
61
- routeMobileExternalWallet(farcasterConnectUri);
62
- setStep(ModalStep.FARCASTER_OAUTH);
28
+ case "FARCASTER":
29
+ verifyFarcaster();
63
30
  break;
64
- case OAuthMethod.TELEGRAM:
31
+ case "TELEGRAM":
65
32
  setStep(ModalStep.TELEGRAM_OAUTH);
66
33
  break;
67
34
  default:
68
- setStep(ModalStep.AWAITING_OAUTH);
69
- const oAuthURL = yield para.getOAuthURL({ method });
70
- refs.popupWindow.current = openPopup({
71
- url: oAuthURL,
72
- target: `${method}AuthPopup`,
73
- type: "OAUTH",
74
- current: refs.popupWindow.current
75
- });
76
- const { email, isError, userExists } = yield para.waitForOAuth({ popupWindow: refs.popupWindow.current });
77
- refs.popupWindow.current = void 0;
78
- if ((isError || !email) && refs.currentStep.current === ModalStep.AWAITING_OAUTH) {
79
- goBack();
80
- return;
81
- }
82
- setAuthInfo({ email });
83
- if (userExists) {
84
- const supportedAuthMethods = yield para.initiateUserLoginV2({ email });
85
- if (supportedAuthMethods.size > 0) {
86
- const biometricLocationHints = supportedAuthMethods.has(AuthMethod.PASSKEY) ? yield para.getUserBiometricLocationHints() : [];
87
- yield setLoginURLs({ supportedAuthMethods, authType: "email" });
88
- setFlow("login");
89
- setStep(ModalStep.BIOMETRIC_LOGIN);
90
- setBiometricLocationHints(biometricLocationHints);
91
- return;
92
- }
93
- }
94
- const supportedCreateAuthMethods = yield para.getSupportedCreateAuthMethods();
95
- setIsIFrameReady(false);
96
- setFlow("signUp");
97
- const supportsPasskey = supportedCreateAuthMethods.has(AuthMethod.PASSKEY);
98
- const supportsPassword = supportedCreateAuthMethods.has(AuthMethod.PASSWORD);
99
- if (supportsPasskey) {
100
- setWebAuthURLForCreate(yield para.shortenLoginLink(yield para.getSetUpBiometricsURL({ authType: "email" })));
101
- if (!supportsPassword) {
102
- setStep(ModalStep.BIOMETRIC_CREATION);
103
- return;
104
- }
105
- }
106
- if (supportsPassword) {
107
- setIFrameUrl(yield para.shortenLoginLink(yield para.getSetupPasswordURL({ authType: "email", theme })));
108
- }
109
- setAuthStepRoute(supportsPasskey ? ModalStep.BIOMETRIC_CREATION : ModalStep.PASSWORD_CREATION);
35
+ verifyOAuth(method);
110
36
  break;
111
37
  }
112
38
  });
@@ -3,37 +3,29 @@ import {
3
3
  __async
4
4
  } from "../../../chunk-MMUBH76A.js";
5
5
  import { jsx, jsxs } from "react/jsx-runtime";
6
- import { AuthMethod, OAuthMethod } from "@getpara/web-sdk";
7
- import { useModalStore, useThemeStore, useUserInfoStore } from "../../stores/index.js";
6
+ import { constructUrl, getPortalBaseURL } from "@getpara/web-sdk";
8
7
  import styled from "styled-components";
9
8
  import { useEffect, useRef, useState } from "react";
10
9
  import { HeroSpinner } from "@getpara/react-common";
11
- import { ModalStep } from "../../utils/steps.js";
12
10
  import { CpslSpinner } from "@getpara/react-components";
13
11
  import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
14
- import { useSetLoginURLs } from "../../hooks/useSetLoginURLs.js";
12
+ import { useAuthActions } from "../../../provider/providers/AuthProvider.js";
15
13
  function TelegramOAuthStep() {
16
14
  const iframe = useRef();
17
15
  const para = useInternalClient();
18
- const setFlow = useModalStore((state) => state.setFlow);
19
- const setStep = useModalStore((state) => state.setStep);
20
- const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
21
- const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
22
- const setIFrameUrl = useModalStore((state) => state.setIFrameUrl);
23
- const setIsIFrameReady = useModalStore((state) => state.setIsIFrameReady);
24
- const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
25
- const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
26
- const theme = useThemeStore((state) => state.theme);
27
- const setLoginURLs = useSetLoginURLs();
28
- const [url, setUrl] = useState(void 0);
16
+ const { verifyTelegram } = useAuthActions();
17
+ const [url, setUrl] = useState();
29
18
  const [isWaiting, setIsWaiting] = useState(false);
30
19
  const [isLoaded, setIsLoaded] = useState(false);
31
20
  const [isError, setIsError] = useState(false);
32
21
  useEffect(() => {
33
22
  if (!url) {
34
- para.getOAuthURL({ method: OAuthMethod.TELEGRAM }).then((url2) => {
35
- setUrl(url2);
36
- });
23
+ setUrl(
24
+ constructUrl({
25
+ base: getPortalBaseURL(para.ctx, true),
26
+ path: "/auth/telegram"
27
+ })
28
+ );
37
29
  }
38
30
  }, [url]);
39
31
  useEffect(() => {
@@ -50,48 +42,7 @@ function TelegramOAuthStep() {
50
42
  case "TELEGRAM_SUCCESS":
51
43
  if (!!event.data.payload) {
52
44
  const authObject = event.data.payload;
53
- const result = yield para.verifyTelegram(authObject);
54
- if (!result.isValid) {
55
- setIsWaiting(false);
56
- setIsError(true);
57
- iframe.current && iframe.current.contentWindow.postMessage({ type: "TELEGRAM_FAILED" }, "*");
58
- return;
59
- }
60
- const { telegramUserId, isNewUser, supportedAuthMethods, biometricHints } = result;
61
- const pfpUrl = authObject.photo_url;
62
- const displayName = authObject.username ? `@${authObject.username}` : authObject.first_name ? `${authObject.first_name}${authObject.last_name ? ` ${authObject.last_name}` : ""}` : `Telegram User @${telegramUserId}`;
63
- setAuthInfo({
64
- telegramUserId,
65
- pfpUrl,
66
- displayName
67
- });
68
- if (isNewUser) {
69
- const supportedCreateAuthMethods = yield para.getSupportedCreateAuthMethods();
70
- setIsIFrameReady(false);
71
- setFlow("signUp");
72
- const supportsPasskey = supportedCreateAuthMethods.has(AuthMethod.PASSKEY);
73
- if (supportsPasskey) {
74
- setWebAuthURLForCreate(
75
- yield para.shortenLoginLink(yield para.getSetUpBiometricsURL({ authType: "telegram" }))
76
- );
77
- setStep(ModalStep.BIOMETRIC_CREATION);
78
- }
79
- if (supportedCreateAuthMethods.has(AuthMethod.PASSWORD)) {
80
- setIFrameUrl(yield para.shortenLoginLink(yield para.getSetupPasswordURL({ authType: "telegram", theme })));
81
- setAuthStepRoute(supportsPasskey ? ModalStep.BIOMETRIC_CREATION : ModalStep.PASSWORD_CREATION);
82
- }
83
- } else {
84
- setFlow("login");
85
- const supportedAuthMethodsSet = new Set(supportedAuthMethods);
86
- biometricHints && setBiometricLocationHints(biometricHints);
87
- yield setLoginURLs({
88
- supportedAuthMethods: supportedAuthMethodsSet,
89
- authType: "telegram",
90
- displayName,
91
- pfpUrl
92
- });
93
- setStep(ModalStep.BIOMETRIC_LOGIN);
94
- }
45
+ verifyTelegram(authObject);
95
46
  }
96
47
  break;
97
48
  }
@@ -13,7 +13,7 @@ const AddingFunds = () => {
13
13
  /* @__PURE__ */ jsxs(CpslText, { children: [
14
14
  "Follow the prompts presented by",
15
15
  " ",
16
- OnRampPurchaseStatus ? ON_RAMP_PROVIDERS[onRampPurchase.provider].name : "the provider",
16
+ OnRampPurchaseStatus && (onRampPurchase == null ? void 0 : onRampPurchase.provider) ? ON_RAMP_PROVIDERS[onRampPurchase.provider].name : "the provider",
17
17
  "."
18
18
  ] })
19
19
  ] });
@@ -4,13 +4,15 @@ import {
4
4
  } from "../../../chunk-MMUBH76A.js";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { CpslButton, CpslText } from "@getpara/react-components";
7
- import { useModalStore, useThemeStore, useUserInfoStore } from "../../stores/index.js";
7
+ import { useModalStore } from "../../stores/index.js";
8
8
  import { ModalStep } from "../../utils/steps.js";
9
9
  import { Heading, InnerStepContainer, StepContainer, StyledCpslTileButton } from "../common.js";
10
10
  import { styled } from "styled-components";
11
11
  import { useCopyToClipboard } from "@getpara/react-common";
12
12
  import { getMailtoLink } from "../../utils/getMailtoLink.js";
13
13
  import { useState } from "react";
14
+ import { useStore } from "../../../provider/stores/useStore.js";
15
+ import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
14
16
  const SaveRecoverySecret = ({
15
17
  email,
16
18
  value,
@@ -48,10 +50,14 @@ const SaveRecoverySecret = ({
48
50
  ] });
49
51
  };
50
52
  const RecoverySecretStep = () => {
51
- const hideWallets = useThemeStore((state) => state.hideWallets);
53
+ const para = useInternalClient();
54
+ const hideWallets = useStore((state) => {
55
+ var _a;
56
+ return (_a = state.modalConfig) == null ? void 0 : _a.hideWallets;
57
+ });
52
58
  const setStep = useModalStore((state) => state.setStep);
53
- const authInfo = useUserInfoStore((state) => state.getAuthInfo());
54
- const recoveryShare = useUserInfoStore((state) => state.recoveryShare);
59
+ const authInfo = para.authInfo;
60
+ const recoveryShare = useModalStore((state) => state.recoveryShare);
55
61
  const backupDecryptionKey = JSON.parse(recoveryShare || "{}").backupDecryptionKey;
56
62
  const onComplete = () => __async(void 0, null, function* () {
57
63
  setStep(ModalStep.WALLET_CREATION_DONE);
@@ -18,37 +18,23 @@ import { Heading, QRContainer, FilledDisabledInput, StepContainer, InnerStepCont
18
18
  import { ModalStep } from "../../utils/steps.js";
19
19
  import { styled } from "styled-components";
20
20
  import { useCopyToClipboard } from "@getpara/react-common";
21
- import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
21
+ import { useEnable2fa } from "../../../provider/index.js";
22
22
  const Setup2FAStep = ({ onClose }) => {
23
23
  const isLogin = useModalStore((state) => state.isLogin());
24
24
  const setStep = useModalStore((state) => state.setStep);
25
- const para = useInternalClient();
25
+ const twoFactorStatus = useModalStore((state) => state.twoFactorStatus);
26
+ const { enable2fa, isPending } = useEnable2fa();
26
27
  const isVerifying = useModalStore((state) => state.step === ModalStep.VERIFY_2FA);
27
28
  const [copied, copy] = useCopyToClipboard();
28
29
  const inputRef = useRef(null);
29
- const [qrCodeValue, setQrCodeValue] = useState(null);
30
30
  const [code, setCode] = useState("");
31
31
  const [codeError, setCodeError] = useState("");
32
- const [isVerifyingCode, setIsVerifyingCode] = useState(false);
33
- const params = qrCodeValue ? new URL(qrCodeValue).searchParams : void 0;
32
+ const params = (twoFactorStatus == null ? void 0 : twoFactorStatus.uri) ? new URL(twoFactorStatus.uri).searchParams : void 0;
34
33
  const secret = params == null ? void 0 : params.get("secret");
35
- useEffect(() => {
36
- function fetchOtpAuthUrl() {
37
- return __async(this, null, function* () {
38
- try {
39
- const { uri } = yield para.setup2FA();
40
- setQrCodeValue(uri);
41
- } catch (error) {
42
- console.error("Error fetching OTPAuth URL:", error);
43
- }
44
- });
45
- }
46
- fetchOtpAuthUrl();
47
- }, []);
48
34
  useEffect(() => {
49
35
  setTimeout(() => {
50
- var _a, _b, _c;
51
- (_c = (_b = (_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.shadowRoot.querySelectorAll("input")) == null ? void 0 : _b[0]) == null ? void 0 : _c.focus();
36
+ var _a, _b, _c, _d;
37
+ (_d = (_c = (_b = (_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelectorAll("input")) == null ? void 0 : _c[0]) == null ? void 0 : _d.focus();
52
38
  }, 10);
53
39
  }, [isVerifying]);
54
40
  useEffect(() => {
@@ -73,28 +59,33 @@ const Setup2FAStep = ({ onClose }) => {
73
59
  setCode(e.detail.value.trim());
74
60
  };
75
61
  const handleSubmitCode = () => __async(void 0, null, function* () {
76
- setIsVerifyingCode(true);
77
62
  if (code.length === 6 && /^\d+$/.test(code)) {
78
- try {
79
- yield para.enable2FA({ verificationCode: code });
80
- setStep(ModalStep.TWO_FACTOR_DONE);
81
- } catch (e) {
82
- setCodeError("Incorrect Code");
83
- }
63
+ enable2fa(
64
+ { verificationCode: code },
65
+ {
66
+ onSuccess: () => {
67
+ setStep(ModalStep.TWO_FACTOR_DONE);
68
+ },
69
+ onError: () => {
70
+ setCodeError("Incorrect Code");
71
+ }
72
+ }
73
+ );
84
74
  } else {
85
75
  setCodeError("Incorrect Code");
86
76
  }
87
- setIsVerifyingCode(false);
88
77
  });
89
78
  const handleCopy = () => {
90
- copy(secret);
79
+ if (secret) {
80
+ copy(secret);
81
+ }
91
82
  };
92
83
  return /* @__PURE__ */ jsxs(StepContainer, { children: [
93
84
  /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
94
85
  /* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: "Turn on Two-Factor authentication" }),
95
86
  isVerifying && /* @__PURE__ */ jsx(CpslText, { variant: "bodyS", color: "secondary", weight: "medium", children: "Please enter the code from your authenticator app." })
96
87
  ] }),
97
- /* @__PURE__ */ jsx(InnerStepContainer, { children: isVerifying ? /* @__PURE__ */ jsx(Fragment, { children: isVerifyingCode ? /* @__PURE__ */ jsx(CpslSpinner, {}) : /* @__PURE__ */ jsx(
88
+ /* @__PURE__ */ jsx(InnerStepContainer, { children: isVerifying ? /* @__PURE__ */ jsx(Fragment, { children: isPending ? /* @__PURE__ */ jsx(CpslSpinner, {}) : /* @__PURE__ */ jsx(
98
89
  "form",
99
90
  {
100
91
  onSubmit: (e) => __async(void 0, null, function* () {
@@ -117,11 +108,11 @@ const Setup2FAStep = ({ onClose }) => {
117
108
  }
118
109
  ) }) : /* @__PURE__ */ jsxs(Fragment, { children: [
119
110
  /* @__PURE__ */ jsx(CpslText, { variant: "bodyS", color: "secondary", weight: "medium", children: "Scan with your preferred authenticator app." }),
120
- /* @__PURE__ */ jsx(QRContainer, { children: !qrCodeValue ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: qrCodeValue }) })
111
+ /* @__PURE__ */ jsx(QRContainer, { children: !(twoFactorStatus == null ? void 0 : twoFactorStatus.uri) ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: twoFactorStatus.uri }) })
121
112
  ] }) }),
122
113
  !isVerifying && /* @__PURE__ */ jsxs(Fragment, { children: [
123
114
  /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(CpslDivider, { children: "or enter the code manually" }) }),
124
- /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(FilledDisabledInput, { disabled: true, value: secret, noAutoDisable: true, children: /* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: handleCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: copied ? "check" : "copy" }) }) }) }),
115
+ /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(FilledDisabledInput, { disabled: true, value: secret != null ? secret : "", noAutoDisable: true, children: /* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: handleCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: copied ? "check" : "copy" }) }) }) }),
125
116
  /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
126
117
  /* @__PURE__ */ jsx(CpslButton, { fullWidth: true, onClick: handleNext, children: "Continue" }),
127
118
  /* @__PURE__ */ jsx(SkipButton, { variant: "ghost", onClick: handleSkip, children: "Skip" })
@@ -8,7 +8,7 @@ import { jsx } from "react/jsx-runtime";
8
8
  import React from "react";
9
9
  const STRIPE_PUBLISHABLE_KEY = "pk_live_51MvquNGrzDeP5yP9EgVSMBPQbrbg0oHDjPIIXypePd0jzOFjbadyfO7wBKLHhUtbKIUiEUVC3YYcTJyAmJ8xA7JE00T2UDfYKz";
10
10
  const STRIPE_PUBLISHABLE_KEY_TEST = "pk_test_51MvquNGrzDeP5yP98WgPaAUgQ50I3OpfPhVfiLO47FBHepJnZRPO62IzZY2uxT5ovhSS10RwcTcnaVil1mcJOzIi00dHapODdS";
11
- const CryptoElementsContext = React.createContext(null);
11
+ const CryptoElementsContext = React.createContext({ onramp: null });
12
12
  CryptoElementsContext.displayName = "CryptoElementsContext";
13
13
  const CryptoElements = ({ stripeOnramp, children }) => {
14
14
  const [ctx, setContext] = React.useState(() => ({
@@ -3,9 +3,12 @@ import "../../../chunk-MMUBH76A.js";
3
3
  import { jsx, jsxs } from "react/jsx-runtime";
4
4
  import { CpslButton, CpslText } from "@getpara/react-components";
5
5
  import { Heading, StepContainer, InnerStepContainer, HeroIcon } from "../common.js";
6
- import { useThemeStore } from "../../stores/index.js";
6
+ import { useStore } from "../../../provider/stores/useStore.js";
7
7
  const TwoFactorDoneStep = ({ onClose }) => {
8
- const hideWallets = useThemeStore((state) => state.hideWallets);
8
+ const hideWallets = useStore((state) => {
9
+ var _a;
10
+ return (_a = state.modalConfig) == null ? void 0 : _a.hideWallets;
11
+ });
9
12
  return /* @__PURE__ */ jsxs(StepContainer, { children: [
10
13
  /* @__PURE__ */ jsx(HeroIcon, { icon: "checkCircleFilled" }),
11
14
  /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
@@ -6,92 +6,75 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  import { CpslCodeInput, CpslSpinner, CpslText } from "@getpara/react-components";
7
7
  import { useEffect, useRef, useState } from "react";
8
8
  import { styled } from "styled-components";
9
- import { ModalStep } from "../../utils/steps.js";
10
- import { useModalStore, useThemeStore, useUserInfoStore } from "../../stores/index.js";
11
9
  import { Heading, InnerStepContainer, StepContainer } from "../common.js";
12
- import { AuthMethod } from "@getpara/core-sdk";
10
+ import { displayPhoneNumber } from "@getpara/core-sdk";
13
11
  import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
12
+ import { useAuthActions } from "../../../provider/providers/AuthProvider.js";
13
+ import { useResendVerificationCode } from "../../../provider/index.js";
14
14
  const VerificationCodeStep = () => {
15
- const theme = useThemeStore((state) => state.theme);
16
- const authInfo = useUserInfoStore((state) => state.getAuthInfo());
17
- const setStep = useModalStore((state) => state.setStep);
18
- const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
19
- const setIFrameUrl = useModalStore((state) => state.setIFrameUrl);
20
- const setIsIFrameReady = useModalStore((state) => state.setIsIFrameReady);
21
- const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
22
15
  const para = useInternalClient();
16
+ const authInfo = para.authInfo;
17
+ const { verifyNewAccount, isVerifyNewAccountPending, verifyNewAccountError } = useAuthActions();
18
+ const { resendVerificationCode } = useResendVerificationCode();
23
19
  const inputRef = useRef(null);
24
20
  const [code, setCode] = useState("");
25
- const [codeError, setCodeError] = useState("");
26
- const [resendStatus, setResendStatus] = useState("Resend.");
21
+ const [isPending, setIsPending] = useState(false);
22
+ const [codeError, setCodeError] = useState(null);
27
23
  const [resendDisabled, setResendDisabled] = useState(false);
28
- const [isVerifying, setIsVerifying] = useState(false);
29
24
  const isEmail = (authInfo == null ? void 0 : authInfo.authType) === "email";
30
25
  useEffect(() => {
31
26
  setTimeout(() => {
32
- var _a, _b;
33
- (_b = (_a = inputRef.current.shadowRoot.querySelectorAll("input")) == null ? void 0 : _a[0]) == null ? void 0 : _b.focus();
27
+ var _a, _b, _c, _d;
28
+ (_d = (_c = (_b = (_a = inputRef.current) == null ? void 0 : _a.shadowRoot) == null ? void 0 : _b.querySelectorAll("input")) == null ? void 0 : _c[0]) == null ? void 0 : _d.focus();
34
29
  }, 10);
35
30
  }, []);
36
31
  useEffect(() => {
32
+ setCodeError(null);
37
33
  if (code.length === 6) {
38
34
  handleSubmitCode();
39
35
  }
40
36
  }, [code]);
37
+ useEffect(() => {
38
+ if (isVerifyNewAccountPending) {
39
+ setIsPending(isVerifyNewAccountPending);
40
+ }
41
+ }, [isVerifyNewAccountPending]);
41
42
  const handleResendClick = () => __async(void 0, null, function* () {
42
43
  if (!resendDisabled) {
43
- setResendStatus("Resent!");
44
44
  setResendDisabled(true);
45
- isEmail ? yield para.resendVerificationCode() : yield para.resendVerificationCodeByPhone();
46
- setTimeout(() => {
47
- setResendStatus("Resend.");
48
- setResendDisabled(false);
49
- }, 3e3);
45
+ resendVerificationCode(void 0, {
46
+ onSettled: () => {
47
+ setTimeout(() => {
48
+ setResendDisabled(false);
49
+ }, 3e3);
50
+ }
51
+ });
50
52
  }
51
53
  });
52
54
  const handleCodeInput = (e) => {
53
- if (codeError) {
54
- setCodeError("");
55
- }
56
55
  setCode(e.detail.value.trim());
57
56
  };
58
57
  const handleSubmitCode = () => __async(void 0, null, function* () {
59
- setIsVerifying(true);
60
58
  if (code.length === 6 && /^\d+$/.test(code)) {
61
- try {
62
- const supportedCreateAuthMethods = yield para.getSupportedCreateAuthMethods();
63
- if (supportedCreateAuthMethods.has(AuthMethod.PASSWORD) && supportedCreateAuthMethods.has(AuthMethod.PASSKEY)) {
64
- setIsIFrameReady(false);
65
- const webAuthUrl = isEmail ? yield para.verifyEmail({ verificationCode: code }) : yield para.verifyPhone({ verificationCode: code });
66
- const passwordAuthUrl = yield para.getSetupPasswordURL({ authType: authInfo == null ? void 0 : authInfo.authType, theme });
67
- setWebAuthURLForCreate(yield para.shortenLoginLink(webAuthUrl));
68
- setIFrameUrl(yield para.shortenLoginLink(passwordAuthUrl));
69
- setAuthStepRoute(ModalStep.BIOMETRIC_CREATION);
70
- return;
71
- } else if (supportedCreateAuthMethods.has(AuthMethod.PASSWORD)) {
72
- setIsIFrameReady(false);
73
- isEmail ? yield para.verifyEmail({ verificationCode: code }) : yield para.verifyPhone({ verificationCode: code });
74
- const url = yield para.getSetupPasswordURL({ authType: authInfo == null ? void 0 : authInfo.authType, theme });
75
- setIFrameUrl(yield para.shortenLoginLink(url));
76
- setAuthStepRoute(ModalStep.PASSWORD_CREATION);
77
- return;
78
- } else {
79
- const url = isEmail ? yield para.verifyEmail({ verificationCode: code }) : yield para.verifyPhone({ verificationCode: code });
80
- setWebAuthURLForCreate(yield para.shortenLoginLink(url));
81
- setStep(ModalStep.BIOMETRIC_CREATION);
82
- }
83
- } catch (e) {
84
- if (e.message.includes("429")) {
85
- setCodeError("Too many incorrect attempts. Please try again in 10 minutes.");
86
- } else {
87
- setCodeError("Incorrect code.");
88
- }
89
- }
59
+ verifyNewAccount(code);
90
60
  } else {
91
61
  setCodeError("Incorrect code.");
92
62
  }
93
- setIsVerifying(false);
94
63
  });
64
+ useEffect(() => {
65
+ if (!!verifyNewAccountError) {
66
+ setIsPending(false);
67
+ const status = verifyNewAccountError.status;
68
+ switch (status) {
69
+ case 429:
70
+ setCodeError("Too many incorrect attempts. Please try again in 10 minutes.");
71
+ break;
72
+ default:
73
+ setCodeError("Incorrect code.");
74
+ break;
75
+ }
76
+ }
77
+ }, [verifyNewAccountError]);
95
78
  return /* @__PURE__ */ jsxs(StepContainer, { $wide: true, children: [
96
79
  /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
97
80
  /* @__PURE__ */ jsxs(Heading, { variant: "headingS", weight: "bold", children: [
@@ -99,11 +82,12 @@ const VerificationCodeStep = () => {
99
82
  isEmail ? "Email" : "Phone Number"
100
83
  ] }),
101
84
  /* @__PURE__ */ jsxs(InlineText, { variant: "bodyS", color: "secondary", children: [
102
- "Please enter the code we sent to ",
103
- /* @__PURE__ */ jsx(InlineText, { variant: "bodyS", children: authInfo == null ? void 0 : authInfo.identifier })
85
+ "Please enter the code we sent to",
86
+ " ",
87
+ /* @__PURE__ */ jsx(InlineText, { variant: "bodyS", children: (authInfo == null ? void 0 : authInfo.authType) === "phone" ? displayPhoneNumber(authInfo.identifier) : authInfo.identifier })
104
88
  ] })
105
89
  ] }),
106
- /* @__PURE__ */ jsx(InnerStepContainer, { children: isVerifying ? /* @__PURE__ */ jsx(CpslSpinner, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
90
+ /* @__PURE__ */ jsx(InnerStepContainer, { children: isPending ? /* @__PURE__ */ jsx(CpslSpinner, {}) : /* @__PURE__ */ jsxs(Fragment, { children: [
107
91
  /* @__PURE__ */ jsx(
108
92
  "form",
109
93
  {
@@ -119,7 +103,7 @@ const VerificationCodeStep = () => {
119
103
  type: "number",
120
104
  code,
121
105
  onCpslInput: handleCodeInput,
122
- errorText: codeError,
106
+ errorText: codeError || "",
123
107
  onKeyDown: (e) => __async(void 0, null, function* () {
124
108
  return e.key === "Enter" && (yield handleSubmitCode());
125
109
  })
@@ -136,7 +120,7 @@ const VerificationCodeStep = () => {
136
120
  variant: "bodyS",
137
121
  style: { cursor: resendDisabled ? "default" : "pointer" },
138
122
  onClick: handleResendClick,
139
- children: resendStatus
123
+ children: resendDisabled ? "Resent!" : "Resend."
140
124
  }
141
125
  )
142
126
  ] })