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

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 (183) hide show
  1. package/dist/cli/cli.mjs +1 -6
  2. package/dist/index.js +11 -6499
  3. package/dist/modal/ParaModal.js +262 -0
  4. package/dist/modal/components/Account/Account.js +139 -0
  5. package/dist/modal/components/AddFunds/AddFunds.d.ts +0 -2
  6. package/dist/modal/components/AddFunds/AddFunds.js +69 -0
  7. package/dist/modal/components/AddFunds/AddFundsAsset.d.ts +1 -0
  8. package/dist/modal/components/AddFunds/AddFundsAsset.js +125 -0
  9. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +78 -0
  10. package/dist/modal/components/AddFunds/AddFundsContext.d.ts +31 -0
  11. package/dist/modal/components/AddFunds/AddFundsContext.js +160 -0
  12. package/dist/modal/components/AddFunds/AddFundsDone.js +49 -0
  13. package/dist/modal/components/AddFunds/AddFundsProvider.d.ts +1 -0
  14. package/dist/modal/components/AddFunds/AddFundsProvider.js +109 -0
  15. package/dist/modal/components/AddFunds/AddFundsReceive.d.ts +1 -0
  16. package/dist/modal/components/AddFunds/AddFundsReceive.js +83 -0
  17. package/dist/modal/components/AddFunds/AddFundsSettings.d.ts +1 -0
  18. package/dist/modal/components/AddFunds/AddFundsSettings.js +237 -0
  19. package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
  20. package/dist/modal/components/AddFunds/common.d.ts +19 -0
  21. package/dist/modal/components/AddFunds/common.js +24 -0
  22. package/dist/modal/components/AddFunds/index.js +4 -0
  23. package/dist/modal/components/AuthInput/AuthInput.js +262 -0
  24. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
  25. package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
  26. package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +4 -3
  27. package/dist/modal/components/AuthMainStep/AuthMainStep.js +50 -0
  28. package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +4 -3
  29. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +157 -0
  30. package/dist/modal/components/AuthOptions/AuthOptions.d.ts +4 -3
  31. package/dist/modal/components/AuthOptions/AuthOptions.js +67 -0
  32. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
  33. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
  34. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
  35. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +5 -1
  36. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +49 -0
  37. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +63 -0
  38. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +55 -0
  39. package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
  40. package/dist/modal/components/Body/Body.d.ts +4 -3
  41. package/dist/modal/components/Body/Body.js +327 -0
  42. package/dist/modal/components/ChainSwitch/ChainSwitch.js +95 -0
  43. package/dist/modal/components/ChainSwitch/config.js +17 -0
  44. package/dist/modal/components/Controls/Controls.js +77 -0
  45. package/dist/modal/components/Controls/Selects.js +189 -0
  46. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +144 -0
  47. package/dist/modal/components/ExternalWalletStep/config.js +17 -0
  48. package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +34 -0
  49. package/dist/modal/components/ExternalWallets/ExternalWallets.js +173 -0
  50. package/dist/modal/components/Footer/Footer.js +95 -0
  51. package/dist/modal/components/Header/Header.js +43 -0
  52. package/dist/modal/components/Header/hooks/useStepTitle.js +54 -0
  53. package/dist/modal/components/Hero/Hero.js +116 -0
  54. package/dist/modal/components/IFrameStep/IFrameStep.js +59 -0
  55. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +31 -0
  56. package/dist/modal/components/ModalContent/ModalContent.js +95 -0
  57. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +27 -0
  58. package/dist/modal/components/OAuth/OAuth.d.ts +2 -2
  59. package/dist/modal/components/OAuth/OAuth.js +79 -0
  60. package/dist/modal/components/OAuth/TelegramOAuthStep.js +90 -0
  61. package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
  62. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
  63. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +107 -0
  64. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +132 -0
  65. package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
  66. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +27 -0
  67. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +143 -0
  68. package/dist/modal/components/Waiting/Waiting.js +17 -0
  69. package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
  70. package/dist/modal/components/WalletCard/WalletCard.d.ts +3 -3
  71. package/dist/modal/components/WalletCard/WalletCard.js +128 -0
  72. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +73 -0
  73. package/dist/modal/components/common.d.ts +32 -13
  74. package/dist/modal/components/common.js +175 -0
  75. package/dist/modal/components/index.js +2 -0
  76. package/dist/modal/constants/constants.d.ts +9 -2
  77. package/dist/modal/constants/constants.js +138 -0
  78. package/dist/modal/constants/defaults.js +10 -0
  79. package/dist/modal/constants/oAuthLogos.d.ts +3 -3
  80. package/dist/modal/constants/oAuthLogos.js +24 -0
  81. package/dist/modal/hooks/useGoBack.js +43 -0
  82. package/dist/modal/index.d.ts +1 -2
  83. package/dist/modal/index.js +29 -0
  84. package/dist/modal/stores/index.js +2 -0
  85. package/dist/modal/stores/modal/actions.js +133 -0
  86. package/dist/modal/stores/modal/useModalStore.d.ts +12 -4
  87. package/dist/modal/stores/modal/useModalStore.js +68 -0
  88. package/dist/modal/types/commonTypes.d.ts +0 -47
  89. package/dist/modal/types/commonTypes.js +1 -0
  90. package/dist/modal/types/externalWallets.d.ts +2 -0
  91. package/dist/modal/types/externalWallets.js +32 -0
  92. package/dist/modal/types/modalProps.d.ts +10 -2
  93. package/dist/modal/types/modalProps.js +12 -0
  94. package/dist/modal/utils/authInputHelpers.d.ts +7 -0
  95. package/dist/modal/utils/authInputHelpers.js +38 -0
  96. package/dist/modal/utils/authLayoutHelpers.js +8 -0
  97. package/dist/modal/utils/countryCodes.js +45 -0
  98. package/dist/modal/utils/getMailtoLink.js +10 -0
  99. package/dist/modal/utils/getTileButtonFlex.js +20 -0
  100. package/dist/modal/utils/isPasskeySupported.js +15 -0
  101. package/dist/modal/utils/openPopup.js +60 -0
  102. package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
  103. package/dist/modal/utils/steps.d.ts +6 -0
  104. package/dist/modal/utils/steps.js +247 -0
  105. package/dist/modal/utils/stringFormatters.d.ts +1 -0
  106. package/dist/modal/utils/stringFormatters.js +19 -0
  107. package/dist/modal/utils/validateOnRampConfig.js +32 -0
  108. package/dist/package.json +6 -0
  109. package/dist/provider/ParaProvider.js +83 -0
  110. package/dist/provider/actions/getAccount.d.ts +8 -1
  111. package/dist/provider/actions/getAccount.js +51 -0
  112. package/dist/provider/actions/getWallet.d.ts +2 -2
  113. package/dist/provider/actions/getWallet.js +14 -0
  114. package/dist/provider/actions/index.d.ts +2 -0
  115. package/dist/provider/actions/index.js +59 -0
  116. package/dist/provider/actions/utils.js +15 -0
  117. package/dist/provider/components/CosmosWalletWrapper.js +34 -0
  118. package/dist/provider/components/EvmWalletWrapper.js +34 -0
  119. package/dist/provider/components/ExternalWalletWrapper.js +139 -0
  120. package/dist/provider/components/SolanaWalletWrapper.js +36 -0
  121. package/dist/provider/external/getParaCosmosConnector.js +22 -0
  122. package/dist/provider/external/getParaEvmConnector.js +22 -0
  123. package/dist/provider/external/getParaSolanaConnector.js +22 -0
  124. package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +18 -0
  125. package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +21 -0
  126. package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +14 -0
  127. package/dist/provider/hooks/index.js +4 -0
  128. package/dist/provider/hooks/mutations/index.d.ts +1 -0
  129. package/dist/provider/hooks/mutations/index.js +61 -0
  130. package/dist/provider/hooks/mutations/utils.js +22 -0
  131. package/dist/provider/hooks/queries/index.d.ts +1 -0
  132. package/dist/provider/hooks/queries/index.js +10 -0
  133. package/dist/provider/hooks/queries/useAccount.js +21 -0
  134. package/dist/provider/hooks/queries/useWallet.js +22 -0
  135. package/dist/provider/hooks/queries/useWalletBalance.d.ts +6 -0
  136. package/dist/provider/hooks/queries/useWalletBalance.js +55 -0
  137. package/dist/provider/hooks/utils/index.js +10 -0
  138. package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
  139. package/dist/provider/hooks/utils/useClient.js +10 -0
  140. package/dist/provider/hooks/utils/useEventListeners.d.ts +1 -1
  141. package/dist/provider/hooks/utils/useEventListeners.js +147 -0
  142. package/dist/provider/hooks/utils/useInternalClient.js +10 -0
  143. package/dist/provider/hooks/utils/useModal.js +17 -0
  144. package/dist/provider/hooks/utils/useWalletState.d.ts +3 -3
  145. package/dist/provider/hooks/utils/useWalletState.js +48 -0
  146. package/dist/provider/index.js +9 -0
  147. package/dist/provider/providers/AuthProvider.d.ts +10 -6
  148. package/dist/provider/providers/AuthProvider.js +498 -0
  149. package/dist/provider/providers/CosmosExternalWalletProvider.js +66 -0
  150. package/dist/provider/providers/EvmExternalWalletProvider.js +74 -0
  151. package/dist/provider/providers/ExternalWalletProvider.d.ts +5 -2
  152. package/dist/provider/providers/ExternalWalletProvider.js +428 -0
  153. package/dist/provider/providers/SolanaExternalWalletProvider.js +66 -0
  154. package/dist/provider/stores/getters.d.ts +1 -1
  155. package/dist/provider/stores/getters.js +13 -0
  156. package/dist/provider/stores/setters.js +7 -0
  157. package/dist/provider/stores/slices/client.js +9 -0
  158. package/dist/provider/stores/slices/config.js +9 -0
  159. package/dist/provider/stores/slices/externalWallets.js +40 -0
  160. package/dist/provider/stores/slices/index.js +5 -0
  161. package/dist/provider/stores/slices/modal.js +16 -0
  162. package/dist/provider/stores/slices/wallet.js +13 -0
  163. package/dist/provider/stores/types.d.ts +7 -4
  164. package/dist/provider/stores/types.js +1 -0
  165. package/dist/provider/stores/useStore.js +28 -0
  166. package/dist/provider/types/externalWalletProviders.d.ts +2 -2
  167. package/dist/provider/types/externalWalletProviders.js +1 -0
  168. package/dist/provider/types/provider.d.ts +9 -3
  169. package/dist/provider/types/provider.js +1 -0
  170. package/dist/provider/types/query.js +1 -0
  171. package/dist/provider/types/utils.js +1 -0
  172. package/dist/provider/utils/constants.d.ts +5 -0
  173. package/dist/provider/utils/constants.js +10 -0
  174. package/dist/provider/utils/paraConfigTypeGuards.js +13 -0
  175. package/dist/provider/utils/renameMutations.js +18 -0
  176. package/package.json +18 -16
  177. package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
  178. package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
  179. package/dist/chunk-MMUBH76A.js.br +0 -0
  180. package/dist/chunk-MMUBH76A.js.gz +0 -0
  181. package/dist/index.js.br +0 -0
  182. package/dist/index.js.gz +0 -0
  183. /package/dist/modal/{components/AuthInput → utils}/countryCodes.d.ts +0 -0
@@ -0,0 +1,428 @@
1
+ "use client";
2
+ import {
3
+ __async
4
+ } from "../../chunk-MMUBH76A.js";
5
+ import { jsx } from "react/jsx-runtime";
6
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
7
+ import { isIOS, isIOSWebview, isMobile, truncateAddress } from "@getpara/web-sdk";
8
+ import { useInternalClient } from "../hooks/utils/useInternalClient.js";
9
+ import { useStore } from "../stores/useStore.js";
10
+ import { ModalStep } from "../../modal/index.js";
11
+ import { useModalStore } from "../../modal/stores/index.js";
12
+ import { useVerifyExternalWallet, useWalletState } from "../hooks/index.js";
13
+ import { useAuthActions } from "./AuthProvider.js";
14
+ const defaultExternalWallet = {
15
+ wallets: [],
16
+ chains: [],
17
+ chainId: void 0,
18
+ wallet: void 0,
19
+ qrUri: void 0,
20
+ chainIdSwitchingTo: void 0,
21
+ walletDisplayHelpers: { showExtension: false, showMobile: false, isSolanaMobileIOS: false, isCosmosMobileWallet: false },
22
+ username: void 0,
23
+ avatar: void 0,
24
+ connectExternalWallet: () => Promise.resolve(),
25
+ disconnectExternalWallet: () => Promise.resolve(),
26
+ switchChain: () => Promise.resolve(),
27
+ setChainIdSwitchingTo: () => {
28
+ },
29
+ connectEmbeddedToExternalConnectors: () => Promise.resolve(),
30
+ verifyWalletSignature: () => Promise.resolve({}),
31
+ getWalletBalance: () => Promise.resolve(void 0),
32
+ isExternalWalletVerifying: false
33
+ };
34
+ const ExternalWalletContext = createContext(defaultExternalWallet);
35
+ function ExternalWalletProvider({ children }) {
36
+ const evmContext = useStore((state) => state.evmContext);
37
+ const cosmosContext = useStore((state) => state.cosmosContext);
38
+ const solanaContext = useStore((state) => state.solanaContext);
39
+ const externalWallets = useStore((state) => state.externalWallets);
40
+ const externalWalletsWithFullAuth = useStore((state) => state.externalWalletsWithFullAuth);
41
+ const {
42
+ wallets: evmWallets,
43
+ disconnect: evmDisconnect,
44
+ chains: evmChains,
45
+ chainId: evmChainId,
46
+ switchChain: evmSwitchChain,
47
+ username: evmUsername,
48
+ avatar: evmAvatar,
49
+ connectParaEmbedded: evmConnectParaEmbedded,
50
+ signVerificationMessage: evmSignVerificationMessage,
51
+ getWalletBalance: evmGetWalletBalance
52
+ } = useContext(evmContext);
53
+ const {
54
+ wallets: solanaWallets,
55
+ disconnect: solanaDisconnect,
56
+ signVerificationMessage: solanaSignVerificationMessage
57
+ } = useContext(solanaContext);
58
+ const {
59
+ wallets: cosmosWallets,
60
+ disconnect: cosmosDisconnect,
61
+ chains: cosmosChains,
62
+ chainId: cosmosChainId,
63
+ switchChain: cosmosSwitchChain,
64
+ connectParaEmbedded: cosmosConnectParaEmbedded,
65
+ signVerificationMessage: cosmosSignVerificationMessage
66
+ } = useContext(cosmosContext);
67
+ const onLoginRef = useStore((state) => state.onLoginRef);
68
+ const setStep = useModalStore((state) => state.setStep);
69
+ const setStepDirection = useModalStore((state) => state.setStepDirection);
70
+ const setIsExternalWalletConnecting = useModalStore((state) => state.setIsExternalWalletConnecting);
71
+ const isExternalWalletConnecting = useModalStore((state) => state.isExternalWalletConnecting);
72
+ const setSelectedExternalWalletId = useModalStore((state) => state.setSelectedExternalWalletId);
73
+ const selectedExternalWalletId = useModalStore((state) => state.selectedExternalWalletId);
74
+ const setExternalWalletError = useModalStore((state) => state.setExternalWalletError);
75
+ const setIsUsingMobileConnector = useModalStore((state) => state.setIsUsingMobileConnector);
76
+ const isUsingMobileConnector = useModalStore((state) => state.isUsingMobileConnector);
77
+ const para = useInternalClient();
78
+ const { setSelectedWallet } = useWalletState();
79
+ const { onNewAuthState } = useAuthActions();
80
+ const { mutate: verifyExternalWallet } = useVerifyExternalWallet();
81
+ const [qrUri, setQrUri] = useState();
82
+ const [chainIdSwitchingTo, setChainIdSwitchingTo] = useState();
83
+ const [isExternalWalletVerifying, setIsExternalWalletVerifying] = useState(false);
84
+ const wallets = [...evmWallets, ...solanaWallets, ...cosmosWallets].filter((w) => externalWallets.includes(w.id.toUpperCase())).sort(
85
+ (a, b) => externalWallets.indexOf(a.id.toUpperCase()) - externalWallets.indexOf(b.id.toUpperCase())
86
+ ).sort((a, b) => a.installed === b.installed ? 0 : a.installed ? -1 : 1);
87
+ const wallet = useMemo(() => wallets.find((w) => w.id === selectedExternalWalletId), [wallets, selectedExternalWalletId]);
88
+ const updateQrUri = () => __async(this, null, function* () {
89
+ var _a;
90
+ const uri = yield (_a = wallet == null ? void 0 : wallet.getQrUri) == null ? void 0 : _a.call(wallet);
91
+ setQrUri(uri);
92
+ });
93
+ useEffect(() => {
94
+ if (wallet) {
95
+ if (!qrUri) {
96
+ updateQrUri();
97
+ }
98
+ } else if (qrUri) {
99
+ setQrUri(void 0);
100
+ }
101
+ }, [wallet]);
102
+ const getWalletBalance = useCallback(() => __async(this, null, function* () {
103
+ var _a;
104
+ const walletType = (_a = Object.values(para.externalWallets || {})[0]) == null ? void 0 : _a.type;
105
+ switch (walletType) {
106
+ case "EVM": {
107
+ return yield evmGetWalletBalance();
108
+ }
109
+ default: {
110
+ return void 0;
111
+ }
112
+ }
113
+ }), [evmGetWalletBalance, selectedExternalWalletId]);
114
+ const chains = useMemo(() => {
115
+ var _a;
116
+ const walletType = (_a = Object.values(para.externalWallets || {})[0]) == null ? void 0 : _a.type;
117
+ switch (walletType) {
118
+ case "COSMOS": {
119
+ return cosmosChains;
120
+ }
121
+ case "EVM": {
122
+ return evmChains;
123
+ }
124
+ default: {
125
+ return [];
126
+ }
127
+ }
128
+ }, [cosmosChains, evmChains, selectedExternalWalletId]);
129
+ const chainId = useMemo(() => {
130
+ var _a;
131
+ const walletType = (_a = Object.values(para.externalWallets || {})[0]) == null ? void 0 : _a.type;
132
+ switch (walletType) {
133
+ case "COSMOS": {
134
+ return cosmosChainId;
135
+ }
136
+ case "EVM": {
137
+ return evmChainId == null ? void 0 : evmChainId.toString();
138
+ }
139
+ default: {
140
+ return void 0;
141
+ }
142
+ }
143
+ }, [cosmosChains, evmChains, selectedExternalWalletId]);
144
+ const switchChain = useCallback(
145
+ (chainId2) => __async(this, null, function* () {
146
+ var _a;
147
+ const walletType = (_a = Object.values(para.externalWallets || {})[0]) == null ? void 0 : _a.type;
148
+ if (walletType) {
149
+ let resp;
150
+ setExternalWalletError();
151
+ setChainIdSwitchingTo(chainId2);
152
+ switch (walletType) {
153
+ case "COSMOS": {
154
+ setStep(ModalStep.CHAIN_SWITCH);
155
+ resp = yield cosmosSwitchChain(chainId2);
156
+ break;
157
+ }
158
+ case "EVM": {
159
+ setStep(ModalStep.CHAIN_SWITCH);
160
+ resp = yield evmSwitchChain(parseInt(chainId2));
161
+ break;
162
+ }
163
+ default: {
164
+ resp = {};
165
+ break;
166
+ }
167
+ }
168
+ if (resp.error) {
169
+ setExternalWalletError(resp.error);
170
+ } else {
171
+ setChainIdSwitchingTo(void 0);
172
+ setStepDirection(-1);
173
+ setStep(ModalStep.ACCOUNT_MAIN);
174
+ }
175
+ }
176
+ }),
177
+ [evmSwitchChain, cosmosSwitchChain]
178
+ );
179
+ const verifyWalletSignature = useCallback(() => __async(this, null, function* () {
180
+ var _a;
181
+ setExternalWalletError();
182
+ setIsExternalWalletVerifying(true);
183
+ const walletType = (_a = Object.values(para.externalWallets)[0]) == null ? void 0 : _a.type;
184
+ let verifyExternalWalletParams;
185
+ switch (walletType) {
186
+ case "COSMOS":
187
+ {
188
+ const { address, signature, error, cosmosPublicKeyHex, cosmosSigner } = yield cosmosSignVerificationMessage();
189
+ if (error) {
190
+ setExternalWalletError([error]);
191
+ } else if (signature && address) {
192
+ verifyExternalWalletParams = {
193
+ externalWallet: {
194
+ type: "COSMOS",
195
+ address
196
+ },
197
+ signedMessage: signature,
198
+ cosmosPublicKeyHex,
199
+ cosmosSigner
200
+ };
201
+ }
202
+ }
203
+ break;
204
+ case "EVM":
205
+ {
206
+ const { signature, error, address } = yield evmSignVerificationMessage();
207
+ if (error) {
208
+ setExternalWalletError([error]);
209
+ } else if (signature && address) {
210
+ verifyExternalWalletParams = {
211
+ externalWallet: {
212
+ type: "EVM",
213
+ address
214
+ },
215
+ signedMessage: signature
216
+ };
217
+ }
218
+ }
219
+ break;
220
+ case "SOLANA":
221
+ {
222
+ const { signature, error, address } = yield solanaSignVerificationMessage();
223
+ if (error) {
224
+ setExternalWalletError([error]);
225
+ } else if (signature && address) {
226
+ verifyExternalWalletParams = {
227
+ externalWallet: {
228
+ type: "SOLANA",
229
+ address
230
+ },
231
+ signedMessage: signature
232
+ };
233
+ }
234
+ }
235
+ break;
236
+ default:
237
+ break;
238
+ }
239
+ if (verifyExternalWalletParams) {
240
+ if (!(verifyExternalWalletParams == null ? void 0 : verifyExternalWalletParams.externalWallet) || !(verifyExternalWalletParams == null ? void 0 : verifyExternalWalletParams.signedMessage)) {
241
+ console.error("No signature or address found on the verifyWalletSignature response.");
242
+ return;
243
+ }
244
+ verifyExternalWallet(verifyExternalWalletParams, {
245
+ onSuccess: onNewAuthState,
246
+ onError: (e) => {
247
+ console.error("Error verifying signature:", e);
248
+ setExternalWalletError(["Signature verification failed."]);
249
+ },
250
+ onSettled: () => {
251
+ setIsExternalWalletVerifying(false);
252
+ }
253
+ });
254
+ return verifyExternalWalletParams;
255
+ }
256
+ setIsExternalWalletVerifying(false);
257
+ return void 0;
258
+ }), [cosmosSignVerificationMessage, evmSignVerificationMessage, solanaSignVerificationMessage]);
259
+ const connectExternalWallet = useCallback(
260
+ (wallet2, isMobileConnect, isManualWalletConnect, isResetAfterManualWalletConnect) => __async(this, null, function* () {
261
+ if (isExternalWalletConnecting && isManualWalletConnect) {
262
+ yield evmDisconnect();
263
+ yield solanaDisconnect();
264
+ yield cosmosDisconnect();
265
+ setQrUri(void 0);
266
+ setIsExternalWalletConnecting(false);
267
+ }
268
+ if (isResetAfterManualWalletConnect || isManualWalletConnect || !isExternalWalletConnecting) {
269
+ setExternalWalletError();
270
+ setIsExternalWalletConnecting(true);
271
+ setIsUsingMobileConnector(isMobileConnect);
272
+ const { address, error, authState } = yield isMobileConnect ? wallet2.connectMobile(isManualWalletConnect) : wallet2.connect();
273
+ if (error) {
274
+ setExternalWalletError([error]);
275
+ setIsUsingMobileConnector();
276
+ if (isManualWalletConnect && error === "Connection request rejected") {
277
+ setExternalWalletError();
278
+ yield connectExternalWallet(wallet2, false, false, true);
279
+ yield updateQrUri();
280
+ return;
281
+ }
282
+ } else if (address) {
283
+ if (!!authState && (externalWalletsWithFullAuth == null ? void 0 : externalWalletsWithFullAuth.includes(wallet2.id.toUpperCase()))) {
284
+ onNewAuthState(authState);
285
+ } else {
286
+ setStep(ModalStep.LOGIN_DONE);
287
+ }
288
+ }
289
+ setIsExternalWalletConnecting(false);
290
+ }
291
+ }),
292
+ [isExternalWalletConnecting, externalWalletsWithFullAuth]
293
+ );
294
+ const disconnectExternalWallet = () => __async(this, null, function* () {
295
+ yield para.logout();
296
+ yield evmDisconnect();
297
+ yield cosmosDisconnect();
298
+ setSelectedExternalWalletId();
299
+ yield solanaDisconnect();
300
+ });
301
+ const walletDisplayHelpers = {
302
+ // Show the extension screen if on web and the wallet is an extension and installed or the wallet isn't a mobile wallet
303
+ // Also show the extension connection if on desktop for a solana wallet (no walletConnect)
304
+ showExtension: !isMobile() && ((wallet == null ? void 0 : wallet.isExtension) && (wallet == null ? void 0 : wallet.installed) || !(wallet == null ? void 0 : wallet.isMobile) || (wallet == null ? void 0 : wallet.type) === "SOLANA"),
305
+ // Show the mobile screen if on mobile and the wallet is a mobile wallet or if on desktop and the wallet isn't installed
306
+ showMobile: isMobile() && (wallet == null ? void 0 : wallet.isMobile) || !isMobile() && !(wallet == null ? void 0 : wallet.installed),
307
+ isSolanaMobileIOS: isIOS() && isMobile() && !isIOSWebview() && (wallet == null ? void 0 : wallet.type) === "SOLANA",
308
+ isCosmosMobileWallet: (wallet == null ? void 0 : wallet.type) === "COSMOS" && !!isUsingMobileConnector
309
+ };
310
+ const username = useMemo(() => {
311
+ let username2;
312
+ const storedExternalWallet = Object.values(para.externalWallets || {})[0];
313
+ if (storedExternalWallet) {
314
+ const walletType = storedExternalWallet == null ? void 0 : storedExternalWallet.type;
315
+ switch (walletType) {
316
+ case "EVM": {
317
+ username2 = evmUsername ? evmUsername.startsWith("0x") ? truncateAddress(evmUsername, "EVM") : evmUsername : void 0;
318
+ break;
319
+ }
320
+ default: {
321
+ username2 = storedExternalWallet.address && storedExternalWallet.type ? truncateAddress(storedExternalWallet.address, storedExternalWallet.type) : void 0;
322
+ break;
323
+ }
324
+ }
325
+ }
326
+ return username2;
327
+ }, [evmUsername, wallet]);
328
+ const avatar = useMemo(() => {
329
+ var _a;
330
+ const walletType = (_a = Object.values(para.externalWallets || {})[0]) == null ? void 0 : _a.type;
331
+ if (walletType) {
332
+ switch (walletType) {
333
+ case "EVM": {
334
+ return evmAvatar;
335
+ }
336
+ default: {
337
+ return void 0;
338
+ }
339
+ }
340
+ }
341
+ }, [evmAvatar, wallet]);
342
+ const connectEmbeddedToExternalConnectors = useCallback(() => __async(this, null, function* () {
343
+ try {
344
+ const { error } = yield evmConnectParaEmbedded();
345
+ if (error) {
346
+ console.warn("Failed to connect Para EVM wallet to Wagmi:", error);
347
+ } else {
348
+ const wallet2 = para.findWallet(void 0, void 0, { type: ["EVM"] });
349
+ if (wallet2) {
350
+ setSelectedWallet({ id: wallet2.id, type: "EVM" });
351
+ }
352
+ }
353
+ } catch (err) {
354
+ console.warn("Error calling connectParaEvmWallet:", err);
355
+ }
356
+ try {
357
+ const { error } = yield cosmosConnectParaEmbedded();
358
+ if (error) {
359
+ console.warn("Failed to connect Para Cosmos wallet to Graz:", error);
360
+ } else {
361
+ const wallet2 = para.findWallet(void 0, void 0, { type: ["COSMOS"] });
362
+ if (wallet2) {
363
+ setSelectedWallet({ id: wallet2.id, type: "COSMOS" });
364
+ }
365
+ }
366
+ } catch (err) {
367
+ console.warn("Error calling connectParaCosmosWallet:", err);
368
+ }
369
+ }), [evmConnectParaEmbedded, cosmosConnectParaEmbedded]);
370
+ useEffect(() => {
371
+ onLoginRef.current = () => __async(this, null, function* () {
372
+ yield connectEmbeddedToExternalConnectors();
373
+ });
374
+ }, [connectEmbeddedToExternalConnectors]);
375
+ return /* @__PURE__ */ jsx(
376
+ ExternalWalletContext.Provider,
377
+ {
378
+ value: useMemo(
379
+ () => ({
380
+ wallets,
381
+ chains,
382
+ chainId,
383
+ wallet,
384
+ qrUri,
385
+ walletDisplayHelpers,
386
+ chainIdSwitchingTo,
387
+ username,
388
+ avatar,
389
+ connectExternalWallet,
390
+ disconnectExternalWallet,
391
+ switchChain,
392
+ setChainIdSwitchingTo,
393
+ connectEmbeddedToExternalConnectors,
394
+ verifyWalletSignature,
395
+ isExternalWalletVerifying,
396
+ getWalletBalance
397
+ }),
398
+ [
399
+ wallets,
400
+ chains,
401
+ chainId,
402
+ wallet,
403
+ qrUri,
404
+ walletDisplayHelpers,
405
+ chainIdSwitchingTo,
406
+ username,
407
+ avatar,
408
+ disconnectExternalWallet,
409
+ connectExternalWallet,
410
+ switchChain,
411
+ setChainIdSwitchingTo,
412
+ connectEmbeddedToExternalConnectors,
413
+ verifyWalletSignature,
414
+ isExternalWalletVerifying,
415
+ getWalletBalance
416
+ ]
417
+ ),
418
+ children
419
+ }
420
+ );
421
+ }
422
+ const useExternalWallets = () => useContext(ExternalWalletContext);
423
+ export {
424
+ ExternalWalletContext,
425
+ ExternalWalletProvider,
426
+ defaultExternalWallet,
427
+ useExternalWallets
428
+ };
@@ -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 { getParaSolanaConnector } from "../external/getParaSolanaConnector.js";
12
+ function SolanaExternalWalletProvider(_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 setSolanaContext = useStore((state) => state.setSolanaContext);
23
+ const setSolanaProvider = useStore((state) => state.setSolanaProvider);
24
+ const SolanaProvider = useStore((state) => state.SolanaProvider);
25
+ const setSolanaWallets = useStore((state) => state.setSolanaWallets);
26
+ const solanaWallets = useStore((state) => state.solanaWallets);
27
+ const isLoadingLib = useStore((state) => state.isLoadingSolanaLib);
28
+ const setIsLoadingLib = useStore((state) => state.setIsLoadingSolanaLib);
29
+ const filteredWallets = useMemo(
30
+ () => solanaWallets.filter((w) => walletsFromProps.includes(w().id.toUpperCase())),
31
+ [solanaWallets, walletsFromProps]
32
+ );
33
+ useEffect(() => {
34
+ const loadLib = () => __async(this, null, function* () {
35
+ if (SolanaProvider) {
36
+ return;
37
+ }
38
+ const { Provider, context, wallets } = yield getParaSolanaConnector();
39
+ if (Provider) {
40
+ setSolanaProvider(Provider);
41
+ }
42
+ if (wallets) {
43
+ setSolanaWallets(wallets);
44
+ }
45
+ if (context) {
46
+ setSolanaContext(context);
47
+ }
48
+ setIsLoadingLib(false);
49
+ });
50
+ loadLib();
51
+ }, []);
52
+ if (isLoadingLib) {
53
+ return null;
54
+ }
55
+ if (SolanaProvider) {
56
+ return /* @__PURE__ */ jsx(SolanaProvider, __spreadProps(__spreadValues({}, rest), { config: __spreadProps(__spreadValues({}, rest == null ? void 0 : rest.config), { wallets: filteredWallets }), children }));
57
+ } else if (isUsing) {
58
+ console.warn("@getpara/solana-wallet-connectors is required to use an external Solana wallet.");
59
+ }
60
+ return children;
61
+ }
62
+ const MemoizedSolanaExternalWalletProvider = memo(SolanaExternalWalletProvider);
63
+ export {
64
+ MemoizedSolanaExternalWalletProvider,
65
+ SolanaExternalWalletProvider
66
+ };
@@ -1,4 +1,4 @@
1
1
  export declare const getClient: () => import("@getpara/web-sdk").ParaWeb | undefined;
2
2
  export declare const getIsOpen: () => boolean;
3
3
  export declare const getSelectedWalletId: () => string | undefined;
4
- export declare const getSelectedWalletType: () => import("@getpara/user-management-client").WalletType | undefined;
4
+ export declare const getSelectedWalletType: () => "EVM" | "SOLANA" | "COSMOS" | undefined;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import "../../chunk-MMUBH76A.js";
3
+ import { vanillaStore } from "./useStore.js";
4
+ const getClient = () => vanillaStore.getState().client;
5
+ const getIsOpen = () => vanillaStore.getState().isOpen;
6
+ const getSelectedWalletId = () => vanillaStore.getState().selectedWalletId;
7
+ const getSelectedWalletType = () => vanillaStore.getState().selectedWalletType;
8
+ export {
9
+ getClient,
10
+ getIsOpen,
11
+ getSelectedWalletId,
12
+ getSelectedWalletType
13
+ };
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import "../../chunk-MMUBH76A.js";
3
+ import { vanillaStore } from "./useStore.js";
4
+ const setIsOpen = (isOpen) => vanillaStore.setState({ isOpen });
5
+ export {
6
+ setIsOpen
7
+ };
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ const createClientSlice = (set) => ({
4
+ client: void 0,
5
+ setClient: (client) => set({ client })
6
+ });
7
+ export {
8
+ createClientSlice
9
+ };
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ const createConfigSlice = (set) => ({
4
+ appName: "",
5
+ setAppName: (appName) => set({ appName })
6
+ });
7
+ export {
8
+ createConfigSlice
9
+ };
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ import { EvmExternalWalletContext } from "../../external/stubs/EvmExternalWalletContextStub.js";
4
+ import { CosmosExternalWalletContext } from "../../external/stubs/CosmosExternalWalletContextStub.js";
5
+ import { SolanaExternalWalletContext } from "../../external/stubs/SolanaExternalWalletContextStub.js";
6
+ import { createRef } from "react";
7
+ const createExternalWalletsSlice = (set) => ({
8
+ externalWallets: [],
9
+ setExternalWallets: (externalWallets) => set({ externalWallets }),
10
+ externalWalletsWithFullAuth: [],
11
+ setExternalWalletsWithFullAuth: (externalWalletsWithFullAuth) => set({ externalWalletsWithFullAuth }),
12
+ evmContext: EvmExternalWalletContext,
13
+ setEvmContext: (evmContext) => set({ evmContext }),
14
+ EvmProvider: void 0,
15
+ setEvmProvider: (EvmProvider) => set({ EvmProvider }),
16
+ evmWallets: [],
17
+ setEvmWallets: (evmWallets) => set({ evmWallets }),
18
+ isLoadingEvmLib: true,
19
+ setIsLoadingEvmLib: (isLoadingEvmLib) => set({ isLoadingEvmLib }),
20
+ cosmosContext: CosmosExternalWalletContext,
21
+ setCosmosContext: (cosmosContext) => set({ cosmosContext }),
22
+ CosmosProvider: void 0,
23
+ setCosmosProvider: (CosmosProvider) => set({ CosmosProvider }),
24
+ cosmosWallets: [],
25
+ setCosmosWallets: (cosmosWallets) => set({ cosmosWallets }),
26
+ isLoadingCosmosLib: true,
27
+ setIsLoadingCosmosLib: (isLoadingCosmosLib) => set({ isLoadingCosmosLib }),
28
+ solanaContext: SolanaExternalWalletContext,
29
+ setSolanaContext: (solanaContext) => set({ solanaContext }),
30
+ SolanaProvider: void 0,
31
+ setSolanaProvider: (SolanaProvider) => set({ SolanaProvider }),
32
+ solanaWallets: [],
33
+ setSolanaWallets: (solanaWallets) => set({ solanaWallets }),
34
+ isLoadingSolanaLib: true,
35
+ setIsLoadingSolanaLib: (isLoadingSolanaLib) => set({ isLoadingSolanaLib }),
36
+ onLoginRef: createRef()
37
+ });
38
+ export {
39
+ createExternalWalletsSlice
40
+ };
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ export * from "./client.js";
3
+ export * from "./modal.js";
4
+ export * from "./wallet.js";
5
+ export * from "./externalWallets.js";
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ const createModalSlice = (set, get) => {
4
+ var _a, _b, _c, _d, _e, _f, _g;
5
+ return {
6
+ modalConfig: void 0,
7
+ setModalConfig: (modalConfig) => set({ modalConfig }),
8
+ isDarkTheme: ((_c = (_b = (_a = get()) == null ? void 0 : _a.modalConfig) == null ? void 0 : _b.theme) == null ? void 0 : _c.mode) === "dark",
9
+ oAuthLogoVariant: (_g = (_f = (_e = (_d = get()) == null ? void 0 : _d.modalConfig) == null ? void 0 : _e.theme) == null ? void 0 : _f.oAuthLogoVariant) != null ? _g : "default",
10
+ isOpen: false,
11
+ setIsOpen: (isOpen) => set({ isOpen })
12
+ };
13
+ };
14
+ export {
15
+ createModalSlice
16
+ };
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import "../../../chunk-MMUBH76A.js";
3
+ const createWalletSlice = (set) => ({
4
+ rpcUrl: void 0,
5
+ setRpcUrl: (rpcUrl) => set({ rpcUrl }),
6
+ selectedWalletId: void 0,
7
+ selectedWalletType: void 0,
8
+ setSelectedWallet: (selectedWalletId, selectedWalletType) => set({ selectedWalletId, selectedWalletType }),
9
+ clearSelectedWallet: () => set({ selectedWalletId: void 0, selectedWalletType: void 0 })
10
+ });
11
+ export {
12
+ createWalletSlice
13
+ };
@@ -1,10 +1,11 @@
1
1
  import { Context, MutableRefObject } from 'react';
2
- import ParaWeb, { WalletType } from '@getpara/web-sdk';
2
+ import ParaWeb, { TWalletType } from '@getpara/web-sdk';
3
3
  import { EvmExternalWalletContextType, ParaEvmProvider, WalletList as EvmWalletList } from '@getpara/evm-wallet-connectors';
4
4
  import { CosmosExternalWalletContextType, ParaCosmosProvider, WalletList as CosmosWalletList } from '@getpara/cosmos-wallet-connectors';
5
5
  import { ParaSolanaProvider, SolanaExternalWalletContextType, WalletList as SolanaWalletList } from '@getpara/solana-wallet-connectors';
6
- import { ParaModalProps, TExternalWallet } from '../../modal/index.js';
6
+ import { ParaModalProps } from '../../modal/index.js';
7
7
  import { OAuthLogoVariantType } from '../../modal/types/modalProps.js';
8
+ import { type TExternalWallet } from '@getpara/react-common';
8
9
  export interface ClientSlice {
9
10
  client?: ParaWeb;
10
11
  setClient: (_: ParaWeb) => void;
@@ -22,9 +23,11 @@ export interface ModalSlice {
22
23
  setIsOpen: (_: boolean) => void;
23
24
  }
24
25
  export interface WalletSlice {
26
+ rpcUrl?: string;
27
+ setRpcUrl: (_?: string) => void;
25
28
  selectedWalletId?: string;
26
- selectedWalletType?: WalletType;
27
- setSelectedWallet: (_?: string, __?: WalletType) => void;
29
+ selectedWalletType?: TWalletType;
30
+ setSelectedWallet: (_?: string, __?: TWalletType) => void;
28
31
  clearSelectedWallet: () => void;
29
32
  }
30
33
  export interface ExternalWalletsSlice {
@@ -0,0 +1 @@
1
+ "use client";
@@ -0,0 +1,28 @@
1
+ "use client";
2
+ import {
3
+ __spreadValues
4
+ } from "../../chunk-MMUBH76A.js";
5
+ import { createStore, useStore as useZustandStore } from "zustand";
6
+ import { createClientSlice, createExternalWalletsSlice, createModalSlice, createWalletSlice } from "./slices/index.js";
7
+ import { createJSONStorage, persist } from "zustand/middleware";
8
+ import { createConfigSlice } from "./slices/config.js";
9
+ const vanillaStore = createStore()(
10
+ persist(
11
+ (...a) => __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, createClientSlice(...a)), createModalSlice(...a)), createWalletSlice(...a)), createExternalWalletsSlice(...a)), createConfigSlice(...a)),
12
+ {
13
+ version: 1,
14
+ name: "@PARA/provider-state",
15
+ storage: createJSONStorage(() => localStorage),
16
+ partialize: (state) => ({
17
+ selectedWalletId: state.selectedWalletId,
18
+ selectedWalletType: state.selectedWalletType
19
+ })
20
+ }
21
+ )
22
+ );
23
+ const createBoundedUseStore = (store) => (selector) => useZustandStore(store, selector);
24
+ const useStore = createBoundedUseStore(vanillaStore);
25
+ export {
26
+ useStore,
27
+ vanillaStore
28
+ };