@getpara/react-sdk 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (180) hide show
  1. package/dist/index.d.ts +5 -0
  2. package/dist/index.js +4 -0
  3. package/dist/modal/ParaModal.d.ts +2 -0
  4. package/dist/modal/ParaModal.js +250 -0
  5. package/dist/modal/components/Account/Account.d.ts +5 -0
  6. package/dist/modal/components/Account/Account.js +59 -0
  7. package/dist/modal/components/AddFunds/AddFunds.d.ts +3 -0
  8. package/dist/modal/components/AddFunds/AddFunds.js +146 -0
  9. package/dist/modal/components/AddFunds/AddFundsAwaiting.d.ts +1 -0
  10. package/dist/modal/components/AddFunds/AddFundsAwaiting.js +64 -0
  11. package/dist/modal/components/AddFunds/AddFundsDone.d.ts +6 -0
  12. package/dist/modal/components/AddFunds/AddFundsDone.js +26 -0
  13. package/dist/modal/components/AddFunds/MoonPayEmbed.d.ts +2 -0
  14. package/dist/modal/components/AddFunds/MoonPayEmbed.js +2 -0
  15. package/dist/modal/components/AddFunds/index.d.ts +3 -0
  16. package/dist/modal/components/AddFunds/index.js +3 -0
  17. package/dist/modal/components/AuthInput/AuthInput.d.ts +6 -0
  18. package/dist/modal/components/AuthInput/AuthInput.js +214 -0
  19. package/dist/modal/components/AuthInput/countryCodes.d.ts +8 -0
  20. package/dist/modal/components/AuthInput/countryCodes.js +40 -0
  21. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.d.ts +7 -0
  22. package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +23 -0
  23. package/dist/modal/components/AuthInput/phoneMasks.d.ts +247 -0
  24. package/dist/modal/components/AuthInput/phoneMasks.js +247 -0
  25. package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +8 -0
  26. package/dist/modal/components/AuthMainStep/AuthMainStep.js +21 -0
  27. package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +8 -0
  28. package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +89 -0
  29. package/dist/modal/components/AuthOptions/AuthOptions.d.ts +8 -0
  30. package/dist/modal/components/AuthOptions/AuthOptions.js +28 -0
  31. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.d.ts +1 -0
  32. package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +7 -0
  33. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.d.ts +1 -0
  34. package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +5 -0
  35. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.d.ts +1 -0
  36. package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +7 -0
  37. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +1 -0
  38. package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +18 -0
  39. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.d.ts +4 -0
  40. package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +17 -0
  41. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.d.ts +1 -0
  42. package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +127 -0
  43. package/dist/modal/components/Body/AnimatedHeightWrapper.d.ts +6 -0
  44. package/dist/modal/components/Body/AnimatedHeightWrapper.js +26 -0
  45. package/dist/modal/components/Body/Body.d.ts +12 -0
  46. package/dist/modal/components/Body/Body.js +232 -0
  47. package/dist/modal/components/ChainSwitch/ChainSwitch.d.ts +1 -0
  48. package/dist/modal/components/ChainSwitch/ChainSwitch.js +77 -0
  49. package/dist/modal/components/ChainSwitch/config.d.ts +7 -0
  50. package/dist/modal/components/ChainSwitch/config.js +11 -0
  51. package/dist/modal/components/Controls/Controls.d.ts +5 -0
  52. package/dist/modal/components/Controls/Controls.js +54 -0
  53. package/dist/modal/components/Controls/Selects.d.ts +2 -0
  54. package/dist/modal/components/Controls/Selects.js +157 -0
  55. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.d.ts +1 -0
  56. package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +116 -0
  57. package/dist/modal/components/ExternalWalletStep/config.d.ts +7 -0
  58. package/dist/modal/components/ExternalWalletStep/config.js +11 -0
  59. package/dist/modal/components/ExternalWallets/ExternalWallets.d.ts +1 -0
  60. package/dist/modal/components/ExternalWallets/ExternalWallets.js +142 -0
  61. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.d.ts +7 -0
  62. package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +118 -0
  63. package/dist/modal/components/Footer/Footer.d.ts +1 -0
  64. package/dist/modal/components/Footer/Footer.js +71 -0
  65. package/dist/modal/components/Header/Header.d.ts +1 -0
  66. package/dist/modal/components/Header/Header.js +24 -0
  67. package/dist/modal/components/Header/hooks/useStepTitle.d.ts +3 -0
  68. package/dist/modal/components/Header/hooks/useStepTitle.js +42 -0
  69. package/dist/modal/components/Hero/Hero.d.ts +1 -0
  70. package/dist/modal/components/Hero/Hero.js +118 -0
  71. package/dist/modal/components/IFrameStep/IFrameStep.d.ts +1 -0
  72. package/dist/modal/components/IFrameStep/IFrameStep.js +41 -0
  73. package/dist/modal/components/LoginDoneStep/LoginDoneStep.d.ts +1 -0
  74. package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +18 -0
  75. package/dist/modal/components/ModalContent/ModalContent.d.ts +10 -0
  76. package/dist/modal/components/ModalContent/ModalContent.js +276 -0
  77. package/dist/modal/components/OAuth/FarcasterOAuthStep.d.ts +2 -0
  78. package/dist/modal/components/OAuth/FarcasterOAuthStep.js +81 -0
  79. package/dist/modal/components/OAuth/OAuth.d.ts +6 -0
  80. package/dist/modal/components/OAuth/OAuth.js +124 -0
  81. package/dist/modal/components/OAuth/TelegramOAuthStep.d.ts +1 -0
  82. package/dist/modal/components/OAuth/TelegramOAuthStep.js +132 -0
  83. package/dist/modal/components/OnRampComponents/AddingFunds.d.ts +1 -0
  84. package/dist/modal/components/OnRampComponents/AddingFunds.js +10 -0
  85. package/dist/modal/components/OnRampComponents/OnRampProviderButton.d.ts +9 -0
  86. package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +72 -0
  87. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.d.ts +6 -0
  88. package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +67 -0
  89. package/dist/modal/components/Setup2FAStep/Setup2FAStep.d.ts +5 -0
  90. package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +104 -0
  91. package/dist/modal/components/StripeComponents/StripeComponents.d.ts +16 -0
  92. package/dist/modal/components/StripeComponents/StripeComponents.js +78 -0
  93. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.d.ts +5 -0
  94. package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +8 -0
  95. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.d.ts +1 -0
  96. package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +130 -0
  97. package/dist/modal/components/Waiting/Waiting.d.ts +6 -0
  98. package/dist/modal/components/Waiting/Waiting.js +6 -0
  99. package/dist/modal/components/WalletCard/PartnerIcon.d.ts +6 -0
  100. package/dist/modal/components/WalletCard/PartnerIcon.js +29 -0
  101. package/dist/modal/components/WalletCard/WalletCard.d.ts +18 -0
  102. package/dist/modal/components/WalletCard/WalletCard.js +91 -0
  103. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.d.ts +6 -0
  104. package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +49 -0
  105. package/dist/modal/components/common.d.ts +19 -0
  106. package/dist/modal/components/common.js +67 -0
  107. package/dist/modal/components/index.d.ts +1 -0
  108. package/dist/modal/components/index.js +1 -0
  109. package/dist/modal/constants/constants.d.ts +32 -0
  110. package/dist/modal/constants/constants.js +93 -0
  111. package/dist/modal/constants/defaults.d.ts +5 -0
  112. package/dist/modal/constants/defaults.js +5 -0
  113. package/dist/modal/constants/oAuthLogos.d.ts +8 -0
  114. package/dist/modal/constants/oAuthLogos.js +18 -0
  115. package/dist/modal/css/modal.css +13 -0
  116. package/dist/modal/hooks/useActiveWallet.d.ts +1 -0
  117. package/dist/modal/hooks/useActiveWallet.js +9 -0
  118. package/dist/modal/hooks/useEmbeddedExternalConnection.d.ts +1 -0
  119. package/dist/modal/hooks/useEmbeddedExternalConnection.js +46 -0
  120. package/dist/modal/hooks/useGoBack.d.ts +1 -0
  121. package/dist/modal/hooks/useGoBack.js +34 -0
  122. package/dist/modal/index.d.ts +10 -0
  123. package/dist/modal/index.js +9 -0
  124. package/dist/modal/providers/CosmosExternalWalletContextStub.d.ts +29 -0
  125. package/dist/modal/providers/CosmosExternalWalletContextStub.js +18 -0
  126. package/dist/modal/providers/EvmExternalWalletContextStub.d.ts +33 -0
  127. package/dist/modal/providers/EvmExternalWalletContextStub.js +22 -0
  128. package/dist/modal/providers/ExternalWalletContext.d.ts +75 -0
  129. package/dist/modal/providers/ExternalWalletContext.js +252 -0
  130. package/dist/modal/providers/SolanaExternalWalletContextStub.d.ts +21 -0
  131. package/dist/modal/providers/SolanaExternalWalletContextStub.js +12 -0
  132. package/dist/modal/public/Inter-VariableFont_slnt,wght.ttf +0 -0
  133. package/dist/modal/stores/externalWalletProvider/actions.d.ts +3 -0
  134. package/dist/modal/stores/externalWalletProvider/actions.js +5 -0
  135. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.d.ts +20 -0
  136. package/dist/modal/stores/externalWalletProvider/useExternalWalletProviderStore.js +13 -0
  137. package/dist/modal/stores/index.d.ts +4 -0
  138. package/dist/modal/stores/index.js +4 -0
  139. package/dist/modal/stores/modal/actions.d.ts +3 -0
  140. package/dist/modal/stores/modal/actions.js +65 -0
  141. package/dist/modal/stores/modal/useModalStore.d.ts +82 -0
  142. package/dist/modal/stores/modal/useModalStore.js +41 -0
  143. package/dist/modal/stores/para/actions.d.ts +3 -0
  144. package/dist/modal/stores/para/actions.js +5 -0
  145. package/dist/modal/stores/para/useParaStore.d.ts +10 -0
  146. package/dist/modal/stores/para/useParaStore.js +3 -0
  147. package/dist/modal/stores/theme/actions.d.ts +3 -0
  148. package/dist/modal/stores/theme/actions.js +24 -0
  149. package/dist/modal/stores/theme/useThemeStore.d.ts +20 -0
  150. package/dist/modal/stores/theme/useThemeStore.js +14 -0
  151. package/dist/modal/stores/userInfo/actions.d.ts +3 -0
  152. package/dist/modal/stores/userInfo/actions.js +28 -0
  153. package/dist/modal/stores/userInfo/useUserInfoStore.d.ts +19 -0
  154. package/dist/modal/stores/userInfo/useUserInfoStore.js +9 -0
  155. package/dist/modal/types/commonTypes.d.ts +48 -0
  156. package/dist/modal/types/commonTypes.js +1 -0
  157. package/dist/modal/types/externalWallets.d.ts +31 -0
  158. package/dist/modal/types/externalWallets.js +21 -0
  159. package/dist/modal/types/modalProps.d.ts +138 -0
  160. package/dist/modal/types/modalProps.js +7 -0
  161. package/dist/modal/utils/authLayoutHelpers.d.ts +3 -0
  162. package/dist/modal/utils/authLayoutHelpers.js +2 -0
  163. package/dist/modal/utils/getMailtoLink.d.ts +1 -0
  164. package/dist/modal/utils/getMailtoLink.js +5 -0
  165. package/dist/modal/utils/getTileButtonFlex.d.ts +1 -0
  166. package/dist/modal/utils/getTileButtonFlex.js +15 -0
  167. package/dist/modal/utils/isPasskeySupported.d.ts +1 -0
  168. package/dist/modal/utils/isPasskeySupported.js +10 -0
  169. package/dist/modal/utils/openPopup.d.ts +1 -0
  170. package/dist/modal/utils/openPopup.js +55 -0
  171. package/dist/modal/utils/routeMobileExternalWallet.d.ts +1 -0
  172. package/dist/modal/utils/routeMobileExternalWallet.js +35 -0
  173. package/dist/modal/utils/steps.d.ts +112 -0
  174. package/dist/modal/utils/steps.js +215 -0
  175. package/dist/modal/utils/stringFormatters.d.ts +4 -0
  176. package/dist/modal/utils/stringFormatters.js +12 -0
  177. package/dist/modal/utils/validateOnRampConfig.d.ts +5 -0
  178. package/dist/modal/utils/validateOnRampConfig.js +26 -0
  179. package/package.json +51 -0
  180. package/styles.css/package.json +3 -0
@@ -0,0 +1,18 @@
1
+ export const brandedOAuthLogos = {
2
+ GOOGLE: 'googleBrand',
3
+ TWITTER: 'twitter',
4
+ APPLE: 'apple',
5
+ DISCORD: 'discordBrand',
6
+ FACEBOOK: 'facebookBrand',
7
+ FARCASTER: 'farcasterBrand',
8
+ TELEGRAM: 'telegramBrand',
9
+ };
10
+ export const oAuthLogos = {
11
+ GOOGLE: 'google',
12
+ TWITTER: 'twitter',
13
+ APPLE: 'apple',
14
+ DISCORD: 'discord',
15
+ FACEBOOK: 'facebook',
16
+ FARCASTER: 'farcaster',
17
+ TELEGRAM: 'telegram',
18
+ };
@@ -0,0 +1,13 @@
1
+ @import url('@getpara/react-components/css/capsule-core.css');
2
+
3
+ @font-face {
4
+ font-family: 'Inter';
5
+ src: url('../public/Inter-VariableFont_slnt,wght.ttf') format('truetype');
6
+ }
7
+
8
+ html {
9
+ --cpsl-default-font: 'Inter', sans-serif;
10
+ -webkit-overflow-scrolling: touch;
11
+
12
+ --wcm-z-index: 11000 !important;
13
+ }
@@ -0,0 +1 @@
1
+ export declare function useActiveWallet(): Omit<import("@getpara/core-sdk").Wallet, "signer">;
@@ -0,0 +1,9 @@
1
+ import { useMemo } from 'react';
2
+ import { useParaStore, useModalStore } from '../stores/index.js';
3
+ export function useActiveWallet() {
4
+ const para = useParaStore(state => state.para);
5
+ const [activeWalletId, activeWalletType] = useModalStore(state => state.activeWallet);
6
+ return useMemo(() => {
7
+ return para.findWallet(activeWalletId, activeWalletType, { forbidPregen: true });
8
+ }, [para, activeWalletId, activeWalletType]);
9
+ }
@@ -0,0 +1 @@
1
+ export declare const useEmbeddedExternalConnection: () => () => Promise<void>;
@@ -0,0 +1,46 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { useExternalWalletProviderStore } from '../stores/externalWalletProvider/useExternalWalletProviderStore.js';
11
+ export const useEmbeddedExternalConnection = () => {
12
+ // Get the connectParaEvmWallet action if available. This is used to trigger Para as an active connection when the user logs in using a non external wallet method.
13
+ const connectParaEvmWallet = useExternalWalletProviderStore(state => state.connectParaEvmWallet);
14
+ const EvmProvider = useExternalWalletProviderStore(state => state.EvmProvider);
15
+ const evmContext = useExternalWalletProviderStore(state => state.evmContext);
16
+ const connectParaCosmosWallet = useExternalWalletProviderStore(state => state.connectParaCosmosWallet);
17
+ const CosmosProvider = useExternalWalletProviderStore(state => state.CosmosProvider);
18
+ const cosmosContext = useExternalWalletProviderStore(state => state.cosmosContext);
19
+ const connectEmbeddedToExternalConnectors = () => __awaiter(void 0, void 0, void 0, function* () {
20
+ // If we're in the ParaEvmProvider context call the connect method to trigger Para as an active connection
21
+ if (evmContext && EvmProvider && connectParaEvmWallet) {
22
+ try {
23
+ const { error } = yield connectParaEvmWallet();
24
+ if (error) {
25
+ console.warn('Failed to connect Para EVM wallet to Wagmi:', error);
26
+ }
27
+ }
28
+ catch (err) {
29
+ console.warn('Error calling connectParaEvmWallet:', err);
30
+ }
31
+ }
32
+ // If we're in the ParaCosmosProvider context call the connect method to trigger Para as an active connection
33
+ if (cosmosContext && CosmosProvider && connectParaCosmosWallet) {
34
+ try {
35
+ const { error } = yield connectParaCosmosWallet();
36
+ if (error) {
37
+ console.warn('Failed to connect Para Cosmos wallet to Graz:', error);
38
+ }
39
+ }
40
+ catch (err) {
41
+ console.warn('Error calling connectParaCosmosWallet:', err);
42
+ }
43
+ }
44
+ });
45
+ return connectEmbeddedToExternalConnectors;
46
+ };
@@ -0,0 +1 @@
1
+ export declare const useGoBack: () => () => void;
@@ -0,0 +1,34 @@
1
+ import { useExternalWallets } from '../providers/ExternalWalletContext.js';
2
+ import { useModalStore } from '../stores/index.js';
3
+ import { getAddFundsStep, ModalStep } from '../utils/steps.js';
4
+ export const useGoBack = () => {
5
+ const currentStep = useModalStore(state => state.step);
6
+ const setStep = useModalStore(state => state.setStep);
7
+ const accountAddFundTab = useModalStore(state => state.accountAddFundTab);
8
+ const decrementStep = useModalStore(state => state.decrementStep);
9
+ const resetState = useModalStore(state => state.resetState);
10
+ const { setChainIdSwitchingTo } = useExternalWallets();
11
+ const goBack = () => {
12
+ if (currentStep === ModalStep.ADD_FUNDS_AWAITING) {
13
+ setStep(getAddFundsStep(accountAddFundTab));
14
+ }
15
+ else {
16
+ decrementStep();
17
+ }
18
+ switch (currentStep) {
19
+ case ModalStep.VERIFY_2FA:
20
+ case ModalStep.BIOMETRIC_CREATION:
21
+ case ModalStep.BIOMETRIC_LOGIN: {
22
+ resetState();
23
+ break;
24
+ }
25
+ }
26
+ switch (currentStep) {
27
+ case ModalStep.CHAIN_SWITCH: {
28
+ setChainIdSwitchingTo();
29
+ break;
30
+ }
31
+ }
32
+ };
33
+ return goBack;
34
+ };
@@ -0,0 +1,10 @@
1
+ export * from './ParaModal.js';
2
+ export type { ParaModalProps, ParaModalHandle, ParaModalTheme } from './types/modalProps.js';
3
+ export { ModalStep, type ModalStepProp } from './utils/steps.js';
4
+ export { AuthLayout } from './types/modalProps.js';
5
+ export * from './utils/openPopup.js';
6
+ export { ON_RAMP_PROVIDERS, ON_RAMP_ASSETS, NETWORKS, getAssetIcon, getAssetName, getNetworkIcon, getNetworkName, } from './constants/constants.js';
7
+ export { SaveRecoverySecret } from './components/RecoverySecretStep/RecoverySecretStep.js';
8
+ export * from './utils/validateOnRampConfig.js';
9
+ export * from './types/externalWallets.js';
10
+ export { useExternalWalletProviderStore } from './stores/externalWalletProvider/useExternalWalletProviderStore.js';
@@ -0,0 +1,9 @@
1
+ export * from './ParaModal.js';
2
+ export { ModalStep } from './utils/steps.js';
3
+ export { AuthLayout } from './types/modalProps.js';
4
+ export * from './utils/openPopup.js';
5
+ export { ON_RAMP_PROVIDERS, ON_RAMP_ASSETS, NETWORKS, getAssetIcon, getAssetName, getNetworkIcon, getNetworkName, } from './constants/constants.js';
6
+ export { SaveRecoverySecret } from './components/RecoverySecretStep/RecoverySecretStep.js';
7
+ export * from './utils/validateOnRampConfig.js';
8
+ export * from './types/externalWallets.js';
9
+ export { useExternalWalletProviderStore } from './stores/externalWalletProvider/useExternalWalletProviderStore.js';
@@ -0,0 +1,29 @@
1
+ import { ReactNode } from 'react';
2
+ import { CommonChain, CommonWallet } from '../types/commonTypes.js';
3
+ import ParaWeb from '@getpara/web-sdk';
4
+ export declare const defaultCosmosExternalWallet: {
5
+ wallets: any[];
6
+ chains: any[];
7
+ chainId: any;
8
+ disconnect: () => Promise<void>;
9
+ switchChain: () => Promise<{}>;
10
+ };
11
+ export type CosmosExternalWalletContextType = {
12
+ wallets: CommonWallet[];
13
+ chains: CommonChain[];
14
+ chainId: string;
15
+ disconnect: () => Promise<void>;
16
+ switchChain: (chainId: string) => Promise<{
17
+ error?: string[];
18
+ }>;
19
+ };
20
+ export declare const CosmosExternalWalletContext: import("react").Context<CosmosExternalWalletContextType>;
21
+ export interface CosmosExternalWalletProviderProps {
22
+ children: ReactNode;
23
+ para: ParaWeb;
24
+ onSwitchWallet: (args: {
25
+ address?: string;
26
+ error?: string;
27
+ }) => void;
28
+ }
29
+ export declare function CosmosExternalWalletProvider({ children }: CosmosExternalWalletProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useMemo } from 'react';
3
+ export const defaultCosmosExternalWallet = {
4
+ wallets: [],
5
+ chains: [],
6
+ chainId: undefined,
7
+ disconnect: () => Promise.resolve(),
8
+ switchChain: () => Promise.resolve({}),
9
+ };
10
+ export const CosmosExternalWalletContext = createContext(defaultCosmosExternalWallet);
11
+ export function CosmosExternalWalletProvider({ children }) {
12
+ const wallets = [];
13
+ const chains = [];
14
+ const chainId = undefined;
15
+ const disconnect = () => Promise.resolve();
16
+ const switchChain = () => Promise.resolve({});
17
+ return (_jsx(CosmosExternalWalletContext.Provider, { value: useMemo(() => ({ wallets, chains, chainId, disconnect, switchChain }), [wallets, chains, chainId, disconnect, switchChain]), children: children }));
18
+ }
@@ -0,0 +1,33 @@
1
+ import { ReactNode } from 'react';
2
+ import { CommonChain, CommonWallet } from '../types/commonTypes.js';
3
+ import ParaWeb from '@getpara/web-sdk';
4
+ export declare const defaultEvmExternalWallet: {
5
+ wallets: any[];
6
+ chains: any[];
7
+ chainId: any;
8
+ username: any;
9
+ avatar: any;
10
+ disconnect: () => Promise<void>;
11
+ switchChain: () => Promise<{}>;
12
+ };
13
+ export type EvmExternalWalletContextType = {
14
+ wallets: CommonWallet[];
15
+ chains: CommonChain[];
16
+ chainId: number;
17
+ username: string;
18
+ avatar?: string;
19
+ disconnect: () => Promise<void>;
20
+ switchChain: (chainId: number) => Promise<{
21
+ error?: string[];
22
+ }>;
23
+ };
24
+ export declare const EvmExternalWalletContext: import("react").Context<EvmExternalWalletContextType>;
25
+ export interface EvmExternalWalletProviderProps {
26
+ children: ReactNode;
27
+ para: ParaWeb;
28
+ onSwitchWallet: (args: {
29
+ address?: string;
30
+ error?: string;
31
+ }) => void;
32
+ }
33
+ export declare function EvmExternalWalletProvider({ children }: EvmExternalWalletProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useMemo } from 'react';
3
+ export const defaultEvmExternalWallet = {
4
+ wallets: [],
5
+ chains: [],
6
+ chainId: undefined,
7
+ username: undefined,
8
+ avatar: undefined,
9
+ disconnect: () => Promise.resolve(),
10
+ switchChain: () => Promise.resolve({}),
11
+ };
12
+ export const EvmExternalWalletContext = createContext(defaultEvmExternalWallet);
13
+ export function EvmExternalWalletProvider({ children }) {
14
+ const wallets = [];
15
+ const chains = [];
16
+ const chainId = undefined;
17
+ const username = undefined;
18
+ const avatar = undefined;
19
+ const disconnect = () => Promise.resolve();
20
+ const switchChain = () => Promise.resolve({});
21
+ return (_jsx(EvmExternalWalletContext.Provider, { value: useMemo(() => ({ wallets, chains, chainId, username, avatar, disconnect, switchChain }), [wallets, chains, chainId, username, avatar, disconnect, switchChain]), children: children }));
22
+ }
@@ -0,0 +1,75 @@
1
+ import { Context, ReactNode } from 'react';
2
+ import { CommonChain, CommonWallet } from '../types/commonTypes.js';
3
+ import { EvmExternalWalletContextType } from './EvmExternalWalletContextStub.js';
4
+ import { TExternalWallet } from '../types/externalWallets.js';
5
+ import { SolanaExternalWalletContextType } from './SolanaExternalWalletContextStub.js';
6
+ import { CosmosExternalWalletContextType } from './CosmosExternalWalletContextStub.js';
7
+ export declare const defaultExternalWallet: {
8
+ wallets: any[];
9
+ chains: any[];
10
+ chainId: any;
11
+ wallet: any;
12
+ qrUri: any;
13
+ chainIdSwitchingTo: any;
14
+ walletDisplayHelpers: {
15
+ showExtension: boolean;
16
+ showMobile: boolean;
17
+ isSolanaMobileIOS: boolean;
18
+ isCosmosMobileWallet: boolean;
19
+ };
20
+ username: any;
21
+ avatar: any;
22
+ connectExternalWallet: () => void;
23
+ disconnectExternalWallet: () => Promise<void>;
24
+ switchChain: () => Promise<void>;
25
+ setChainIdSwitchingTo: () => void;
26
+ };
27
+ export declare const ExternalWalletContext: Context<{
28
+ wallets: CommonWallet[];
29
+ chains: CommonChain[];
30
+ chainId: string;
31
+ wallet?: CommonWallet;
32
+ qrUri?: string;
33
+ chainIdSwitchingTo?: string;
34
+ walletDisplayHelpers: {
35
+ showExtension: boolean;
36
+ showMobile: boolean;
37
+ isSolanaMobileIOS: boolean;
38
+ isCosmosMobileWallet: boolean;
39
+ };
40
+ username?: string;
41
+ avatar?: string;
42
+ connectExternalWallet: (wallet: CommonWallet, isMobile?: boolean, isManualWalletConnect?: boolean) => void;
43
+ disconnectExternalWallet: () => Promise<void>;
44
+ switchChain: (chainId: string) => Promise<void>;
45
+ setChainIdSwitchingTo: (chainId?: string) => void;
46
+ }>;
47
+ interface ExternalWalletProviderProps {
48
+ children: ReactNode;
49
+ walletSort: TExternalWallet[];
50
+ evmContext: Context<EvmExternalWalletContextType>;
51
+ solanaContext: Context<SolanaExternalWalletContextType>;
52
+ cosmosContext: Context<CosmosExternalWalletContextType>;
53
+ }
54
+ export declare function ExternalWalletProvider({ children, evmContext, solanaContext, cosmosContext, walletSort, }: ExternalWalletProviderProps): import("react/jsx-runtime").JSX.Element;
55
+ export declare const useExternalWallets: () => {
56
+ wallets: CommonWallet[];
57
+ chains: CommonChain[];
58
+ chainId: string;
59
+ wallet?: CommonWallet;
60
+ qrUri?: string;
61
+ chainIdSwitchingTo?: string;
62
+ walletDisplayHelpers: {
63
+ showExtension: boolean;
64
+ showMobile: boolean;
65
+ isSolanaMobileIOS: boolean;
66
+ isCosmosMobileWallet: boolean;
67
+ };
68
+ username?: string;
69
+ avatar?: string;
70
+ connectExternalWallet: (wallet: CommonWallet, isMobile?: boolean, isManualWalletConnect?: boolean) => void;
71
+ disconnectExternalWallet: () => Promise<void>;
72
+ switchChain: (chainId: string) => Promise<void>;
73
+ setChainIdSwitchingTo: (chainId?: string) => void;
74
+ };
75
+ export {};
@@ -0,0 +1,252 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
12
+ import { useParaStore, useModalStore } from '../stores/index.js';
13
+ import { ModalStep } from '../utils/steps.js';
14
+ import { WalletType, isIOS, isIOSWebview, isMobile, truncateAddress } from '@getpara/web-sdk';
15
+ export const defaultExternalWallet = {
16
+ wallets: [],
17
+ chains: [],
18
+ chainId: undefined,
19
+ wallet: undefined,
20
+ qrUri: undefined,
21
+ chainIdSwitchingTo: undefined,
22
+ walletDisplayHelpers: {
23
+ showExtension: false,
24
+ showMobile: false,
25
+ isSolanaMobileIOS: false,
26
+ isCosmosMobileWallet: false,
27
+ },
28
+ username: undefined,
29
+ avatar: undefined,
30
+ connectExternalWallet: () => { },
31
+ disconnectExternalWallet: () => Promise.resolve(),
32
+ switchChain: () => Promise.resolve(),
33
+ setChainIdSwitchingTo: () => { },
34
+ };
35
+ export const ExternalWalletContext = createContext(defaultExternalWallet);
36
+ export function ExternalWalletProvider({ children, evmContext, solanaContext, cosmosContext, walletSort, }) {
37
+ const { wallets: evmWallets, disconnect: evmDisconnect, chains: evmChains, chainId: evmChainId, switchChain: evmSwitchChain, username: evmUsername, avatar: evmAvatar, } = useContext(evmContext);
38
+ const { wallets: solanaWallets, disconnect: solanaDisconnect } = useContext(solanaContext);
39
+ const { wallets: cosmosWallets, disconnect: cosmosDisconnect, chains: cosmosChains, chainId: cosmosChainId, switchChain: cosmosSwitchChain, } = useContext(cosmosContext);
40
+ const setStep = useModalStore(state => state.setStep);
41
+ const setStepDirection = useModalStore(state => state.setStepDirection);
42
+ const setIsExternalWalletConnecting = useModalStore(state => state.setIsExternalWalletConnecting);
43
+ const isExternalWalletConnecting = useModalStore(state => state.isExternalWalletConnecting);
44
+ const setSelectedExternalWalletId = useModalStore(state => state.setSelectedExternalWalletId);
45
+ const selectedExternalWalletId = useModalStore(state => state.selectedExternalWalletId);
46
+ const setExternalWalletError = useModalStore(state => state.setExternalWalletError);
47
+ const setIsUsingMobileConnector = useModalStore(state => state.setIsUsingMobileConnector);
48
+ const isUsingMobileConnector = useModalStore(state => state.isUsingMobileConnector);
49
+ const para = useParaStore(state => state.para);
50
+ const [qrUri, setQrUri] = useState();
51
+ const [chainIdSwitchingTo, setChainIdSwitchingTo] = useState();
52
+ // Filter any wallets that aren't included in the sort array, sort by the array then sort by installed extensions
53
+ const wallets = [...evmWallets, ...solanaWallets, ...cosmosWallets]
54
+ .filter(w => walletSort.includes(w.id.toUpperCase()))
55
+ .sort((a, b) => walletSort.indexOf(a.id.toUpperCase()) -
56
+ walletSort.indexOf(b.id.toUpperCase()))
57
+ .sort((a, b) => (a.installed === b.installed ? 0 : a.installed ? -1 : 1));
58
+ const wallet = useMemo(() => wallets.find(w => w.id === selectedExternalWalletId), [wallets, selectedExternalWalletId]);
59
+ const updateQrUri = () => __awaiter(this, void 0, void 0, function* () {
60
+ var _a;
61
+ const uri = yield ((_a = wallet === null || wallet === void 0 ? void 0 : wallet.getQrUri) === null || _a === void 0 ? void 0 : _a.call(wallet));
62
+ setQrUri(uri);
63
+ });
64
+ useEffect(() => {
65
+ if (wallet) {
66
+ if (!qrUri) {
67
+ updateQrUri();
68
+ }
69
+ }
70
+ else if (qrUri) {
71
+ setQrUri(undefined);
72
+ }
73
+ }, [wallet]);
74
+ const chains = useMemo(() => {
75
+ var _a, _b, _c;
76
+ const walletType = (_c = para.externalWallets[(_b = (_a = para.currentExternalWalletAddresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '']) === null || _c === void 0 ? void 0 : _c.type;
77
+ switch (walletType) {
78
+ case WalletType.COSMOS: {
79
+ return cosmosChains;
80
+ }
81
+ case WalletType.EVM: {
82
+ return evmChains;
83
+ }
84
+ default: {
85
+ return [];
86
+ }
87
+ }
88
+ }, [cosmosChains, evmChains, selectedExternalWalletId]);
89
+ const chainId = useMemo(() => {
90
+ var _a, _b, _c;
91
+ const walletType = (_c = para.externalWallets[(_b = (_a = para.currentExternalWalletAddresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '']) === null || _c === void 0 ? void 0 : _c.type;
92
+ switch (walletType) {
93
+ case WalletType.COSMOS: {
94
+ return cosmosChainId;
95
+ }
96
+ case WalletType.EVM: {
97
+ return evmChainId === null || evmChainId === void 0 ? void 0 : evmChainId.toString();
98
+ }
99
+ default: {
100
+ return undefined;
101
+ }
102
+ }
103
+ }, [cosmosChains, evmChains, selectedExternalWalletId]);
104
+ const switchChain = useCallback((chainId) => __awaiter(this, void 0, void 0, function* () {
105
+ var _a, _b, _c;
106
+ const walletType = (_c = para.externalWallets[(_b = (_a = para.currentExternalWalletAddresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '']) === null || _c === void 0 ? void 0 : _c.type;
107
+ if (walletType) {
108
+ let resp;
109
+ setExternalWalletError();
110
+ setChainIdSwitchingTo(chainId);
111
+ switch (walletType) {
112
+ case WalletType.COSMOS: {
113
+ setStep(ModalStep.CHAIN_SWITCH);
114
+ resp = yield cosmosSwitchChain(chainId);
115
+ break;
116
+ }
117
+ case WalletType.EVM: {
118
+ setStep(ModalStep.CHAIN_SWITCH);
119
+ resp = yield evmSwitchChain(parseInt(chainId));
120
+ break;
121
+ }
122
+ default: {
123
+ break;
124
+ }
125
+ }
126
+ if (resp.error) {
127
+ setExternalWalletError(resp.error);
128
+ }
129
+ else {
130
+ setChainIdSwitchingTo(undefined);
131
+ setStepDirection(-1);
132
+ setStep(ModalStep.ACCOUNT_MAIN);
133
+ }
134
+ }
135
+ }), [evmSwitchChain, cosmosSwitchChain]);
136
+ const connectExternalWallet = useCallback((wallet, isMobileConnect, isManualWalletConnect, isResetAfterManualWalletConnect) => __awaiter(this, void 0, void 0, function* () {
137
+ // If triggering the WC modal manually from desktop, disconnect the current connection attempt to trigger the mobile connection attempt
138
+ if (isExternalWalletConnecting && isManualWalletConnect) {
139
+ yield evmDisconnect();
140
+ yield solanaDisconnect();
141
+ yield cosmosDisconnect();
142
+ setQrUri(undefined);
143
+ setIsExternalWalletConnecting(false);
144
+ }
145
+ if (isResetAfterManualWalletConnect || isManualWalletConnect || !isExternalWalletConnecting) {
146
+ setExternalWalletError();
147
+ setIsExternalWalletConnecting(true);
148
+ setIsUsingMobileConnector(isMobileConnect);
149
+ const { address, error } = yield (isMobileConnect ? wallet.connectMobile(isManualWalletConnect) : wallet.connect());
150
+ if (error) {
151
+ setExternalWalletError([error]);
152
+ setIsUsingMobileConnector();
153
+ // If triggering the WC modal manually from desktop, attempt desktop reconnect on connection rejection
154
+ if (isManualWalletConnect && error === 'Connection request rejected') {
155
+ setExternalWalletError();
156
+ yield connectExternalWallet(wallet, false, false, true);
157
+ yield updateQrUri();
158
+ return;
159
+ }
160
+ }
161
+ else if (address) {
162
+ setStep(ModalStep.LOGIN_DONE);
163
+ }
164
+ setIsExternalWalletConnecting(false);
165
+ }
166
+ }), [isExternalWalletConnecting]);
167
+ const disconnectExternalWallet = () => __awaiter(this, void 0, void 0, function* () {
168
+ yield evmDisconnect();
169
+ yield solanaDisconnect();
170
+ yield cosmosDisconnect();
171
+ setSelectedExternalWalletId();
172
+ });
173
+ const walletDisplayHelpers = {
174
+ // Show the extension screen if on web and the wallet is an extension and installed or the wallet isn't a mobile wallet
175
+ // Also show the extension connection if on desktop for a solana wallet (no walletConnect)
176
+ showExtension: !isMobile() && (((wallet === null || wallet === void 0 ? void 0 : wallet.isExtension) && (wallet === null || wallet === void 0 ? void 0 : wallet.installed)) || !(wallet === null || wallet === void 0 ? void 0 : wallet.isMobile) || (wallet === null || wallet === void 0 ? void 0 : wallet.type) === WalletType.SOLANA),
177
+ // Show the mobile screen if on mobile and the wallet is a mobile wallet or if on desktop and the wallet isn't installed
178
+ showMobile: (isMobile() && (wallet === null || wallet === void 0 ? void 0 : wallet.isMobile)) || (!isMobile() && !(wallet === null || wallet === void 0 ? void 0 : wallet.installed)),
179
+ isSolanaMobileIOS: isIOS() && isMobile() && !isIOSWebview() && (wallet === null || wallet === void 0 ? void 0 : wallet.type) === WalletType.SOLANA,
180
+ isCosmosMobileWallet: (wallet === null || wallet === void 0 ? void 0 : wallet.type) === WalletType.COSMOS && isUsingMobileConnector,
181
+ };
182
+ const username = useMemo(() => {
183
+ var _a, _b;
184
+ let username;
185
+ const storedExternalWallet = para.externalWallets[(_b = (_a = para.currentExternalWalletAddresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : ''];
186
+ if (storedExternalWallet) {
187
+ const walletType = storedExternalWallet === null || storedExternalWallet === void 0 ? void 0 : storedExternalWallet.type;
188
+ switch (walletType) {
189
+ case WalletType.EVM: {
190
+ // If evmUsername is an EVM address, format it, else return it since it should be an ENS name
191
+ username = evmUsername
192
+ ? evmUsername.startsWith('0x')
193
+ ? truncateAddress(evmUsername, 'EVM')
194
+ : evmUsername
195
+ : undefined;
196
+ break;
197
+ }
198
+ default: {
199
+ username = storedExternalWallet.address
200
+ ? truncateAddress(storedExternalWallet.address, storedExternalWallet.type)
201
+ : undefined;
202
+ break;
203
+ }
204
+ }
205
+ }
206
+ return username;
207
+ }, [evmUsername, wallet]);
208
+ const avatar = useMemo(() => {
209
+ var _a, _b, _c;
210
+ const walletType = (_c = para.externalWallets[(_b = (_a = para.currentExternalWalletAddresses) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : '']) === null || _c === void 0 ? void 0 : _c.type;
211
+ if (walletType) {
212
+ switch (walletType) {
213
+ case WalletType.EVM: {
214
+ return evmAvatar;
215
+ }
216
+ default: {
217
+ return undefined;
218
+ }
219
+ }
220
+ }
221
+ }, [evmAvatar, wallet]);
222
+ return (_jsx(ExternalWalletContext.Provider, { value: useMemo(() => ({
223
+ wallets,
224
+ chains,
225
+ chainId,
226
+ wallet,
227
+ qrUri,
228
+ walletDisplayHelpers,
229
+ chainIdSwitchingTo,
230
+ username,
231
+ avatar,
232
+ connectExternalWallet,
233
+ disconnectExternalWallet,
234
+ switchChain,
235
+ setChainIdSwitchingTo,
236
+ }), [
237
+ wallets,
238
+ chains,
239
+ chainId,
240
+ wallet,
241
+ qrUri,
242
+ walletDisplayHelpers,
243
+ chainIdSwitchingTo,
244
+ username,
245
+ avatar,
246
+ disconnectExternalWallet,
247
+ connectExternalWallet,
248
+ switchChain,
249
+ setChainIdSwitchingTo,
250
+ ]), children: children }));
251
+ }
252
+ export const useExternalWallets = () => useContext(ExternalWalletContext);
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from 'react';
2
+ import { CommonWallet } from '../types/commonTypes.js';
3
+ import ParaWeb from '@getpara/web-sdk';
4
+ export declare const defaultSolanaExternalWallet: {
5
+ wallets: any[];
6
+ disconnect: () => Promise<void>;
7
+ };
8
+ export type SolanaExternalWalletContextType = {
9
+ wallets: CommonWallet[];
10
+ disconnect: () => Promise<void>;
11
+ };
12
+ export declare const SolanaExternalWalletContext: import("react").Context<SolanaExternalWalletContextType>;
13
+ export interface SolanaExternalWalletProviderProps {
14
+ children: ReactNode;
15
+ para: ParaWeb;
16
+ onSwitchWallet: (args: {
17
+ address?: string;
18
+ error?: string;
19
+ }) => void;
20
+ }
21
+ export declare function SolanaExternalWalletProvider({ children }: SolanaExternalWalletProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useMemo } from 'react';
3
+ export const defaultSolanaExternalWallet = {
4
+ wallets: [],
5
+ disconnect: () => Promise.resolve(),
6
+ };
7
+ export const SolanaExternalWalletContext = createContext(defaultSolanaExternalWallet);
8
+ export function SolanaExternalWalletProvider({ children }) {
9
+ const wallets = [];
10
+ const disconnect = () => Promise.resolve();
11
+ return (_jsx(SolanaExternalWalletContext.Provider, { value: useMemo(() => ({ wallets, disconnect }), [wallets, disconnect]), children: children }));
12
+ }
@@ -0,0 +1,3 @@
1
+ import { StoreApi } from 'zustand';
2
+ import { ExternalWalletProviderActions, ExternalWalletProviderStore } from './useExternalWalletProviderStore.js';
3
+ export declare const getActions: (set: StoreApi<ExternalWalletProviderStore>["setState"]) => ExternalWalletProviderActions;
@@ -0,0 +1,5 @@
1
+ export const getActions = (set) => ({
2
+ updateState: state => {
3
+ set(state);
4
+ },
5
+ });