@getpara/react-sdk 1.7.0 → 1.8.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 (158) hide show
  1. package/dist/index.js +6 -6657
  2. package/dist/modal/ParaModal.js +362 -0
  3. package/dist/modal/components/Account/Account.js +77 -0
  4. package/dist/modal/components/AddFunds/AddFunds.js +220 -0
  5. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +72 -0
  6. package/dist/modal/components/AddFunds/AddFundsDone.js +43 -0
  7. package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
  8. package/dist/modal/components/AddFunds/index.js +4 -0
  9. package/dist/modal/components/AuthInput/AuthInput.js +283 -0
  10. package/dist/modal/components/AuthInput/countryCodes.js +42 -0
  11. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
  12. package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
  13. package/dist/modal/components/AuthMainStep/AuthMainStep.js +37 -0
  14. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +113 -0
  15. package/dist/modal/components/AuthOptions/AuthOptions.js +33 -0
  16. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
  17. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
  18. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
  19. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +44 -0
  20. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +55 -0
  21. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +93 -0
  22. package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
  23. package/dist/modal/components/Body/Body.js +308 -0
  24. package/dist/modal/components/ChainSwitch/ChainSwitch.js +94 -0
  25. package/dist/modal/components/ChainSwitch/config.js +17 -0
  26. package/dist/modal/components/Controls/Controls.js +74 -0
  27. package/dist/modal/components/Controls/Selects.js +234 -0
  28. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +140 -0
  29. package/dist/modal/components/ExternalWalletStep/config.js +17 -0
  30. package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +96 -0
  31. package/dist/modal/components/ExternalWallets/ExternalWallets.js +172 -0
  32. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +124 -0
  33. package/dist/modal/components/Footer/Footer.js +93 -0
  34. package/dist/modal/components/Header/Header.js +43 -0
  35. package/dist/modal/components/Header/hooks/useStepTitle.js +50 -0
  36. package/dist/modal/components/Hero/Hero.js +116 -0
  37. package/dist/modal/components/IFrameStep/IFrameStep.js +55 -0
  38. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +28 -0
  39. package/dist/modal/components/ModalContent/ModalContent.js +324 -0
  40. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
  41. package/dist/modal/components/OAuth/OAuth.js +153 -0
  42. package/dist/modal/components/OAuth/TelegramOAuthStep.js +139 -0
  43. package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
  44. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
  45. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +101 -0
  46. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +141 -0
  47. package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
  48. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +24 -0
  49. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +159 -0
  50. package/dist/modal/components/Waiting/Waiting.js +17 -0
  51. package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
  52. package/dist/modal/components/WalletCard/WalletCard.js +127 -0
  53. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +52 -0
  54. package/dist/modal/components/common.d.ts +6 -6
  55. package/dist/modal/components/common.js +96 -0
  56. package/dist/modal/components/index.js +2 -0
  57. package/dist/modal/constants/constants.d.ts +1 -1
  58. package/dist/modal/constants/constants.js +111 -0
  59. package/dist/modal/constants/defaults.js +10 -0
  60. package/dist/modal/constants/oAuthLogos.js +24 -0
  61. package/dist/modal/hooks/useActiveWallet.js +15 -0
  62. package/dist/modal/hooks/useCreateAccount.js +72 -0
  63. package/dist/modal/hooks/useEmbeddedExternalConnection.js +54 -0
  64. package/dist/modal/hooks/useGoBack.js +42 -0
  65. package/dist/modal/hooks/useSetLoginURLs.js +49 -0
  66. package/dist/modal/hooks/useWalletBalance.d.ts +4 -0
  67. package/dist/modal/hooks/useWalletBalance.js +47 -0
  68. package/dist/modal/index.js +33 -0
  69. package/dist/modal/providers/CosmosExternalWalletContextStub.js +38 -0
  70. package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +2 -0
  71. package/dist/modal/providers/EvmExternalWalletContextStub.js +55 -0
  72. package/dist/modal/providers/ExternalWalletContext.d.ts +3 -0
  73. package/dist/modal/providers/ExternalWalletContext.js +394 -0
  74. package/dist/modal/providers/SolanaExternalWalletContextStub.js +32 -0
  75. package/dist/modal/stores/externalWalletProvider/actions.js +10 -0
  76. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +21 -0
  77. package/dist/modal/stores/index.js +4 -0
  78. package/dist/modal/stores/modal/actions.js +70 -0
  79. package/dist/modal/stores/modal/useModalStore.js +65 -0
  80. package/dist/modal/stores/theme/actions.js +28 -0
  81. package/dist/modal/stores/theme/useThemeStore.js +21 -0
  82. package/dist/modal/stores/userInfo/actions.js +30 -0
  83. package/dist/modal/stores/userInfo/useUserInfoStore.js +17 -0
  84. package/dist/modal/types/commonTypes.js +1 -0
  85. package/dist/modal/types/externalWallets.js +32 -0
  86. package/dist/modal/types/modalProps.d.ts +4 -0
  87. package/dist/modal/types/modalProps.js +12 -0
  88. package/dist/modal/utils/authLayoutHelpers.js +8 -0
  89. package/dist/modal/utils/getMailtoLink.js +10 -0
  90. package/dist/modal/utils/getTileButtonFlex.js +20 -0
  91. package/dist/modal/utils/openPopup.js +60 -0
  92. package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
  93. package/dist/modal/utils/steps.js +232 -0
  94. package/dist/modal/utils/stringFormatters.d.ts +1 -0
  95. package/dist/modal/utils/stringFormatters.js +19 -0
  96. package/dist/modal/utils/validateOnRampConfig.js +32 -0
  97. package/dist/package.json +3 -1
  98. package/dist/provider/ParaProvider.js +22 -0
  99. package/dist/provider/actions/checkIfUserExists.js +21 -0
  100. package/dist/provider/actions/createUser.js +26 -0
  101. package/dist/provider/actions/getAccount.js +22 -0
  102. package/dist/provider/actions/getWallet.js +14 -0
  103. package/dist/provider/actions/getWalletBalance.d.ts +2 -0
  104. package/dist/provider/actions/getWalletBalance.js +14 -0
  105. package/dist/provider/actions/initiateLogin.js +20 -0
  106. package/dist/provider/actions/keepSessionAlive.js +20 -0
  107. package/dist/provider/actions/logout.js +17 -0
  108. package/dist/provider/actions/signMessage.js +20 -0
  109. package/dist/provider/actions/signTransaction.js +20 -0
  110. package/dist/provider/actions/waitForAccountCreation.js +21 -0
  111. package/dist/provider/actions/waitForLoginAndSetup.js +24 -0
  112. package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +21 -0
  113. package/dist/provider/hooks/index.js +4 -0
  114. package/dist/provider/hooks/mutations/index.js +24 -0
  115. package/dist/provider/hooks/mutations/useCheckIfUserExists.js +23 -0
  116. package/dist/provider/hooks/mutations/useCreateUser.js +20 -0
  117. package/dist/provider/hooks/mutations/useInitiateLogin.js +23 -0
  118. package/dist/provider/hooks/mutations/useKeepSessionAlive.js +20 -0
  119. package/dist/provider/hooks/mutations/useLogout.js +30 -0
  120. package/dist/provider/hooks/mutations/useSignMessage.js +39 -0
  121. package/dist/provider/hooks/mutations/useSignTransaction.js +39 -0
  122. package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +30 -0
  123. package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +30 -0
  124. package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +30 -0
  125. package/dist/provider/hooks/queries/index.d.ts +1 -0
  126. package/dist/provider/hooks/queries/index.js +10 -0
  127. package/dist/provider/hooks/queries/useAccount.js +21 -0
  128. package/dist/provider/hooks/queries/useWallet.js +22 -0
  129. package/dist/provider/hooks/queries/useWalletBalance.d.ts +7 -0
  130. package/dist/provider/hooks/queries/useWalletBalance.js +26 -0
  131. package/dist/provider/hooks/utils/index.js +10 -0
  132. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
  133. package/dist/provider/hooks/utils/useClient.js +10 -0
  134. package/dist/provider/hooks/utils/useEventListeners.js +105 -0
  135. package/dist/provider/hooks/utils/useInternalClient.js +10 -0
  136. package/dist/provider/hooks/utils/useModal.js +17 -0
  137. package/dist/provider/hooks/utils/useWalletState.js +33 -0
  138. package/dist/provider/index.js +8 -0
  139. package/dist/provider/stores/getters.js +13 -0
  140. package/dist/provider/stores/slices/client.js +9 -0
  141. package/dist/provider/stores/slices/index.js +4 -0
  142. package/dist/provider/stores/slices/modal.js +9 -0
  143. package/dist/provider/stores/slices/wallet.js +13 -0
  144. package/dist/provider/stores/types.d.ts +2 -0
  145. package/dist/provider/stores/types.js +1 -0
  146. package/dist/provider/stores/useStore.js +27 -0
  147. package/dist/provider/types/provider.js +1 -0
  148. package/dist/provider/types/query.js +1 -0
  149. package/dist/provider/types/utils.js +1 -0
  150. package/dist/provider/utils/constants.js +11 -0
  151. package/dist/provider/utils/renameMutations.js +16 -0
  152. package/package.json +5 -5
  153. package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
  154. package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
  155. package/dist/chunk-MMUBH76A.js.br +0 -0
  156. package/dist/chunk-MMUBH76A.js.gz +0 -0
  157. package/dist/index.js.br +0 -0
  158. package/dist/index.js.gz +0 -0
@@ -0,0 +1,72 @@
1
+ "use client";
2
+ import {
3
+ __spreadValues
4
+ } from "../../../chunk-MMUBH76A.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { StepContainer } from "../common.js";
7
+ import { OnRampProvider } from "@getpara/web-sdk";
8
+ import { useModalStore, useThemeStore } from "../../stores/index.js";
9
+ import { lazy, useEffect, useMemo, useState } from "react";
10
+ import { ModalStep } from "../../utils/steps.js";
11
+ import { RampEmbed, StripeEmbed } from "@getpara/react-common";
12
+ import styled from "styled-components";
13
+ import { useGoBack } from "../../hooks/useGoBack.js";
14
+ import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
15
+ const STEPS = {
16
+ CANCELLED: ModalStep.ADD_FUNDS_FAILURE,
17
+ FINISHED: ModalStep.ADD_FUNDS_SUCCESS
18
+ };
19
+ const AddFundsAwaiting = () => {
20
+ const setStep = useModalStore((state) => state.setStep);
21
+ const goBack = useGoBack();
22
+ const onRampConfig = useModalStore((state) => state.onRampConfig);
23
+ const onRampPurchase = useModalStore((state) => state.onRampPurchase);
24
+ const setOnRampPurchase = useModalStore((state) => state.setOnRampPurchase);
25
+ const para = useInternalClient();
26
+ const appName = useThemeStore((state) => state.appName);
27
+ const isDark = useThemeStore((state) => state.isDark);
28
+ const [MoonPayEmbed, setMoonPayEmbed] = useState(null);
29
+ const props = {
30
+ para,
31
+ appName,
32
+ onRampConfig,
33
+ onRampPurchase,
34
+ isDark,
35
+ isEmbedded: true,
36
+ setOnRampPurchase,
37
+ onClose: goBack
38
+ };
39
+ useEffect(() => {
40
+ const _MoonPayEmbed = lazy(() => import("./MoonPayEmbed.js"));
41
+ setMoonPayEmbed(_MoonPayEmbed);
42
+ }, []);
43
+ const onRampEmbed = useMemo(() => {
44
+ if (!onRampPurchase.id) {
45
+ return null;
46
+ }
47
+ switch (onRampPurchase == null ? void 0 : onRampPurchase.provider) {
48
+ case OnRampProvider.STRIPE:
49
+ return /* @__PURE__ */ jsx(StripeEmbed, __spreadValues({}, props));
50
+ case OnRampProvider.MOONPAY:
51
+ return !MoonPayEmbed || typeof window === "undefined" ? null : /* @__PURE__ */ jsx(MoonPayEmbed, __spreadValues({}, props));
52
+ case OnRampProvider.RAMP:
53
+ return /* @__PURE__ */ jsx(RampEmbed, __spreadValues({ apiKey: onRampConfig.rampApiKey }, props));
54
+ }
55
+ }, [onRampPurchase == null ? void 0 : onRampPurchase.provider, MoonPayEmbed]);
56
+ useEffect(() => {
57
+ let timeoutId;
58
+ if ((onRampPurchase == null ? void 0 : onRampPurchase.status) && ["CANCELLED", "FINISHED"].includes(onRampPurchase.status)) {
59
+ timeoutId = setTimeout(() => {
60
+ setStep(STEPS[onRampPurchase.status]);
61
+ }, 5e3);
62
+ }
63
+ return () => clearTimeout(timeoutId);
64
+ }, [onRampPurchase == null ? void 0 : onRampPurchase.status]);
65
+ return /* @__PURE__ */ jsx(Container, { $wide: true, children: onRampEmbed });
66
+ };
67
+ const Container = styled(StepContainer)`
68
+ flex: 1;
69
+ `;
70
+ export {
71
+ AddFundsAwaiting
72
+ };
@@ -0,0 +1,43 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { Heading, HeroIcon, InnerStepContainer, StepContainer } from "../common.js";
5
+ import { useModalStore, useThemeStore } from "../../stores/index.js";
6
+ import { useMemo } from "react";
7
+ import { CpslButton, CpslText } from "@getpara/react-components";
8
+ import { getAddFundsStep } from "../../utils/steps.js";
9
+ const AddFundsDone = ({ isSuccess, onClose }) => {
10
+ const hideWallets = useThemeStore((state) => state.hideWallets);
11
+ const setStep = useModalStore((state) => state.setStep);
12
+ const onRampPurchase = useModalStore((state) => state.onRampPurchase);
13
+ const accountAddFundTab = useModalStore((state) => state.accountAddFundTab);
14
+ const formatter = useMemo(() => {
15
+ return new Intl.NumberFormat("en-US", {
16
+ style: "currency",
17
+ currency: (onRampPurchase == null ? void 0 : onRampPurchase.fiat) || "USD"
18
+ });
19
+ }, [onRampPurchase == null ? void 0 : onRampPurchase.fiat]);
20
+ const heading = isSuccess ? "Transaction Successful" : "Something Went Wrong";
21
+ const text = isSuccess ? `${formatter.format(parseFloat(onRampPurchase == null ? void 0 : onRampPurchase.fiatQuantity))} is now available in your ${hideWallets ? "account" : "wallet"}.` : `No funds were added to your ${hideWallets ? "account" : "wallet"}.`;
22
+ const buttonText = isSuccess ? "Done" : "Try Again";
23
+ return /* @__PURE__ */ jsxs(StepContainer, { children: [
24
+ /* @__PURE__ */ jsx(HeroIcon, { icon: "checkCircleFilled" }),
25
+ /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
26
+ /* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: heading }),
27
+ /* @__PURE__ */ jsx(CpslText, { variant: "bodyS", color: "secondary", children: text })
28
+ ] }),
29
+ /* @__PURE__ */ jsx(
30
+ CpslButton,
31
+ {
32
+ fullWidth: true,
33
+ onClick: () => {
34
+ isSuccess ? onClose() : setStep(getAddFundsStep(accountAddFundTab));
35
+ },
36
+ children: buttonText
37
+ }
38
+ )
39
+ ] });
40
+ };
41
+ export {
42
+ AddFundsDone
43
+ };
@@ -1,7 +1,5 @@
1
1
  "use client";
2
- import "./chunk-MMUBH76A.js";
3
-
4
- // src/modal/components/AddFunds/MoonPayEmbed.tsx
2
+ import "../../../chunk-MMUBH76A.js";
5
3
  import { MoonPayEmbed } from "@getpara/react-common";
6
4
  var MoonPayEmbed_default = MoonPayEmbed;
7
5
  export {
@@ -0,0 +1,4 @@
1
+ "use client";
2
+ export * from "./AddFunds.js";
3
+ export * from "./AddFundsAwaiting.js";
4
+ export * from "./AddFundsDone.js";
@@ -0,0 +1,283 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../../../chunk-MMUBH76A.js";
5
+ import { jsx, jsxs } from "react/jsx-runtime";
6
+ import {
7
+ CpslButton,
8
+ CpslIcon,
9
+ CpslInput,
10
+ CpslSelect,
11
+ CpslSelectItem,
12
+ CpslSpinner,
13
+ CpslText
14
+ } from "@getpara/react-components";
15
+ import { useRef, useState } from "react";
16
+ import styled from "styled-components";
17
+ import countryCodes from "./countryCodes.js";
18
+ import { useModalStore, useUserInfoStore } from "../../stores/index.js";
19
+ import { EMAIL_REGEX, MOBILE_SIZE } from "../../constants/constants.js";
20
+ import { useDropdownPosition } from "./hooks/useDropdownPosition.js";
21
+ import { ModalStep } from "../../utils/steps.js";
22
+ import { defaultPhoneMask, phoneMasks } from "./phoneMasks.js";
23
+ import { AuthMethod } from "@getpara/web-sdk";
24
+ import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
25
+ import { useSetLoginURLs } from "../../hooks/useSetLoginURLs.js";
26
+ const DEFAULT_COUNTRY = { label: "United States", value: "+1", selectedLabel: "US", icon: "US" };
27
+ function isCcMatch(countryCode, option) {
28
+ return countryCode === "+1" ? option.selectedLabel === "US" : option.value === countryCode;
29
+ }
30
+ const AuthInput = ({ disableEmailLogin, disablePhoneLogin }) => {
31
+ var _a, _b;
32
+ const inputRef = useRef(null);
33
+ const { dropdownMaxHeight, dropdownWidth } = useDropdownPosition(inputRef);
34
+ const para = useInternalClient();
35
+ const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
36
+ const authInfo = useUserInfoStore((state) => state.getAuthInfo());
37
+ const setFlow = useModalStore((state) => state.setFlow);
38
+ const setStep = useModalStore((state) => state.setStep);
39
+ const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
40
+ const setLoginURLs = useSetLoginURLs();
41
+ const [countryCode, setCountryCode] = useState(
42
+ (authInfo == null ? void 0 : authInfo.authType) === "phone" ? authInfo.auth.countryCode || "+1" : "+1"
43
+ );
44
+ const [identifier, setIdentifier] = useState(
45
+ (() => {
46
+ if (!authInfo || ["telegram", "farcaster"].includes(authInfo.authType)) {
47
+ return "";
48
+ }
49
+ if (authInfo.authType !== "phone") {
50
+ return authInfo.identifier;
51
+ }
52
+ return authInfo.auth.phone;
53
+ })()
54
+ );
55
+ const [identifierType, setIdentifierType] = useState(
56
+ authInfo && (authInfo.authType === "email" || authInfo.authType === "phone") ? authInfo.authType : void 0
57
+ );
58
+ const [matchedCountryCode, setMatchedCountryCode] = useState(
59
+ (_a = countryCodes.find((option) => isCcMatch(countryCode, option))) != null ? _a : DEFAULT_COUNTRY
60
+ );
61
+ const [isLoggingIn, setIsLoggingIn] = useState(false);
62
+ const [error, setError] = useState("");
63
+ const [search, setSearch] = useState("");
64
+ const isEmail = identifierType === "email";
65
+ const isPhone = identifierType === "phone";
66
+ const isUnknown = !identifierType;
67
+ const filteredCountryCodes = search ? countryCodes.filter(
68
+ (cc) => cc.selectedLabel.toLowerCase().includes(search.toLowerCase()) || cc.label.toLowerCase().includes(search.toLowerCase()) || cc.value.toLowerCase().includes(search.toLowerCase())
69
+ ) : countryCodes;
70
+ const handleSearchInput = (ev) => {
71
+ setSearch(ev.detail);
72
+ };
73
+ const handleIdentifierInput = (ev) => {
74
+ const newIdentifier = ev.detail.value;
75
+ let isNewPhone = false, isNewEmail = false;
76
+ if (!disablePhoneLogin) {
77
+ const countryCodeInputMatch = countryCodes.find((option) => isCcMatch(newIdentifier, option));
78
+ if (countryCodeInputMatch) {
79
+ setCountryCode(countryCodeInputMatch.value);
80
+ setMatchedCountryCode(countryCodeInputMatch);
81
+ setIdentifierType("phone");
82
+ setIdentifier("");
83
+ return;
84
+ }
85
+ isNewPhone = !isEmail && isPhone ? /\d+$/.test(newIdentifier) : /\d\d\d+$/.test(newIdentifier);
86
+ }
87
+ if (!disableEmailLogin) {
88
+ isNewEmail = /\D.*$/.test(newIdentifier);
89
+ }
90
+ setIdentifierType(isNewEmail ? "email" : isNewPhone ? "phone" : void 0);
91
+ setIdentifier(newIdentifier);
92
+ };
93
+ const handleCountryCodeInput = (ev) => {
94
+ const matchedCountryCode2 = countryCodes.find((code) => code.selectedLabel === ev.detail);
95
+ setCountryCode(matchedCountryCode2.value);
96
+ setMatchedCountryCode(matchedCountryCode2);
97
+ };
98
+ const login = () => __async(void 0, null, function* () {
99
+ setError("");
100
+ if (isUnknown) {
101
+ setError("Please enter a valid email or phone number!");
102
+ return;
103
+ }
104
+ let auth;
105
+ if (isEmail) {
106
+ if (!EMAIL_REGEX.test(identifier)) {
107
+ setError("Please enter a valid email!");
108
+ return;
109
+ }
110
+ yield para.logout();
111
+ auth = { email: identifier };
112
+ setAuthInfo(auth);
113
+ const userExists = yield para.checkIfUserExists({ email: identifier });
114
+ if (userExists) {
115
+ const supportedAuthMethods = yield para.initiateUserLoginV2(auth);
116
+ const biometricLocationHints = supportedAuthMethods.has(AuthMethod.PASSKEY) ? yield para.getUserBiometricLocationHints() : [];
117
+ yield setLoginURLs({ supportedAuthMethods, authType: "email" });
118
+ setFlow("login");
119
+ setStep(ModalStep.BIOMETRIC_LOGIN);
120
+ setBiometricLocationHints(biometricLocationHints);
121
+ return;
122
+ }
123
+ yield para.createUser(auth);
124
+ setFlow("signUp");
125
+ setStep(ModalStep.VERIFICATIONS);
126
+ return;
127
+ }
128
+ if (isPhone) {
129
+ yield para.logout();
130
+ let userExists = false;
131
+ try {
132
+ userExists = yield para.checkIfUserExistsByPhone({ phone: identifier, countryCode });
133
+ } catch (error2) {
134
+ setError("Please enter a valid phone number!");
135
+ return;
136
+ }
137
+ auth = { phone: identifier, countryCode };
138
+ setAuthInfo(auth);
139
+ if (userExists) {
140
+ const supportedAuthMethods = yield para.initiateUserLoginV2(auth);
141
+ const biometricLocationHints = supportedAuthMethods.has(AuthMethod.PASSKEY) ? yield para.getUserBiometricLocationHints() : [];
142
+ yield setLoginURLs({ supportedAuthMethods, authType: "phone" });
143
+ setFlow("login");
144
+ setStep(ModalStep.BIOMETRIC_LOGIN);
145
+ setBiometricLocationHints(biometricLocationHints);
146
+ return;
147
+ }
148
+ yield para.createUserByPhone(auth);
149
+ setFlow("signUp");
150
+ setStep(ModalStep.VERIFICATIONS);
151
+ return;
152
+ }
153
+ });
154
+ const handleSubmit = () => __async(void 0, null, function* () {
155
+ setIsLoggingIn(true);
156
+ yield login();
157
+ setIsLoggingIn(false);
158
+ });
159
+ if (disableEmailLogin && disablePhoneLogin) {
160
+ return null;
161
+ }
162
+ return /* @__PURE__ */ jsx(
163
+ "form",
164
+ {
165
+ onSubmit: (e) => __async(void 0, null, function* () {
166
+ e.preventDefault();
167
+ yield handleSubmit();
168
+ }),
169
+ children: /* @__PURE__ */ jsxs(
170
+ StyledInput,
171
+ {
172
+ ref: inputRef,
173
+ id: "authInput",
174
+ placeholder: isEmail || disablePhoneLogin ? "Enter email" : isPhone || disableEmailLogin ? "Enter phone" : "Enter email or phone",
175
+ onCpslInput: handleIdentifierInput,
176
+ value: identifier,
177
+ errorText: error,
178
+ autofocus: true,
179
+ inputMode: "email",
180
+ onKeyDown: (e) => __async(void 0, null, function* () {
181
+ return e.key === "Enter" && handleSubmit();
182
+ }),
183
+ contrastText: true,
184
+ isPhone,
185
+ mask: identifierType === "phone" ? (_b = phoneMasks[matchedCountryCode.selectedLabel]) != null ? _b : defaultPhoneMask : void 0,
186
+ enterkeyhint: "go",
187
+ noAutoDisable: true,
188
+ disabled: isLoggingIn,
189
+ "data-testid": "auth-input",
190
+ children: [
191
+ /* @__PURE__ */ jsxs(IconContainer, { slot: "start", children: [
192
+ !disableEmailLogin && (isUnknown || isEmail) && /* @__PURE__ */ jsx(CpslIcon, { "aria-label": "email", icon: "mail" }),
193
+ !disablePhoneLogin && isUnknown && /* @__PURE__ */ jsx(CpslIcon, { "aria-label": "phone", icon: "phone" }),
194
+ isPhone && /* @__PURE__ */ jsxs(
195
+ CountryCodeSelect,
196
+ {
197
+ selectedValue: matchedCountryCode.selectedLabel,
198
+ onCpslSelectValueChange: handleCountryCodeInput,
199
+ showFormattedSelectedItem: true,
200
+ autoWidth: true,
201
+ dropdownMaxHeight,
202
+ anchorElId: "authInput",
203
+ $width: dropdownWidth,
204
+ showSearch: true,
205
+ searchPlaceholder: "Search Countries",
206
+ onCpslSearchChange: handleSearchInput,
207
+ "data-testid": "country-code-select",
208
+ children: [
209
+ matchedCountryCode && /* @__PURE__ */ jsxs(SelectedItem, { slot: "selected-item", children: [
210
+ /* @__PURE__ */ jsx(CpslText, { children: matchedCountryCode.selectedLabel }),
211
+ /* @__PURE__ */ jsx(CpslText, { children: matchedCountryCode.value })
212
+ ] }),
213
+ filteredCountryCodes.map((cc) => /* @__PURE__ */ jsxs(StyledSelectItem, { slot: "items", value: cc.selectedLabel, children: [
214
+ /* @__PURE__ */ jsx(CpslText, { children: cc.label }),
215
+ /* @__PURE__ */ jsx(CpslText, { children: cc.value })
216
+ ] }, cc.selectedLabel))
217
+ ]
218
+ }
219
+ )
220
+ ] }),
221
+ identifier && /* @__PURE__ */ jsx(CpslButton, { slot: "end", size: "small", fullWidth: true, disabled: isLoggingIn, onClick: handleSubmit, children: isLoggingIn ? /* @__PURE__ */ jsx(CpslSpinner, { size: 16 }) : /* @__PURE__ */ jsx(CpslIcon, { icon: "arrowNarrow" }) })
222
+ ]
223
+ },
224
+ "email"
225
+ )
226
+ }
227
+ );
228
+ };
229
+ const IconContainer = styled.div`
230
+ height: 100%;
231
+ display: flex;
232
+ align-items: center;
233
+ gap: 8px;
234
+ padding-right: 12px;
235
+ border-right: 1px solid var(--cpsl-color-background-16);
236
+
237
+ & cpsl-icon {
238
+ --icon-color: var(--cpsl-color-contrast);
239
+ }
240
+ `;
241
+ const CountryCodeSelect = styled(CpslSelect)`
242
+ --container-height: 100%;
243
+ --container-padding-start: 0px;
244
+ --container-padding-end: 0px;
245
+ --container-border-width: 0px;
246
+ --container-gap: 4px;
247
+ --container-background-color: transparent;
248
+ --container-box-shadow: none;
249
+
250
+ &::part(dropdown) {
251
+ width: ${({ $width }) => `${$width - 2}px`};
252
+ }
253
+
254
+ &::part(popover) {
255
+ @media (max-width: ${MOBILE_SIZE}px) {
256
+ top: unset !important;
257
+ bottom: 16px;
258
+ }
259
+
260
+ cpsl-auth-modal.force-mobile-media & {
261
+ top: unset !important;
262
+ bottom: 16px;
263
+ }
264
+ }
265
+ `;
266
+ const StyledSelectItem = styled(CpslSelectItem)`
267
+ &::part(inner-container) {
268
+ justify-content: space-between;
269
+ }
270
+ `;
271
+ const SelectedItem = styled.div`
272
+ display: flex;
273
+ gap: 4px;
274
+ align-items: center;
275
+ `;
276
+ const StyledInput = styled(CpslInput)`
277
+ --container-background-color: var(--cpsl-color-background-8);
278
+ --input-background-color: var(--cpsl-color-background-8);
279
+ --container-padding-end: 8px;
280
+ `;
281
+ export {
282
+ AuthInput
283
+ };
@@ -0,0 +1,42 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import { getCountries, getCountryCallingCode } from "libphonenumber-js";
4
+ const excludedCountries = [
5
+ "AC",
6
+ "CG",
7
+ "CI",
8
+ "CV",
9
+ "GF",
10
+ "GP",
11
+ "MF",
12
+ "NC",
13
+ "PM",
14
+ "RE",
15
+ "SD",
16
+ "SH",
17
+ "SJ",
18
+ "TA",
19
+ "VA",
20
+ "WF",
21
+ "XK",
22
+ "YT"
23
+ ];
24
+ const generateCountryCodes = () => {
25
+ const countries = getCountries();
26
+ const countryList = countries.filter((country) => !excludedCountries.includes(country)).map((country) => {
27
+ const countryCode = getCountryCallingCode(country);
28
+ const countryName = new Intl.DisplayNames(["en"], { type: "region" }).of(country);
29
+ return {
30
+ label: countryName,
31
+ value: `+${countryCode}`,
32
+ selectedLabel: country,
33
+ icon: country
34
+ };
35
+ }).sort((a, b) => a.label.localeCompare(b.label));
36
+ return countryList;
37
+ };
38
+ const countryCodes = generateCountryCodes();
39
+ var countryCodes_default = countryCodes;
40
+ export {
41
+ countryCodes_default as default
42
+ };
@@ -0,0 +1,33 @@
1
+ "use client";
2
+ import "../../../../chunk-MMUBH76A.js";
3
+ import { useEffect, useState } from "react";
4
+ const useDropdownPosition = (inputRef) => {
5
+ const [dropdownMaxHeight, setDropdownMaxHeight] = useState();
6
+ const [dropdownWidth, setDropdownWidth] = useState();
7
+ const [mobileAnchor, setMobileAnchor] = useState();
8
+ const resize = () => {
9
+ var _a, _b, _c;
10
+ if (typeof window !== "undefined") {
11
+ const newMaxHeight = Math.max(
12
+ window.innerHeight - ((_a = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _a.getBoundingClientRect().bottom) - 20,
13
+ window.innerHeight * 0.25
14
+ );
15
+ setDropdownMaxHeight(newMaxHeight);
16
+ setDropdownWidth((_b = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _b.getBoundingClientRect().width);
17
+ setMobileAnchor((_c = inputRef == null ? void 0 : inputRef.current) == null ? void 0 : _c.getBoundingClientRect().height);
18
+ }
19
+ };
20
+ if (inputRef.current && !dropdownMaxHeight) {
21
+ resize();
22
+ }
23
+ useEffect(() => {
24
+ typeof window !== "undefined" && window.addEventListener("resize", resize);
25
+ return () => {
26
+ typeof window !== "undefined" && window.removeEventListener("resize", resize);
27
+ };
28
+ }, []);
29
+ return { dropdownMaxHeight, dropdownWidth, mobileAnchor, resize };
30
+ };
31
+ export {
32
+ useDropdownPosition
33
+ };