@getpara/react-sdk 1.7.1 → 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.
- package/dist/index.js +6 -6659
- package/dist/modal/ParaModal.js +362 -0
- package/dist/modal/components/Account/Account.js +77 -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 +55 -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 +308 -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 +234 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +140 -0
- package/dist/modal/components/ExternalWalletStep/config.js +17 -0
- package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +96 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +172 -0
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +124 -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 +116 -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 +324 -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.d.ts +6 -6
- package/dist/modal/components/common.js +96 -0
- package/dist/modal/components/index.js +2 -0
- package/dist/modal/constants/constants.d.ts +1 -1
- 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 +54 -0
- package/dist/modal/hooks/useGoBack.js +42 -0
- package/dist/modal/hooks/useSetLoginURLs.js +49 -0
- package/dist/modal/hooks/useWalletBalance.d.ts +4 -0
- package/dist/modal/hooks/useWalletBalance.js +47 -0
- package/dist/modal/index.js +33 -0
- package/dist/modal/providers/CosmosExternalWalletContextStub.js +38 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +2 -0
- package/dist/modal/providers/EvmExternalWalletContextStub.js +55 -0
- package/dist/modal/providers/ExternalWalletContext.d.ts +3 -0
- package/dist/modal/providers/ExternalWalletContext.js +394 -0
- package/dist/modal/providers/SolanaExternalWalletContextStub.js +32 -0
- package/dist/modal/stores/externalWalletProvider/actions.js +10 -0
- package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +21 -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 +32 -0
- package/dist/modal/types/modalProps.d.ts +4 -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 +232 -0
- package/dist/modal/utils/stringFormatters.d.ts +1 -0
- package/dist/modal/utils/stringFormatters.js +19 -0
- package/dist/modal/utils/validateOnRampConfig.js +32 -0
- package/dist/package.json +3 -1
- 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/getWalletBalance.d.ts +2 -0
- package/dist/provider/actions/getWalletBalance.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 +39 -0
- package/dist/provider/hooks/mutations/useSignTransaction.js +39 -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.d.ts +1 -0
- package/dist/provider/hooks/queries/index.js +10 -0
- package/dist/provider/hooks/queries/useAccount.js +21 -0
- package/dist/provider/hooks/queries/useWallet.js +22 -0
- package/dist/provider/hooks/queries/useWalletBalance.d.ts +7 -0
- package/dist/provider/hooks/queries/useWalletBalance.js +26 -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 +13 -0
- package/dist/provider/stores/types.d.ts +2 -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/constants.js +11 -0
- package/dist/provider/utils/renameMutations.js +16 -0
- package/package.json +5 -5
- 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,324 @@
|
|
|
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
|
+
import { useExternalWallets } from "../../providers/ExternalWalletContext.js";
|
|
27
|
+
function isRampConfig(config) {
|
|
28
|
+
return "hostApiKey" in config;
|
|
29
|
+
}
|
|
30
|
+
const AssetNetworks = {
|
|
31
|
+
[OnRampAsset.SOLANA]: Network.SOLANA,
|
|
32
|
+
[OnRampAsset.ATOM]: Network.COSMOS,
|
|
33
|
+
[OnRampAsset.CELO]: Network.CELO,
|
|
34
|
+
[OnRampAsset.POLYGON]: Network.POLYGON
|
|
35
|
+
};
|
|
36
|
+
const AssetMap = {
|
|
37
|
+
SOLANA: OnRampAsset.SOLANA,
|
|
38
|
+
SOL: OnRampAsset.SOLANA,
|
|
39
|
+
ATOM: OnRampAsset.ATOM,
|
|
40
|
+
CELO: OnRampAsset.CELO,
|
|
41
|
+
POLYGON: OnRampAsset.POLYGON,
|
|
42
|
+
MATIC: OnRampAsset.POLYGON,
|
|
43
|
+
USDC: OnRampAsset.USDC,
|
|
44
|
+
ETH: OnRampAsset.ETHEREUM,
|
|
45
|
+
ETHEREUM: OnRampAsset.ETHEREUM
|
|
46
|
+
};
|
|
47
|
+
const ModalContent = forwardRef(
|
|
48
|
+
({
|
|
49
|
+
onRampConfig: propsOnRampConfig,
|
|
50
|
+
twoFactorAuthEnabled = false,
|
|
51
|
+
recoverySecretStepEnabled = false,
|
|
52
|
+
oAuthMethods,
|
|
53
|
+
disableEmailLogin,
|
|
54
|
+
disablePhoneLogin,
|
|
55
|
+
onClose,
|
|
56
|
+
onRampTestMode,
|
|
57
|
+
loginTransitionOverride,
|
|
58
|
+
createWalletOverride
|
|
59
|
+
}, ref) => {
|
|
60
|
+
var _a;
|
|
61
|
+
const para = useInternalClient();
|
|
62
|
+
const refs = useModalStore((state) => state.refs);
|
|
63
|
+
const currentStep = useModalStore((state) => state.step);
|
|
64
|
+
const webAuthURLForLogin = useModalStore((state) => state.webAuthURLForLogin);
|
|
65
|
+
const passwordUrlForLogin = useModalStore((state) => state.passwordUrlForLogin);
|
|
66
|
+
const isLogin = useModalStore((state) => state.isLogin());
|
|
67
|
+
const onRampConfig = useModalStore((state) => state.onRampConfig);
|
|
68
|
+
const setStep = useModalStore((state) => state.setStep);
|
|
69
|
+
const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
|
|
70
|
+
const setWebAuthURLForLogin = useModalStore((state) => state.setWebAuthURLForLogin);
|
|
71
|
+
const setPasswordUrlForLogin = useModalStore((state) => state.setPasswordUrlForLogin);
|
|
72
|
+
const setSupportedAuthMethods = useModalStore((state) => state.setSupportedAuthMethods);
|
|
73
|
+
const setOnRampConfig = useModalStore((state) => state.setOnRampConfig);
|
|
74
|
+
const accountAddFundTab = useModalStore((state) => state.accountAddFundTab);
|
|
75
|
+
const setAccountAddFundTab = useModalStore((state) => state.setAccountAddFundTab);
|
|
76
|
+
const setRecoveryShare = useUserInfoStore((state) => state.setRecoveryShare);
|
|
77
|
+
const authStepRoute = useModalStore((state) => state.authStepRoute);
|
|
78
|
+
const isIFrameReady = useModalStore((state) => state.isIFrameReady);
|
|
79
|
+
const goBack = useGoBack();
|
|
80
|
+
const createAccount = useCreateAccount();
|
|
81
|
+
const biometricLocationHints = useModalStore((state) => {
|
|
82
|
+
var _a2;
|
|
83
|
+
return (_a2 = state.biometricLocationHints) != null ? _a2 : [];
|
|
84
|
+
});
|
|
85
|
+
const formattedHints = useMemo(() => formatBiometricHints(biometricLocationHints), [biometricLocationHints]);
|
|
86
|
+
const passkeysSupported = useModalStore((state) => state.isPasskeySupported);
|
|
87
|
+
const [hasHints, isOnKnownDevice] = [(biometricLocationHints == null ? void 0 : biometricLocationHints.length) > 0, (_a = formattedHints == null ? void 0 : formattedHints.isOnKnownDevice) != null ? _a : false];
|
|
88
|
+
const { disconnectExternalWallet } = useExternalWallets();
|
|
89
|
+
const [walletCreationInProgress, setWalletCreationInProgress] = useState(false);
|
|
90
|
+
const connectEmbeddedToExternalConnectors = useEmbeddedExternalConnection();
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (!!authStepRoute && isIFrameReady) {
|
|
93
|
+
setTimeout(() => {
|
|
94
|
+
setStep(authStepRoute);
|
|
95
|
+
}, 200);
|
|
96
|
+
}
|
|
97
|
+
}, [authStepRoute, isIFrameReady]);
|
|
98
|
+
useImperativeHandle(ref, () => {
|
|
99
|
+
return {
|
|
100
|
+
handleModalClose() {
|
|
101
|
+
handleClose();
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
}, []);
|
|
105
|
+
const is2FASetup = () => __async(void 0, null, function* () {
|
|
106
|
+
if (!twoFactorAuthEnabled) {
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
try {
|
|
110
|
+
const { isSetup } = yield para.check2FAStatus();
|
|
111
|
+
return isSetup;
|
|
112
|
+
} catch (error) {
|
|
113
|
+
console.error("An error occurred while checking 2FA:", error);
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
function awaitLoginTransition() {
|
|
118
|
+
return __async(this, null, function* () {
|
|
119
|
+
const { isComplete, isError, needsWallet } = yield para.waitForLoginAndSetup({
|
|
120
|
+
popupWindow: refs.popupWindow.current
|
|
121
|
+
});
|
|
122
|
+
if (isError) {
|
|
123
|
+
[ModalStep.AWAITING_BIOMETRIC_LOGIN, ModalStep.AWAITING_PASSWORD_LOGIN].includes(refs.currentStep.current) && goBack();
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (isComplete) {
|
|
127
|
+
setWebAuthURLForLogin("");
|
|
128
|
+
setPasswordUrlForLogin("");
|
|
129
|
+
setSupportedAuthMethods(/* @__PURE__ */ new Set());
|
|
130
|
+
setBiometricLocationHints();
|
|
131
|
+
if (needsWallet) {
|
|
132
|
+
setStep(ModalStep.AWAITING_WALLET_CREATION);
|
|
133
|
+
} else {
|
|
134
|
+
yield connectEmbeddedToExternalConnectors();
|
|
135
|
+
if (yield is2FASetup()) {
|
|
136
|
+
setStep(ModalStep.LOGIN_DONE);
|
|
137
|
+
} else {
|
|
138
|
+
setStep(ModalStep.SETUP_2FA);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
if (currentStep !== ModalStep.AWAITING_WALLET_CREATION || walletCreationInProgress) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
function genWallet() {
|
|
149
|
+
return __async(this, null, function* () {
|
|
150
|
+
setWalletCreationInProgress(true);
|
|
151
|
+
let recoverySecret, walletIds;
|
|
152
|
+
if (!createWalletOverride) {
|
|
153
|
+
const created = yield para.waitForPasskeyAndCreateWallet();
|
|
154
|
+
recoverySecret = created.recoverySecret;
|
|
155
|
+
walletIds = created.walletIds;
|
|
156
|
+
} else {
|
|
157
|
+
const created = yield createWalletOverride(para);
|
|
158
|
+
const fetchedWallets = (yield para.fetchWallets()).filter((wallet) => !!wallet.address);
|
|
159
|
+
const newWallets = {};
|
|
160
|
+
for (const wallet of fetchedWallets) {
|
|
161
|
+
newWallets[wallet.id] = __spreadProps(__spreadValues({}, entityToWallet(wallet)), {
|
|
162
|
+
signer: ""
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
para.setWallets(newWallets);
|
|
166
|
+
recoverySecret = created.recoverySecret;
|
|
167
|
+
walletIds = created.walletIds;
|
|
168
|
+
}
|
|
169
|
+
yield para.setCurrentWalletIds(walletIds);
|
|
170
|
+
yield connectEmbeddedToExternalConnectors();
|
|
171
|
+
if (recoverySecretStepEnabled) {
|
|
172
|
+
setRecoveryShare(recoverySecret);
|
|
173
|
+
}
|
|
174
|
+
setWalletCreationInProgress(false);
|
|
175
|
+
if (!recoverySecret || !recoverySecretStepEnabled) {
|
|
176
|
+
setStep(ModalStep.WALLET_CREATION_DONE);
|
|
177
|
+
} else {
|
|
178
|
+
setStep(ModalStep.SECRET);
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
genWallet();
|
|
183
|
+
}, [isLogin, currentStep]);
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
const isAwaitingLogin = [
|
|
186
|
+
ModalStep.AWAITING_PASSWORD_LOGIN,
|
|
187
|
+
ModalStep.AWAITING_BIOMETRIC_LOGIN,
|
|
188
|
+
ModalStep.BIOMETRIC_LOGIN
|
|
189
|
+
].includes(currentStep);
|
|
190
|
+
const isUnknownDeviceWithHints = hasHints && !isOnKnownDevice;
|
|
191
|
+
const isPasskeyUnsupported = !passkeysSupported;
|
|
192
|
+
const hasLoginURLs = !!webAuthURLForLogin || !!passwordUrlForLogin;
|
|
193
|
+
const userNeedsToLogin = isAwaitingLogin || isUnknownDeviceWithHints || isPasskeyUnsupported;
|
|
194
|
+
if (userNeedsToLogin && hasLoginURLs) {
|
|
195
|
+
if (loginTransitionOverride) {
|
|
196
|
+
function loginOverride() {
|
|
197
|
+
return __async(this, null, function* () {
|
|
198
|
+
yield loginTransitionOverride(para);
|
|
199
|
+
setWebAuthURLForLogin("");
|
|
200
|
+
setPasswordUrlForLogin("");
|
|
201
|
+
setBiometricLocationHints();
|
|
202
|
+
yield connectEmbeddedToExternalConnectors();
|
|
203
|
+
if (yield is2FASetup()) {
|
|
204
|
+
setStep(ModalStep.LOGIN_DONE);
|
|
205
|
+
} else {
|
|
206
|
+
setStep(ModalStep.SETUP_2FA);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
loginOverride();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (typeof window !== "undefined") {
|
|
214
|
+
refs.poll.current = {
|
|
215
|
+
action: "login",
|
|
216
|
+
timeout: window.setTimeout(awaitLoginTransition, DEFAULTS.LOGGIN_POLLING_DELAY_MS)
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return () => {
|
|
220
|
+
var _a2;
|
|
221
|
+
if (typeof window !== "undefined" && !!refs.poll.current) {
|
|
222
|
+
window.clearTimeout((_a2 = refs.poll.current) == null ? void 0 : _a2.timeout);
|
|
223
|
+
}
|
|
224
|
+
para.exitLogin();
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}, [currentStep, webAuthURLForLogin, passwordUrlForLogin]);
|
|
228
|
+
const handleClose = () => {
|
|
229
|
+
onClose();
|
|
230
|
+
if (currentStep === ModalStep.EXTERNAL_WALLET_VERIFICATION && para.isExternalWalletAuth) {
|
|
231
|
+
disconnectExternalWallet();
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
useEffect(() => {
|
|
235
|
+
var _a2, _b, _c;
|
|
236
|
+
refs.currentStep.current = currentStep;
|
|
237
|
+
let resetPoll = false;
|
|
238
|
+
if (![ModalStep.AWAITING_BIOMETRIC_CREATION, ModalStep.PASSWORD_CREATION].includes(currentStep)) {
|
|
239
|
+
para.exitAccountCreation();
|
|
240
|
+
resetPoll = ["createPassword", "createPasskey"].includes((_a2 = refs.poll.current) == null ? void 0 : _a2.action);
|
|
241
|
+
}
|
|
242
|
+
if (![ModalStep.AWAITING_PASSWORD_LOGIN, ModalStep.AWAITING_BIOMETRIC_LOGIN, ModalStep.BIOMETRIC_LOGIN].includes(
|
|
243
|
+
currentStep
|
|
244
|
+
)) {
|
|
245
|
+
para.exitLogin();
|
|
246
|
+
resetPoll = ((_b = refs.poll.current) == null ? void 0 : _b.action) === "login";
|
|
247
|
+
}
|
|
248
|
+
if (![ModalStep.AWAITING_OAUTH, ModalStep.FARCASTER_OAUTH].includes(currentStep)) {
|
|
249
|
+
para.exitOAuth();
|
|
250
|
+
}
|
|
251
|
+
if (currentStep === ModalStep.PASSWORD_CREATION) {
|
|
252
|
+
createAccount.withPassword();
|
|
253
|
+
}
|
|
254
|
+
if (resetPoll && typeof window !== "undefined") {
|
|
255
|
+
window.clearTimeout((_c = refs.poll.current) == null ? void 0 : _c.timeout);
|
|
256
|
+
refs.poll.current = void 0;
|
|
257
|
+
}
|
|
258
|
+
}, [currentStep]);
|
|
259
|
+
useEffect(() => {
|
|
260
|
+
if (!onRampConfig) {
|
|
261
|
+
para.ctx.client.getOnRampConfig().then((res) => {
|
|
262
|
+
var _a2, _b;
|
|
263
|
+
let newOnRampConfig;
|
|
264
|
+
if (!!propsOnRampConfig) {
|
|
265
|
+
const { enabledFlows, network, asset, providers, testMode } = propsOnRampConfig;
|
|
266
|
+
const rampConfig = providers.find((config) => isRampConfig(config));
|
|
267
|
+
newOnRampConfig = {
|
|
268
|
+
isBuyEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.BUY),
|
|
269
|
+
isReceiveEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.RECEIVE),
|
|
270
|
+
isWithdrawEnabled: !enabledFlows || enabledFlows.some((str) => EnabledFlow[str] === EnabledFlow.WITHDRAW),
|
|
271
|
+
allowedAssets: network ? { [Network[network]]: asset ? [AssetMap[asset]] : true } : asset ? { [(_a2 = AssetNetworks[AssetMap[asset]]) != null ? _a2 : Network.ETHEREUM]: [AssetMap[asset]] } : res.allowedAssets,
|
|
272
|
+
assetInfo: res.assetInfo,
|
|
273
|
+
providers: providers.map(({ id }) => OnRampProvider[id]),
|
|
274
|
+
rampApiKey: (_b = rampConfig == null ? void 0 : rampConfig.hostApiKey) != null ? _b : res.rampApiKey,
|
|
275
|
+
testMode: testMode != null ? testMode : onRampTestMode
|
|
276
|
+
};
|
|
277
|
+
} else {
|
|
278
|
+
newOnRampConfig = __spreadProps(__spreadValues({}, res), { testMode: onRampTestMode });
|
|
279
|
+
}
|
|
280
|
+
setOnRampConfig(newOnRampConfig);
|
|
281
|
+
if (!accountAddFundTab) {
|
|
282
|
+
setAccountAddFundTab(
|
|
283
|
+
newOnRampConfig.isBuyEnabled ? EnabledFlow.BUY : newOnRampConfig.isReceiveEnabled ? EnabledFlow.RECEIVE : newOnRampConfig.isWithdrawEnabled ? EnabledFlow.WITHDRAW : void 0
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
}).catch();
|
|
287
|
+
}
|
|
288
|
+
}, []);
|
|
289
|
+
useEffect(() => {
|
|
290
|
+
if (!!onRampConfig) {
|
|
291
|
+
setOnRampConfig(__spreadProps(__spreadValues({}, onRampConfig), { testMode: onRampTestMode }));
|
|
292
|
+
}
|
|
293
|
+
}, [onRampTestMode]);
|
|
294
|
+
useEffect(() => {
|
|
295
|
+
const init = () => __async(void 0, null, function* () {
|
|
296
|
+
if (!(yield para.isFullyLoggedIn())) {
|
|
297
|
+
yield disconnectExternalWallet();
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
init();
|
|
301
|
+
return () => {
|
|
302
|
+
var _a2;
|
|
303
|
+
window.clearTimeout((_a2 = refs.poll.current) == null ? void 0 : _a2.timeout);
|
|
304
|
+
para.exitLoops();
|
|
305
|
+
};
|
|
306
|
+
}, []);
|
|
307
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
308
|
+
/* @__PURE__ */ jsx(
|
|
309
|
+
Body,
|
|
310
|
+
{
|
|
311
|
+
oAuthMethods,
|
|
312
|
+
twoFactorAuthEnabled,
|
|
313
|
+
disableEmailLogin,
|
|
314
|
+
disablePhoneLogin,
|
|
315
|
+
onClose: handleClose
|
|
316
|
+
}
|
|
317
|
+
),
|
|
318
|
+
/* @__PURE__ */ jsx(Footer, {})
|
|
319
|
+
] });
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
export {
|
|
323
|
+
ModalContent
|
|
324
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,153 @@
|
|
|
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
|
+
};
|