@getpara/react-sdk 1.6.0 → 1.6.1-dev.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.
- package/dist/index.js +6 -6367
- package/dist/modal/ParaModal.js +337 -0
- package/dist/modal/components/Account/Account.js +69 -0
- package/dist/modal/components/AddFunds/AddFunds.js +220 -0
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +72 -0
- package/dist/modal/components/AddFunds/AddFundsDone.js +43 -0
- package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
- package/dist/modal/components/AddFunds/index.js +4 -0
- package/dist/modal/components/AuthInput/AuthInput.js +283 -0
- package/dist/modal/components/AuthInput/countryCodes.js +42 -0
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
- package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
- package/dist/modal/components/AuthMainStep/AuthMainStep.js +37 -0
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +113 -0
- package/dist/modal/components/AuthOptions/AuthOptions.js +33 -0
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +44 -0
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +52 -0
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +93 -0
- package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
- package/dist/modal/components/Body/Body.js +304 -0
- package/dist/modal/components/ChainSwitch/ChainSwitch.js +94 -0
- package/dist/modal/components/ChainSwitch/config.js +17 -0
- package/dist/modal/components/Controls/Controls.js +74 -0
- package/dist/modal/components/Controls/Selects.js +213 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +151 -0
- package/dist/modal/components/ExternalWalletStep/config.js +17 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +172 -0
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +123 -0
- package/dist/modal/components/Footer/Footer.js +93 -0
- package/dist/modal/components/Header/Header.js +43 -0
- package/dist/modal/components/Header/hooks/useStepTitle.js +50 -0
- package/dist/modal/components/Hero/Hero.js +122 -0
- package/dist/modal/components/IFrameStep/IFrameStep.js +55 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +28 -0
- package/dist/modal/components/ModalContent/ModalContent.js +310 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
- package/dist/modal/components/OAuth/OAuth.js +153 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +139 -0
- package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +101 -0
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +141 -0
- package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +24 -0
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +159 -0
- package/dist/modal/components/Waiting/Waiting.js +17 -0
- package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
- package/dist/modal/components/WalletCard/WalletCard.js +127 -0
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +52 -0
- package/dist/modal/components/common.js +83 -0
- package/dist/modal/components/index.js +2 -0
- package/dist/modal/constants/constants.js +111 -0
- package/dist/modal/constants/defaults.js +10 -0
- package/dist/modal/constants/oAuthLogos.js +24 -0
- package/dist/modal/hooks/useActiveWallet.js +15 -0
- package/dist/modal/hooks/useCreateAccount.js +72 -0
- package/dist/modal/hooks/useEmbeddedExternalConnection.js +39 -0
- package/dist/modal/hooks/useGoBack.js +35 -0
- package/dist/modal/hooks/useSetLoginURLs.d.ts +8 -0
- package/dist/modal/hooks/useSetLoginURLs.js +45 -0
- package/dist/modal/index.js +32 -0
- package/dist/modal/providers/CosmosExternalWalletContextStub.js +34 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.js +38 -0
- package/dist/modal/providers/ExternalWalletContext.js +275 -0
- package/dist/modal/providers/SolanaExternalWalletContextStub.js +19 -0
- package/dist/modal/stores/externalWalletProvider/actions.js +10 -0
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +20 -0
- package/dist/modal/stores/index.js +4 -0
- package/dist/modal/stores/modal/actions.js +70 -0
- package/dist/modal/stores/modal/useModalStore.js +65 -0
- package/dist/modal/stores/theme/actions.js +28 -0
- package/dist/modal/stores/theme/useThemeStore.js +21 -0
- package/dist/modal/stores/userInfo/actions.js +30 -0
- package/dist/modal/stores/userInfo/useUserInfoStore.js +17 -0
- package/dist/modal/types/commonTypes.js +1 -0
- package/dist/modal/types/externalWallets.js +31 -0
- package/dist/modal/types/modalProps.js +12 -0
- package/dist/modal/utils/authLayoutHelpers.js +8 -0
- package/dist/modal/utils/getMailtoLink.js +10 -0
- package/dist/modal/utils/getTileButtonFlex.js +20 -0
- package/dist/modal/utils/openPopup.js +60 -0
- package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
- package/dist/modal/utils/steps.js +228 -0
- package/dist/modal/utils/stringFormatters.js +14 -0
- package/dist/modal/utils/validateOnRampConfig.js +32 -0
- package/dist/provider/ParaProvider.js +22 -0
- package/dist/provider/actions/checkIfUserExists.js +21 -0
- package/dist/provider/actions/createUser.js +26 -0
- package/dist/provider/actions/getAccount.js +22 -0
- package/dist/provider/actions/getWallet.js +14 -0
- package/dist/provider/actions/initiateLogin.js +20 -0
- package/dist/provider/actions/keepSessionAlive.js +20 -0
- package/dist/provider/actions/logout.js +17 -0
- package/dist/provider/actions/signMessage.js +20 -0
- package/dist/provider/actions/signTransaction.js +20 -0
- package/dist/provider/actions/waitForAccountCreation.js +21 -0
- package/dist/provider/actions/waitForLoginAndSetup.js +24 -0
- package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +21 -0
- package/dist/provider/hooks/index.js +4 -0
- package/dist/provider/hooks/mutations/index.js +24 -0
- package/dist/provider/hooks/mutations/useCheckIfUserExists.js +23 -0
- package/dist/provider/hooks/mutations/useCreateUser.js +20 -0
- package/dist/provider/hooks/mutations/useInitiateLogin.js +23 -0
- package/dist/provider/hooks/mutations/useKeepSessionAlive.js +20 -0
- package/dist/provider/hooks/mutations/useLogout.js +30 -0
- package/dist/provider/hooks/mutations/useSignMessage.js +33 -0
- package/dist/provider/hooks/mutations/useSignTransaction.js +33 -0
- package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +30 -0
- package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +30 -0
- package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +30 -0
- package/dist/provider/hooks/queries/index.js +8 -0
- package/dist/provider/hooks/queries/useAccount.js +21 -0
- package/dist/provider/hooks/queries/useWallet.js +22 -0
- package/dist/provider/hooks/utils/index.js +10 -0
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
- package/dist/provider/hooks/utils/useClient.js +10 -0
- package/dist/provider/hooks/utils/useEventListeners.js +105 -0
- package/dist/provider/hooks/utils/useInternalClient.js +10 -0
- package/dist/provider/hooks/utils/useModal.js +17 -0
- package/dist/provider/hooks/utils/useWalletState.js +33 -0
- package/dist/provider/index.js +8 -0
- package/dist/provider/stores/getters.js +13 -0
- package/dist/provider/stores/slices/client.js +9 -0
- package/dist/provider/stores/slices/index.js +4 -0
- package/dist/provider/stores/slices/modal.js +9 -0
- package/dist/provider/stores/slices/wallet.js +11 -0
- package/dist/provider/stores/types.js +1 -0
- package/dist/provider/stores/useStore.js +27 -0
- package/dist/provider/types/provider.js +1 -0
- package/dist/provider/types/query.js +1 -0
- package/dist/provider/types/utils.js +1 -0
- package/dist/provider/utils/renameMutations.js +16 -0
- package/package.json +2 -2
- package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
- package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
- package/dist/chunk-MMUBH76A.js.br +0 -0
- package/dist/chunk-MMUBH76A.js.gz +0 -0
- package/dist/index.js.br +0 -0
- 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
|
+
};
|
|
@@ -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
|
+
};
|