@getpara/react-sdk 1.7.1 → 1.9.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 (160) hide show
  1. package/dist/index.js +6 -6659
  2. package/dist/modal/ParaModal.js +364 -0
  3. package/dist/modal/components/Account/Account.js +77 -0
  4. package/dist/modal/components/AddFunds/AddFunds.js +220 -0
  5. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +72 -0
  6. package/dist/modal/components/AddFunds/AddFundsDone.js +43 -0
  7. package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
  8. package/dist/modal/components/AddFunds/index.js +4 -0
  9. package/dist/modal/components/AuthInput/AuthInput.js +283 -0
  10. package/dist/modal/components/AuthInput/countryCodes.js +42 -0
  11. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
  12. package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
  13. package/dist/modal/components/AuthMainStep/AuthMainStep.js +37 -0
  14. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +113 -0
  15. package/dist/modal/components/AuthOptions/AuthOptions.js +33 -0
  16. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
  17. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
  18. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
  19. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +44 -0
  20. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.d.ts +3 -1
  21. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +55 -0
  22. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +93 -0
  23. package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
  24. package/dist/modal/components/Body/Body.js +308 -0
  25. package/dist/modal/components/ChainSwitch/ChainSwitch.js +94 -0
  26. package/dist/modal/components/ChainSwitch/config.js +17 -0
  27. package/dist/modal/components/Controls/Controls.js +74 -0
  28. package/dist/modal/components/Controls/Selects.js +234 -0
  29. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +140 -0
  30. package/dist/modal/components/ExternalWalletStep/config.js +17 -0
  31. package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +96 -0
  32. package/dist/modal/components/ExternalWallets/ExternalWallets.js +172 -0
  33. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +124 -0
  34. package/dist/modal/components/Footer/Footer.js +93 -0
  35. package/dist/modal/components/Header/Header.js +43 -0
  36. package/dist/modal/components/Header/hooks/useStepTitle.js +50 -0
  37. package/dist/modal/components/Hero/Hero.js +116 -0
  38. package/dist/modal/components/IFrameStep/IFrameStep.js +55 -0
  39. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +28 -0
  40. package/dist/modal/components/ModalContent/ModalContent.js +324 -0
  41. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
  42. package/dist/modal/components/OAuth/OAuth.js +153 -0
  43. package/dist/modal/components/OAuth/TelegramOAuthStep.js +139 -0
  44. package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
  45. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
  46. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +101 -0
  47. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +141 -0
  48. package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
  49. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +24 -0
  50. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +159 -0
  51. package/dist/modal/components/Waiting/Waiting.js +17 -0
  52. package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
  53. package/dist/modal/components/WalletCard/WalletCard.js +127 -0
  54. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +52 -0
  55. package/dist/modal/components/common.d.ts +6 -6
  56. package/dist/modal/components/common.js +96 -0
  57. package/dist/modal/components/index.js +2 -0
  58. package/dist/modal/constants/constants.d.ts +1 -1
  59. package/dist/modal/constants/constants.js +112 -0
  60. package/dist/modal/constants/defaults.js +10 -0
  61. package/dist/modal/constants/oAuthLogos.js +24 -0
  62. package/dist/modal/hooks/useActiveWallet.js +15 -0
  63. package/dist/modal/hooks/useCreateAccount.d.ts +3 -1
  64. package/dist/modal/hooks/useCreateAccount.js +77 -0
  65. package/dist/modal/hooks/useEmbeddedExternalConnection.js +54 -0
  66. package/dist/modal/hooks/useGoBack.js +42 -0
  67. package/dist/modal/hooks/useSetLoginURLs.js +49 -0
  68. package/dist/modal/hooks/useWalletBalance.d.ts +4 -0
  69. package/dist/modal/hooks/useWalletBalance.js +47 -0
  70. package/dist/modal/index.js +33 -0
  71. package/dist/modal/providers/CosmosExternalWalletContextStub.js +38 -0
  72. package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +2 -0
  73. package/dist/modal/providers/EvmExternalWalletContextStub.js +55 -0
  74. package/dist/modal/providers/ExternalWalletContext.d.ts +3 -0
  75. package/dist/modal/providers/ExternalWalletContext.js +394 -0
  76. package/dist/modal/providers/SolanaExternalWalletContextStub.js +32 -0
  77. package/dist/modal/stores/externalWalletProvider/actions.js +10 -0
  78. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +21 -0
  79. package/dist/modal/stores/index.js +4 -0
  80. package/dist/modal/stores/modal/actions.js +70 -0
  81. package/dist/modal/stores/modal/useModalStore.js +65 -0
  82. package/dist/modal/stores/theme/actions.js +28 -0
  83. package/dist/modal/stores/theme/useThemeStore.js +21 -0
  84. package/dist/modal/stores/userInfo/actions.js +30 -0
  85. package/dist/modal/stores/userInfo/useUserInfoStore.js +17 -0
  86. package/dist/modal/types/commonTypes.js +1 -0
  87. package/dist/modal/types/externalWallets.js +32 -0
  88. package/dist/modal/types/modalProps.d.ts +4 -0
  89. package/dist/modal/types/modalProps.js +12 -0
  90. package/dist/modal/utils/authLayoutHelpers.js +8 -0
  91. package/dist/modal/utils/getMailtoLink.js +10 -0
  92. package/dist/modal/utils/getTileButtonFlex.js +20 -0
  93. package/dist/modal/utils/openPopup.js +60 -0
  94. package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
  95. package/dist/modal/utils/steps.js +232 -0
  96. package/dist/modal/utils/stringFormatters.d.ts +1 -0
  97. package/dist/modal/utils/stringFormatters.js +19 -0
  98. package/dist/modal/utils/validateOnRampConfig.js +32 -0
  99. package/dist/package.json +3 -1
  100. package/dist/provider/ParaProvider.js +22 -0
  101. package/dist/provider/actions/checkIfUserExists.js +21 -0
  102. package/dist/provider/actions/createUser.js +26 -0
  103. package/dist/provider/actions/getAccount.js +22 -0
  104. package/dist/provider/actions/getWallet.js +14 -0
  105. package/dist/provider/actions/getWalletBalance.d.ts +2 -0
  106. package/dist/provider/actions/getWalletBalance.js +14 -0
  107. package/dist/provider/actions/initiateLogin.js +20 -0
  108. package/dist/provider/actions/keepSessionAlive.js +20 -0
  109. package/dist/provider/actions/logout.js +17 -0
  110. package/dist/provider/actions/signMessage.js +20 -0
  111. package/dist/provider/actions/signTransaction.js +20 -0
  112. package/dist/provider/actions/waitForAccountCreation.js +21 -0
  113. package/dist/provider/actions/waitForLoginAndSetup.js +24 -0
  114. package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +21 -0
  115. package/dist/provider/hooks/index.js +4 -0
  116. package/dist/provider/hooks/mutations/index.js +24 -0
  117. package/dist/provider/hooks/mutations/useCheckIfUserExists.js +23 -0
  118. package/dist/provider/hooks/mutations/useCreateUser.js +20 -0
  119. package/dist/provider/hooks/mutations/useInitiateLogin.js +23 -0
  120. package/dist/provider/hooks/mutations/useKeepSessionAlive.js +20 -0
  121. package/dist/provider/hooks/mutations/useLogout.js +30 -0
  122. package/dist/provider/hooks/mutations/useSignMessage.js +39 -0
  123. package/dist/provider/hooks/mutations/useSignTransaction.js +39 -0
  124. package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +30 -0
  125. package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +30 -0
  126. package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +30 -0
  127. package/dist/provider/hooks/queries/index.d.ts +1 -0
  128. package/dist/provider/hooks/queries/index.js +10 -0
  129. package/dist/provider/hooks/queries/useAccount.js +21 -0
  130. package/dist/provider/hooks/queries/useWallet.js +22 -0
  131. package/dist/provider/hooks/queries/useWalletBalance.d.ts +7 -0
  132. package/dist/provider/hooks/queries/useWalletBalance.js +26 -0
  133. package/dist/provider/hooks/utils/index.js +10 -0
  134. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
  135. package/dist/provider/hooks/utils/useClient.js +10 -0
  136. package/dist/provider/hooks/utils/useEventListeners.js +105 -0
  137. package/dist/provider/hooks/utils/useInternalClient.js +10 -0
  138. package/dist/provider/hooks/utils/useModal.js +17 -0
  139. package/dist/provider/hooks/utils/useWalletState.js +33 -0
  140. package/dist/provider/index.js +8 -0
  141. package/dist/provider/stores/getters.js +13 -0
  142. package/dist/provider/stores/slices/client.js +9 -0
  143. package/dist/provider/stores/slices/index.js +4 -0
  144. package/dist/provider/stores/slices/modal.js +9 -0
  145. package/dist/provider/stores/slices/wallet.js +13 -0
  146. package/dist/provider/stores/types.d.ts +2 -0
  147. package/dist/provider/stores/types.js +1 -0
  148. package/dist/provider/stores/useStore.js +27 -0
  149. package/dist/provider/types/provider.js +1 -0
  150. package/dist/provider/types/query.js +1 -0
  151. package/dist/provider/types/utils.js +1 -0
  152. package/dist/provider/utils/constants.js +11 -0
  153. package/dist/provider/utils/renameMutations.js +16 -0
  154. package/package.json +5 -5
  155. package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
  156. package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
  157. package/dist/chunk-MMUBH76A.js.br +0 -0
  158. package/dist/chunk-MMUBH76A.js.gz +0 -0
  159. package/dist/index.js.br +0 -0
  160. package/dist/index.js.gz +0 -0
@@ -0,0 +1,364 @@
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 { hasEmbeddedAuth, hasExternalWallet } from "./utils/authLayoutHelpers.js";
20
+ import { useModal, useWalletState } from "../provider/index.js";
21
+ import { useStore } from "../provider/stores/useStore.js";
22
+ import { getExternalWalletDisplayName } from "@getpara/react-common";
23
+ import { useInternalClient } from "../provider/hooks/utils/useInternalClient.js";
24
+ import { useExternalWalletProviderStore } from "./stores/externalWalletProvider/useExternalWalletProviderStore.js";
25
+ defineCustomElements();
26
+ const ParaModal = forwardRef(
27
+ (_a, ref) => {
28
+ var _b = _a, { para, isOpen, externalWalletsWithParaAuth, rpcUrl: rpcUrlFromProps } = _b, rest = __objRest(_b, ["para", "isOpen", "externalWalletsWithParaAuth", "rpcUrl"]);
29
+ const [isInitialized, setIsInitialized] = useState(false);
30
+ const setClient = useStore((state) => state.setClient);
31
+ const client = useStore((state) => state.client);
32
+ const rpcUrl = useStore((state) => state.rpcUrl);
33
+ const setRpcUrl = useStore((state) => state.setRpcUrl);
34
+ const { closeModal, openModal } = useModal();
35
+ const updateExternalWalletProviderState = useExternalWalletProviderStore((state) => state.updateState);
36
+ useEffect(() => {
37
+ updateExternalWalletProviderState({ fullAuthWallets: externalWalletsWithParaAuth });
38
+ }, [externalWalletsWithParaAuth]);
39
+ useEffect(() => {
40
+ if (!client) {
41
+ setClient(para);
42
+ }
43
+ setIsInitialized(true);
44
+ }, []);
45
+ useEffect(() => {
46
+ if (rpcUrl !== rpcUrlFromProps) {
47
+ setRpcUrl(rpcUrlFromProps);
48
+ }
49
+ }, [rpcUrlFromProps]);
50
+ useEffect(() => {
51
+ if (!isOpen) {
52
+ closeModal();
53
+ }
54
+ if (isOpen) {
55
+ openModal();
56
+ }
57
+ }, [isOpen]);
58
+ if (!isInitialized) {
59
+ return null;
60
+ }
61
+ return /* @__PURE__ */ jsx(ParaModalInner, __spreadValues({ ref, para, externalWalletsWithParaAuth }, rest));
62
+ }
63
+ );
64
+ const ParaModalInner = forwardRef(
65
+ (_c, ref) => {
66
+ var _d = _c, {
67
+ theme,
68
+ appName,
69
+ logo,
70
+ disableEmailLogin = false,
71
+ disablePhoneLogin = false,
72
+ oAuthMethods,
73
+ bareModal = false,
74
+ className,
75
+ currentStepOverride,
76
+ externalWallets,
77
+ authLayout = [AuthLayout.AUTH_FULL, AuthLayout.EXTERNAL_FULL],
78
+ embeddedModal,
79
+ onModalStepChange,
80
+ hideWallets = false,
81
+ onClose,
82
+ externalWalletsWithParaAuth
83
+ } = _d, rest = __objRest(_d, [
84
+ "theme",
85
+ "appName",
86
+ "logo",
87
+ "disableEmailLogin",
88
+ "disablePhoneLogin",
89
+ "oAuthMethods",
90
+ "bareModal",
91
+ "className",
92
+ "currentStepOverride",
93
+ "externalWallets",
94
+ "authLayout",
95
+ "embeddedModal",
96
+ "onModalStepChange",
97
+ "hideWallets",
98
+ "onClose",
99
+ "externalWalletsWithParaAuth"
100
+ ]);
101
+ const modalContentRef = useRef(null);
102
+ const updateThemeState = useThemeStore((state) => state.updateState);
103
+ const refs = useModalStore((state) => state.refs);
104
+ const setWebAuthURLForLogin = useModalStore((state) => state.setWebAuthURLForLogin);
105
+ const setWebAuthURLForCreate = useModalStore((state) => state.setWebAuthURLForCreate);
106
+ const setBiometricLocationHints = useModalStore((state) => state.setBiometricLocationHints);
107
+ const currentStep = useModalStore((state) => state.step);
108
+ const setOnModalStepChange = useModalStore((state) => state.setOnModalStepChange);
109
+ const setStep = useModalStore((state) => state.setStep);
110
+ const setAuthInfo = useUserInfoStore((state) => state.setAuthInfo);
111
+ const hasPreviousStep = useModalStore((state) => state.hasPreviousStep());
112
+ const setFlow = useModalStore((state) => state.setFlow);
113
+ const setIsFullyLoggedIn = useModalStore((state) => state.setIsFullyLoggedIn);
114
+ const goBack = useGoBack();
115
+ const setAuthLayout = useThemeStore((state) => state.setAuthLayout);
116
+ const storedAuthLayout = useThemeStore((state) => state.authLayout);
117
+ const resetModalState = useModalStore((state) => state.resetState);
118
+ const resetUserInfoState = useUserInfoStore((state) => state.resetState);
119
+ const setRecoveryShare = useUserInfoStore((state) => state.setRecoveryShare);
120
+ const { isOpen, closeModal } = useModal();
121
+ const para = useInternalClient();
122
+ const { selectedWallet, setSelectedWallet } = useWalletState();
123
+ const setIsPasskeySupported = useModalStore((state) => state.setIsPasskeySupported);
124
+ const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
125
+ const [isModalMounted, setIsModalMounted] = useState(false);
126
+ const [isInit, setIsInit] = useState(false);
127
+ const [ready, setIsReady] = useState(false);
128
+ useImperativeHandle(ref, () => {
129
+ return {
130
+ goBack() {
131
+ goBack();
132
+ },
133
+ canGoBack() {
134
+ return hasPreviousStep;
135
+ },
136
+ currentStep() {
137
+ return currentStep;
138
+ },
139
+ handleModalClose() {
140
+ var _a;
141
+ (_a = modalContentRef == null ? void 0 : modalContentRef.current) == null ? void 0 : _a.handleModalClose();
142
+ }
143
+ };
144
+ }, [hasPreviousStep, currentStep]);
145
+ const initModal = () => __async(void 0, null, function* () {
146
+ const isAccount = yield para.isFullyLoggedIn();
147
+ setIsPasskeySupported(yield isPasskeySupported());
148
+ if (currentStepOverride) {
149
+ setStep(ModalStep[currentStepOverride.toUpperCase()]);
150
+ } else if (isAccount) {
151
+ setFlow("account");
152
+ setStep(ModalStep.ACCOUNT_MAIN);
153
+ setIsFullyLoggedIn(true);
154
+ } else {
155
+ if (currentStep !== ModalStep.AUTH_MAIN && currentStep !== ModalStep.SECRET) {
156
+ setStep(ModalStep.AUTH_MAIN);
157
+ setFlow();
158
+ setWebAuthURLForLogin();
159
+ setWebAuthURLForCreate();
160
+ setBiometricLocationHints();
161
+ setAuthStepRoute();
162
+ }
163
+ setSelectedWallet({ id: void 0, type: void 0 });
164
+ setIsFullyLoggedIn(false);
165
+ }
166
+ switch (true) {
167
+ case para.isEmail:
168
+ setAuthInfo({ email: para.getEmail() });
169
+ break;
170
+ case para.isPhone:
171
+ {
172
+ const { phone, countryCode } = para.getPhone();
173
+ setAuthInfo({ phone, countryCode });
174
+ }
175
+ break;
176
+ case para.isFarcaster:
177
+ setAuthInfo({ farcasterUsername: para.getFarcasterUsername() });
178
+ break;
179
+ case para.isTelegram:
180
+ setAuthInfo({ telegramUserId: para.telegramUserId });
181
+ if (!isAccount) {
182
+ setStep(ModalStep.TELEGRAM_OAUTH);
183
+ }
184
+ break;
185
+ case para.isExternalWalletAuth:
186
+ const externalWallets2 = Object.values(para.externalWallets);
187
+ const externalWalletWithFullAuth = externalWallets2.find((w) => w.isExternalWithParaAuth);
188
+ setAuthInfo({
189
+ displayName: getExternalWalletDisplayName({
190
+ address: externalWalletWithFullAuth.address,
191
+ type: externalWalletWithFullAuth.type
192
+ }),
193
+ externalWalletAddress: externalWalletWithFullAuth.address
194
+ });
195
+ break;
196
+ }
197
+ setIsInit(true);
198
+ });
199
+ useEffect(() => {
200
+ let _authLayout = authLayout;
201
+ if (!(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout)) {
202
+ _authLayout = _authLayout.filter((l) => !l.includes("EXTERNAL"));
203
+ }
204
+ if (disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout)) {
205
+ _authLayout = _authLayout.filter((l) => !l.includes("AUTH"));
206
+ }
207
+ if (JSON.stringify(storedAuthLayout) !== JSON.stringify(_authLayout)) {
208
+ setAuthLayout(_authLayout);
209
+ }
210
+ }, [disableEmailLogin, disablePhoneLogin, oAuthMethods, externalWallets, authLayout]);
211
+ useEffect(() => {
212
+ setOnModalStepChange(onModalStepChange);
213
+ }, [onModalStepChange]);
214
+ useEffect(() => {
215
+ var _a;
216
+ updateThemeState({
217
+ logo,
218
+ appName,
219
+ oAuthLogoVariant: (_a = theme == null ? void 0 : theme.oAuthLogoVariant) != null ? _a : "default",
220
+ bareModal,
221
+ embeddedModal,
222
+ hideWallets
223
+ });
224
+ }, [logo, appName, theme == null ? void 0 : theme.oAuthLogoVariant, bareModal, embeddedModal, hideWallets]);
225
+ useEffect(() => {
226
+ if (theme) {
227
+ generateTheme(theme);
228
+ updateThemeState({ isDark: theme.mode === "dark", theme });
229
+ }
230
+ }, [theme]);
231
+ useEffect(() => {
232
+ if (para) {
233
+ initModal();
234
+ if (bareModal) {
235
+ setIsModalMounted(true);
236
+ }
237
+ } else {
238
+ console.error("A Para instance must be provided.");
239
+ }
240
+ }, []);
241
+ useEffect(() => {
242
+ if (isOpen && para) {
243
+ initModal();
244
+ }
245
+ }, [isOpen]);
246
+ const updateActiveWallet = () => {
247
+ if (!(selectedWallet == null ? void 0 : selectedWallet.id) || !para.findWallet(selectedWallet == null ? void 0 : selectedWallet.id)) {
248
+ const defaultWallet = para.findWallet(void 0, void 0, { forbidPregen: true });
249
+ setSelectedWallet({ id: defaultWallet == null ? void 0 : defaultWallet.id, type: defaultWallet == null ? void 0 : defaultWallet.type });
250
+ }
251
+ };
252
+ useEffect(() => {
253
+ updateActiveWallet();
254
+ }, [para]);
255
+ useEffect(() => {
256
+ const closePopupWindow = () => {
257
+ var _a;
258
+ (_a = refs.popupWindow.current) == null ? void 0 : _a.close();
259
+ };
260
+ if (typeof window !== "undefined") {
261
+ window.addEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
262
+ window.addEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
263
+ window.addEventListener("beforeunload", closePopupWindow);
264
+ }
265
+ setIsReady(true);
266
+ return () => {
267
+ if (typeof window !== "undefined") {
268
+ window.removeEventListener(ParaEvent.WALLETS_CHANGE_EVENT, updateActiveWallet);
269
+ window.removeEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, updateActiveWallet);
270
+ window.removeEventListener("beforeunload", closePopupWindow);
271
+ }
272
+ };
273
+ }, []);
274
+ const handleClose = () => {
275
+ closeModal();
276
+ onClose == null ? void 0 : onClose();
277
+ };
278
+ const handleModalEntering = () => {
279
+ setIsModalMounted(true);
280
+ };
281
+ const handleModalExited = () => __async(void 0, null, function* () {
282
+ if (!bareModal) {
283
+ setIsModalMounted(false);
284
+ }
285
+ if (RESET_TO_AUTH_STEPS.includes(currentStep)) {
286
+ resetModalState();
287
+ resetUserInfoState();
288
+ setRecoveryShare(null);
289
+ } else if (RESET_TO_ACCOUNT_STEPS.includes(currentStep)) {
290
+ setStep(ModalStep.LOGIN_DONE);
291
+ }
292
+ if (para) {
293
+ yield initModal();
294
+ para.exitLoops();
295
+ }
296
+ if (!bareModal) {
297
+ setIsInit(false);
298
+ }
299
+ });
300
+ if (!ready) {
301
+ return null;
302
+ }
303
+ if (!para) {
304
+ console.error("A Para instance is required.");
305
+ return null;
306
+ }
307
+ if (!(storedAuthLayout == null ? void 0 : storedAuthLayout.length)) {
308
+ const hasExternalWalletError = !(externalWallets == null ? void 0 : externalWallets.length) && hasExternalWallet(authLayout);
309
+ const hasEmbeddedWalletError = disableEmailLogin && disablePhoneLogin && !(oAuthMethods == null ? void 0 : oAuthMethods.length) && hasEmbeddedAuth(authLayout);
310
+ if (hasExternalWalletError || hasEmbeddedWalletError) {
311
+ if (hasExternalWalletError) {
312
+ console.error("At least one external wallet must be provided if external wallet auth is enabled.");
313
+ }
314
+ if (hasEmbeddedWalletError) {
315
+ console.error(
316
+ "At least one login method (email, phone or OAuth) must be provided if embedded wallet auth is enabled."
317
+ );
318
+ }
319
+ } else {
320
+ console.error("At least one auth layout selection is required.");
321
+ }
322
+ return null;
323
+ }
324
+ return /* @__PURE__ */ jsx(ExternalWalletsWrapper, { wallets: externalWallets, externalWalletsWithFullAuth: externalWalletsWithParaAuth, children: /* @__PURE__ */ jsx(
325
+ StyledAuthModal,
326
+ {
327
+ enterTransitionDuration: DEFAULTS.ANIMATION_DURATION,
328
+ exitTransitionDuration: DEFAULTS.ANIMATION_DURATION,
329
+ open: isOpen,
330
+ onCpslModalExited: handleModalExited,
331
+ onCpslModalEntering: handleModalEntering,
332
+ onCpslModalRequestClose: handleClose,
333
+ noOverlay: bareModal,
334
+ className,
335
+ "data-testid": "modal",
336
+ $embeddedModal: embeddedModal,
337
+ children: isModalMounted && (isInit && embeddedModal || !embeddedModal) && /* @__PURE__ */ jsx(
338
+ ModalContent,
339
+ __spreadValues({
340
+ oAuthMethods,
341
+ disableEmailLogin,
342
+ disablePhoneLogin,
343
+ onClose: handleClose
344
+ }, rest)
345
+ )
346
+ }
347
+ ) });
348
+ }
349
+ );
350
+ const StyledAuthModal = styled(CpslAuthModal)`
351
+ ${({ $embeddedModal }) => $embeddedModal && `
352
+ &::part(modal-body-card) {
353
+ --card-box-shadow: none;
354
+ --card-border-width: 0px;
355
+ };
356
+
357
+ &::part(modal-footer) {
358
+ --card-box-shadow: none;
359
+ --card-border-width: 0px;
360
+ };`}
361
+ `;
362
+ export {
363
+ ParaModal
364
+ };
@@ -0,0 +1,77 @@
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 { useWalletBalance } from "../../hooks/useWalletBalance.js";
14
+ import { formatBalanceString } from "../../utils/stringFormatters.js";
15
+ const Account = ({ onClose }) => {
16
+ const onRampConfig = useModalStore((state) => state.onRampConfig);
17
+ const setStep = useModalStore((state) => state.setStep);
18
+ const hideWallets = useThemeStore((state) => state.hideWallets);
19
+ const { disconnectExternalWallet } = useExternalWallets();
20
+ const { balance, isLoading: isBalanceLoading } = useWalletBalance();
21
+ const [isDisconnecting, setIsDisconnecting] = useState(false);
22
+ const isOnRampLoaded = !!onRampConfig;
23
+ const handleBuyClick = () => {
24
+ setStep(ModalStep.ADD_FUNDS_BUY);
25
+ };
26
+ const handleReceiveClick = () => {
27
+ setStep(ModalStep.ADD_FUNDS_RECEIVE);
28
+ };
29
+ const handleSellClick = () => {
30
+ setStep(ModalStep.ADD_FUNDS_WITHDRAW);
31
+ };
32
+ const handleDisconnectClick = () => __async(void 0, null, function* () {
33
+ setIsDisconnecting(true);
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
+ isBalanceLoading ? /* @__PURE__ */ jsx(BalanceContainer, { children: /* @__PURE__ */ jsx(CpslSpinner, { size: 39 }) }) : balance !== void 0 && /* @__PURE__ */ jsx(BalanceContainer, { children: /* @__PURE__ */ jsx(CpslText, { variant: "headingS", weight: "medium", children: formatBalanceString(balance) }) }),
41
+ /* @__PURE__ */ jsx(ButtonContainer, { children: isOnRampLoaded ? /* @__PURE__ */ jsxs(Fragment, { children: [
42
+ onRampConfig.isBuyEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "creditCard", onClick: handleBuyClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Buy Crypto" }) }),
43
+ onRampConfig.isReceiveEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "qrCode02", onClick: handleReceiveClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Receive" }) }),
44
+ onRampConfig.isWithdrawEnabled && /* @__PURE__ */ jsx(OptionButton, { icon: "arrowCircleBrokenDownLeft", onClick: handleSellClick, children: /* @__PURE__ */ jsx(CpslText, { variant: "bodyXS", color: "secondary", weight: "medium", children: "Withdraw" }) })
45
+ ] }) : /* @__PURE__ */ jsx(CpslSpinner, {}) }),
46
+ /* @__PURE__ */ jsx(DisconnectButton, { variant: "destructive", fullWidth: true, onClick: handleDisconnectClick, disabled: isDisconnecting, children: isDisconnecting ? /* @__PURE__ */ jsx(CpslSpinner, { size: 16 }) : /* @__PURE__ */ jsxs(Fragment, { children: [
47
+ hideWallets ? "Logout" : "Disconnect Wallet",
48
+ /* @__PURE__ */ jsx(CpslIcon, { icon: "logOut", slot: "end" })
49
+ ] }) })
50
+ ] }) });
51
+ };
52
+ const ButtonContainer = styled.div`
53
+ display: flex;
54
+ align-items: center;
55
+ justify-content: center;
56
+ gap: 8px;
57
+ width: 100%;
58
+ height: 88px;
59
+ `;
60
+ const OptionButton = styled(StyledCpslTileButton)`
61
+ flex: 1;
62
+
63
+ --button-icon-color: var(--cpsl-color-text-primary);
64
+ `;
65
+ const DisconnectButton = styled(CpslButton)`
66
+ --button-border-width: 0px;
67
+ `;
68
+ const BalanceContainer = styled.div`
69
+ display: flex;
70
+ justify-content: center;
71
+ align-items: center;
72
+ padding-top: 8px;
73
+ padding-bottom: 24px;
74
+ `;
75
+ export {
76
+ Account
77
+ };
@@ -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 or SVM-based networks",
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
+ };