@getpara/react-sdk 2.0.0-alpha.20 → 2.0.0-alpha.21

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 (88) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -5
  3. package/dist/modal/ParaModal.js +15 -5
  4. package/dist/modal/components/Account/Account.js +14 -8
  5. package/dist/modal/components/Account/AccountProfile.d.ts +1 -0
  6. package/dist/modal/components/Account/AccountProfile.js +170 -0
  7. package/dist/modal/components/Account/AccountProfileLink.d.ts +1 -0
  8. package/dist/modal/components/Account/AccountProfileLink.js +205 -0
  9. package/dist/modal/components/Account/AccountProfileLinkOptions.d.ts +1 -0
  10. package/dist/modal/components/Account/AccountProfileLinkOptions.js +98 -0
  11. package/dist/modal/components/Account/AccountProfileUnlink.d.ts +1 -0
  12. package/dist/modal/components/Account/AccountProfileUnlink.js +47 -0
  13. package/dist/modal/components/AuthInput/AuthInput.d.ts +17 -3
  14. package/dist/modal/components/AuthInput/AuthInput.js +116 -101
  15. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +2 -2
  16. package/dist/modal/components/AuthOptions/AuthOptions.js +26 -1
  17. package/dist/modal/components/Body/Body.js +21 -2
  18. package/dist/modal/components/Controls/Selects.js +3 -19
  19. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +7 -0
  20. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +70 -39
  21. package/dist/modal/components/Header/hooks/useStepTitle.js +7 -1
  22. package/dist/modal/components/OAuth/FarcasterOAuthStep.d.ts +1 -0
  23. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +6 -2
  24. package/dist/modal/components/OAuth/OAuth.js +2 -2
  25. package/dist/modal/components/OAuth/TelegramOAuthStep.d.ts +7 -0
  26. package/dist/modal/components/OAuth/TelegramOAuthStep.js +36 -52
  27. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.d.ts +12 -1
  28. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +40 -23
  29. package/dist/modal/components/common.d.ts +18 -1
  30. package/dist/modal/components/common.js +86 -0
  31. package/dist/modal/constants/constants.d.ts +1 -1
  32. package/dist/modal/constants/constants.js +1 -1
  33. package/dist/modal/constants/oAuthLogos.d.ts +15 -6
  34. package/dist/modal/constants/oAuthLogos.js +148 -19
  35. package/dist/modal/hooks/useTelegramLogin.d.ts +12 -0
  36. package/dist/modal/hooks/useTelegramLogin.js +65 -0
  37. package/dist/modal/stores/modal/actions.js +6 -1
  38. package/dist/modal/stores/modal/useModalStore.d.ts +4 -3
  39. package/dist/modal/stores/modal/useModalStore.js +7 -2
  40. package/dist/modal/types/modalProps.d.ts +6 -1
  41. package/dist/modal/utils/authInputHelpers.d.ts +3 -5
  42. package/dist/modal/utils/authInputHelpers.js +23 -20
  43. package/dist/modal/utils/getWalletDisplayName.d.ts +5 -0
  44. package/dist/modal/utils/getWalletDisplayName.js +22 -0
  45. package/dist/modal/utils/steps.d.ts +10 -2
  46. package/dist/modal/utils/steps.js +18 -2
  47. package/dist/provider/ParaProvider.js +6 -5
  48. package/dist/provider/actions/index.d.ts +19 -0
  49. package/dist/provider/actions/index.js +47 -29
  50. package/dist/provider/actions/utils.d.ts +3 -2
  51. package/dist/provider/actions/utils.js +25 -6
  52. package/dist/provider/components/CosmosWalletWrapper.js +2 -2
  53. package/dist/provider/components/EvmWalletWrapper.js +2 -2
  54. package/dist/provider/components/ExternalWalletWrapper.js +2 -1
  55. package/dist/provider/components/SolanaWalletWrapper.js +2 -2
  56. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.d.ts +0 -10
  57. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +2 -12
  58. package/dist/provider/external/stubs/EvmExternalWalletContextStub.d.ts +0 -1
  59. package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +2 -15
  60. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.d.ts +0 -6
  61. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +2 -8
  62. package/dist/provider/hooks/mutations/core.d.ts +27 -0
  63. package/dist/provider/hooks/mutations/core.js +66 -0
  64. package/dist/provider/hooks/mutations/index.d.ts +3 -28
  65. package/dist/provider/hooks/mutations/index.js +4 -60
  66. package/dist/provider/hooks/mutations/useLinkAccount.d.ts +9 -0
  67. package/dist/provider/hooks/mutations/useLinkAccount.js +18 -0
  68. package/dist/provider/hooks/mutations/utils.d.ts +11 -4
  69. package/dist/provider/hooks/mutations/utils.js +35 -4
  70. package/dist/provider/hooks/queries/core.d.ts +2 -0
  71. package/dist/provider/hooks/queries/core.js +13 -0
  72. package/dist/provider/hooks/queries/index.d.ts +1 -0
  73. package/dist/provider/hooks/queries/index.js +1 -0
  74. package/dist/provider/hooks/queries/utils.d.ts +4 -0
  75. package/dist/provider/hooks/queries/utils.js +24 -0
  76. package/dist/provider/hooks/utils/useModal.d.ts +4 -1
  77. package/dist/provider/hooks/utils/useModal.js +12 -2
  78. package/dist/provider/providers/AccountLinkProvider.d.ts +42 -0
  79. package/dist/provider/providers/AccountLinkProvider.js +443 -0
  80. package/dist/provider/providers/AuthProvider.d.ts +3 -1
  81. package/dist/provider/providers/AuthProvider.js +8 -5
  82. package/dist/provider/providers/ExternalWalletProvider.d.ts +18 -32
  83. package/dist/provider/providers/ExternalWalletProvider.js +167 -36
  84. package/dist/provider/stores/slices/modal.js +3 -1
  85. package/dist/provider/stores/types.d.ts +2 -1
  86. package/dist/provider/types/utils.d.ts +25 -6
  87. package/dist/provider/utils/renameMutations.d.ts +2 -2
  88. package/package.json +8 -8
@@ -7,19 +7,49 @@ import {
7
7
  import { renameCoreMutations } from "../../utils/renameMutations.js";
8
8
  import { useClient } from "../utils/index.js";
9
9
  import { useMutation, useMutationState } from "@tanstack/react-query";
10
- function generateHook(method, action, defaultParams) {
10
+ import { useInternalClient } from "../utils/useInternalClient.js";
11
+ function generateCoreMutation(method, action, {
12
+ delay,
13
+ defaultParams
14
+ } = {}) {
11
15
  return () => {
12
16
  const para = useClient();
13
17
  const mutation = useMutation({
14
18
  mutationKey: [method],
15
19
  mutationFn: (args) => __async(this, null, function* () {
16
- const result = yield action(para, args != null ? args : defaultParams);
17
- return result;
20
+ if (typeof delay === "number") yield new Promise((resolve) => setTimeout(resolve, delay));
21
+ try {
22
+ const result = yield action(para, args != null ? args : defaultParams);
23
+ return result;
24
+ } catch (error) {
25
+ throw error;
26
+ }
18
27
  })
19
28
  });
20
29
  return renameCoreMutations(mutation, method);
21
30
  };
22
31
  }
32
+ function generateInternalMutation(method, action, {
33
+ delay,
34
+ defaultParams
35
+ } = {}) {
36
+ return () => {
37
+ const para = useInternalClient();
38
+ const mutation = useMutation({
39
+ mutationKey: [method],
40
+ mutationFn: (args) => __async(this, null, function* () {
41
+ if (typeof delay === "number") yield new Promise((resolve) => setTimeout(resolve, delay));
42
+ try {
43
+ const result = yield action(para, args != null ? args : defaultParams);
44
+ return result;
45
+ } catch (error) {
46
+ throw error;
47
+ }
48
+ })
49
+ });
50
+ return mutation;
51
+ };
52
+ }
23
53
  function generateStateHook(method) {
24
54
  return () => {
25
55
  const frames = useMutationState({
@@ -54,6 +84,7 @@ function generateStateHook(method) {
54
84
  };
55
85
  }
56
86
  export {
57
- generateHook,
87
+ generateCoreMutation,
88
+ generateInternalMutation,
58
89
  generateStateHook
59
90
  };
@@ -0,0 +1,2 @@
1
+ export declare const useLinkedAccounts: () => import("../../types/utils.js").CoreMethodQueryHook<"getLinkedAccounts">;
2
+ export declare const useAccountLinkInProgress: () => import("../../types/utils.js").CoreMethodQueryHook<"accountLinkInProgress">;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import * as actions from "../../actions/index.js";
4
+ import { generateCoreQueryHook } from "./utils.js";
5
+ const useLinkedAccounts = generateCoreQueryHook("getLinkedAccounts", actions.getLinkedAccounts);
6
+ const useAccountLinkInProgress = generateCoreQueryHook(
7
+ "accountLinkInProgress",
8
+ actions.accountLinkInProgress
9
+ );
10
+ export {
11
+ useAccountLinkInProgress,
12
+ useLinkedAccounts
13
+ };
@@ -1,3 +1,4 @@
1
1
  export { useAccount } from './useAccount.js';
2
2
  export { useWallet } from './useWallet.js';
3
3
  export { useWalletBalance } from './useWalletBalance.js';
4
+ export * from './core.js';
@@ -3,6 +3,7 @@ import "../../../chunk-MMUBH76A.js";
3
3
  import { useAccount } from "./useAccount.js";
4
4
  import { useWallet } from "./useWallet.js";
5
5
  import { useWalletBalance } from "./useWalletBalance.js";
6
+ export * from "./core.js";
6
7
  export {
7
8
  useAccount,
8
9
  useWallet,
@@ -0,0 +1,4 @@
1
+ import ParaWeb, { CoreMethodName, CoreMethods } from '@getpara/web-sdk';
2
+ import { CoreMethodQueryHook } from '../../types/utils.js';
3
+ import { CoreAction } from '../../actions/utils.js';
4
+ export declare function generateCoreQueryHook<const method extends CoreMethodName & keyof CoreMethods>(method: method, action: CoreAction<method> & ((_: ParaWeb) => Promise<unknown>)): () => CoreMethodQueryHook<method>;
@@ -0,0 +1,24 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../../../chunk-MMUBH76A.js";
5
+ import { useClient } from "../utils/index.js";
6
+ import { useQuery } from "@tanstack/react-query";
7
+ function generateCoreQueryHook(method, action) {
8
+ return () => {
9
+ const para = useClient();
10
+ return useQuery({
11
+ queryKey: [method],
12
+ queryFn: () => __async(this, null, function* () {
13
+ if (!para) {
14
+ return null;
15
+ }
16
+ const result = yield action(para);
17
+ return result;
18
+ })
19
+ });
20
+ };
21
+ }
22
+ export {
23
+ generateCoreQueryHook
24
+ };
@@ -1,8 +1,11 @@
1
+ import { ModalStep } from '../../../modal/index.js';
1
2
  /**
2
3
  * Hook for controlling the Para modal
3
4
  */
4
5
  export declare const useModal: () => {
5
6
  isOpen: boolean;
6
- openModal: () => void;
7
+ openModal: ({ step }?: {
8
+ step?: ModalStep;
9
+ }) => void;
7
10
  closeModal: () => void;
8
11
  };
@@ -1,13 +1,23 @@
1
1
  "use client";
2
2
  import "../../../chunk-MMUBH76A.js";
3
+ import { useModalStore } from "../../../modal/stores/index.js";
3
4
  import { useStore } from "../../stores/useStore.js";
4
5
  const useModal = () => {
5
6
  const isOpen = useStore((state) => state.isOpen);
6
7
  const setIsOpen = useStore((state) => state.setIsOpen);
7
- const openModal = () => {
8
- setIsOpen(true);
8
+ const openedToStep = useStore((state) => state.openedToStep);
9
+ const setStep = useModalStore((state) => state.setStep);
10
+ const openModal = ({ step } = {}) => {
11
+ if (step) {
12
+ openedToStep.current = step;
13
+ setStep(step);
14
+ }
15
+ if (!isOpen) {
16
+ setIsOpen(true);
17
+ }
9
18
  };
10
19
  const closeModal = () => {
20
+ openedToStep.current = null;
11
21
  setIsOpen(false);
12
22
  };
13
23
  return { isOpen, openModal, closeModal };
@@ -0,0 +1,42 @@
1
+ import { PropsWithChildren } from 'react';
2
+ import { MutationStatus } from '@tanstack/react-query';
3
+ import { AccountLinkError, AccountLinkInProgress as CoreAccountLinkInProgress, LinkedAccount, LinkedAccounts, SupportedAccountLinks, TelegramAuthResponse, TExternalWallet, TLinkedAccountType, Auth, InternalMethodParams } from '@getpara/web-sdk';
4
+ type AccountLinkInProgress = Partial<CoreAccountLinkInProgress & {
5
+ pendingWalletType?: TExternalWallet;
6
+ }>;
7
+ export type ModalLinkAccountArgs = undefined | {
8
+ auth: Auth<'email' | 'phone'>;
9
+ } | {
10
+ type: Exclude<TLinkedAccountType, 'EXTERNAL_WALLET'> | 'X';
11
+ } | {
12
+ externalWallet: TExternalWallet;
13
+ } | {
14
+ options: SupportedAccountLinks;
15
+ };
16
+ type Value = {
17
+ isEnabled: boolean;
18
+ accountLinkInProgress: AccountLinkInProgress | undefined;
19
+ accountLinkOptions: SupportedAccountLinks;
20
+ linkAccount: (_: ModalLinkAccountArgs) => Promise<void>;
21
+ isLinkAccountPending: boolean;
22
+ verifyEmailOrPhoneLink: (verificationCode: string) => void;
23
+ verifyOAuthLink: (method: InternalMethodParams<'verifyOAuthLink'>['method']) => void;
24
+ verifyFarcasterLink: () => void;
25
+ verifyTelegramLink: (telegramAuthResponse: TelegramAuthResponse) => void;
26
+ verifyLinkedAccount: (accountLinkInProgress: AccountLinkInProgress) => void;
27
+ linkAccountStatus: MutationStatus;
28
+ linkAccountError: string | null;
29
+ setLinkAccountError: (_: AccountLinkError | null) => void;
30
+ unlinkingAccount: LinkedAccount | undefined;
31
+ unlinkAccount: (linkedAccount: LinkedAccount) => void;
32
+ unlinkAccountConfirm: () => void;
33
+ isUnlinkAccountPending: boolean;
34
+ cancelLinkAccount: () => void;
35
+ onAccountLinked: (_: AccountLinkInProgress) => void;
36
+ onAccountLinkVerified: (_: LinkedAccounts) => void;
37
+ resetMutations: () => void;
38
+ };
39
+ export declare const AccountLinkContext: import("react").Context<Value>;
40
+ export declare const AccountLinkProvider: ({ children }: PropsWithChildren) => import("react/jsx-runtime").JSX.Element;
41
+ export declare const useAccountLinking: () => Value;
42
+ export {};
@@ -0,0 +1,443 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../../chunk-MMUBH76A.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { createContext, useContext, useEffect, useMemo, useState } from "react";
7
+ import { useAccount, useAccountLinkInProgress, useModal } from "../index.js";
8
+ import * as actions from "../actions/index.js";
9
+ import { useQueryClient } from "@tanstack/react-query";
10
+ import {
11
+ AccountLinkError,
12
+ LINKED_ACCOUNT_TYPES
13
+ } from "@getpara/web-sdk";
14
+ import { useModalStore } from "../../modal/stores/index.js";
15
+ import { ModalStep, openPopup } from "../../modal/index.js";
16
+ import { useGoBack } from "../../modal/hooks/useGoBack.js";
17
+ import { useExternalWallets } from "./ExternalWalletProvider.js";
18
+ import { useInternalClient } from "../hooks/utils/useInternalClient.js";
19
+ import { generateInternalMutation } from "../hooks/mutations/utils.js";
20
+ import { validateAuth } from "../../modal/utils/authInputHelpers.js";
21
+ import { extractAuthInfo } from "@getpara/user-management-client";
22
+ import { useStore } from "../stores/useStore.js";
23
+ const AccountLinkContext = createContext({
24
+ isEnabled: false,
25
+ accountLinkInProgress: void 0,
26
+ accountLinkOptions: [...LINKED_ACCOUNT_TYPES],
27
+ linkAccount: () => Promise.resolve(),
28
+ isLinkAccountPending: false,
29
+ verifyEmailOrPhoneLink: () => {
30
+ },
31
+ verifyOAuthLink: () => {
32
+ },
33
+ verifyFarcasterLink: () => {
34
+ },
35
+ verifyTelegramLink: () => {
36
+ },
37
+ verifyLinkedAccount: () => {
38
+ },
39
+ unlinkingAccount: void 0,
40
+ linkAccountStatus: "idle",
41
+ linkAccountError: null,
42
+ setLinkAccountError: () => {
43
+ },
44
+ unlinkAccount: () => {
45
+ },
46
+ unlinkAccountConfirm: () => {
47
+ },
48
+ isUnlinkAccountPending: false,
49
+ cancelLinkAccount: () => {
50
+ },
51
+ onAccountLinked: () => {
52
+ },
53
+ onAccountLinkVerified: () => {
54
+ },
55
+ resetMutations: () => {
56
+ }
57
+ // externalWalletQrUri: undefined,
58
+ });
59
+ const useLinkAccount = generateInternalMutation("linkAccount", actions.linkAccount);
60
+ const useUnlinkAccount = generateInternalMutation("unlinkAccount", actions.unlinkAccount);
61
+ const useVerifyOAuthLink = generateInternalMutation("verifyOAuthLink", actions.verifyOAuthLink, { delay: 500 });
62
+ const useVerifyEmailOrPhoneLink = generateInternalMutation("verifyEmailOrPhoneLink", actions.verifyEmailOrPhoneLink);
63
+ const useVerifyFarcasterLink = generateInternalMutation("verifyFarcasterLink", actions.verifyFarcasterLink, {
64
+ delay: 500
65
+ });
66
+ const useVerifyTelegramLink = generateInternalMutation("verifyTelegramLink", actions.verifyTelegramLink);
67
+ const useVerifyExternalWalletLink = generateInternalMutation("verifyExternalWalletLink", actions.verifyExternalWalletLink);
68
+ const AccountLinkProvider = ({ children }) => {
69
+ const para = useInternalClient();
70
+ const queryClient = useQueryClient();
71
+ const { data: account } = useAccount();
72
+ const { data: coreAccountLinkInProgress } = useAccountLinkInProgress();
73
+ const {
74
+ wallet: connectedWallet,
75
+ wallets,
76
+ signMessage,
77
+ isSigningMessage,
78
+ requestInfo: externalWalletRequestInfo,
79
+ disconnectBase
80
+ } = useExternalWallets();
81
+ const { isOpen, openModal } = useModal();
82
+ const includeWalletVerification = useStore((state) => state.includeWalletVerification);
83
+ const setStep = useModalStore((state) => state.setStep);
84
+ const setFarcasterConnectUri = useModalStore((state) => state.setFarcasterConnectUri);
85
+ const refs = useModalStore((state) => state.refs);
86
+ const externalWalletError = useModalStore((state) => state.externalWalletError);
87
+ const accountLinkOptions = useModalStore((state) => state.accountLinkOptions) || [...LINKED_ACCOUNT_TYPES];
88
+ const setAccountLinkOptions = useModalStore((state) => state.setAccountLinkOptions);
89
+ const goBack = useGoBack();
90
+ const { mutateAsync: mutateLinkAccountAsync, isPending: isLinkAccountPending } = useLinkAccount();
91
+ const { mutate: mutateUnlinkAccount, isPending: isUnlinkAccountPending } = useUnlinkAccount();
92
+ const {
93
+ mutate: mutateVerifyEmailOrPhoneLink,
94
+ status: statusVerifyEmailOrPhoneLink,
95
+ reset: resetVerifyEmailOrPhoneLink
96
+ } = useVerifyEmailOrPhoneLink();
97
+ const { mutate: mutateVerifyOAuthLink, status: statusVerifyOAuthLink, reset: resetVerifyOAuthLink } = useVerifyOAuthLink();
98
+ const {
99
+ mutate: mutateVerifyFarcasterLink,
100
+ status: statusVerifyFarcasterLink,
101
+ reset: resetVerifyFarcasterLink
102
+ } = useVerifyFarcasterLink();
103
+ const {
104
+ mutateAsync: mutateVerifyTelegramLinkAsync,
105
+ status: statusVerifyTelegramLink,
106
+ reset: resetVerifyTelegramLink
107
+ } = useVerifyTelegramLink();
108
+ const {
109
+ mutateAsync: mutateAsyncVerifyExternalWalletLink,
110
+ status: statusVerifyExternalWalletLink,
111
+ reset: resetVerifyExternalWalletLink
112
+ } = useVerifyExternalWalletLink();
113
+ const isEnabled = !!(account == null ? void 0 : account.isConnected) && !(account == null ? void 0 : account.isGuestMode) && (!(account == null ? void 0 : account.externalWallet) || includeWalletVerification);
114
+ const [accountLinkInProgress, setAccountLinkInProgress] = useState(
115
+ coreAccountLinkInProgress
116
+ );
117
+ const [unlinkingAccount, setUnlinkingAccount] = useState(void 0);
118
+ const [linkAccountError, setLinkAccountError] = useState(null);
119
+ const [linkAccountStatus, setLinkAccountStatus] = useState("pending");
120
+ const linkAccount = (args) => __async(void 0, null, function* () {
121
+ if (!isEnabled) {
122
+ setLinkAccountError(AccountLinkError.NotAuthenticated);
123
+ throw new Error(AccountLinkError.NotAuthenticated);
124
+ }
125
+ setLinkAccountError(null);
126
+ switch (true) {
127
+ case !args:
128
+ case (args && "options" in args):
129
+ {
130
+ const options = (args == null ? void 0 : args.options) || (para == null ? void 0 : para.supportedAccountLinks) || [...LINKED_ACCOUNT_TYPES];
131
+ if (options.length < 2) {
132
+ throw new Error("Account linking options array must contain 2 or more items");
133
+ }
134
+ setAccountLinkOptions(options);
135
+ openModal({ step: ModalStep.ACCOUNT_PROFILE_LIST });
136
+ }
137
+ break;
138
+ case (args && "externalWallet" in args):
139
+ {
140
+ const providerId = args.externalWallet;
141
+ if (providerId === (connectedWallet == null ? void 0 : connectedWallet.internalId)) {
142
+ throw new Error(`Cannot link the currently connected external wallet: ${providerId}`);
143
+ }
144
+ setAccountLinkInProgress({ type: "EXTERNAL_WALLET", pendingWalletType: providerId });
145
+ const linkWallet = wallets.find((w) => w.internalId === providerId);
146
+ if (!linkWallet) {
147
+ throw new Error(`wallet not installed: ${providerId}`);
148
+ }
149
+ openModal({ step: ModalStep.ACCOUNT_PROFILE_ADD });
150
+ try {
151
+ const externalWallet = yield externalWalletRequestInfo(providerId);
152
+ const accountLinkInProgress2 = yield mutateLinkAccountAsync({ externalWallet });
153
+ yield onAccountLinked(accountLinkInProgress2);
154
+ const signatureVerificationMessage = accountLinkInProgress2.externalWallet.signatureVerificationMessage;
155
+ yield new Promise((resolve) => setTimeout(resolve, 100));
156
+ const {
157
+ signature: signedMessage,
158
+ cosmosPublicKeyHex,
159
+ cosmosSigner
160
+ } = yield signMessage({
161
+ message: signatureVerificationMessage,
162
+ externalWallet: accountLinkInProgress2.externalWallet
163
+ });
164
+ const updatedAccounts = yield mutateAsyncVerifyExternalWalletLink({
165
+ signedMessage,
166
+ cosmosPublicKeyHex,
167
+ cosmosSigner
168
+ });
169
+ yield onAccountLinkVerified(updatedAccounts);
170
+ } catch (e) {
171
+ console.error(e);
172
+ setLinkAccountError(`Error authenticating external wallet: ${e.message}`);
173
+ } finally {
174
+ if (linkWallet.type === "EVM" || linkWallet.type === "SOLANA") {
175
+ yield disconnectBase(providerId);
176
+ }
177
+ }
178
+ }
179
+ break;
180
+ default: {
181
+ switch (true) {
182
+ case "auth" in args:
183
+ {
184
+ validateAuth(args.auth);
185
+ const authInfo = extractAuthInfo(args.auth, { isRequired: true });
186
+ setAccountLinkInProgress({
187
+ type: authInfo.authType.toUpperCase(),
188
+ identifier: authInfo.identifier
189
+ });
190
+ }
191
+ break;
192
+ case "type" in args: {
193
+ if (args.type === "EMAIL" || args.type === "PHONE" || !isOpen) {
194
+ setAccountLinkInProgress({ type: args.type === "X" ? "TWITTER" : args.type });
195
+ }
196
+ break;
197
+ }
198
+ }
199
+ if (!isOpen) {
200
+ openModal({ step: ModalStep.ACCOUNT_PROFILE_ADD });
201
+ }
202
+ try {
203
+ const accountLinkInProgress2 = yield mutateLinkAccountAsync(args);
204
+ yield onAccountLinked(accountLinkInProgress2);
205
+ } catch (e) {
206
+ setLinkAccountError(e.message);
207
+ }
208
+ }
209
+ }
210
+ });
211
+ const onAccountLinked = (accountLinkInProgress2) => __async(void 0, null, function* () {
212
+ queryClient.setQueryData(["accountLinkInProgress"], accountLinkInProgress2 != null ? accountLinkInProgress2 : null);
213
+ setStep(ModalStep.ACCOUNT_PROFILE_ADD);
214
+ switch (accountLinkInProgress2.type) {
215
+ case "EMAIL":
216
+ case "PHONE":
217
+ case "TELEGRAM":
218
+ case "EXTERNAL_WALLET":
219
+ break;
220
+ case "FARCASTER":
221
+ verifyFarcasterLink();
222
+ break;
223
+ default:
224
+ verifyLinkedAccount(accountLinkInProgress2);
225
+ }
226
+ });
227
+ const verifyEmailOrPhoneLink = (verificationCode) => __async(void 0, null, function* () {
228
+ mutateVerifyEmailOrPhoneLink(
229
+ { verificationCode },
230
+ {
231
+ onSuccess: onAccountLinkVerified,
232
+ onError: onAccountLinkError
233
+ }
234
+ );
235
+ });
236
+ const verifyOAuthLink = (method) => __async(void 0, null, function* () {
237
+ mutateVerifyOAuthLink(
238
+ {
239
+ method,
240
+ isCanceled: () => {
241
+ var _a;
242
+ return !!((_a = refs.popupWindow.current) == null ? void 0 : _a.closed);
243
+ },
244
+ onOAuthUrl: (oAuthUrl) => {
245
+ refs.popupWindow.current = openPopup({
246
+ url: oAuthUrl,
247
+ target: `${method}AuthPopup`,
248
+ type: "OAUTH",
249
+ current: refs.popupWindow.current
250
+ });
251
+ }
252
+ },
253
+ {
254
+ onSuccess: onAccountLinkVerified,
255
+ onError: onAccountLinkError
256
+ }
257
+ );
258
+ });
259
+ const verifyFarcasterLink = () => __async(void 0, null, function* () {
260
+ mutateVerifyFarcasterLink(
261
+ {
262
+ isCanceled: () => refs.currentStep.current !== ModalStep.ACCOUNT_PROFILE_ADD,
263
+ onConnectUri: (connectUri) => {
264
+ setFarcasterConnectUri(connectUri);
265
+ }
266
+ },
267
+ {
268
+ onSuccess: onAccountLinkVerified,
269
+ onError: () => {
270
+ if (refs.currentStep.current === ModalStep.ACCOUNT_PROFILE_ADD) {
271
+ goBack();
272
+ }
273
+ }
274
+ }
275
+ );
276
+ });
277
+ const verifyTelegramLink = (telegramAuthResponse) => __async(void 0, null, function* () {
278
+ try {
279
+ const accounts = yield mutateVerifyTelegramLinkAsync({
280
+ telegramAuthResponse
281
+ });
282
+ onAccountLinkVerified(accounts);
283
+ } catch (e) {
284
+ onAccountLinkError(e);
285
+ throw e;
286
+ }
287
+ });
288
+ const verifyLinkedAccount = ({ type }) => {
289
+ switch (type) {
290
+ case "EMAIL":
291
+ case "PHONE":
292
+ case "TELEGRAM":
293
+ case "EXTERNAL_WALLET":
294
+ break;
295
+ case "FARCASTER":
296
+ verifyFarcasterLink();
297
+ break;
298
+ default:
299
+ verifyOAuthLink(type);
300
+ break;
301
+ }
302
+ };
303
+ const onAccountLinkVerified = (updatedAccounts) => {
304
+ queryClient.setQueryData(["getLinkedAccounts"], () => updatedAccounts);
305
+ setTimeout(() => {
306
+ setStep(ModalStep.ACCOUNT_PROFILE);
307
+ }, 2e3);
308
+ };
309
+ const onAccountLinkError = (e) => {
310
+ setLinkAccountError(e instanceof Error ? e.message : e);
311
+ };
312
+ const unlinkAccount = (linkedAccount) => {
313
+ setUnlinkingAccount(linkedAccount);
314
+ setStep(ModalStep.ACCOUNT_PROFILE_REMOVE);
315
+ };
316
+ const unlinkAccountConfirm = () => {
317
+ mutateUnlinkAccount(
318
+ {
319
+ linkedAccountId: unlinkingAccount.id
320
+ },
321
+ {
322
+ onSuccess: (updatedAccounts) => {
323
+ queryClient.setQueryData(["getLinkedAccounts"], () => updatedAccounts);
324
+ setUnlinkingAccount(void 0);
325
+ setStep(ModalStep.ACCOUNT_PROFILE);
326
+ }
327
+ }
328
+ );
329
+ };
330
+ const cancelLinkAccount = () => {
331
+ mutateUnlinkAccount(void 0);
332
+ };
333
+ const resetMutations = () => {
334
+ resetVerifyEmailOrPhoneLink();
335
+ resetVerifyFarcasterLink();
336
+ resetVerifyOAuthLink();
337
+ resetVerifyTelegramLink();
338
+ resetVerifyExternalWalletLink();
339
+ };
340
+ useEffect(() => {
341
+ setAccountLinkInProgress((prev) => {
342
+ return coreAccountLinkInProgress != null ? coreAccountLinkInProgress : prev;
343
+ });
344
+ }, [coreAccountLinkInProgress]);
345
+ useEffect(() => {
346
+ if (!isOpen) {
347
+ setLinkAccountError(null);
348
+ setAccountLinkInProgress(void 0);
349
+ setUnlinkingAccount(void 0);
350
+ resetMutations();
351
+ }
352
+ }, [isOpen]);
353
+ useEffect(() => {
354
+ setLinkAccountStatus(() => {
355
+ if (!isEnabled || !accountLinkInProgress) {
356
+ return "idle";
357
+ }
358
+ if ((accountLinkInProgress.type === "EMAIL" || accountLinkInProgress.type === "PHONE") && !accountLinkInProgress.identifier) {
359
+ return "idle";
360
+ }
361
+ if (linkAccountError) return "error";
362
+ switch (true) {
363
+ case accountLinkInProgress.type === "TELEGRAM":
364
+ return statusVerifyTelegramLink;
365
+ case accountLinkInProgress.type === "FARCASTER":
366
+ return statusVerifyFarcasterLink;
367
+ case accountLinkInProgress.type === "EMAIL":
368
+ case accountLinkInProgress.type === "PHONE":
369
+ return statusVerifyEmailOrPhoneLink;
370
+ case accountLinkInProgress.type === "EXTERNAL_WALLET":
371
+ if (isSigningMessage) return "pending";
372
+ return externalWalletError && externalWalletError.length > 0 ? "error" : statusVerifyExternalWalletLink === "idle" ? "pending" : statusVerifyExternalWalletLink;
373
+ default:
374
+ return statusVerifyOAuthLink;
375
+ }
376
+ });
377
+ }, [
378
+ linkAccountError,
379
+ isEnabled,
380
+ accountLinkInProgress,
381
+ statusVerifyEmailOrPhoneLink,
382
+ statusVerifyFarcasterLink,
383
+ statusVerifyOAuthLink,
384
+ statusVerifyTelegramLink,
385
+ statusVerifyExternalWalletLink,
386
+ externalWalletError,
387
+ isSigningMessage
388
+ ]);
389
+ const value = useMemo(
390
+ () => ({
391
+ isEnabled,
392
+ accountLinkInProgress,
393
+ accountLinkOptions,
394
+ linkAccount,
395
+ isLinkAccountPending,
396
+ verifyOAuthLink,
397
+ verifyFarcasterLink,
398
+ verifyTelegramLink,
399
+ verifyEmailOrPhoneLink,
400
+ verifyLinkedAccount,
401
+ linkAccountStatus,
402
+ linkAccountError,
403
+ setLinkAccountError,
404
+ unlinkingAccount,
405
+ unlinkAccount,
406
+ unlinkAccountConfirm,
407
+ isUnlinkAccountPending,
408
+ cancelLinkAccount,
409
+ onAccountLinked,
410
+ onAccountLinkVerified,
411
+ resetMutations
412
+ }),
413
+ [
414
+ isEnabled,
415
+ accountLinkInProgress,
416
+ accountLinkOptions,
417
+ linkAccount,
418
+ isLinkAccountPending,
419
+ verifyOAuthLink,
420
+ verifyFarcasterLink,
421
+ verifyTelegramLink,
422
+ verifyEmailOrPhoneLink,
423
+ verifyLinkedAccount,
424
+ linkAccountStatus,
425
+ linkAccountError,
426
+ setLinkAccountError,
427
+ unlinkAccount,
428
+ unlinkAccountConfirm,
429
+ isUnlinkAccountPending,
430
+ cancelLinkAccount,
431
+ onAccountLinked,
432
+ onAccountLinkVerified,
433
+ resetMutations
434
+ ]
435
+ );
436
+ return /* @__PURE__ */ jsx(AccountLinkContext.Provider, { value, children });
437
+ };
438
+ const useAccountLinking = () => useContext(AccountLinkContext);
439
+ export {
440
+ AccountLinkContext,
441
+ AccountLinkProvider,
442
+ useAccountLinking
443
+ };
@@ -3,15 +3,17 @@ import { PropsWithChildren } from 'react';
3
3
  import { AuthMethod, CoreMethodParams, AuthState, AuthStateSignup, AuthStateLogin } from '@getpara/web-sdk';
4
4
  import { ParaModalProps } from '../../modal/types/modalProps.js';
5
5
  import { TelegramAuthResponse, VerifiedAuth } from '@getpara/user-management-client';
6
+ import { MutationStatus } from '@tanstack/react-query';
6
7
  type Value = {
7
8
  signUpOrLogIn: (_: VerifiedAuth) => void;
8
9
  isSignUpOrLogInPending: boolean;
9
10
  verifyNewAccount: (_: string) => void;
10
- isVerifyNewAccountPending: boolean;
11
+ verifyNewAccountStatus: MutationStatus;
11
12
  verifyNewAccountError: Error | null;
12
13
  verifyOAuth: (_: CoreMethodParams<'verifyOAuth'>['method']) => void;
13
14
  verifyFarcaster: () => void;
14
15
  verifyTelegram: (_: TelegramAuthResponse) => void;
16
+ verifyTelegramStatus: MutationStatus;
15
17
  onNewAuthState: (_: AuthState) => void;
16
18
  presentSignupUi: (_: AuthMethod, __: AuthStateSignup) => void;
17
19
  presentLoginUi: (_: AuthMethod, __: AuthStateLogin) => void;