@getpara/react-sdk 2.0.0-alpha.3 → 2.0.0-alpha.31

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 (244) hide show
  1. package/dist/cli/cli.mjs +23 -13
  2. package/dist/index.d.ts +0 -1
  3. package/dist/index.js +6 -6499
  4. package/dist/modal/ParaModal.js +305 -0
  5. package/dist/modal/components/Account/Account.js +148 -0
  6. package/dist/modal/components/Account/AccountProfile.d.ts +1 -0
  7. package/dist/modal/components/Account/AccountProfile.js +168 -0
  8. package/dist/modal/components/Account/AccountProfileLink.d.ts +1 -0
  9. package/dist/modal/components/Account/AccountProfileLink.js +206 -0
  10. package/dist/modal/components/Account/AccountProfileLinkOptions.d.ts +1 -0
  11. package/dist/modal/components/Account/AccountProfileLinkOptions.js +111 -0
  12. package/dist/modal/components/Account/AccountProfileUnlink.d.ts +1 -0
  13. package/dist/modal/components/Account/AccountProfileUnlink.js +47 -0
  14. package/dist/modal/components/AddFunds/AddFunds.d.ts +0 -2
  15. package/dist/modal/components/AddFunds/AddFunds.js +69 -0
  16. package/dist/modal/components/AddFunds/AddFundsAsset.d.ts +1 -0
  17. package/dist/modal/components/AddFunds/AddFundsAsset.js +125 -0
  18. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +78 -0
  19. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +31 -0
  20. package/dist/modal/components/AddFunds/AddFundsContext.js +160 -0
  21. package/dist/modal/components/AddFunds/AddFundsDone.js +49 -0
  22. package/dist/modal/components/AddFunds/AddFundsProvider.d.ts +1 -0
  23. package/dist/modal/components/AddFunds/AddFundsProvider.js +109 -0
  24. package/dist/modal/components/AddFunds/AddFundsReceive.d.ts +1 -0
  25. package/dist/modal/components/AddFunds/AddFundsReceive.js +83 -0
  26. package/dist/modal/components/AddFunds/AddFundsSettings.d.ts +1 -0
  27. package/dist/modal/components/AddFunds/AddFundsSettings.js +237 -0
  28. package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
  29. package/dist/modal/components/AddFunds/common.d.ts +19 -0
  30. package/dist/modal/components/AddFunds/common.js +24 -0
  31. package/dist/modal/components/AddFunds/index.js +4 -0
  32. package/dist/modal/components/AuthInput/AuthInput.d.ts +17 -3
  33. package/dist/modal/components/AuthInput/AuthInput.js +277 -0
  34. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
  35. package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
  36. package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +4 -3
  37. package/dist/modal/components/AuthMainStep/AuthMainStep.js +50 -0
  38. package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +4 -3
  39. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +164 -0
  40. package/dist/modal/components/AuthOptions/AuthOptions.d.ts +4 -3
  41. package/dist/modal/components/AuthOptions/AuthOptions.js +85 -0
  42. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
  43. package/dist/modal/components/AwaitingIFrameStep/AwaitingIFrameStep.d.ts +1 -0
  44. package/dist/modal/components/AwaitingIFrameStep/AwaitingIFrameStep.js +12 -0
  45. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
  46. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
  47. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +5 -1
  48. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +49 -0
  49. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +62 -0
  50. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +48 -0
  51. package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
  52. package/dist/modal/components/Body/Body.d.ts +4 -3
  53. package/dist/modal/components/Body/Body.js +354 -0
  54. package/dist/modal/components/ChainSwitch/ChainSwitch.js +95 -0
  55. package/dist/modal/components/ChainSwitch/config.js +17 -0
  56. package/dist/modal/components/Controls/Controls.js +78 -0
  57. package/dist/modal/components/Controls/Selects.js +173 -0
  58. package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.d.ts +1 -0
  59. package/dist/modal/components/ExternalWalletNetworkSelectStep/ExternalWalletNetworkSelectStep.js +75 -0
  60. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +7 -0
  61. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +175 -0
  62. package/dist/modal/components/ExternalWalletStep/config.js +17 -0
  63. package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +39 -0
  64. package/dist/modal/components/ExternalWallets/ExternalWallets.js +184 -0
  65. package/dist/modal/components/Footer/Footer.js +95 -0
  66. package/dist/modal/components/Header/Header.js +43 -0
  67. package/dist/modal/components/Header/hooks/useStepTitle.js +62 -0
  68. package/dist/modal/components/Hero/Hero.js +116 -0
  69. package/dist/modal/components/IFrameStep/IFrameStep.js +59 -0
  70. package/dist/modal/components/LoginDoneStep/LoginDoneStep.d.ts +4 -0
  71. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +44 -0
  72. package/dist/modal/components/ModalContent/ModalContent.js +88 -0
  73. package/dist/modal/components/OAuth/FarcasterOAuthStep.d.ts +1 -0
  74. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +31 -0
  75. package/dist/modal/components/OAuth/OAuth.d.ts +2 -2
  76. package/dist/modal/components/OAuth/OAuth.js +79 -0
  77. package/dist/modal/components/OAuth/TelegramOAuthStep.d.ts +7 -0
  78. package/dist/modal/components/OAuth/TelegramOAuthStep.js +74 -0
  79. package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
  80. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
  81. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +107 -0
  82. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +132 -0
  83. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +27 -0
  84. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.d.ts +12 -1
  85. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +160 -0
  86. package/dist/modal/components/Waiting/Waiting.d.ts +1 -1
  87. package/dist/modal/components/Waiting/Waiting.js +17 -0
  88. package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
  89. package/dist/modal/components/WalletCard/WalletCard.d.ts +3 -3
  90. package/dist/modal/components/WalletCard/WalletCard.js +128 -0
  91. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +83 -0
  92. package/dist/modal/components/common.d.ts +49 -13
  93. package/dist/modal/components/common.js +261 -0
  94. package/dist/modal/components/index.js +2 -0
  95. package/dist/modal/constants/constants.d.ts +10 -2
  96. package/dist/modal/constants/constants.js +142 -0
  97. package/dist/modal/constants/defaults.js +10 -0
  98. package/dist/modal/constants/oAuthLogos.d.ts +15 -6
  99. package/dist/modal/constants/oAuthLogos.js +158 -0
  100. package/dist/modal/constants/walletTypeConfig.d.ts +6 -0
  101. package/dist/modal/constants/walletTypeConfig.js +13 -0
  102. package/dist/modal/hooks/useGoBack.js +43 -0
  103. package/dist/modal/hooks/useTelegramLogin.d.ts +12 -0
  104. package/dist/modal/hooks/useTelegramLogin.js +65 -0
  105. package/dist/modal/index.d.ts +1 -2
  106. package/dist/modal/index.js +29 -0
  107. package/dist/modal/stores/index.js +2 -0
  108. package/dist/modal/stores/modal/actions.js +135 -0
  109. package/dist/modal/stores/modal/useModalStore.d.ts +15 -6
  110. package/dist/modal/stores/modal/useModalStore.js +73 -0
  111. package/dist/modal/types/commonTypes.d.ts +0 -47
  112. package/dist/modal/types/commonTypes.js +1 -0
  113. package/dist/modal/types/modalProps.d.ts +15 -2
  114. package/dist/modal/types/modalProps.js +12 -0
  115. package/dist/modal/utils/authInputHelpers.d.ts +5 -0
  116. package/dist/modal/utils/authInputHelpers.js +41 -0
  117. package/dist/modal/utils/authLayoutHelpers.js +8 -0
  118. package/dist/modal/utils/countryCodes.js +45 -0
  119. package/dist/modal/utils/getMailtoLink.js +10 -0
  120. package/dist/modal/utils/getTileButtonFlex.js +20 -0
  121. package/dist/modal/utils/getWalletDisplayName.d.ts +5 -0
  122. package/dist/modal/utils/getWalletDisplayName.js +22 -0
  123. package/dist/modal/utils/isPasskeySupported.js +15 -0
  124. package/dist/modal/utils/openPopup.js +60 -0
  125. package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
  126. package/dist/modal/utils/steps.d.ts +26 -4
  127. package/dist/modal/utils/steps.js +279 -0
  128. package/dist/modal/utils/stringFormatters.d.ts +1 -0
  129. package/dist/modal/utils/stringFormatters.js +19 -0
  130. package/dist/modal/utils/validateOnRampConfig.js +32 -0
  131. package/dist/package.json +6 -0
  132. package/dist/provider/ParaProvider.js +117 -0
  133. package/dist/provider/actions/getEmbeddedAccount.d.ts +26 -0
  134. package/dist/provider/actions/getEmbeddedAccount.js +52 -0
  135. package/dist/provider/actions/getWallet.d.ts +3 -3
  136. package/dist/provider/actions/getWallet.js +18 -0
  137. package/dist/provider/actions/index.d.ts +22 -0
  138. package/dist/provider/actions/index.js +79 -0
  139. package/dist/provider/actions/utils.d.ts +4 -3
  140. package/dist/provider/actions/utils.js +34 -0
  141. package/dist/provider/components/CosmosWalletWrapper.js +43 -0
  142. package/dist/provider/components/EvmWalletWrapper.js +43 -0
  143. package/dist/provider/components/ExternalWalletWrapper.js +140 -0
  144. package/dist/provider/components/SolanaWalletWrapper.js +44 -0
  145. package/dist/provider/external/getParaCosmosConnector.js +19 -0
  146. package/dist/provider/external/getParaCosmosLib.d.ts +4 -0
  147. package/dist/provider/external/getParaCosmosLib.js +16 -0
  148. package/dist/provider/external/getParaEvmConnector.js +19 -0
  149. package/dist/provider/external/getParaEvmLib.d.ts +4 -0
  150. package/dist/provider/external/getParaEvmLib.js +16 -0
  151. package/dist/provider/external/getParaSolanaConnector.js +19 -0
  152. package/dist/provider/external/getParaSolanaLib.d.ts +4 -0
  153. package/dist/provider/external/getParaSolanaLib.js +16 -0
  154. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.d.ts +1 -11
  155. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +8 -0
  156. package/dist/provider/external/stubs/EvmExternalWalletContextStub.d.ts +1 -2
  157. package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +8 -0
  158. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.d.ts +1 -7
  159. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +8 -0
  160. package/dist/provider/hooks/index.js +4 -0
  161. package/dist/provider/hooks/mutations/core.d.ts +27 -0
  162. package/dist/provider/hooks/mutations/core.js +66 -0
  163. package/dist/provider/hooks/mutations/index.d.ts +3 -25
  164. package/dist/provider/hooks/mutations/index.js +9 -0
  165. package/dist/provider/hooks/mutations/useLinkAccount.d.ts +9 -0
  166. package/dist/provider/hooks/mutations/useLinkAccount.js +18 -0
  167. package/dist/provider/hooks/mutations/utils.d.ts +11 -3
  168. package/dist/provider/hooks/mutations/utils.js +90 -0
  169. package/dist/provider/hooks/queries/core.d.ts +4 -0
  170. package/dist/provider/hooks/queries/core.js +16 -0
  171. package/dist/provider/hooks/queries/index.d.ts +2 -0
  172. package/dist/provider/hooks/queries/index.js +11 -0
  173. package/dist/provider/hooks/queries/useAccount.d.ts +91 -2
  174. package/dist/provider/hooks/queries/useAccount.js +138 -0
  175. package/dist/provider/hooks/queries/useIsFullyLoggedIn.d.ts +5 -0
  176. package/dist/provider/hooks/queries/useIsFullyLoggedIn.js +24 -0
  177. package/dist/provider/hooks/queries/useWallet.d.ts +1 -1
  178. package/dist/provider/hooks/queries/useWallet.js +26 -0
  179. package/dist/provider/hooks/queries/useWalletBalance.d.ts +6 -0
  180. package/dist/provider/hooks/queries/useWalletBalance.js +55 -0
  181. package/dist/provider/hooks/queries/utils.d.ts +7 -0
  182. package/dist/provider/hooks/queries/utils.js +25 -0
  183. package/dist/provider/hooks/utils/index.js +10 -0
  184. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
  185. package/dist/provider/hooks/utils/useClient.d.ts +1 -1
  186. package/dist/provider/hooks/utils/useClient.js +10 -0
  187. package/dist/provider/hooks/utils/useEventListeners.d.ts +1 -1
  188. package/dist/provider/hooks/utils/useEventListeners.js +157 -0
  189. package/dist/provider/hooks/utils/useFormattedBiometricHints.d.ts +4 -0
  190. package/dist/provider/hooks/utils/useFormattedBiometricHints.js +27 -0
  191. package/dist/provider/hooks/utils/useInternalClient.js +10 -0
  192. package/dist/provider/hooks/utils/useModal.d.ts +4 -1
  193. package/dist/provider/hooks/utils/useModal.js +27 -0
  194. package/dist/provider/hooks/utils/useWalletState.d.ts +3 -3
  195. package/dist/provider/hooks/utils/useWalletState.js +48 -0
  196. package/dist/provider/index.d.ts +2 -0
  197. package/dist/provider/index.js +11 -0
  198. package/dist/provider/providers/AccountLinkProvider.d.ts +47 -0
  199. package/dist/provider/providers/AccountLinkProvider.js +452 -0
  200. package/dist/provider/providers/AuthProvider.d.ts +12 -6
  201. package/dist/provider/providers/AuthProvider.js +553 -0
  202. package/dist/provider/providers/CosmosExternalWalletProvider.js +66 -0
  203. package/dist/provider/providers/EvmExternalWalletProvider.js +74 -0
  204. package/dist/provider/providers/ExternalWalletProvider.d.ts +21 -35
  205. package/dist/provider/providers/ExternalWalletProvider.js +596 -0
  206. package/dist/provider/providers/SolanaExternalWalletProvider.js +66 -0
  207. package/dist/provider/stores/getters.d.ts +1 -1
  208. package/dist/provider/stores/getters.js +13 -0
  209. package/dist/provider/stores/setters.js +7 -0
  210. package/dist/provider/stores/slices/analytics.d.ts +3 -0
  211. package/dist/provider/stores/slices/analytics.js +9 -0
  212. package/dist/provider/stores/slices/client.js +9 -0
  213. package/dist/provider/stores/slices/config.js +9 -0
  214. package/dist/provider/stores/slices/externalWallets.js +46 -0
  215. package/dist/provider/stores/slices/index.d.ts +1 -0
  216. package/dist/provider/stores/slices/index.js +6 -0
  217. package/dist/provider/stores/slices/modal.js +18 -0
  218. package/dist/provider/stores/slices/wallet.js +13 -0
  219. package/dist/provider/stores/types.d.ts +20 -5
  220. package/dist/provider/stores/types.js +1 -0
  221. package/dist/provider/stores/useStore.js +34 -0
  222. package/dist/provider/types/externalWalletProviders.d.ts +2 -2
  223. package/dist/provider/types/externalWalletProviders.js +1 -0
  224. package/dist/provider/types/provider.d.ts +25 -5
  225. package/dist/provider/types/provider.js +1 -0
  226. package/dist/provider/types/query.js +1 -0
  227. package/dist/provider/types/utils.d.ts +28 -5
  228. package/dist/provider/types/utils.js +1 -0
  229. package/dist/provider/utils/constants.d.ts +5 -0
  230. package/dist/provider/utils/constants.js +10 -0
  231. package/dist/provider/utils/paraConfigTypeGuards.js +13 -0
  232. package/dist/provider/utils/renameMutations.d.ts +2 -2
  233. package/dist/provider/utils/renameMutations.js +18 -0
  234. package/package.json +40 -39
  235. package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
  236. package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
  237. package/dist/chunk-MMUBH76A.js.br +0 -0
  238. package/dist/chunk-MMUBH76A.js.gz +0 -0
  239. package/dist/index.js.br +0 -0
  240. package/dist/index.js.gz +0 -0
  241. package/dist/modal/components/StripeComponents/StripeComponents.d.ts +0 -16
  242. package/dist/modal/types/externalWallets.d.ts +0 -31
  243. package/dist/provider/actions/getAccount.d.ts +0 -19
  244. /package/dist/modal/{components/AuthInput → utils}/countryCodes.d.ts +0 -0
@@ -0,0 +1,553 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __spreadProps,
5
+ __spreadValues
6
+ } from "../../chunk-MMUBH76A.js";
7
+ import { jsx } from "react/jsx-runtime";
8
+ import { useUserAgent } from "@getpara/react-common";
9
+ import { createContext, useCallback, useContext, useEffect, useMemo } from "react";
10
+ import { useModalStore } from "../../modal/stores/index.js";
11
+ import { ModalStep } from "../../modal/utils/steps.js";
12
+ import {
13
+ useSignUpOrLogIn,
14
+ useVerifyNewAccount,
15
+ useWaitForSignup,
16
+ useWaitForLogin,
17
+ useWaitForWalletCreation,
18
+ useVerifyOAuth,
19
+ useVerifyFarcaster,
20
+ useVerifyTelegram,
21
+ useSetup2fa,
22
+ useLogout,
23
+ useCreateGuestWallets
24
+ } from "../index.js";
25
+ import { DEFAULTS } from "../../modal/constants/defaults.js";
26
+ import { openPopup } from "../../modal/utils/openPopup.js";
27
+ import {
28
+ AuthMethod,
29
+ entityToWallet,
30
+ getPortalBaseURL
31
+ } from "@getpara/web-sdk";
32
+ import { useInternalClient } from "../../provider/hooks/utils/useInternalClient.js";
33
+ import { useGoBack } from "../../modal/hooks/useGoBack.js";
34
+ import { isExternalWallet } from "@getpara/user-management-client";
35
+ import { routeMobileExternalWallet } from "../../modal/utils/routeMobileExternalWallet.js";
36
+ import { useStore } from "../stores/useStore.js";
37
+ import { useFormattedBiometricHints } from "../hooks/utils/useFormattedBiometricHints.js";
38
+ import { useQueryClient } from "@tanstack/react-query";
39
+ const AuthContext = createContext({
40
+ signUpOrLogIn: () => {
41
+ },
42
+ isSignUpOrLogInPending: false,
43
+ verifyNewAccount: () => {
44
+ },
45
+ verifyNewAccountStatus: "idle",
46
+ verifyNewAccountError: null,
47
+ verifyOAuth: () => {
48
+ },
49
+ verifyFarcaster: () => {
50
+ },
51
+ verifyTelegram: () => {
52
+ },
53
+ verifyTelegramStatus: "idle",
54
+ onNewAuthState: () => {
55
+ },
56
+ isSetup2faPending: false,
57
+ presentSignupUi: () => {
58
+ },
59
+ presentLoginUi: () => {
60
+ },
61
+ createGuestWallets: () => {
62
+ },
63
+ isCreateGuestWalletsPending: false,
64
+ logout: () => {
65
+ }
66
+ });
67
+ function AuthProvider({
68
+ children,
69
+ is2faEnabled = false,
70
+ isRecoverySecretStepEnabled = false,
71
+ overrides = {}
72
+ }) {
73
+ const queryClient = useQueryClient();
74
+ const para = useInternalClient();
75
+ const userAgent = useUserAgent();
76
+ const onLoginRef = useStore((state) => state.onLoginRef);
77
+ const setIsOpen = useStore((state) => state.setIsOpen);
78
+ const bareModal = useStore((state) => {
79
+ var _a;
80
+ return (_a = state.modalConfig) == null ? void 0 : _a.bareModal;
81
+ });
82
+ const refs = useModalStore((state) => state.refs);
83
+ const setFlow = useModalStore((state) => state.setFlow);
84
+ const currentStep = useModalStore((state) => state.step);
85
+ const setStep = useModalStore((state) => state.setStep);
86
+ const setAuthStepRoute = useModalStore((state) => state.setAuthStepRoute);
87
+ const setIFrameUrl = useModalStore((state) => state.setIFrameUrl);
88
+ const setIsIFrameReady = useModalStore((state) => state.setIsIFrameReady);
89
+ const iFrameUrl = useModalStore((state) => state.iFrameUrl);
90
+ const loginState = useModalStore((state) => state.getLoginState());
91
+ const signupState = useModalStore((state) => state.getSignupState());
92
+ const setAuthState = useModalStore((state) => state.setAuthState);
93
+ const setFarcasterConnectUri = useModalStore((state) => state.setFarcasterConnectUri);
94
+ const setTwoFactorStatus = useModalStore((state) => state.setTwoFactorStatus);
95
+ const setRecoveryShare = useModalStore((state) => state.setRecoveryShare);
96
+ const authStepRoute = useModalStore((state) => state.authStepRoute);
97
+ const isIFrameReady = useModalStore((state) => state.isIFrameReady);
98
+ const goBack = useGoBack();
99
+ const { mutate: mutateSignUpOrLogIn, isPending: isSignUpOrLogInPending } = useSignUpOrLogIn();
100
+ const {
101
+ mutate: mutateVerifyNewAccount,
102
+ status: verifyNewAccountStatus,
103
+ error: verifyNewAccountError
104
+ } = useVerifyNewAccount();
105
+ const { mutate: mutateVerifyOAuth } = useVerifyOAuth();
106
+ const { mutate: mutateVerifyFarcaster } = useVerifyFarcaster();
107
+ const { mutate: mutateVerifyTelegram, status: verifyTelegramStatus } = useVerifyTelegram();
108
+ const { mutate: mutateWaitForLogin } = useWaitForLogin();
109
+ const { mutate: mutateWaitForSignup } = useWaitForSignup();
110
+ const { mutateAsync: mutateAsyncWaitForWalletCreation } = useWaitForWalletCreation();
111
+ const { mutate: mutateSetup2fa, isPending: isSetup2faPending } = useSetup2fa();
112
+ const { mutate: mutateCreateGuestWallets, isPending: isCreateGuestWalletsPending } = useCreateGuestWallets();
113
+ const { mutate: mutateLogout } = useLogout();
114
+ const { data: biometricHints } = useFormattedBiometricHints();
115
+ const goBackIfPopupClosedOnSteps = (steps) => {
116
+ var _a;
117
+ if (((_a = refs.popupWindow.current) == null ? void 0 : _a.closed) && (!refs.currentStep.current || steps.includes(refs.currentStep.current))) {
118
+ refs.popupWindow.current = null;
119
+ goBack();
120
+ }
121
+ };
122
+ const cancelIfExitedSteps = (steps) => {
123
+ const stepNow = refs.currentStep.current;
124
+ return !!stepNow && !steps.includes(stepNow);
125
+ };
126
+ const setupListener = () => {
127
+ window.addEventListener("message", function handleMessage(event) {
128
+ var _a;
129
+ const portalBase = getPortalBaseURL(para.ctx);
130
+ if (!event.origin.startsWith(portalBase)) {
131
+ return;
132
+ }
133
+ if (((_a = event.data) == null ? void 0 : _a.type) === "CLOSE_WINDOW") {
134
+ if (event.data.success) {
135
+ setAuthStepRoute();
136
+ setIFrameUrl();
137
+ setIsIFrameReady(false);
138
+ setStep(ModalStep.AWAITING_IFRAME);
139
+ }
140
+ window.removeEventListener("message", handleMessage);
141
+ }
142
+ });
143
+ };
144
+ const signup = () => {
145
+ if (typeof window !== "undefined") {
146
+ refs.poll.current = {
147
+ action: "signup",
148
+ timeout: window == null ? void 0 : window.setTimeout(() => __async(this, null, function* () {
149
+ mutateWaitForSignup(
150
+ {
151
+ isCanceled: () => cancelIfExitedSteps([
152
+ ModalStep.BIOMETRIC_CREATION,
153
+ ModalStep.AWAITING_BIOMETRIC_CREATION,
154
+ ModalStep.PASSWORD_CREATION,
155
+ ModalStep.AWAITING_IFRAME,
156
+ ModalStep.VERIFICATIONS,
157
+ ModalStep.EXTERNAL_WALLET_VERIFICATION
158
+ ]),
159
+ onPoll: () => {
160
+ goBackIfPopupClosedOnSteps([ModalStep.AWAITING_BIOMETRIC_CREATION]);
161
+ }
162
+ },
163
+ {
164
+ onSuccess: () => {
165
+ if (para.isNoWalletConfig) {
166
+ onLoginComplete({
167
+ on2faSetupOrError: () => setStep(ModalStep.LOGIN_DONE),
168
+ on2faNotSetup: () => setStep(ModalStep.SETUP_2FA)
169
+ });
170
+ } else {
171
+ createWallets();
172
+ }
173
+ },
174
+ onError: () => {
175
+ if (refs.currentStep.current && [ModalStep.AWAITING_BIOMETRIC_CREATION, ModalStep.PASSWORD_CREATION].includes(refs.currentStep.current)) {
176
+ setStep(ModalStep.BIOMETRIC_CREATION);
177
+ }
178
+ },
179
+ onSettled: () => {
180
+ var _a;
181
+ window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
182
+ refs.poll.current = null;
183
+ refs.popupWindow.current = null;
184
+ }
185
+ }
186
+ );
187
+ }), DEFAULTS.POLLING_INTERVAL_MS)
188
+ };
189
+ }
190
+ };
191
+ const presentSignupUi = useCallback(
192
+ (method, authState) => {
193
+ switch (method) {
194
+ case AuthMethod.PASSKEY:
195
+ if (refs.currentStep.current !== ModalStep.AWAITING_BIOMETRIC_CREATION) {
196
+ setStep(ModalStep.AWAITING_BIOMETRIC_CREATION);
197
+ }
198
+ refs.popupWindow.current = openPopup({
199
+ url: authState.passkeyUrl,
200
+ target: "ParaPasskey",
201
+ type: "CREATE_PASSKEY",
202
+ current: refs.popupWindow.current
203
+ });
204
+ break;
205
+ case AuthMethod.PASSWORD:
206
+ setupListener();
207
+ if (isIFrameReady) {
208
+ setStep(ModalStep.PASSWORD_CREATION);
209
+ } else {
210
+ setIFrameUrl(authState.passwordUrl);
211
+ setIsIFrameReady(false);
212
+ setAuthStepRoute(ModalStep.PASSWORD_CREATION);
213
+ }
214
+ break;
215
+ }
216
+ },
217
+ [isIFrameReady]
218
+ );
219
+ const login = (authState) => {
220
+ if (authState.isWalletSelectionNeeded || authState.passkeyUrl) {
221
+ setStep(ModalStep.BIOMETRIC_LOGIN);
222
+ } else {
223
+ setupListener();
224
+ setIFrameUrl(authState.passwordUrl);
225
+ setIsIFrameReady(false);
226
+ setStep(ModalStep.EMBEDDED_PASSWORD_LOGIN);
227
+ }
228
+ refs.poll.current = {
229
+ action: "login",
230
+ timeout: window == null ? void 0 : window.setTimeout(() => __async(this, null, function* () {
231
+ mutateWaitForLogin(
232
+ {
233
+ isCanceled: () => cancelIfExitedSteps([
234
+ ModalStep.BIOMETRIC_LOGIN,
235
+ ModalStep.EMBEDDED_PASSWORD_LOGIN,
236
+ ModalStep.AWAITING_BIOMETRIC_LOGIN,
237
+ ModalStep.AWAITING_PASSWORD_LOGIN,
238
+ ModalStep.AWAITING_IFRAME
239
+ ]),
240
+ onPoll: () => {
241
+ goBackIfPopupClosedOnSteps([
242
+ ModalStep.AWAITING_BIOMETRIC_LOGIN,
243
+ ModalStep.AWAITING_PASSWORD_LOGIN,
244
+ ModalStep.EMBEDDED_PASSWORD_LOGIN
245
+ ]);
246
+ }
247
+ },
248
+ {
249
+ onSuccess: ({ needsWallet }) => {
250
+ if (needsWallet && !para.isNoWalletConfig) {
251
+ createWallets();
252
+ } else {
253
+ onLoginComplete({
254
+ on2faSetupOrError: () => setStep(ModalStep.LOGIN_DONE),
255
+ on2faNotSetup: () => setStep(ModalStep.SETUP_2FA)
256
+ });
257
+ }
258
+ },
259
+ onSettled: () => {
260
+ var _a;
261
+ window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
262
+ refs.poll.current = null;
263
+ refs.popupWindow.current = null;
264
+ }
265
+ }
266
+ );
267
+ }), DEFAULTS.LOGGIN_POLLING_DELAY_MS)
268
+ };
269
+ };
270
+ const presentLoginUi = useCallback(
271
+ (method, authState) => {
272
+ const isPasskey = method === AuthMethod.PASSKEY, isPassword = !isPasskey;
273
+ if (overrides.login) {
274
+ function loginOverride() {
275
+ return __async(this, null, function* () {
276
+ var _a, _b;
277
+ yield (_a = overrides == null ? void 0 : overrides.login) == null ? void 0 : _a.call(overrides, para);
278
+ yield (_b = onLoginRef.current) == null ? void 0 : _b.call(onLoginRef);
279
+ yield onLoginComplete();
280
+ });
281
+ }
282
+ loginOverride();
283
+ return;
284
+ }
285
+ refs.popupWindow.current = openPopup({
286
+ url: isPassword ? authState.passwordUrl : authState.passkeyUrl,
287
+ target: isPassword ? "ParaPassword" : "ParaPasskey",
288
+ type: isPassword ? "LOGIN_PASSWORD" : "LOGIN_PASSKEY",
289
+ current: refs.popupWindow.current
290
+ });
291
+ setStep(isPassword ? ModalStep.AWAITING_PASSWORD_LOGIN : ModalStep.AWAITING_BIOMETRIC_LOGIN);
292
+ },
293
+ [loginState, biometricHints]
294
+ );
295
+ const onNewAuthState = (authState) => __async(this, null, function* () {
296
+ refs.popupWindow.current = null;
297
+ setAuthState(authState);
298
+ switch (authState.stage) {
299
+ case "verify":
300
+ if (isExternalWallet(authState.auth) && authState.signatureVerificationMessage) {
301
+ setStep(ModalStep.EXTERNAL_WALLET_VERIFICATION);
302
+ } else {
303
+ setStep(ModalStep.VERIFICATIONS);
304
+ }
305
+ break;
306
+ case "login":
307
+ login(authState);
308
+ break;
309
+ case "signup":
310
+ {
311
+ const isPassword = !!authState.passwordUrl, isPasswordOnly = isPassword && (!authState.passkeyUrl || (userAgent == null ? void 0 : userAgent.device.type) === "mobile" && !authState.isPasskeySupported);
312
+ if (isPassword) {
313
+ setIFrameUrl(authState.passwordUrl);
314
+ setIsIFrameReady(false);
315
+ }
316
+ signup();
317
+ if (isPasswordOnly) {
318
+ presentSignupUi(AuthMethod.PASSWORD, authState);
319
+ } else {
320
+ setStep(ModalStep.BIOMETRIC_CREATION);
321
+ }
322
+ }
323
+ break;
324
+ }
325
+ });
326
+ const signUpOrLogIn = (auth) => __async(this, null, function* () {
327
+ mutateSignUpOrLogIn(
328
+ { auth, useShortUrls: true },
329
+ {
330
+ onSuccess: onNewAuthState
331
+ }
332
+ );
333
+ });
334
+ const verifyNewAccount = (verificationCode) => __async(this, null, function* () {
335
+ mutateVerifyNewAccount(
336
+ { verificationCode, useShortUrls: true },
337
+ {
338
+ onSuccess: onNewAuthState
339
+ }
340
+ );
341
+ });
342
+ const verifyOAuth = (method) => __async(this, null, function* () {
343
+ setStep(ModalStep.AWAITING_OAUTH);
344
+ mutateVerifyOAuth(
345
+ {
346
+ method,
347
+ isCanceled: () => {
348
+ var _a;
349
+ return ((_a = refs.popupWindow.current) == null ? void 0 : _a.closed) || cancelIfExitedSteps([ModalStep.AWAITING_OAUTH]);
350
+ },
351
+ onPoll: () => {
352
+ goBackIfPopupClosedOnSteps([ModalStep.AWAITING_OAUTH]);
353
+ },
354
+ onOAuthUrl: (oAuthUrl) => {
355
+ refs.popupWindow.current = openPopup({
356
+ url: oAuthUrl,
357
+ target: `${method}AuthPopup`,
358
+ type: "OAUTH",
359
+ current: refs.popupWindow.current
360
+ });
361
+ },
362
+ useShortUrls: true
363
+ },
364
+ {
365
+ onSuccess: onNewAuthState,
366
+ onError: () => {
367
+ goBackIfPopupClosedOnSteps([ModalStep.AWAITING_OAUTH]);
368
+ }
369
+ }
370
+ );
371
+ });
372
+ const verifyFarcaster = () => __async(this, null, function* () {
373
+ setStep(ModalStep.FARCASTER_OAUTH);
374
+ mutateVerifyFarcaster(
375
+ {
376
+ isCanceled: () => refs.currentStep.current !== ModalStep.FARCASTER_OAUTH,
377
+ onConnectUri: (connectUri) => {
378
+ setFarcasterConnectUri(connectUri);
379
+ routeMobileExternalWallet(connectUri);
380
+ },
381
+ useShortUrls: true
382
+ },
383
+ {
384
+ onSuccess: onNewAuthState,
385
+ onError: () => {
386
+ if (refs.currentStep.current === ModalStep.FARCASTER_OAUTH) {
387
+ goBack();
388
+ }
389
+ }
390
+ }
391
+ );
392
+ });
393
+ const verifyTelegram = (telegramAuthResponse) => __async(this, null, function* () {
394
+ mutateVerifyTelegram(
395
+ {
396
+ telegramAuthResponse,
397
+ useShortUrls: true
398
+ },
399
+ {
400
+ onSuccess: onNewAuthState
401
+ }
402
+ );
403
+ });
404
+ const onLoginComplete = useCallback(
405
+ (..._0) => __async(this, [..._0], function* ({
406
+ on2faSetupOrError,
407
+ on2faNotSetup
408
+ } = {}) {
409
+ var _a;
410
+ yield queryClient.invalidateQueries({ queryKey: ["isFullyLoggedIn"] });
411
+ setAuthState();
412
+ yield (_a = onLoginRef.current) == null ? void 0 : _a.call(onLoginRef);
413
+ if (is2faEnabled) {
414
+ mutateSetup2fa(void 0, {
415
+ onSuccess: (status) => {
416
+ setTwoFactorStatus(status);
417
+ if (!status.isSetup && !!status.uri) {
418
+ on2faNotSetup == null ? void 0 : on2faNotSetup();
419
+ } else {
420
+ on2faSetupOrError == null ? void 0 : on2faSetupOrError();
421
+ }
422
+ },
423
+ onError: () => {
424
+ on2faSetupOrError == null ? void 0 : on2faSetupOrError();
425
+ }
426
+ });
427
+ } else {
428
+ on2faSetupOrError == null ? void 0 : on2faSetupOrError();
429
+ }
430
+ }),
431
+ [is2faEnabled]
432
+ );
433
+ const createWallets = useCallback(() => __async(this, null, function* () {
434
+ var _a;
435
+ if (refs.currentStep.current !== ModalStep.AWAITING_WALLET_CREATION) {
436
+ setStep(ModalStep.AWAITING_WALLET_CREATION);
437
+ }
438
+ let recoverySecret, walletIds;
439
+ try {
440
+ if (overrides.createWallets) {
441
+ ({ recoverySecret, walletIds } = yield (_a = overrides == null ? void 0 : overrides.createWallets) == null ? void 0 : _a.call(overrides, para));
442
+ const fetchedWallets = (yield para.fetchWallets()).filter((wallet) => !!wallet.address);
443
+ const newWallets = {};
444
+ for (const wallet of fetchedWallets) {
445
+ newWallets[wallet.id] = __spreadProps(__spreadValues({}, entityToWallet(wallet)), {
446
+ signer: ""
447
+ });
448
+ }
449
+ para.setWallets(newWallets);
450
+ } else {
451
+ ({ recoverySecret, walletIds } = yield mutateAsyncWaitForWalletCreation({
452
+ isCanceled: () => false
453
+ }));
454
+ }
455
+ if (walletIds) {
456
+ yield para.setCurrentWalletIds(walletIds);
457
+ }
458
+ if (recoverySecret && isRecoverySecretStepEnabled) {
459
+ setRecoveryShare(recoverySecret);
460
+ }
461
+ setStep(recoverySecret && isRecoverySecretStepEnabled ? ModalStep.SECRET : ModalStep.WALLET_CREATION_DONE);
462
+ onLoginComplete();
463
+ } catch (e) {
464
+ }
465
+ }), [para, isRecoverySecretStepEnabled, overrides == null ? void 0 : overrides.createWallets]);
466
+ const createGuestWallets = () => {
467
+ if (bareModal) {
468
+ setFlow("guest");
469
+ setStep(ModalStep.AWAITING_GUEST_WALLET_CREATION);
470
+ } else {
471
+ setIsOpen(false);
472
+ }
473
+ mutateCreateGuestWallets(void 0, {
474
+ onSuccess: () => {
475
+ },
476
+ onSettled: () => {
477
+ }
478
+ });
479
+ };
480
+ const logout = () => {
481
+ mutateLogout();
482
+ };
483
+ const isPasswordIFrameLoading = !!iFrameUrl && iFrameUrl === (signupState == null ? void 0 : signupState.passwordUrl) && !isIFrameReady;
484
+ const value = useMemo(
485
+ () => ({
486
+ presentSignupUi,
487
+ presentLoginUi,
488
+ signUpOrLogIn,
489
+ isSignUpOrLogInPending,
490
+ verifyNewAccount,
491
+ verifyNewAccountStatus: isPasswordIFrameLoading ? "pending" : verifyNewAccountStatus,
492
+ verifyNewAccountError,
493
+ verifyOAuth,
494
+ verifyFarcaster,
495
+ verifyTelegram,
496
+ verifyTelegramStatus,
497
+ onNewAuthState,
498
+ isSetup2faPending,
499
+ createGuestWallets,
500
+ isCreateGuestWalletsPending,
501
+ logout,
502
+ biometricHints: biometricHints || void 0
503
+ }),
504
+ [
505
+ presentSignupUi,
506
+ presentLoginUi,
507
+ signUpOrLogIn,
508
+ isSignUpOrLogInPending,
509
+ verifyNewAccount,
510
+ verifyNewAccountStatus,
511
+ isPasswordIFrameLoading,
512
+ verifyNewAccountError,
513
+ verifyOAuth,
514
+ verifyFarcaster,
515
+ verifyTelegram,
516
+ verifyTelegramStatus,
517
+ onNewAuthState,
518
+ isSetup2faPending,
519
+ createGuestWallets,
520
+ isCreateGuestWalletsPending,
521
+ logout,
522
+ biometricHints
523
+ ]
524
+ );
525
+ useEffect(() => {
526
+ if (!!authStepRoute && isIFrameReady && refs.currentStep.current !== authStepRoute) {
527
+ setTimeout(() => {
528
+ setStep(authStepRoute);
529
+ }, 200);
530
+ }
531
+ }, [authStepRoute, isIFrameReady]);
532
+ useEffect(() => {
533
+ refs.currentStep.current = currentStep;
534
+ }, [currentStep]);
535
+ useEffect(() => {
536
+ if (refs.currentStep.current === ModalStep.AWAITING_GUEST_WALLET_CREATION && !isCreateGuestWalletsPending) {
537
+ setStep(ModalStep.ACCOUNT_MAIN);
538
+ }
539
+ }, [isCreateGuestWalletsPending]);
540
+ useEffect(() => {
541
+ return () => {
542
+ var _a;
543
+ window == null ? void 0 : window.clearTimeout((_a = refs.poll.current) == null ? void 0 : _a.timeout);
544
+ };
545
+ }, []);
546
+ return /* @__PURE__ */ jsx(AuthContext.Provider, { value, children });
547
+ }
548
+ const useAuthActions = () => useContext(AuthContext);
549
+ export {
550
+ AuthContext,
551
+ AuthProvider,
552
+ useAuthActions
553
+ };
@@ -0,0 +1,66 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __objRest,
5
+ __spreadProps,
6
+ __spreadValues
7
+ } from "../../chunk-MMUBH76A.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import { memo, useEffect, useMemo } from "react";
10
+ import { useStore } from "../stores/useStore.js";
11
+ import { getParaCosmosConnector } from "../external/getParaCosmosConnector.js";
12
+ function CosmosExternalWalletProvider(_a) {
13
+ var _b = _a, {
14
+ children,
15
+ isUsing,
16
+ wallets: walletsFromProps
17
+ } = _b, rest = __objRest(_b, [
18
+ "children",
19
+ "isUsing",
20
+ "wallets"
21
+ ]);
22
+ const setCosmosContext = useStore((state) => state.setCosmosContext);
23
+ const setCosmosProvider = useStore((state) => state.setCosmosProvider);
24
+ const CosmosProvider = useStore((state) => state.CosmosProvider);
25
+ const setCosmosWallets = useStore((state) => state.setCosmosWallets);
26
+ const cosmosWallets = useStore((state) => state.cosmosWallets);
27
+ const isLoadingLib = useStore((state) => state.isLoadingCosmosLib);
28
+ const setIsLoadingLib = useStore((state) => state.setIsLoadingCosmosLib);
29
+ const filteredWallets = useMemo(
30
+ () => cosmosWallets.filter((w) => walletsFromProps.includes(w().id.toUpperCase())),
31
+ [cosmosWallets, walletsFromProps]
32
+ );
33
+ useEffect(() => {
34
+ const loadLib = () => __async(this, null, function* () {
35
+ if (CosmosProvider) {
36
+ return;
37
+ }
38
+ const { Provider, context, wallets } = yield getParaCosmosConnector();
39
+ if (Provider) {
40
+ setCosmosProvider(Provider);
41
+ }
42
+ if (wallets) {
43
+ setCosmosWallets(wallets);
44
+ }
45
+ if (context) {
46
+ setCosmosContext(context);
47
+ }
48
+ setIsLoadingLib(false);
49
+ });
50
+ loadLib();
51
+ }, []);
52
+ if (isLoadingLib) {
53
+ return null;
54
+ }
55
+ if (CosmosProvider) {
56
+ return /* @__PURE__ */ jsx(CosmosProvider, __spreadProps(__spreadValues({}, rest), { config: __spreadProps(__spreadValues({}, rest == null ? void 0 : rest.config), { wallets: filteredWallets }), children }));
57
+ } else if (isUsing) {
58
+ console.warn("@getpara/cosmos-wallet-connectors is required to use an external Cosmos wallet.");
59
+ }
60
+ return children;
61
+ }
62
+ const MemoizedCosmosExternalWalletProvider = memo(CosmosExternalWalletProvider);
63
+ export {
64
+ CosmosExternalWalletProvider,
65
+ MemoizedCosmosExternalWalletProvider
66
+ };
@@ -0,0 +1,74 @@
1
+ "use client";
2
+ import {
3
+ __async,
4
+ __objRest,
5
+ __spreadProps,
6
+ __spreadValues
7
+ } from "../../chunk-MMUBH76A.js";
8
+ import { jsx } from "react/jsx-runtime";
9
+ import { useEffect, useMemo } from "react";
10
+ import { getParaEvmConnector } from "../external/getParaEvmConnector.js";
11
+ import { useStore } from "../stores/useStore.js";
12
+ function EvmExternalWalletProvider(_a) {
13
+ var _b = _a, {
14
+ children,
15
+ isUsing,
16
+ wallets: walletsFromProps
17
+ } = _b, rest = __objRest(_b, [
18
+ "children",
19
+ "isUsing",
20
+ "wallets"
21
+ ]);
22
+ const setEvmContext = useStore((state) => state.setEvmContext);
23
+ const setEvmProvider = useStore((state) => state.setEvmProvider);
24
+ const EvmProvider = useStore((state) => state.EvmProvider);
25
+ const setEvmWallets = useStore((state) => state.setEvmWallets);
26
+ const evmWallets = useStore((state) => state.evmWallets);
27
+ const isLoadingLib = useStore((state) => state.isLoadingEvmLib);
28
+ const setIsLoadingLib = useStore((state) => state.setIsLoadingEvmLib);
29
+ const filteredWallets = useMemo(
30
+ () => evmWallets.filter(
31
+ (w) => {
32
+ var _a2, _b2, _c, _d;
33
+ return walletsFromProps.includes(
34
+ w({
35
+ appName: (_b2 = (_a2 = rest == null ? void 0 : rest.config) == null ? void 0 : _a2.appName) != null ? _b2 : "",
36
+ projectId: (_d = (_c = rest == null ? void 0 : rest.config) == null ? void 0 : _c.projectId) != null ? _d : ""
37
+ }).id.toUpperCase()
38
+ );
39
+ }
40
+ ),
41
+ [evmWallets, walletsFromProps]
42
+ );
43
+ useEffect(() => {
44
+ const loadLib = () => __async(this, null, function* () {
45
+ if (EvmProvider) {
46
+ return;
47
+ }
48
+ const { Provider, context, wallets } = yield getParaEvmConnector();
49
+ if (Provider) {
50
+ setEvmProvider(Provider);
51
+ }
52
+ if (wallets) {
53
+ setEvmWallets(wallets);
54
+ }
55
+ if (context) {
56
+ setEvmContext(context);
57
+ }
58
+ setIsLoadingLib(false);
59
+ });
60
+ loadLib();
61
+ }, []);
62
+ if (isLoadingLib) {
63
+ return null;
64
+ }
65
+ if (EvmProvider) {
66
+ return /* @__PURE__ */ jsx(EvmProvider, __spreadProps(__spreadValues({}, rest), { config: __spreadProps(__spreadValues({}, rest == null ? void 0 : rest.config), { wallets: filteredWallets }), children }));
67
+ } else if (isUsing) {
68
+ console.warn("@getpara/evm-wallet-connectors is required to use an external EVM wallet.");
69
+ }
70
+ return children;
71
+ }
72
+ export {
73
+ EvmExternalWalletProvider
74
+ };