@getpara/react-sdk 1.6.1-dev.0 → 1.7.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/{modal/components/AddFunds/MoonPayEmbed.js → MoonPayEmbed-Q2HP2BFI.js} +3 -1
- 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 +6657 -6
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.d.ts +1 -0
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.d.ts +2 -1
- package/dist/modal/components/common.d.ts +4 -0
- package/dist/modal/index.d.ts +1 -0
- package/dist/modal/providers/CosmosExternalWalletContextStub.d.ts +13 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +11 -0
- package/dist/modal/providers/ExternalWalletContext.d.ts +15 -1
- package/dist/modal/providers/SolanaExternalWalletContextStub.d.ts +11 -0
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.d.ts +2 -0
- package/dist/modal/types/commonTypes.d.ts +12 -2
- package/dist/modal/types/externalWallets.d.ts +2 -0
- package/dist/modal/types/modalProps.d.ts +6 -0
- package/dist/modal/utils/steps.d.ts +2 -0
- package/dist/provider/utils/constants.d.ts +5 -0
- package/package.json +5 -5
- package/dist/modal/ParaModal.js +0 -337
- package/dist/modal/components/Account/Account.js +0 -69
- package/dist/modal/components/AddFunds/AddFunds.js +0 -220
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +0 -72
- package/dist/modal/components/AddFunds/AddFundsDone.js +0 -43
- package/dist/modal/components/AddFunds/index.js +0 -4
- package/dist/modal/components/AuthInput/AuthInput.js +0 -283
- package/dist/modal/components/AuthInput/countryCodes.js +0 -42
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +0 -33
- package/dist/modal/components/AuthInput/phoneMasks.js +0 -253
- package/dist/modal/components/AuthMainStep/AuthMainStep.js +0 -37
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +0 -113
- package/dist/modal/components/AuthOptions/AuthOptions.js +0 -33
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +0 -18
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +0 -10
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +0 -18
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +0 -44
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +0 -52
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +0 -93
- package/dist/modal/components/Body/AnimatedHeightWrapper.js +0 -29
- package/dist/modal/components/Body/Body.js +0 -304
- package/dist/modal/components/ChainSwitch/ChainSwitch.js +0 -94
- package/dist/modal/components/ChainSwitch/config.js +0 -17
- package/dist/modal/components/Controls/Controls.js +0 -74
- package/dist/modal/components/Controls/Selects.js +0 -213
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +0 -151
- package/dist/modal/components/ExternalWalletStep/config.js +0 -17
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +0 -172
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +0 -123
- package/dist/modal/components/Footer/Footer.js +0 -93
- package/dist/modal/components/Header/Header.js +0 -43
- package/dist/modal/components/Header/hooks/useStepTitle.js +0 -50
- package/dist/modal/components/Hero/Hero.js +0 -122
- package/dist/modal/components/IFrameStep/IFrameStep.js +0 -55
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +0 -28
- package/dist/modal/components/ModalContent/ModalContent.js +0 -310
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +0 -81
- package/dist/modal/components/OAuth/OAuth.js +0 -153
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +0 -139
- package/dist/modal/components/OnRampComponents/AddingFunds.js +0 -23
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +0 -77
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +0 -101
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +0 -141
- package/dist/modal/components/StripeComponents/StripeComponents.js +0 -88
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +0 -24
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +0 -159
- package/dist/modal/components/Waiting/Waiting.js +0 -17
- package/dist/modal/components/WalletCard/PartnerIcon.js +0 -34
- package/dist/modal/components/WalletCard/WalletCard.js +0 -127
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +0 -52
- package/dist/modal/components/common.js +0 -83
- package/dist/modal/components/index.js +0 -2
- package/dist/modal/constants/constants.js +0 -111
- package/dist/modal/constants/defaults.js +0 -10
- package/dist/modal/constants/oAuthLogos.js +0 -24
- package/dist/modal/hooks/useActiveWallet.js +0 -15
- package/dist/modal/hooks/useCreateAccount.js +0 -72
- package/dist/modal/hooks/useEmbeddedExternalConnection.js +0 -39
- package/dist/modal/hooks/useGoBack.js +0 -35
- package/dist/modal/hooks/useSetLoginURLs.js +0 -45
- package/dist/modal/index.js +0 -32
- package/dist/modal/providers/CosmosExternalWalletContextStub.js +0 -34
- package/dist/modal/providers/EvmExternalWalletContextStub.js +0 -38
- package/dist/modal/providers/ExternalWalletContext.js +0 -275
- package/dist/modal/providers/SolanaExternalWalletContextStub.js +0 -19
- package/dist/modal/stores/externalWalletProvider/actions.js +0 -10
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +0 -20
- package/dist/modal/stores/index.js +0 -4
- package/dist/modal/stores/modal/actions.js +0 -70
- package/dist/modal/stores/modal/useModalStore.js +0 -65
- package/dist/modal/stores/theme/actions.js +0 -28
- package/dist/modal/stores/theme/useThemeStore.js +0 -21
- package/dist/modal/stores/userInfo/actions.js +0 -30
- package/dist/modal/stores/userInfo/useUserInfoStore.js +0 -17
- package/dist/modal/types/commonTypes.js +0 -1
- package/dist/modal/types/externalWallets.js +0 -31
- package/dist/modal/types/modalProps.js +0 -12
- package/dist/modal/utils/authLayoutHelpers.js +0 -8
- package/dist/modal/utils/getMailtoLink.js +0 -10
- package/dist/modal/utils/getTileButtonFlex.js +0 -20
- package/dist/modal/utils/openPopup.js +0 -60
- package/dist/modal/utils/routeMobileExternalWallet.js +0 -31
- package/dist/modal/utils/steps.js +0 -228
- package/dist/modal/utils/stringFormatters.js +0 -14
- package/dist/modal/utils/validateOnRampConfig.js +0 -32
- package/dist/provider/ParaProvider.js +0 -22
- package/dist/provider/actions/checkIfUserExists.js +0 -21
- package/dist/provider/actions/createUser.js +0 -26
- package/dist/provider/actions/getAccount.js +0 -22
- package/dist/provider/actions/getWallet.js +0 -14
- package/dist/provider/actions/initiateLogin.js +0 -20
- package/dist/provider/actions/keepSessionAlive.js +0 -20
- package/dist/provider/actions/logout.js +0 -17
- package/dist/provider/actions/signMessage.js +0 -20
- package/dist/provider/actions/signTransaction.js +0 -20
- package/dist/provider/actions/waitForAccountCreation.js +0 -21
- package/dist/provider/actions/waitForLoginAndSetup.js +0 -24
- package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +0 -21
- package/dist/provider/hooks/index.js +0 -4
- package/dist/provider/hooks/mutations/index.js +0 -24
- package/dist/provider/hooks/mutations/useCheckIfUserExists.js +0 -23
- package/dist/provider/hooks/mutations/useCreateUser.js +0 -20
- package/dist/provider/hooks/mutations/useInitiateLogin.js +0 -23
- package/dist/provider/hooks/mutations/useKeepSessionAlive.js +0 -20
- package/dist/provider/hooks/mutations/useLogout.js +0 -30
- package/dist/provider/hooks/mutations/useSignMessage.js +0 -33
- package/dist/provider/hooks/mutations/useSignTransaction.js +0 -33
- package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +0 -30
- package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +0 -30
- package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +0 -30
- package/dist/provider/hooks/queries/index.js +0 -8
- package/dist/provider/hooks/queries/useAccount.js +0 -21
- package/dist/provider/hooks/queries/useWallet.js +0 -22
- package/dist/provider/hooks/utils/index.js +0 -10
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +0 -74
- package/dist/provider/hooks/utils/useClient.js +0 -10
- package/dist/provider/hooks/utils/useEventListeners.js +0 -105
- package/dist/provider/hooks/utils/useInternalClient.js +0 -10
- package/dist/provider/hooks/utils/useModal.js +0 -17
- package/dist/provider/hooks/utils/useWalletState.js +0 -33
- package/dist/provider/index.js +0 -8
- package/dist/provider/stores/getters.js +0 -13
- package/dist/provider/stores/slices/client.js +0 -9
- package/dist/provider/stores/slices/index.js +0 -4
- package/dist/provider/stores/slices/modal.js +0 -9
- package/dist/provider/stores/slices/wallet.js +0 -11
- package/dist/provider/stores/types.js +0 -1
- package/dist/provider/stores/useStore.js +0 -27
- package/dist/provider/types/provider.js +0 -1
- package/dist/provider/types/query.js +0 -1
- package/dist/provider/types/utils.js +0 -1
- package/dist/provider/utils/renameMutations.js +0 -16
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
__async,
|
|
4
|
-
__spreadProps,
|
|
5
|
-
__spreadValues
|
|
6
|
-
} from "../../../chunk-MMUBH76A.js";
|
|
7
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useState } from "react";
|
|
9
|
-
import {
|
|
10
|
-
entityToWallet,
|
|
11
|
-
OnRampProvider,
|
|
12
|
-
OnRampAsset,
|
|
13
|
-
Network,
|
|
14
|
-
EnabledFlow
|
|
15
|
-
} from "@getpara/web-sdk";
|
|
16
|
-
import { useModalStore, useUserInfoStore } from "../../stores/index.js";
|
|
17
|
-
import { ModalStep } from "../../utils/steps.js";
|
|
18
|
-
import { Body } from "../Body/Body.js";
|
|
19
|
-
import { Footer } from "../Footer/Footer.js";
|
|
20
|
-
import { DEFAULTS } from "../../constants/defaults.js";
|
|
21
|
-
import { useGoBack } from "../../hooks/useGoBack.js";
|
|
22
|
-
import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
|
|
23
|
-
import { useEmbeddedExternalConnection } from "../../hooks/useEmbeddedExternalConnection.js";
|
|
24
|
-
import { useCreateAccount } from "../../hooks/useCreateAccount.js";
|
|
25
|
-
import { formatBiometricHints } from "@getpara/react-common";
|
|
26
|
-
function isRampConfig(config) {
|
|
27
|
-
return "hostApiKey" in config;
|
|
28
|
-
}
|
|
29
|
-
const AssetNetworks = {
|
|
30
|
-
[OnRampAsset.SOLANA]: Network.SOLANA,
|
|
31
|
-
[OnRampAsset.ATOM]: Network.COSMOS,
|
|
32
|
-
[OnRampAsset.CELO]: Network.CELO,
|
|
33
|
-
[OnRampAsset.POLYGON]: Network.POLYGON
|
|
34
|
-
};
|
|
35
|
-
const AssetMap = {
|
|
36
|
-
SOLANA: OnRampAsset.SOLANA,
|
|
37
|
-
SOL: OnRampAsset.SOLANA,
|
|
38
|
-
ATOM: OnRampAsset.ATOM,
|
|
39
|
-
CELO: OnRampAsset.CELO,
|
|
40
|
-
POLYGON: OnRampAsset.POLYGON,
|
|
41
|
-
MATIC: OnRampAsset.POLYGON,
|
|
42
|
-
USDC: OnRampAsset.USDC,
|
|
43
|
-
ETH: OnRampAsset.ETHEREUM,
|
|
44
|
-
ETHEREUM: OnRampAsset.ETHEREUM
|
|
45
|
-
};
|
|
46
|
-
const ModalContent = forwardRef(
|
|
47
|
-
({
|
|
48
|
-
onRampConfig: propsOnRampConfig,
|
|
49
|
-
twoFactorAuthEnabled = false,
|
|
50
|
-
recoverySecretStepEnabled = false,
|
|
51
|
-
oAuthMethods,
|
|
52
|
-
disableEmailLogin,
|
|
53
|
-
disablePhoneLogin,
|
|
54
|
-
onClose,
|
|
55
|
-
onRampTestMode,
|
|
56
|
-
loginTransitionOverride,
|
|
57
|
-
createWalletOverride
|
|
58
|
-
}, ref) => {
|
|
59
|
-
var _a;
|
|
60
|
-
const para = useInternalClient();
|
|
61
|
-
const refs = useModalStore((state) => state.refs);
|
|
62
|
-
const currentStep = useModalStore((state) => state.step);
|
|
63
|
-
const webAuthURLForLogin = useModalStore((state) => state.webAuthURLForLogin);
|
|
64
|
-
const passwordUrlForLogin = useModalStore((state) => state.passwordUrlForLogin);
|
|
65
|
-
const isLogin = useModalStore((state) => state.isLogin());
|
|
66
|
-
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
67
|
-
const setStep = useModalStore((state) => state.setStep);
|
|
68
|
-
const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
|
|
69
|
-
const setWebAuthURLForLogin = useModalStore((state) => state.setWebAuthURLForLogin);
|
|
70
|
-
const setPasswordUrlForLogin = useModalStore((state) => state.setPasswordUrlForLogin);
|
|
71
|
-
const setSupportedAuthMethods = useModalStore((state) => state.setSupportedAuthMethods);
|
|
72
|
-
const setOnRampConfig = useModalStore((state) => state.setOnRampConfig);
|
|
73
|
-
const accountAddFundTab = useModalStore((state) => state.accountAddFundTab);
|
|
74
|
-
const setAccountAddFundTab = useModalStore((state) => state.setAccountAddFundTab);
|
|
75
|
-
const setRecoveryShare = useUserInfoStore((state) => state.setRecoveryShare);
|
|
76
|
-
const authStepRoute = useModalStore((state) => state.authStepRoute);
|
|
77
|
-
const isIFrameReady = useModalStore((state) => state.isIFrameReady);
|
|
78
|
-
const goBack = useGoBack();
|
|
79
|
-
const createAccount = useCreateAccount();
|
|
80
|
-
const biometricLocationHints = useModalStore((state) => {
|
|
81
|
-
var _a2;
|
|
82
|
-
return (_a2 = state.biometricLocationHints) != null ? _a2 : [];
|
|
83
|
-
});
|
|
84
|
-
const formattedHints = useMemo(() => formatBiometricHints(biometricLocationHints), [biometricLocationHints]);
|
|
85
|
-
const passkeysSupported = useModalStore((state) => state.isPasskeySupported);
|
|
86
|
-
const [hasHints, isOnKnownDevice] = [(biometricLocationHints == null ? void 0 : biometricLocationHints.length) > 0, (_a = formattedHints == null ? void 0 : formattedHints.isOnKnownDevice) != null ? _a : false];
|
|
87
|
-
const [walletCreationInProgress, setWalletCreationInProgress] = useState(false);
|
|
88
|
-
const connectEmbeddedToExternalConnectors = useEmbeddedExternalConnection();
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
if (!!authStepRoute && isIFrameReady) {
|
|
91
|
-
setTimeout(() => {
|
|
92
|
-
setStep(authStepRoute);
|
|
93
|
-
}, 200);
|
|
94
|
-
}
|
|
95
|
-
}, [authStepRoute, isIFrameReady]);
|
|
96
|
-
useImperativeHandle(ref, () => {
|
|
97
|
-
return {
|
|
98
|
-
handleModalClose() {
|
|
99
|
-
handleClose();
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
}, []);
|
|
103
|
-
const is2FASetup = () => __async(void 0, null, function* () {
|
|
104
|
-
if (!twoFactorAuthEnabled) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
try {
|
|
108
|
-
const { isSetup } = yield para.check2FAStatus();
|
|
109
|
-
return isSetup;
|
|
110
|
-
} catch (error) {
|
|
111
|
-
console.error("An error occurred while checking 2FA:", error);
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
function awaitLoginTransition() {
|
|
116
|
-
return __async(this, null, function* () {
|
|
117
|
-
var _a2;
|
|
118
|
-
const { isComplete, isError, needsWallet } = yield para.waitForLoginAndSetup({
|
|
119
|
-
popupWindow: refs.popupWindow.current
|
|
120
|
-
});
|
|
121
|
-
window.clearTimeout((_a2 = refs.poll.current) == null ? void 0 : _a2.timeout);
|
|
122
|
-
refs.poll.current = void 0;
|
|
123
|
-
refs.popupWindow.current = void 0;
|
|
124
|
-
if (isError) {
|
|
125
|
-
[ModalStep.AWAITING_BIOMETRIC_LOGIN, ModalStep.AWAITING_PASSWORD_LOGIN].includes(refs.currentStep.current) && goBack();
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
if (isComplete) {
|
|
129
|
-
setWebAuthURLForLogin("");
|
|
130
|
-
setPasswordUrlForLogin("");
|
|
131
|
-
setSupportedAuthMethods(/* @__PURE__ */ new Set());
|
|
132
|
-
setBiometricLocationHints();
|
|
133
|
-
if (needsWallet) {
|
|
134
|
-
setStep(ModalStep.AWAITING_WALLET_CREATION);
|
|
135
|
-
} else {
|
|
136
|
-
yield connectEmbeddedToExternalConnectors();
|
|
137
|
-
if (yield is2FASetup()) {
|
|
138
|
-
setStep(ModalStep.LOGIN_DONE);
|
|
139
|
-
} else {
|
|
140
|
-
setStep(ModalStep.SETUP_2FA);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
useEffect(() => {
|
|
147
|
-
if (currentStep !== ModalStep.AWAITING_WALLET_CREATION || walletCreationInProgress) {
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
function genWallet() {
|
|
151
|
-
return __async(this, null, function* () {
|
|
152
|
-
setWalletCreationInProgress(true);
|
|
153
|
-
let recoverySecret, walletIds;
|
|
154
|
-
if (!createWalletOverride) {
|
|
155
|
-
const created = yield para.waitForPasskeyAndCreateWallet();
|
|
156
|
-
recoverySecret = created.recoverySecret;
|
|
157
|
-
walletIds = created.walletIds;
|
|
158
|
-
} else {
|
|
159
|
-
const created = yield createWalletOverride(para);
|
|
160
|
-
const fetchedWallets = (yield para.fetchWallets()).filter((wallet) => !!wallet.address);
|
|
161
|
-
const newWallets = {};
|
|
162
|
-
for (const wallet of fetchedWallets) {
|
|
163
|
-
newWallets[wallet.id] = __spreadProps(__spreadValues({}, entityToWallet(wallet)), {
|
|
164
|
-
signer: ""
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
para.setWallets(newWallets);
|
|
168
|
-
recoverySecret = created.recoverySecret;
|
|
169
|
-
walletIds = created.walletIds;
|
|
170
|
-
}
|
|
171
|
-
yield para.setCurrentWalletIds(walletIds);
|
|
172
|
-
if (recoverySecretStepEnabled) {
|
|
173
|
-
setRecoveryShare(recoverySecret);
|
|
174
|
-
}
|
|
175
|
-
setWalletCreationInProgress(false);
|
|
176
|
-
if (!recoverySecret || !recoverySecretStepEnabled) {
|
|
177
|
-
setStep(ModalStep.WALLET_CREATION_DONE);
|
|
178
|
-
} else {
|
|
179
|
-
setStep(ModalStep.SECRET);
|
|
180
|
-
}
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
genWallet();
|
|
184
|
-
}, [isLogin, currentStep]);
|
|
185
|
-
useEffect(() => {
|
|
186
|
-
const isAwaitingLogin = [ModalStep.AWAITING_BIOMETRIC_LOGIN, ModalStep.AWAITING_PASSWORD_LOGIN].includes(currentStep);
|
|
187
|
-
const isUnknownDeviceWithHints = hasHints && !isOnKnownDevice;
|
|
188
|
-
const isPasskeyUnsupported = !passkeysSupported;
|
|
189
|
-
const hasLoginURLs = webAuthURLForLogin || passwordUrlForLogin;
|
|
190
|
-
const userNeedsToLogin = isAwaitingLogin || isUnknownDeviceWithHints || isPasskeyUnsupported;
|
|
191
|
-
if (userNeedsToLogin && hasLoginURLs) {
|
|
192
|
-
if (loginTransitionOverride) {
|
|
193
|
-
function loginOverride() {
|
|
194
|
-
return __async(this, null, function* () {
|
|
195
|
-
yield loginTransitionOverride(para);
|
|
196
|
-
setWebAuthURLForLogin("");
|
|
197
|
-
setPasswordUrlForLogin("");
|
|
198
|
-
setBiometricLocationHints();
|
|
199
|
-
yield connectEmbeddedToExternalConnectors();
|
|
200
|
-
if (yield is2FASetup()) {
|
|
201
|
-
setStep(ModalStep.LOGIN_DONE);
|
|
202
|
-
} else {
|
|
203
|
-
setStep(ModalStep.SETUP_2FA);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
loginOverride();
|
|
208
|
-
return;
|
|
209
|
-
}
|
|
210
|
-
if (typeof window !== "undefined") {
|
|
211
|
-
refs.poll.current = {
|
|
212
|
-
action: "login",
|
|
213
|
-
timeout: window.setTimeout(awaitLoginTransition, DEFAULTS.LOGGIN_POLLING_DELAY_MS)
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
return () => {
|
|
217
|
-
var _a2;
|
|
218
|
-
if (typeof window !== "undefined" && !!refs.poll.current) {
|
|
219
|
-
window.clearTimeout((_a2 = refs.poll.current) == null ? void 0 : _a2.timeout);
|
|
220
|
-
}
|
|
221
|
-
para.exitLogin();
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
}, [currentStep, webAuthURLForLogin, passwordUrlForLogin]);
|
|
225
|
-
const handleClose = () => {
|
|
226
|
-
onClose();
|
|
227
|
-
};
|
|
228
|
-
useEffect(() => {
|
|
229
|
-
var _a2, _b, _c;
|
|
230
|
-
refs.currentStep.current = currentStep;
|
|
231
|
-
let resetPoll = false;
|
|
232
|
-
if (![ModalStep.AWAITING_BIOMETRIC_CREATION, ModalStep.PASSWORD_CREATION].includes(currentStep)) {
|
|
233
|
-
para.exitAccountCreation();
|
|
234
|
-
resetPoll = ["createPassword", "createPasskey"].includes((_a2 = refs.poll.current) == null ? void 0 : _a2.action);
|
|
235
|
-
}
|
|
236
|
-
if (![ModalStep.AWAITING_PASSWORD_LOGIN, ModalStep.AWAITING_BIOMETRIC_LOGIN].includes(currentStep)) {
|
|
237
|
-
para.exitLogin();
|
|
238
|
-
resetPoll = ((_b = refs.poll.current) == null ? void 0 : _b.action) === "login";
|
|
239
|
-
}
|
|
240
|
-
if (![ModalStep.AWAITING_OAUTH, ModalStep.FARCASTER_OAUTH].includes(currentStep)) {
|
|
241
|
-
para.exitOAuth();
|
|
242
|
-
}
|
|
243
|
-
if (currentStep === ModalStep.PASSWORD_CREATION) {
|
|
244
|
-
createAccount.withPassword();
|
|
245
|
-
}
|
|
246
|
-
if (resetPoll && typeof window !== "undefined") {
|
|
247
|
-
window.clearTimeout((_c = refs.poll.current) == null ? void 0 : _c.timeout);
|
|
248
|
-
refs.poll.current = void 0;
|
|
249
|
-
}
|
|
250
|
-
}, [currentStep]);
|
|
251
|
-
useEffect(() => {
|
|
252
|
-
if (!onRampConfig) {
|
|
253
|
-
para.ctx.client.getOnRampConfig().then((res) => {
|
|
254
|
-
var _a2, _b;
|
|
255
|
-
let newOnRampConfig;
|
|
256
|
-
if (!!propsOnRampConfig) {
|
|
257
|
-
const { enabledFlows, network, asset, providers, testMode } = propsOnRampConfig;
|
|
258
|
-
const rampConfig = providers.find((config) => isRampConfig(config));
|
|
259
|
-
newOnRampConfig = {
|
|
260
|
-
isBuyEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.BUY),
|
|
261
|
-
isReceiveEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.RECEIVE),
|
|
262
|
-
isWithdrawEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.WITHDRAW),
|
|
263
|
-
allowedAssets: network ? { [Network[network]]: asset ? [AssetMap[asset]] : true } : asset ? { [(_a2 = AssetNetworks[AssetMap[asset]]) != null ? _a2 : Network.ETHEREUM]: [AssetMap[asset]] } : res.allowedAssets,
|
|
264
|
-
assetInfo: res.assetInfo,
|
|
265
|
-
providers: providers.map(({ id }) => OnRampProvider[id]),
|
|
266
|
-
rampApiKey: (_b = rampConfig == null ? void 0 : rampConfig.hostApiKey) != null ? _b : res.rampApiKey,
|
|
267
|
-
testMode: testMode != null ? testMode : onRampTestMode
|
|
268
|
-
};
|
|
269
|
-
} else {
|
|
270
|
-
newOnRampConfig = __spreadProps(__spreadValues({}, res), { testMode: onRampTestMode });
|
|
271
|
-
}
|
|
272
|
-
setOnRampConfig(newOnRampConfig);
|
|
273
|
-
if (!accountAddFundTab) {
|
|
274
|
-
setAccountAddFundTab(
|
|
275
|
-
newOnRampConfig.isBuyEnabled ? EnabledFlow.BUY : newOnRampConfig.isReceiveEnabled ? EnabledFlow.RECEIVE : newOnRampConfig.isWithdrawEnabled ? EnabledFlow.WITHDRAW : void 0
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
}).catch();
|
|
279
|
-
}
|
|
280
|
-
}, []);
|
|
281
|
-
useEffect(() => {
|
|
282
|
-
if (!!onRampConfig) {
|
|
283
|
-
setOnRampConfig(__spreadProps(__spreadValues({}, onRampConfig), { testMode: onRampTestMode }));
|
|
284
|
-
}
|
|
285
|
-
}, [onRampTestMode]);
|
|
286
|
-
useEffect(() => {
|
|
287
|
-
return () => {
|
|
288
|
-
var _a2;
|
|
289
|
-
window.clearTimeout((_a2 = refs.poll.current) == null ? void 0 : _a2.timeout);
|
|
290
|
-
para.exitLoops();
|
|
291
|
-
};
|
|
292
|
-
}, []);
|
|
293
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
294
|
-
/* @__PURE__ */ jsx(
|
|
295
|
-
Body,
|
|
296
|
-
{
|
|
297
|
-
oAuthMethods,
|
|
298
|
-
twoFactorAuthEnabled,
|
|
299
|
-
disableEmailLogin,
|
|
300
|
-
disablePhoneLogin,
|
|
301
|
-
onClose: handleClose
|
|
302
|
-
}
|
|
303
|
-
),
|
|
304
|
-
/* @__PURE__ */ jsx(Footer, {})
|
|
305
|
-
] });
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
export {
|
|
309
|
-
ModalContent
|
|
310
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
__async
|
|
4
|
-
} from "../../../chunk-MMUBH76A.js";
|
|
5
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { useEffect } from "react";
|
|
7
|
-
import { CpslButton, CpslIcon, CpslQrCode, CpslSpinner, CpslText } from "@getpara/react-components";
|
|
8
|
-
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";
|
|
14
|
-
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
|
-
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
|
-
return /* @__PURE__ */ jsx(StepContainer, { $wide: true, children: isMobile() ? /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
65
|
-
/* @__PURE__ */ jsx(CpslText, { weight: "medium", color: "secondary", children: `Don\u2019t have Farcaster` }),
|
|
66
|
-
/* @__PURE__ */ jsxs(CpslButton, { as: "a", href: "https://link.warpcast.com/download-qr", target: "_blank", variant: "secondary", children: [
|
|
67
|
-
/* @__PURE__ */ jsx(CpslIcon, { slot: "start", icon: "linkExternal" }),
|
|
68
|
-
`Get Farcaster`
|
|
69
|
-
] })
|
|
70
|
-
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
71
|
-
/* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: "Sign in using Farcaster" }),
|
|
72
|
-
/* @__PURE__ */ jsxs(InnerStepContainer, { children: [
|
|
73
|
-
/* @__PURE__ */ jsx(CenteredText, { variant: "bodyS", color: "secondary", weight: "medium", children: "Scan the QR code with your phone's camera to proceed." }),
|
|
74
|
-
/* @__PURE__ */ jsx(QRContainer, { children: !farcasterConnectUri ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: farcasterConnectUri }) })
|
|
75
|
-
] })
|
|
76
|
-
] }) });
|
|
77
|
-
};
|
|
78
|
-
var FarcasterOAuthStep_default = FarcasterOAuthStep;
|
|
79
|
-
export {
|
|
80
|
-
FarcasterOAuthStep_default as default
|
|
81
|
-
};
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
__async
|
|
4
|
-
} from "../../../chunk-MMUBH76A.js";
|
|
5
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
-
import { AuthMethod, OAuthMethod } from "@getpara/web-sdk";
|
|
7
|
-
import { styled } from "styled-components";
|
|
8
|
-
import { useModalStore, useUserInfoStore } from "../../stores/index.js";
|
|
9
|
-
import { ModalStep } from "../../utils/steps.js";
|
|
10
|
-
import { openPopup } from "../../utils/openPopup.js";
|
|
11
|
-
import { useThemeStore } from "../../stores/theme/useThemeStore.js";
|
|
12
|
-
import { getTileButtonFlex } from "../../utils/getTileButtonFlex.js";
|
|
13
|
-
import { StyledCpslTileButton } from "../common.js";
|
|
14
|
-
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";
|
|
20
|
-
const HAS_MORE_LENGTH = 3;
|
|
21
|
-
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);
|
|
28
|
-
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
|
-
}, []);
|
|
50
|
-
const hasMore = methods.length > HAS_MORE_LENGTH;
|
|
51
|
-
const methodsToShow = showAll || !hasMore ? methods : methods.slice(0, HAS_MORE_LENGTH - 1);
|
|
52
|
-
const handleShowAll = () => {
|
|
53
|
-
setStep(ModalStep.AUTH_MORE);
|
|
54
|
-
};
|
|
55
|
-
const handleMethodClick = (method) => () => __async(void 0, null, function* () {
|
|
56
|
-
switch (method) {
|
|
57
|
-
case OAuthMethod.FARCASTER:
|
|
58
|
-
if (!farcasterConnectUri) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
routeMobileExternalWallet(farcasterConnectUri);
|
|
62
|
-
setStep(ModalStep.FARCASTER_OAUTH);
|
|
63
|
-
break;
|
|
64
|
-
case OAuthMethod.TELEGRAM:
|
|
65
|
-
setStep(ModalStep.TELEGRAM_OAUTH);
|
|
66
|
-
break;
|
|
67
|
-
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);
|
|
110
|
-
break;
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
const useBrandedLogos = oAuthLogoVariant === "default";
|
|
114
|
-
const useDarkLogos = useBrandedLogos ? isDark : oAuthLogoVariant !== "dark";
|
|
115
|
-
const showMoreButton = !showAll && hasMore;
|
|
116
|
-
return /* @__PURE__ */ jsxs(OAuthContainer, { children: [
|
|
117
|
-
methodsToShow.map((method, index) => /* @__PURE__ */ jsx(
|
|
118
|
-
OAuthButton,
|
|
119
|
-
{
|
|
120
|
-
$isDark: useDarkLogos,
|
|
121
|
-
icon: useBrandedLogos ? brandedOAuthLogos[method] : oAuthLogos[method],
|
|
122
|
-
onClick: handleMethodClick(method),
|
|
123
|
-
$index: index,
|
|
124
|
-
$totalItems: showMoreButton ? HAS_MORE_LENGTH : methodsToShow.length
|
|
125
|
-
},
|
|
126
|
-
method
|
|
127
|
-
)),
|
|
128
|
-
showMoreButton && /* @__PURE__ */ jsx(
|
|
129
|
-
OAuthButton,
|
|
130
|
-
{
|
|
131
|
-
$isDark: useDarkLogos,
|
|
132
|
-
icon: "moreLoginOptions",
|
|
133
|
-
onClick: handleShowAll,
|
|
134
|
-
$index: HAS_MORE_LENGTH - 1,
|
|
135
|
-
$totalItems: HAS_MORE_LENGTH
|
|
136
|
-
}
|
|
137
|
-
)
|
|
138
|
-
] });
|
|
139
|
-
};
|
|
140
|
-
const OAuthContainer = styled.div`
|
|
141
|
-
display: flex;
|
|
142
|
-
justify-content: center;
|
|
143
|
-
gap: 8px;
|
|
144
|
-
flex-wrap: wrap;
|
|
145
|
-
`;
|
|
146
|
-
const OAuthButton = styled(StyledCpslTileButton)`
|
|
147
|
-
flex: ${({ $index, $totalItems }) => getTileButtonFlex($index, $totalItems)};
|
|
148
|
-
|
|
149
|
-
--button-icon-color: ${({ $isDark }) => $isDark ? "white" : "black"};
|
|
150
|
-
`;
|
|
151
|
-
export {
|
|
152
|
-
OAuth
|
|
153
|
-
};
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import {
|
|
3
|
-
__async
|
|
4
|
-
} from "../../../chunk-MMUBH76A.js";
|
|
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";
|
|
8
|
-
import styled from "styled-components";
|
|
9
|
-
import { useEffect, useRef, useState } from "react";
|
|
10
|
-
import { HeroSpinner } from "@getpara/react-common";
|
|
11
|
-
import { ModalStep } from "../../utils/steps.js";
|
|
12
|
-
import { CpslSpinner } from "@getpara/react-components";
|
|
13
|
-
import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
|
|
14
|
-
import { useSetLoginURLs } from "../../hooks/useSetLoginURLs.js";
|
|
15
|
-
function TelegramOAuthStep() {
|
|
16
|
-
const iframe = useRef();
|
|
17
|
-
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);
|
|
29
|
-
const [isWaiting, setIsWaiting] = useState(false);
|
|
30
|
-
const [isLoaded, setIsLoaded] = useState(false);
|
|
31
|
-
const [isError, setIsError] = useState(false);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
if (!url) {
|
|
34
|
-
para.getOAuthURL({ method: OAuthMethod.TELEGRAM }).then((url2) => {
|
|
35
|
-
setUrl(url2);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
}, [url]);
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
const updateState = (event) => __async(this, null, function* () {
|
|
41
|
-
switch (event.data.type) {
|
|
42
|
-
case "TELEGRAM_LOGIN":
|
|
43
|
-
setIsWaiting(true);
|
|
44
|
-
setIsError(false);
|
|
45
|
-
break;
|
|
46
|
-
case "TELEGRAM_FAILED":
|
|
47
|
-
setIsWaiting(false);
|
|
48
|
-
setIsError(true);
|
|
49
|
-
break;
|
|
50
|
-
case "TELEGRAM_SUCCESS":
|
|
51
|
-
if (!!event.data.payload) {
|
|
52
|
-
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
|
-
}
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
window == null ? void 0 : window.addEventListener("message", updateState, false);
|
|
100
|
-
return () => {
|
|
101
|
-
window == null ? void 0 : window.removeEventListener("message", updateState, false);
|
|
102
|
-
};
|
|
103
|
-
}, []);
|
|
104
|
-
return /* @__PURE__ */ jsxs(Container, { children: [
|
|
105
|
-
/* @__PURE__ */ jsx(HeroContainer, { children: /* @__PURE__ */ jsx(
|
|
106
|
-
HeroSpinner,
|
|
107
|
-
{
|
|
108
|
-
icon: "telegramBrand",
|
|
109
|
-
status: isWaiting ? "loading" : isError ? "error" : "inactive",
|
|
110
|
-
text: isWaiting ? "Follow the on-screen prompts." : isError ? "Login Failed" : void 0
|
|
111
|
-
}
|
|
112
|
-
) }),
|
|
113
|
-
url && /* @__PURE__ */ jsx(IFrame, { ref: iframe, style: { display: isLoaded ? "block" : "none" }, src: url, onLoad: () => setIsLoaded(true) }),
|
|
114
|
-
(!url || !isLoaded) && /* @__PURE__ */ jsx(CpslSpinner, {})
|
|
115
|
-
] });
|
|
116
|
-
}
|
|
117
|
-
const Container = styled.div`
|
|
118
|
-
display: flex;
|
|
119
|
-
flex-direction: column;
|
|
120
|
-
align-items: center;
|
|
121
|
-
justify-content: center;
|
|
122
|
-
width: 100%;
|
|
123
|
-
`;
|
|
124
|
-
const HeroContainer = styled.div`
|
|
125
|
-
display: flex;
|
|
126
|
-
min-height: 276px;
|
|
127
|
-
flex-direction: column;
|
|
128
|
-
align-items: center;
|
|
129
|
-
gap: 16px;
|
|
130
|
-
flex: 1;
|
|
131
|
-
`;
|
|
132
|
-
const IFrame = styled.iframe`
|
|
133
|
-
width: 100%;
|
|
134
|
-
height: 52px;
|
|
135
|
-
border: none;
|
|
136
|
-
`;
|
|
137
|
-
export {
|
|
138
|
-
TelegramOAuthStep
|
|
139
|
-
};
|