@getpara/react-sdk 1.5.1 → 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.
Files changed (143) hide show
  1. package/dist/index.js +6 -6367
  2. package/dist/modal/ParaModal.js +337 -0
  3. package/dist/modal/components/Account/Account.js +69 -0
  4. package/dist/modal/components/AddFunds/AddFunds.js +220 -0
  5. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +72 -0
  6. package/dist/modal/components/AddFunds/AddFundsDone.js +43 -0
  7. package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
  8. package/dist/modal/components/AddFunds/index.js +4 -0
  9. package/dist/modal/components/AuthInput/AuthInput.js +283 -0
  10. package/dist/modal/components/AuthInput/countryCodes.js +42 -0
  11. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
  12. package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
  13. package/dist/modal/components/AuthMainStep/AuthMainStep.js +37 -0
  14. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +113 -0
  15. package/dist/modal/components/AuthOptions/AuthOptions.js +33 -0
  16. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
  17. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
  18. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
  19. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +44 -0
  20. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +52 -0
  21. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +93 -0
  22. package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
  23. package/dist/modal/components/Body/Body.js +304 -0
  24. package/dist/modal/components/ChainSwitch/ChainSwitch.js +94 -0
  25. package/dist/modal/components/ChainSwitch/config.js +17 -0
  26. package/dist/modal/components/Controls/Controls.js +74 -0
  27. package/dist/modal/components/Controls/Selects.js +213 -0
  28. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +151 -0
  29. package/dist/modal/components/ExternalWalletStep/config.js +17 -0
  30. package/dist/modal/components/ExternalWallets/ExternalWallets.js +172 -0
  31. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +123 -0
  32. package/dist/modal/components/Footer/Footer.js +93 -0
  33. package/dist/modal/components/Header/Header.js +43 -0
  34. package/dist/modal/components/Header/hooks/useStepTitle.js +50 -0
  35. package/dist/modal/components/Hero/Hero.js +122 -0
  36. package/dist/modal/components/IFrameStep/IFrameStep.js +55 -0
  37. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +28 -0
  38. package/dist/modal/components/ModalContent/ModalContent.js +310 -0
  39. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
  40. package/dist/modal/components/OAuth/OAuth.js +153 -0
  41. package/dist/modal/components/OAuth/TelegramOAuthStep.js +139 -0
  42. package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
  43. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
  44. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +101 -0
  45. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +141 -0
  46. package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
  47. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +24 -0
  48. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +159 -0
  49. package/dist/modal/components/Waiting/Waiting.js +17 -0
  50. package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
  51. package/dist/modal/components/WalletCard/WalletCard.js +127 -0
  52. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +52 -0
  53. package/dist/modal/components/common.js +83 -0
  54. package/dist/modal/components/index.js +2 -0
  55. package/dist/modal/constants/constants.js +111 -0
  56. package/dist/modal/constants/defaults.js +10 -0
  57. package/dist/modal/constants/oAuthLogos.js +24 -0
  58. package/dist/modal/hooks/useActiveWallet.js +15 -0
  59. package/dist/modal/hooks/useCreateAccount.js +72 -0
  60. package/dist/modal/hooks/useEmbeddedExternalConnection.js +39 -0
  61. package/dist/modal/hooks/useGoBack.js +35 -0
  62. package/dist/modal/hooks/useSetLoginURLs.d.ts +8 -0
  63. package/dist/modal/hooks/useSetLoginURLs.js +45 -0
  64. package/dist/modal/index.js +32 -0
  65. package/dist/modal/providers/CosmosExternalWalletContextStub.js +34 -0
  66. package/dist/modal/providers/EvmExternalWalletContextStub.js +38 -0
  67. package/dist/modal/providers/ExternalWalletContext.js +275 -0
  68. package/dist/modal/providers/SolanaExternalWalletContextStub.js +19 -0
  69. package/dist/modal/stores/externalWalletProvider/actions.js +10 -0
  70. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +20 -0
  71. package/dist/modal/stores/index.js +4 -0
  72. package/dist/modal/stores/modal/actions.js +70 -0
  73. package/dist/modal/stores/modal/useModalStore.js +65 -0
  74. package/dist/modal/stores/theme/actions.js +28 -0
  75. package/dist/modal/stores/theme/useThemeStore.js +21 -0
  76. package/dist/modal/stores/userInfo/actions.js +30 -0
  77. package/dist/modal/stores/userInfo/useUserInfoStore.js +17 -0
  78. package/dist/modal/types/commonTypes.js +1 -0
  79. package/dist/modal/types/externalWallets.js +31 -0
  80. package/dist/modal/types/modalProps.js +12 -0
  81. package/dist/modal/utils/authLayoutHelpers.js +8 -0
  82. package/dist/modal/utils/getMailtoLink.js +10 -0
  83. package/dist/modal/utils/getTileButtonFlex.js +20 -0
  84. package/dist/modal/utils/openPopup.js +60 -0
  85. package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
  86. package/dist/modal/utils/steps.js +228 -0
  87. package/dist/modal/utils/stringFormatters.js +14 -0
  88. package/dist/modal/utils/validateOnRampConfig.js +32 -0
  89. package/dist/package.json +4 -0
  90. package/dist/provider/ParaProvider.js +22 -0
  91. package/dist/provider/actions/checkIfUserExists.js +21 -0
  92. package/dist/provider/actions/createUser.js +26 -0
  93. package/dist/provider/actions/getAccount.js +22 -0
  94. package/dist/provider/actions/getWallet.js +14 -0
  95. package/dist/provider/actions/initiateLogin.js +20 -0
  96. package/dist/provider/actions/keepSessionAlive.js +20 -0
  97. package/dist/provider/actions/logout.js +17 -0
  98. package/dist/provider/actions/signMessage.js +20 -0
  99. package/dist/provider/actions/signTransaction.js +20 -0
  100. package/dist/provider/actions/waitForAccountCreation.js +21 -0
  101. package/dist/provider/actions/waitForLoginAndSetup.js +24 -0
  102. package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +21 -0
  103. package/dist/provider/hooks/index.js +4 -0
  104. package/dist/provider/hooks/mutations/index.js +24 -0
  105. package/dist/provider/hooks/mutations/useCheckIfUserExists.js +23 -0
  106. package/dist/provider/hooks/mutations/useCreateUser.js +20 -0
  107. package/dist/provider/hooks/mutations/useInitiateLogin.js +23 -0
  108. package/dist/provider/hooks/mutations/useKeepSessionAlive.js +20 -0
  109. package/dist/provider/hooks/mutations/useLogout.js +30 -0
  110. package/dist/provider/hooks/mutations/useSignMessage.js +33 -0
  111. package/dist/provider/hooks/mutations/useSignTransaction.js +33 -0
  112. package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +30 -0
  113. package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +30 -0
  114. package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +30 -0
  115. package/dist/provider/hooks/queries/index.js +8 -0
  116. package/dist/provider/hooks/queries/useAccount.js +21 -0
  117. package/dist/provider/hooks/queries/useWallet.js +22 -0
  118. package/dist/provider/hooks/utils/index.js +10 -0
  119. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
  120. package/dist/provider/hooks/utils/useClient.js +10 -0
  121. package/dist/provider/hooks/utils/useEventListeners.js +105 -0
  122. package/dist/provider/hooks/utils/useInternalClient.js +10 -0
  123. package/dist/provider/hooks/utils/useModal.js +17 -0
  124. package/dist/provider/hooks/utils/useWalletState.js +33 -0
  125. package/dist/provider/index.js +8 -0
  126. package/dist/provider/stores/getters.js +13 -0
  127. package/dist/provider/stores/slices/client.js +9 -0
  128. package/dist/provider/stores/slices/index.js +4 -0
  129. package/dist/provider/stores/slices/modal.js +9 -0
  130. package/dist/provider/stores/slices/wallet.js +11 -0
  131. package/dist/provider/stores/types.js +1 -0
  132. package/dist/provider/stores/useStore.js +27 -0
  133. package/dist/provider/types/provider.js +1 -0
  134. package/dist/provider/types/query.js +1 -0
  135. package/dist/provider/types/utils.js +1 -0
  136. package/dist/provider/utils/renameMutations.js +16 -0
  137. package/package.json +5 -5
  138. package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
  139. package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
  140. package/dist/chunk-MMUBH76A.js.br +0 -0
  141. package/dist/chunk-MMUBH76A.js.gz +0 -0
  142. package/dist/index.js.br +0 -0
  143. package/dist/index.js.gz +0 -0
@@ -0,0 +1,337 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __objRest,
5
+ __spreadValues
6
+ } from "../chunk-MMUBH76A.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { CpslAuthModal, defineCustomElements, generateTheme } from "@getpara/react-components";
9
+ import { ModalContent } from "./components/index.js";
10
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "react";
11
+ import { useModalStore, useUserInfoStore, useThemeStore } from "./stores/index.js";
12
+ import { ModalStep, RESET_TO_ACCOUNT_STEPS, RESET_TO_AUTH_STEPS } from "./utils/steps.js";
13
+ import { AuthLayout } from "./types/modalProps.js";
14
+ import { DEFAULTS } from "./constants/defaults.js";
15
+ import { useGoBack } from "./hooks/useGoBack.js";
16
+ import { isPasskeySupported, ParaEvent } from "@getpara/web-sdk";
17
+ import { ExternalWalletsWrapper } from "./components/ExternalWalletsWrapper/ExternalWalletsWrapper.js";
18
+ import styled from "styled-components";
19
+ import { useExternalWallets } from "./providers/ExternalWalletContext.js";
20
+ import { hasEmbeddedAuth, hasExternalWallet } from "./utils/authLayoutHelpers.js";
21
+ import { useModal, useWalletState } from "../provider/index.js";
22
+ import { useStore } from "../provider/stores/useStore.js";
23
+ import { useInternalClient } from "../provider/hooks/utils/useInternalClient.js";
24
+ defineCustomElements();
25
+ const ParaModal = forwardRef((_a, ref) => {
26
+ var _b = _a, { para, isOpen } = _b, rest = __objRest(_b, ["para", "isOpen"]);
27
+ const [isInitialized, setIsInitialized] = useState(false);
28
+ const setClient = useStore((state) => state.setClient);
29
+ const client = useStore((state) => state.client);
30
+ const { closeModal, openModal } = useModal();
31
+ useEffect(() => {
32
+ if (!client) {
33
+ setClient(para);
34
+ }
35
+ setIsInitialized(true);
36
+ }, []);
37
+ useEffect(() => {
38
+ if (!isOpen) {
39
+ closeModal();
40
+ }
41
+ if (isOpen) {
42
+ openModal();
43
+ }
44
+ }, [isOpen]);
45
+ if (!isInitialized) {
46
+ return null;
47
+ }
48
+ return /* @__PURE__ */ jsx(ParaModalInner, __spreadValues({ ref, para }, rest));
49
+ });
50
+ const ParaModalInner = forwardRef(
51
+ (_c, ref) => {
52
+ var _d = _c, {
53
+ theme,
54
+ appName,
55
+ logo,
56
+ disableEmailLogin = false,
57
+ disablePhoneLogin = false,
58
+ oAuthMethods,
59
+ bareModal = false,
60
+ className,
61
+ currentStepOverride,
62
+ externalWallets,
63
+ authLayout = [AuthLayout.AUTH_FULL, AuthLayout.EXTERNAL_FULL],
64
+ embeddedModal,
65
+ onModalStepChange,
66
+ hideWallets = false,
67
+ onClose
68
+ } = _d, rest = __objRest(_d, [
69
+ "theme",
70
+ "appName",
71
+ "logo",
72
+ "disableEmailLogin",
73
+ "disablePhoneLogin",
74
+ "oAuthMethods",
75
+ "bareModal",
76
+ "className",
77
+ "currentStepOverride",
78
+ "externalWallets",
79
+ "authLayout",
80
+ "embeddedModal",
81
+ "onModalStepChange",
82
+ "hideWallets",
83
+ "onClose"
84
+ ]);
85
+ const modalContentRef = useRef(null);
86
+ const updateThemeState = useThemeStore((state) => state.updateState);
87
+ const refs = useModalStore((state) => state.refs);
88
+ const setWebAuthURLForLogin = useModalStore((state) => state.setWebAuthURLForLogin);
89
+ const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
90
+ const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
91
+ const currentStep = useModalStore((state) => state.step);
92
+ const setOnModalStepChange = useModalStore((state) => state.setOnModalStepChange);
93
+ const setStep = useModalStore((state) => state.setStep);
94
+ const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
95
+ const hasPreviousStep = useModalStore((state) => state.hasPreviousStep());
96
+ const setFlow = useModalStore((state) => state.setFlow);
97
+ const setIsFullyLoggedIn = useModalStore((state) => state.setIsFullyLoggedIn);
98
+ const goBack = useGoBack();
99
+ const setAuthLayout = useThemeStore((state) => state.setAuthLayout);
100
+ const storedAuthLayout = useThemeStore((state) => state.authLayout);
101
+ const resetModalState = useModalStore((state) => state.resetState);
102
+ const resetUserInfoState = useUserInfoStore((state) => state.resetState);
103
+ const setRecoveryShare = useUserInfoStore((state) => state.setRecoveryShare);
104
+ const { disconnectExternalWallet } = useExternalWallets();
105
+ const { isOpen, closeModal } = useModal();
106
+ const para = useInternalClient();
107
+ const { selectedWallet, setSelectedWallet } = useWalletState();
108
+ const setIsPasskeySupported = useModalStore((state) => state.setIsPasskeySupported);
109
+ const [isModalMounted, setIsModalMounted] = useState(false);
110
+ const [isInit, setIsInit] = useState(false);
111
+ const [ready, setIsReady] = useState(false);
112
+ useImperativeHandle(ref, () => {
113
+ return {
114
+ goBack() {
115
+ goBack();
116
+ },
117
+ canGoBack() {
118
+ return hasPreviousStep;
119
+ },
120
+ currentStep() {
121
+ return currentStep;
122
+ },
123
+ handleModalClose() {
124
+ var _a;
125
+ (_a = modalContentRef == null ? void 0 : modalContentRef.current) == null ? void 0 : _a.handleModalClose();
126
+ }
127
+ };
128
+ }, [hasPreviousStep, currentStep]);
129
+ const initModal = () => __async(void 0, null, function* () {
130
+ const isAccount = yield para.isFullyLoggedIn();
131
+ setIsPasskeySupported(yield isPasskeySupported());
132
+ if (currentStepOverride) {
133
+ setStep(ModalStep[currentStepOverride.toUpperCase()]);
134
+ } else if (isAccount) {
135
+ setFlow("account");
136
+ setStep(ModalStep.ACCOUNT_MAIN);
137
+ setIsFullyLoggedIn(true);
138
+ } else {
139
+ if (currentStep !== ModalStep.AUTH_MAIN && currentStep !== ModalStep.SECRET) {
140
+ setStep(ModalStep.AUTH_MAIN);
141
+ setFlow();
142
+ setWebAuthURLForLogin();
143
+ setWebAuthURLForCreate();
144
+ setBiometricLocationHints();
145
+ }
146
+ yield disconnectExternalWallet();
147
+ setSelectedWallet({ id: void 0, type: void 0 });
148
+ setIsFullyLoggedIn(false);
149
+ }
150
+ switch (true) {
151
+ case para.isEmail:
152
+ setAuthInfo({ email: para.getEmail() });
153
+ break;
154
+ case para.isPhone:
155
+ {
156
+ const { phone, countryCode } = para.getPhone();
157
+ setAuthInfo({ phone, countryCode });
158
+ }
159
+ break;
160
+ case para.isFarcaster:
161
+ setAuthInfo({ farcasterUsername: para.getFarcasterUsername() });
162
+ break;
163
+ case para.isTelegram:
164
+ setAuthInfo({ telegramUserId: para.telegramUserId });
165
+ if (!isAccount) {
166
+ setStep(ModalStep.TELEGRAM_OAUTH);
167
+ }
168
+ break;
169
+ }
170
+ setIsInit(true);
171
+ });
172
+ useEffect(() => {
173
+ let _authLayout = authLayout;
174
+ if (!(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout)) {
175
+ _authLayout = _authLayout.filter((l) => !l.includes("EXTERNAL"));
176
+ }
177
+ if (disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout)) {
178
+ _authLayout = _authLayout.filter((l) => !l.includes("AUTH"));
179
+ }
180
+ if (JSON.stringify(storedAuthLayout) !== JSON.stringify(_authLayout)) {
181
+ setAuthLayout(_authLayout);
182
+ }
183
+ }, [disableEmailLogin, disablePhoneLogin, oAuthMethods, externalWallets, authLayout]);
184
+ useEffect(() => {
185
+ setOnModalStepChange(onModalStepChange);
186
+ }, [onModalStepChange]);
187
+ useEffect(() => {
188
+ var _a;
189
+ updateThemeState({
190
+ logo,
191
+ appName,
192
+ oAuthLogoVariant: (_a = theme == null ? void 0 : theme.oAuthLogoVariant) != null ? _a : "default",
193
+ bareModal,
194
+ embeddedModal,
195
+ hideWallets
196
+ });
197
+ }, [logo, appName, theme == null ? void 0 : theme.oAuthLogoVariant, bareModal, embeddedModal, hideWallets]);
198
+ useEffect(() => {
199
+ if (theme) {
200
+ generateTheme(theme);
201
+ updateThemeState({ isDark: theme.mode === "dark", theme });
202
+ }
203
+ }, [theme]);
204
+ useEffect(() => {
205
+ if (para) {
206
+ initModal();
207
+ if (bareModal) {
208
+ setIsModalMounted(true);
209
+ }
210
+ } else {
211
+ console.error("A Para instance must be provided.");
212
+ }
213
+ }, []);
214
+ useEffect(() => {
215
+ if (isOpen && para) {
216
+ initModal();
217
+ }
218
+ }, [isOpen]);
219
+ const updateActiveWallet = () => {
220
+ if (!(selectedWallet == null ? void 0 : selectedWallet.id) || !para.findWallet(selectedWallet == null ? void 0 : selectedWallet.id)) {
221
+ const defaultWallet = para.findWallet(void 0, void 0, { forbidPregen: true });
222
+ setSelectedWallet({ id: defaultWallet == null ? void 0 : defaultWallet.id, type: defaultWallet == null ? void 0 : defaultWallet.type });
223
+ }
224
+ };
225
+ useEffect(() => {
226
+ updateActiveWallet();
227
+ }, [para]);
228
+ useEffect(() => {
229
+ const closePopupWindow = () => {
230
+ var _a;
231
+ (_a = refs.popupWindow.current) == null ? void 0 : _a.close();
232
+ };
233
+ if (typeof window !== "undefined") {
234
+ window.addEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
235
+ window.addEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
236
+ window.addEventListener("beforeunload", closePopupWindow);
237
+ }
238
+ setIsReady(true);
239
+ return () => {
240
+ if (typeof window !== "undefined") {
241
+ window.removeEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
242
+ window.removeEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
243
+ window.removeEventListener("beforeunload", closePopupWindow);
244
+ }
245
+ };
246
+ }, []);
247
+ const handleClose = () => {
248
+ closeModal();
249
+ onClose == null ? void 0 : onClose();
250
+ };
251
+ const handleModalEntering = () => {
252
+ setIsModalMounted(true);
253
+ };
254
+ const handleModalExited = () => __async(void 0, null, function* () {
255
+ if (!bareModal) {
256
+ setIsModalMounted(false);
257
+ }
258
+ if (RESET_TO_AUTH_STEPS.includes(currentStep)) {
259
+ resetModalState();
260
+ resetUserInfoState();
261
+ setRecoveryShare(null);
262
+ } else if (RESET_TO_ACCOUNT_STEPS.includes(currentStep)) {
263
+ setStep(ModalStep.LOGIN_DONE);
264
+ }
265
+ if (para) {
266
+ yield initModal();
267
+ para.exitLoops();
268
+ }
269
+ if (!bareModal) {
270
+ setIsInit(false);
271
+ }
272
+ });
273
+ if (!ready) {
274
+ return null;
275
+ }
276
+ if (!para) {
277
+ console.error("A Para instance is required.");
278
+ return null;
279
+ }
280
+ if (!(storedAuthLayout == null ? void 0 : storedAuthLayout.length)) {
281
+ const hasExternalWalletError = !(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout);
282
+ const hasEmbeddedWalletError = disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout);
283
+ if (hasExternalWalletError || hasEmbeddedWalletError) {
284
+ if (hasExternalWalletError) {
285
+ console.error("At least one external wallet must be provided if external wallet auth is enabled.");
286
+ }
287
+ if (hasEmbeddedWalletError) {
288
+ console.error(
289
+ "At least one login method (email, phone or OAuth) must be provided if embedded wallet auth is enabled."
290
+ );
291
+ }
292
+ } else {
293
+ console.error("At least one auth layout selection is required.");
294
+ }
295
+ return null;
296
+ }
297
+ return /* @__PURE__ */ jsx(ExternalWalletsWrapper, { wallets: externalWallets, children: /* @__PURE__ */ jsx(
298
+ StyledAuthModal,
299
+ {
300
+ enterTransitionDuration: DEFAULTS.ANIMATION_DURATION,
301
+ exitTransitionDuration: DEFAULTS.ANIMATION_DURATION,
302
+ open: isOpen,
303
+ onCpslModalExited: handleModalExited,
304
+ onCpslModalEntering: handleModalEntering,
305
+ onCpslModalRequestClose: handleClose,
306
+ noOverlay: bareModal,
307
+ className,
308
+ "data-testid": "modal",
309
+ $embeddedModal: embeddedModal,
310
+ children: isModalMounted && (isInit && embeddedModal || !embeddedModal) && /* @__PURE__ */ jsx(
311
+ ModalContent,
312
+ __spreadValues({
313
+ oAuthMethods,
314
+ disableEmailLogin,
315
+ disablePhoneLogin,
316
+ onClose: handleClose
317
+ }, rest)
318
+ )
319
+ }
320
+ ) });
321
+ }
322
+ );
323
+ const StyledAuthModal = styled(CpslAuthModal)`
324
+ ${({ $embeddedModal }) => $embeddedModal && `
325
+ &::part(modal-body-card) {
326
+ --card-box-shadow: none;
327
+ --card-border-width: 0px;
328
+ };
329
+
330
+ &::part(modal-footer) {
331
+ --card-box-shadow: none;
332
+ --card-border-width: 0px;
333
+ };`}
334
+ `;
335
+ export {
336
+ ParaModal
337
+ };
@@ -0,0 +1,69 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../../../chunk-MMUBH76A.js";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+ import styled from "styled-components";
7
+ import { InnerStepContainer, StepContainer, StyledCpslTileButton } from "../common.js";
8
+ import { CpslButton, CpslIcon, CpslSpinner, CpslText } from "@getpara/react-components";
9
+ import { useModalStore, useThemeStore } from "../../stores/index.js";
10
+ import { useExternalWallets } from "../../providers/ExternalWalletContext.js";
11
+ import { useState } from "react";
12
+ import { ModalStep } from "../../utils/steps.js";
13
+ import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
14
+ const Account = ({ onClose }) => {
15
+ const onRampConfig = useModalStore((state) => state.onRampConfig);
16
+ const setStep = useModalStore((state) => state.setStep);
17
+ const hideWallets = useThemeStore((state) => state.hideWallets);
18
+ const { disconnectExternalWallet } = useExternalWallets();
19
+ const para = useInternalClient();
20
+ const [isDisconnecting, setIsDisconnecting] = useState(false);
21
+ const isOnRampLoaded = !!onRampConfig;
22
+ const handleBuyClick = () => {
23
+ setStep(ModalStep.ADD_FUNDS_BUY);
24
+ };
25
+ const handleReceiveClick = () => {
26
+ setStep(ModalStep.ADD_FUNDS_RECEIVE);
27
+ };
28
+ const handleSellClick = () => {
29
+ setStep(ModalStep.ADD_FUNDS_WITHDRAW);
30
+ };
31
+ const handleDisconnectClick = () => __async(void 0, null, function* () {
32
+ setIsDisconnecting(true);
33
+ yield para.logout();
34
+ yield disconnectExternalWallet();
35
+ onClose();
36
+ setStep(ModalStep.AUTH_MAIN);
37
+ setIsDisconnecting(false);
38
+ });
39
+ return /* @__PURE__ */ jsx(StepContainer, { $wide: true, children: /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
40
+ /* @__PURE__ */ jsx(ButtonContainer, { children: isOnRampLoaded ? /* @__PURE__ */ jsxs(Fragment, { children: [
41
+ onRampConfig.isBuyEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "creditCard", onClick: handleBuyClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Buy Crypto" }) }),
42
+ onRampConfig.isReceiveEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "qrCode02", onClick: handleReceiveClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Receive" }) }),
43
+ onRampConfig.isWithdrawEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "arrowCircleBrokenDownLeft", onClick: handleSellClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Withdraw" }) })
44
+ ] }) : /* @__PURE__ */ jsx(CpslSpinner, {}) }),
45
+ /* @__PURE__ */ jsx(DisconnectButton, { variant: "destructive", fullWidth: true, onClick: handleDisconnectClick, disabled: isDisconnecting, children: isDisconnecting ? /* @__PURE__ */ jsx(CpslSpinner, { size: 16 }) : /* @__PURE__ */ jsxs(Fragment, { children: [
46
+ hideWallets ? "Logout" : "Disconnect Wallet",
47
+ /* @__PURE__ */ jsx(CpslIcon, { icon: "logOut", slot: "end" })
48
+ ] }) })
49
+ ] }) });
50
+ };
51
+ const ButtonContainer = styled.div`
52
+ display: flex;
53
+ align-items: center;
54
+ justify-content: center;
55
+ gap: 8px;
56
+ width: 100%;
57
+ height: 88px;
58
+ `;
59
+ const OptionButton = styled(StyledCpslTileButton)`
60
+ flex: 1;
61
+
62
+ --button-icon-color: var(--cpsl-color-text-primary);
63
+ `;
64
+ const DisconnectButton = styled(CpslButton)`
65
+ --button-border-width: 0px;
66
+ `;
67
+ export {
68
+ Account
69
+ };
@@ -0,0 +1,220 @@
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 {
9
+ EnabledFlow,
10
+ getOnRampAssets,
11
+ getOnRampNetworks,
12
+ OnRampProvider,
13
+ OnRampPurchaseType,
14
+ toAssetInfoArray,
15
+ WalletType
16
+ } from "@getpara/web-sdk";
17
+ import { CenteredText, FilledDisabledInput, Heading, InnerStepContainer, QRContainer, StepContainer } from "../common.js";
18
+ import {
19
+ CpslButton,
20
+ CpslDivider,
21
+ CpslIcon,
22
+ CpslIdenticon,
23
+ CpslQrCode,
24
+ CpslSpinner,
25
+ CpslTab,
26
+ CpslTabs,
27
+ CpslText
28
+ } from "@getpara/react-components";
29
+ import { useModalStore, useThemeStore } from "../../stores/index.js";
30
+ import { useEffect, useMemo } from "react";
31
+ import { OnRampProviderButton } from "../OnRampComponents/OnRampProviderButton.js";
32
+ import { isMobile } from "@getpara/web-sdk";
33
+ import { useActiveWallet } from "../../hooks/useActiveWallet.js";
34
+ import { getAddFundsStep, ModalStep } from "../../utils/steps.js";
35
+ import { motion, AnimatePresence } from "framer-motion";
36
+ import { useExternalWallets } from "../../providers/ExternalWalletContext.js";
37
+ import { getNetworkFromChainId, getNetworkOrMainNetEquivalent, useCopyToClipboard } from "@getpara/react-common";
38
+ import { formatNetworkList } from "../../utils/stringFormatters.js";
39
+ import styled from "styled-components";
40
+ import { useInternalClient } from "../../../provider/hooks/utils/useInternalClient.js";
41
+ const TABS = [
42
+ [EnabledFlow.BUY, "isBuyEnabled", "creditCard", "Buy"],
43
+ [EnabledFlow.RECEIVE, "isReceiveEnabled", "qrCode", "Receive"],
44
+ [EnabledFlow.WITHDRAW, "isWithdrawEnabled", "arrowCircleBrokenDownLeft", "Withdraw"]
45
+ ];
46
+ const GENERIC_WALLET = {
47
+ [WalletType.EVM]: "Ethereum or EVM-based L2s",
48
+ [WalletType.SOLANA]: "Solana",
49
+ [WalletType.COSMOS]: "Cosmos"
50
+ };
51
+ const AddFunds = () => {
52
+ const [isCopied, copy] = useCopyToClipboard();
53
+ const para = useInternalClient();
54
+ const appName = useThemeStore((state) => state.appName);
55
+ const onRampConfig = useModalStore((state) => state.onRampConfig);
56
+ const hideWallets = useThemeStore((state) => state.hideWallets);
57
+ const storedTab = useModalStore((state) => state.accountAddFundTab);
58
+ const setStep = useModalStore((state) => state.setStep);
59
+ const setOnRampPurchase = useModalStore((state) => state.setOnRampPurchase);
60
+ const { chainId } = useExternalWallets();
61
+ const activeWallet = useActiveWallet();
62
+ const tabs = TABS.filter(([, key]) => !!onRampConfig[key]);
63
+ const isMultiFlow = tabs.length > 1;
64
+ const tab = storedTab != null ? storedTab : tabs[0][0];
65
+ const address = useMemo(
66
+ () => activeWallet ? para.getDisplayAddress(activeWallet.id, { addressType: activeWallet.type }) : "",
67
+ [para, activeWallet == null ? void 0 : activeWallet.id, activeWallet == null ? void 0 : activeWallet.type]
68
+ );
69
+ const onSetTab = (event) => {
70
+ setStep(getAddFundsStep(event.detail.tab));
71
+ };
72
+ const onCopy = () => {
73
+ copy(address);
74
+ };
75
+ const [allowedNetworks, allowedAssets, isProviderAllowed] = useMemo(() => {
76
+ if (!onRampConfig || !activeWallet) {
77
+ return [[], [], {}];
78
+ }
79
+ const action = tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL;
80
+ const detectedNetwork = getNetworkFromChainId(chainId);
81
+ const isExternal = activeWallet.isExternal && !!detectedNetwork;
82
+ const allowedNetworks2 = isExternal ? [getNetworkOrMainNetEquivalent(detectedNetwork, onRampConfig.testMode)] : getOnRampNetworks(onRampConfig.assetInfo, {
83
+ walletType: activeWallet.type,
84
+ allowed: onRampConfig.allowedAssets ? Object.keys(onRampConfig.allowedAssets) : void 0
85
+ });
86
+ const allowedAssetsLookup = allowedNetworks2.reduce((acc, network) => {
87
+ var _a;
88
+ const configValue = (_a = onRampConfig.allowedAssets) == null ? void 0 : _a[network];
89
+ const allowed = configValue === true ? void 0 : configValue;
90
+ return __spreadProps(__spreadValues({}, acc), {
91
+ [network]: getOnRampAssets(onRampConfig.assetInfo, { walletType: activeWallet.type, network, allowed })
92
+ });
93
+ }, {});
94
+ const isProviderAllowed2 = onRampConfig.providers.reduce(
95
+ (acc, id) => {
96
+ const hasMatch = toAssetInfoArray(onRampConfig.assetInfo).some(([type, network, asset, validProviders]) => {
97
+ var _a, _b;
98
+ return type === activeWallet.type && allowedNetworks2.includes(network) && (!allowedAssetsLookup[network] || allowedAssetsLookup[network].includes(asset)) && !!((_b = (_a = validProviders[id]) == null ? void 0 : _a[1]) == null ? void 0 : _b[action]);
99
+ });
100
+ return __spreadProps(__spreadValues({}, acc), {
101
+ [id]: hasMatch
102
+ });
103
+ },
104
+ {}
105
+ );
106
+ return [allowedNetworks2, [...new Set(Object.values(allowedAssetsLookup).flat())], isProviderAllowed2];
107
+ }, [activeWallet == null ? void 0 : activeWallet.type, activeWallet == null ? void 0 : activeWallet.isExternal, tab, onRampConfig.assetInfo, onRampConfig.allowedAssets, chainId]);
108
+ useEffect(() => {
109
+ setOnRampPurchase(void 0);
110
+ }, []);
111
+ useEffect(() => {
112
+ setOnRampPurchase(void 0);
113
+ }, []);
114
+ if (!onRampConfig || !activeWallet) {
115
+ return /* @__PURE__ */ jsx(SpinnerContainer, { children: /* @__PURE__ */ jsx(CpslSpinner, {}) });
116
+ }
117
+ useEffect(() => {
118
+ setOnRampPurchase(void 0);
119
+ }, []);
120
+ return /* @__PURE__ */ jsxs(StepContainer, { children: [
121
+ isMultiFlow && /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsx(CpslTabs, { selectedTab: tab, onCpslTabsChanged: onSetTab, children: TABS.map(([tab2, _, icon, title]) => /* @__PURE__ */ jsxs(CpslTab, { tab: tab2, children: [
122
+ /* @__PURE__ */ jsx(CpslIcon, { slot: "start", icon }),
123
+ title
124
+ ] }, tab2)) }) }),
125
+ /* @__PURE__ */ jsx(Fragment, { children: [EnabledFlow.BUY, EnabledFlow.WITHDRAW].includes(tab) ? /* @__PURE__ */ jsxs(Fragment, { children: [
126
+ /* @__PURE__ */ jsx(Heading, { variant: "headingS", weight: "bold", children: "Choose Provider" }),
127
+ /* @__PURE__ */ jsxs($InnerStepContainer, { children: [
128
+ /* @__PURE__ */ jsxs(NoProviders, { isHidden: Object.values(isProviderAllowed).some((v) => !!v), variant: "bodyM", children: [
129
+ "No providers are available for this ",
130
+ hideWallets ? "account" : "wallet"
131
+ ] }),
132
+ /* @__PURE__ */ jsx(AnimatePresence, { children: onRampConfig.providers.map((id, index) => {
133
+ return isProviderAllowed[id] ? /* @__PURE__ */ jsx(
134
+ motion.div,
135
+ {
136
+ style: { width: "100%" },
137
+ layout: true,
138
+ initial: { opacity: 0, transform: "translateX(25px)" },
139
+ animate: { opacity: 1, transform: "none" },
140
+ exit: { opacity: 0, transform: "translateX(-25px)" },
141
+ transition: { duration: 0.2 },
142
+ children: /* @__PURE__ */ jsx(
143
+ OnRampProviderButton,
144
+ {
145
+ config: onRampConfig,
146
+ index,
147
+ onClick: () => __async(void 0, null, function* () {
148
+ var _a;
149
+ if (!(activeWallet == null ? void 0 : activeWallet.type)) return;
150
+ const isPopup = id !== OnRampProvider.RAMP;
151
+ const { onRampPurchase: newOnRampPurchase } = yield para.initiateOnRampTransaction({
152
+ walletId: activeWallet.isExternal ? void 0 : activeWallet.id,
153
+ externalWalletAddress: activeWallet.isExternal ? activeWallet.id : void 0,
154
+ shouldOpenPopup: isPopup,
155
+ params: {
156
+ type: tab === EnabledFlow.BUY ? OnRampPurchaseType.BUY : OnRampPurchaseType.SELL,
157
+ walletType: activeWallet.type,
158
+ provider: id,
159
+ networks: allowedNetworks,
160
+ assets: allowedAssets,
161
+ defaultNetwork: onRampConfig.defaultOnRampNetwork,
162
+ defaultAsset: onRampConfig.defaultOnRampAsset,
163
+ fiatQuantity: (_a = onRampConfig.defaultBuyAmount) == null ? void 0 : _a[0],
164
+ testMode: onRampConfig.testMode
165
+ }
166
+ });
167
+ setOnRampPurchase(__spreadProps(__spreadValues({}, newOnRampPurchase), { fiat: "USD" }));
168
+ !isPopup && setStep(ModalStep.ADD_FUNDS_AWAITING);
169
+ })
170
+ },
171
+ id
172
+ )
173
+ },
174
+ id
175
+ ) : null;
176
+ }) })
177
+ ] })
178
+ ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
179
+ /* @__PURE__ */ jsx(InnerStepContainer, { children: /* @__PURE__ */ jsxs(FilledDisabledInput, { noAutoDisable: true, readonly: true, placeholder: address, children: [
180
+ /* @__PURE__ */ jsx(CpslIdenticon, { slot: "start", size: "32px", hash: para.getIdenticonHash(activeWallet.id, activeWallet.type) }),
181
+ /* @__PURE__ */ jsx(CpslButton, { slot: "end", variant: "ghost", onClick: onCopy, children: /* @__PURE__ */ jsx(CpslIcon, { icon: isCopied ? "check" : "copy" }) })
182
+ ] }, address) }),
183
+ !isMobile() && /* @__PURE__ */ jsxs(Fragment, { children: [
184
+ /* @__PURE__ */ jsx(CpslDivider, { children: "or" }),
185
+ /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
186
+ /* @__PURE__ */ jsx(QRContainer, { children: !address ? /* @__PURE__ */ jsx(CpslSpinner, { size: 100 }) : /* @__PURE__ */ jsx(CpslQrCode, { url: address }, address) }),
187
+ /* @__PURE__ */ jsx(CpslText, { weight: "semiBold", color: "secondary", children: "Scan with your crypto wallet" })
188
+ ] })
189
+ ] }),
190
+ /* @__PURE__ */ jsxs(InnerStepContainer, { children: [
191
+ /* @__PURE__ */ jsxs(CenteredText, { weight: "semiBold", children: [
192
+ !!onRampConfig.allowedAssets && allowedNetworks.length > 0 || hideWallets ? appName != null ? appName : "This App" : "This Wallet",
193
+ " ",
194
+ "Only Supports:"
195
+ ] }),
196
+ /* @__PURE__ */ jsx(CenteredText, { weight: "medium", color: "secondary", children: !!onRampConfig.allowedAssets && allowedNetworks.length > 0 ? formatNetworkList(allowedNetworks) : GENERIC_WALLET[activeWallet.type] })
197
+ ] })
198
+ ] }) })
199
+ ] });
200
+ };
201
+ const SpinnerContainer = styled(StepContainer)`
202
+ margin: 50% 0;
203
+ `;
204
+ const $InnerStepContainer = styled(InnerStepContainer)`
205
+ position: relative;
206
+ min-height: 270px;
207
+ `;
208
+ const NoProviders = styled(CpslText)`
209
+ width: 100%;
210
+ text-align: center;
211
+ visibility: ${({ isHidden }) => isHidden ? "hidden" : "visible"};
212
+ position: absolute;
213
+ top: 0;
214
+ left: 0;
215
+ right: 0;
216
+ transition: visibility 0.2s;
217
+ `;
218
+ export {
219
+ AddFunds
220
+ };