@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.
- package/dist/cli/cli.mjs +1 -6
- package/dist/index.js +11 -6499
- package/dist/modal/ParaModal.js +262 -0
- package/dist/modal/components/Account/Account.js +139 -0
- package/dist/modal/components/AddFunds/AddFunds.d.ts +0 -2
- package/dist/modal/components/AddFunds/AddFunds.js +69 -0
- package/dist/modal/components/AddFunds/AddFundsAsset.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsAsset.js +125 -0
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +78 -0
- package/dist/modal/components/AddFunds/AddFundsContext.d.ts +31 -0
- package/dist/modal/components/AddFunds/AddFundsContext.js +160 -0
- package/dist/modal/components/AddFunds/AddFundsDone.js +49 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsProvider.js +109 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsReceive.js +83 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.d.ts +1 -0
- package/dist/modal/components/AddFunds/AddFundsSettings.js +237 -0
- package/dist/{MoonPayEmbed-Q2HP2BFI.js → modal/components/AddFunds/MoonPayEmbed.js} +1 -3
- package/dist/modal/components/AddFunds/common.d.ts +19 -0
- package/dist/modal/components/AddFunds/common.js +24 -0
- package/dist/modal/components/AddFunds/index.js +4 -0
- package/dist/modal/components/AuthInput/AuthInput.js +262 -0
- package/dist/modal/components/AuthInput/hooks/useDropdownPosition.js +33 -0
- package/dist/modal/components/AuthInput/phoneMasks.js +253 -0
- package/dist/modal/components/AuthMainStep/AuthMainStep.d.ts +4 -3
- package/dist/modal/components/AuthMainStep/AuthMainStep.js +50 -0
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.d.ts +4 -3
- package/dist/modal/components/AuthMainStep/AuthMainStepContent.js +157 -0
- package/dist/modal/components/AuthOptions/AuthOptions.d.ts +4 -3
- package/dist/modal/components/AuthOptions/AuthOptions.js +67 -0
- package/dist/modal/components/AwaitingBiometricsStep/AwaitingBiometricsStep.js +18 -0
- package/dist/modal/components/AwaitingOAuthStep/AwaitingOAuthStep.js +10 -0
- package/dist/modal/components/AwaitingPasswordStep/AwaitingPasswordStep.js +18 -0
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.d.ts +5 -1
- package/dist/modal/components/AwaitingWalletCreationStep/AwaitingWalletCreationStep.js +49 -0
- package/dist/modal/components/BiometricCreationStep/BiometricCreationStep.js +63 -0
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +55 -0
- package/dist/modal/components/Body/AnimatedHeightWrapper.js +29 -0
- package/dist/modal/components/Body/Body.d.ts +4 -3
- package/dist/modal/components/Body/Body.js +327 -0
- package/dist/modal/components/ChainSwitch/ChainSwitch.js +95 -0
- package/dist/modal/components/ChainSwitch/config.js +17 -0
- package/dist/modal/components/Controls/Controls.js +77 -0
- package/dist/modal/components/Controls/Selects.js +189 -0
- package/dist/modal/components/ExternalWalletStep/ExternalWalletStep.js +144 -0
- package/dist/modal/components/ExternalWalletStep/config.js +17 -0
- package/dist/modal/components/ExternalWalletVerificationStep/ExternalWalletVerificationStep.js +34 -0
- package/dist/modal/components/ExternalWallets/ExternalWallets.js +173 -0
- package/dist/modal/components/Footer/Footer.js +95 -0
- package/dist/modal/components/Header/Header.js +43 -0
- package/dist/modal/components/Header/hooks/useStepTitle.js +54 -0
- package/dist/modal/components/Hero/Hero.js +116 -0
- package/dist/modal/components/IFrameStep/IFrameStep.js +59 -0
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +31 -0
- package/dist/modal/components/ModalContent/ModalContent.js +95 -0
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +27 -0
- package/dist/modal/components/OAuth/OAuth.d.ts +2 -2
- package/dist/modal/components/OAuth/OAuth.js +79 -0
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +90 -0
- package/dist/modal/components/OnRampComponents/AddingFunds.js +23 -0
- package/dist/modal/components/OnRampComponents/OnRampProviderButton.js +77 -0
- package/dist/modal/components/RecoverySecretStep/RecoverySecretStep.js +107 -0
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +132 -0
- package/dist/modal/components/StripeComponents/StripeComponents.js +88 -0
- package/dist/modal/components/TwoFactorDoneStep/TwoFactorDoneStep.js +27 -0
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +143 -0
- package/dist/modal/components/Waiting/Waiting.js +17 -0
- package/dist/modal/components/WalletCard/PartnerIcon.js +34 -0
- package/dist/modal/components/WalletCard/WalletCard.d.ts +3 -3
- package/dist/modal/components/WalletCard/WalletCard.js +128 -0
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +73 -0
- package/dist/modal/components/common.d.ts +32 -13
- package/dist/modal/components/common.js +175 -0
- package/dist/modal/components/index.js +2 -0
- package/dist/modal/constants/constants.d.ts +9 -2
- package/dist/modal/constants/constants.js +138 -0
- package/dist/modal/constants/defaults.js +10 -0
- package/dist/modal/constants/oAuthLogos.d.ts +3 -3
- package/dist/modal/constants/oAuthLogos.js +24 -0
- package/dist/modal/hooks/useGoBack.js +43 -0
- package/dist/modal/index.d.ts +1 -2
- package/dist/modal/index.js +29 -0
- package/dist/modal/stores/index.js +2 -0
- package/dist/modal/stores/modal/actions.js +133 -0
- package/dist/modal/stores/modal/useModalStore.d.ts +12 -4
- package/dist/modal/stores/modal/useModalStore.js +68 -0
- package/dist/modal/types/commonTypes.d.ts +0 -47
- package/dist/modal/types/commonTypes.js +1 -0
- package/dist/modal/types/externalWallets.d.ts +2 -0
- package/dist/modal/types/externalWallets.js +32 -0
- package/dist/modal/types/modalProps.d.ts +10 -2
- package/dist/modal/types/modalProps.js +12 -0
- package/dist/modal/utils/authInputHelpers.d.ts +7 -0
- package/dist/modal/utils/authInputHelpers.js +38 -0
- package/dist/modal/utils/authLayoutHelpers.js +8 -0
- package/dist/modal/utils/countryCodes.js +45 -0
- package/dist/modal/utils/getMailtoLink.js +10 -0
- package/dist/modal/utils/getTileButtonFlex.js +20 -0
- package/dist/modal/utils/isPasskeySupported.js +15 -0
- package/dist/modal/utils/openPopup.js +60 -0
- package/dist/modal/utils/routeMobileExternalWallet.js +31 -0
- package/dist/modal/utils/steps.d.ts +6 -0
- package/dist/modal/utils/steps.js +247 -0
- package/dist/modal/utils/stringFormatters.d.ts +1 -0
- package/dist/modal/utils/stringFormatters.js +19 -0
- package/dist/modal/utils/validateOnRampConfig.js +32 -0
- package/dist/package.json +6 -0
- package/dist/provider/ParaProvider.js +83 -0
- package/dist/provider/actions/getAccount.d.ts +8 -1
- package/dist/provider/actions/getAccount.js +51 -0
- package/dist/provider/actions/getWallet.d.ts +2 -2
- package/dist/provider/actions/getWallet.js +14 -0
- package/dist/provider/actions/index.d.ts +2 -0
- package/dist/provider/actions/index.js +59 -0
- package/dist/provider/actions/utils.js +15 -0
- package/dist/provider/components/CosmosWalletWrapper.js +34 -0
- package/dist/provider/components/EvmWalletWrapper.js +34 -0
- package/dist/provider/components/ExternalWalletWrapper.js +139 -0
- package/dist/provider/components/SolanaWalletWrapper.js +36 -0
- package/dist/provider/external/getParaCosmosConnector.js +22 -0
- package/dist/provider/external/getParaEvmConnector.js +22 -0
- package/dist/provider/external/getParaSolanaConnector.js +22 -0
- package/dist/provider/external/stubs/CosmosExternalWalletContextStub.js +18 -0
- package/dist/provider/external/stubs/EvmExternalWalletContextStub.js +21 -0
- package/dist/provider/external/stubs/SolanaExternalWalletContextStub.js +14 -0
- package/dist/provider/hooks/index.js +4 -0
- package/dist/provider/hooks/mutations/index.d.ts +1 -0
- package/dist/provider/hooks/mutations/index.js +61 -0
- package/dist/provider/hooks/mutations/utils.js +22 -0
- package/dist/provider/hooks/queries/index.d.ts +1 -0
- package/dist/provider/hooks/queries/index.js +10 -0
- package/dist/provider/hooks/queries/useAccount.js +21 -0
- package/dist/provider/hooks/queries/useWallet.js +22 -0
- package/dist/provider/hooks/queries/useWalletBalance.d.ts +6 -0
- package/dist/provider/hooks/queries/useWalletBalance.js +55 -0
- package/dist/provider/hooks/utils/index.js +10 -0
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +74 -0
- package/dist/provider/hooks/utils/useClient.js +10 -0
- package/dist/provider/hooks/utils/useEventListeners.d.ts +1 -1
- package/dist/provider/hooks/utils/useEventListeners.js +147 -0
- package/dist/provider/hooks/utils/useInternalClient.js +10 -0
- package/dist/provider/hooks/utils/useModal.js +17 -0
- package/dist/provider/hooks/utils/useWalletState.d.ts +3 -3
- package/dist/provider/hooks/utils/useWalletState.js +48 -0
- package/dist/provider/index.js +9 -0
- package/dist/provider/providers/AuthProvider.d.ts +10 -6
- package/dist/provider/providers/AuthProvider.js +498 -0
- package/dist/provider/providers/CosmosExternalWalletProvider.js +66 -0
- package/dist/provider/providers/EvmExternalWalletProvider.js +74 -0
- package/dist/provider/providers/ExternalWalletProvider.d.ts +5 -2
- package/dist/provider/providers/ExternalWalletProvider.js +428 -0
- package/dist/provider/providers/SolanaExternalWalletProvider.js +66 -0
- package/dist/provider/stores/getters.d.ts +1 -1
- package/dist/provider/stores/getters.js +13 -0
- package/dist/provider/stores/setters.js +7 -0
- package/dist/provider/stores/slices/client.js +9 -0
- package/dist/provider/stores/slices/config.js +9 -0
- package/dist/provider/stores/slices/externalWallets.js +40 -0
- package/dist/provider/stores/slices/index.js +5 -0
- package/dist/provider/stores/slices/modal.js +16 -0
- package/dist/provider/stores/slices/wallet.js +13 -0
- package/dist/provider/stores/types.d.ts +7 -4
- package/dist/provider/stores/types.js +1 -0
- package/dist/provider/stores/useStore.js +28 -0
- package/dist/provider/types/externalWalletProviders.d.ts +2 -2
- package/dist/provider/types/externalWalletProviders.js +1 -0
- package/dist/provider/types/provider.d.ts +9 -3
- package/dist/provider/types/provider.js +1 -0
- package/dist/provider/types/query.js +1 -0
- package/dist/provider/types/utils.js +1 -0
- package/dist/provider/utils/constants.d.ts +5 -0
- package/dist/provider/utils/constants.js +10 -0
- package/dist/provider/utils/paraConfigTypeGuards.js +13 -0
- package/dist/provider/utils/renameMutations.js +18 -0
- package/package.json +18 -16
- package/dist/MoonPayEmbed-Q2HP2BFI.js.br +0 -0
- package/dist/MoonPayEmbed-Q2HP2BFI.js.gz +0 -0
- package/dist/chunk-MMUBH76A.js.br +0 -0
- package/dist/chunk-MMUBH76A.js.gz +0 -0
- package/dist/index.js.br +0 -0
- package/dist/index.js.gz +0 -0
- /package/dist/modal/{components/AuthInput → utils}/countryCodes.d.ts +0 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async,
|
|
4
|
+
__spreadValues
|
|
5
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
6
|
+
import { useQuery } from "@tanstack/react-query";
|
|
7
|
+
import { useAccount, useClient, useWallet, useWalletState } from "../index.js";
|
|
8
|
+
import { useStore } from "../../stores/useStore.js";
|
|
9
|
+
import { getWalletBalance } from "../../actions/index.js";
|
|
10
|
+
import { useExternalWallets } from "../../providers/ExternalWalletProvider.js";
|
|
11
|
+
import { useCallback } from "react";
|
|
12
|
+
const WALLET_BALANCE_BASE_KEY = "PARA_WALLET_BALANCE";
|
|
13
|
+
const useWalletBalance = (args) => {
|
|
14
|
+
const client = useClient();
|
|
15
|
+
const { data: selectedWallet } = useWallet();
|
|
16
|
+
const {
|
|
17
|
+
selectedWallet: { type: selectedWalletType }
|
|
18
|
+
} = useWalletState();
|
|
19
|
+
const { data: account } = useAccount();
|
|
20
|
+
const rpcUrl = useStore((state) => state.rpcUrl);
|
|
21
|
+
const { getWalletBalance: getExternalWalletBalance, chainId } = useExternalWallets();
|
|
22
|
+
const queryFn = useCallback(() => __async(void 0, null, function* () {
|
|
23
|
+
var _a, _b, _c;
|
|
24
|
+
const skipGetBalance = !selectedWallet || selectedWalletType && ["COSMOS", "SOLANA"].includes(selectedWalletType);
|
|
25
|
+
if (skipGetBalance) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
if (selectedWallet.isExternal) {
|
|
30
|
+
return (_a = yield getExternalWalletBalance()) != null ? _a : null;
|
|
31
|
+
} else {
|
|
32
|
+
const completeArgs = __spreadValues({ walletId: (_b = selectedWallet == null ? void 0 : selectedWallet.id) != null ? _b : "", rpcUrl }, args);
|
|
33
|
+
return (_c = yield getWalletBalance(client, completeArgs)) != null ? _c : null;
|
|
34
|
+
}
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.error("Error fetching wallet balance: ", err);
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
}), [account, selectedWallet, selectedWalletType, rpcUrl, getExternalWalletBalance]);
|
|
40
|
+
return useQuery({
|
|
41
|
+
queryKey: [
|
|
42
|
+
WALLET_BALANCE_BASE_KEY,
|
|
43
|
+
client == null ? void 0 : client.userId,
|
|
44
|
+
selectedWallet == null ? void 0 : selectedWallet.id,
|
|
45
|
+
selectedWallet == null ? void 0 : selectedWallet.type,
|
|
46
|
+
(selectedWallet == null ? void 0 : selectedWallet.isExternal) ? chainId : ""
|
|
47
|
+
],
|
|
48
|
+
queryFn,
|
|
49
|
+
enabled: !!selectedWallet && !!rpcUrl && !!(account == null ? void 0 : account.isConnected)
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export {
|
|
53
|
+
WALLET_BALANCE_BASE_KEY,
|
|
54
|
+
useWalletBalance
|
|
55
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
__async
|
|
4
|
+
} from "../../../chunk-MMUBH76A.js";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import { useAccount, useKeepSessionAlive, useLogout } from "../index.js";
|
|
7
|
+
import { useInternalClient } from "./useInternalClient.js";
|
|
8
|
+
const SESSION_CHECK_INTERVAL = 6e4;
|
|
9
|
+
const SESSION_REFRESH_THRESHOLD = 3e5;
|
|
10
|
+
const useAutoSessionKeepAlive = ({ disabled }) => {
|
|
11
|
+
const client = useInternalClient();
|
|
12
|
+
const { data: account } = useAccount();
|
|
13
|
+
const { logoutAsync } = useLogout();
|
|
14
|
+
const { keepSessionAliveAsync } = useKeepSessionAlive();
|
|
15
|
+
const sessionCheckInterval = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!client || disabled) {
|
|
18
|
+
clearSessionMonitoring();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if ((account == null ? void 0 : account.isConnected) && !account.isGuestMode && client.externalWalletConnectionType !== "CONNECTION_ONLY") {
|
|
22
|
+
setupSessionMonitoring();
|
|
23
|
+
} else {
|
|
24
|
+
clearSessionMonitoring();
|
|
25
|
+
}
|
|
26
|
+
return () => clearSessionMonitoring();
|
|
27
|
+
}, [client, account, disabled]);
|
|
28
|
+
const getSessionExpiry = () => __async(void 0, null, function* () {
|
|
29
|
+
try {
|
|
30
|
+
const sessionCookie = yield client == null ? void 0 : client.retrieveSessionCookie();
|
|
31
|
+
if (!sessionCookie) return null;
|
|
32
|
+
const expiresMatch = sessionCookie.match(/Expires=([^;]+)/);
|
|
33
|
+
return expiresMatch ? new Date(expiresMatch[1]) : null;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const setupSessionMonitoring = () => {
|
|
39
|
+
clearSessionMonitoring();
|
|
40
|
+
sessionCheckInterval.current = setInterval(() => __async(void 0, null, function* () {
|
|
41
|
+
const expiry = yield getSessionExpiry();
|
|
42
|
+
if (!expiry) {
|
|
43
|
+
yield logoutAsync({});
|
|
44
|
+
clearSessionMonitoring();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const timeUntilExpiry = expiry.getTime() - Date.now();
|
|
48
|
+
if (timeUntilExpiry <= 0) {
|
|
49
|
+
yield logoutAsync({});
|
|
50
|
+
clearSessionMonitoring();
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (timeUntilExpiry <= SESSION_REFRESH_THRESHOLD) {
|
|
54
|
+
try {
|
|
55
|
+
yield keepSessionAliveAsync();
|
|
56
|
+
setupSessionMonitoring();
|
|
57
|
+
} catch (err) {
|
|
58
|
+
console.error("Failed to keep session alive:", err);
|
|
59
|
+
yield logoutAsync({});
|
|
60
|
+
clearSessionMonitoring();
|
|
61
|
+
}
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
}), SESSION_CHECK_INTERVAL);
|
|
65
|
+
};
|
|
66
|
+
const clearSessionMonitoring = () => {
|
|
67
|
+
if (sessionCheckInterval.current) {
|
|
68
|
+
clearInterval(sessionCheckInterval.current);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
export {
|
|
73
|
+
useAutoSessionKeepAlive
|
|
74
|
+
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Callbacks } from '../../types/provider.js';
|
|
2
|
-
export declare const useEventListeners: ({ onLogin, onLogout, onAccountSetup, onAccountCreation, onSignMessage, onSignTransaction, onWalletCreated, onPregenWalletClaimed, onExternalWalletChange, onWalletsChange, }?: Callbacks) => void;
|
|
2
|
+
export declare const useEventListeners: ({ onLogin, onLogout, onAccountSetup, onAccountCreation, onSignMessage, onSignTransaction, onWalletCreated, onPregenWalletClaimed, onExternalWalletChange, onWalletsChange, onGuestWalletsCreated, }?: Callbacks) => void;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { useQueryClient } from "@tanstack/react-query";
|
|
4
|
+
import { useCallback, useEffect } from "react";
|
|
5
|
+
import { useWalletState } from "../index.js";
|
|
6
|
+
import {
|
|
7
|
+
ParaEvent
|
|
8
|
+
} from "@getpara/web-sdk";
|
|
9
|
+
import { ACCOUNT_BASE_KEY } from "../queries/useAccount.js";
|
|
10
|
+
import { useStore } from "../../stores/useStore.js";
|
|
11
|
+
import { WALLET_BASE_KEY } from "../queries/useWallet.js";
|
|
12
|
+
const useEventListeners = ({
|
|
13
|
+
onLogin,
|
|
14
|
+
onLogout,
|
|
15
|
+
onAccountSetup,
|
|
16
|
+
onAccountCreation,
|
|
17
|
+
onSignMessage,
|
|
18
|
+
onSignTransaction,
|
|
19
|
+
onWalletCreated,
|
|
20
|
+
onPregenWalletClaimed,
|
|
21
|
+
onExternalWalletChange,
|
|
22
|
+
onWalletsChange,
|
|
23
|
+
onGuestWalletsCreated
|
|
24
|
+
} = {}) => {
|
|
25
|
+
const queryClient = useQueryClient();
|
|
26
|
+
const clearSelectedWallet = useStore((state) => state.clearSelectedWallet);
|
|
27
|
+
const { updateSelectedWallet } = useWalletState();
|
|
28
|
+
const loginOrSetupListener = useCallback(() => {
|
|
29
|
+
queryClient.refetchQueries({ queryKey: [ACCOUNT_BASE_KEY] });
|
|
30
|
+
queryClient.refetchQueries({ queryKey: [WALLET_BASE_KEY] });
|
|
31
|
+
}, [queryClient]);
|
|
32
|
+
const loginListener = useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
loginOrSetupListener();
|
|
35
|
+
onLogin == null ? void 0 : onLogin(event);
|
|
36
|
+
},
|
|
37
|
+
[loginOrSetupListener, onLogin]
|
|
38
|
+
);
|
|
39
|
+
const accountSetupListener = useCallback(
|
|
40
|
+
(event) => {
|
|
41
|
+
loginOrSetupListener();
|
|
42
|
+
onAccountSetup == null ? void 0 : onAccountSetup(event);
|
|
43
|
+
},
|
|
44
|
+
[loginOrSetupListener, onAccountSetup]
|
|
45
|
+
);
|
|
46
|
+
const accountCreationListener = useCallback(
|
|
47
|
+
(event) => {
|
|
48
|
+
onAccountCreation == null ? void 0 : onAccountCreation(event);
|
|
49
|
+
},
|
|
50
|
+
[onAccountCreation]
|
|
51
|
+
);
|
|
52
|
+
const logoutListener = useCallback(
|
|
53
|
+
(event) => {
|
|
54
|
+
queryClient.refetchQueries({ queryKey: [ACCOUNT_BASE_KEY] });
|
|
55
|
+
clearSelectedWallet();
|
|
56
|
+
onLogout == null ? void 0 : onLogout(event);
|
|
57
|
+
},
|
|
58
|
+
[queryClient, clearSelectedWallet, onLogout]
|
|
59
|
+
);
|
|
60
|
+
const signMessageListener = useCallback(
|
|
61
|
+
(event) => {
|
|
62
|
+
onSignMessage == null ? void 0 : onSignMessage(event);
|
|
63
|
+
},
|
|
64
|
+
[onSignMessage]
|
|
65
|
+
);
|
|
66
|
+
const signTransactionListener = useCallback(
|
|
67
|
+
(event) => {
|
|
68
|
+
onSignTransaction == null ? void 0 : onSignTransaction(event);
|
|
69
|
+
},
|
|
70
|
+
[onSignTransaction]
|
|
71
|
+
);
|
|
72
|
+
const walletChangeListener = useCallback(
|
|
73
|
+
(event) => {
|
|
74
|
+
queryClient.refetchQueries({ queryKey: [ACCOUNT_BASE_KEY] });
|
|
75
|
+
updateSelectedWallet();
|
|
76
|
+
onWalletsChange == null ? void 0 : onWalletsChange(event);
|
|
77
|
+
},
|
|
78
|
+
[queryClient, updateSelectedWallet, onWalletsChange]
|
|
79
|
+
);
|
|
80
|
+
const externalWalletChangeListener = useCallback(
|
|
81
|
+
(event) => {
|
|
82
|
+
queryClient.refetchQueries({ queryKey: [ACCOUNT_BASE_KEY] });
|
|
83
|
+
updateSelectedWallet();
|
|
84
|
+
onExternalWalletChange == null ? void 0 : onExternalWalletChange(event);
|
|
85
|
+
},
|
|
86
|
+
[queryClient, updateSelectedWallet, onExternalWalletChange]
|
|
87
|
+
);
|
|
88
|
+
const walletCreatedListener = useCallback(
|
|
89
|
+
(event) => {
|
|
90
|
+
onWalletCreated == null ? void 0 : onWalletCreated(event);
|
|
91
|
+
},
|
|
92
|
+
[onWalletCreated]
|
|
93
|
+
);
|
|
94
|
+
const pregenWalletClaimedListener = useCallback(
|
|
95
|
+
(event) => {
|
|
96
|
+
onPregenWalletClaimed == null ? void 0 : onPregenWalletClaimed(event);
|
|
97
|
+
},
|
|
98
|
+
[onPregenWalletClaimed]
|
|
99
|
+
);
|
|
100
|
+
const guestWalletsCreatedListener = useCallback(
|
|
101
|
+
(event) => {
|
|
102
|
+
onGuestWalletsCreated == null ? void 0 : onGuestWalletsCreated(event);
|
|
103
|
+
},
|
|
104
|
+
[onGuestWalletsCreated]
|
|
105
|
+
);
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
window.addEventListener(ParaEvent.LOGIN_EVENT, loginListener);
|
|
108
|
+
window.addEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
|
|
109
|
+
window.addEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
|
|
110
|
+
window.addEventListener(ParaEvent.LOGOUT_EVENT, logoutListener);
|
|
111
|
+
window.addEventListener(ParaEvent.SIGN_MESSAGE_EVENT, signMessageListener);
|
|
112
|
+
window.addEventListener(ParaEvent.SIGN_TRANSACTION_EVENT, signTransactionListener);
|
|
113
|
+
window.addEventListener(ParaEvent.WALLETS_CHANGE_EVENT, walletChangeListener);
|
|
114
|
+
window.addEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, externalWalletChangeListener);
|
|
115
|
+
window.addEventListener(ParaEvent.WALLET_CREATED, walletCreatedListener);
|
|
116
|
+
window.addEventListener(ParaEvent.PREGEN_WALLET_CLAIMED, pregenWalletClaimedListener);
|
|
117
|
+
window.addEventListener(ParaEvent.GUEST_WALLETS_CREATED, guestWalletsCreatedListener);
|
|
118
|
+
return () => {
|
|
119
|
+
window.removeEventListener(ParaEvent.LOGIN_EVENT, loginListener);
|
|
120
|
+
window.removeEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
|
|
121
|
+
window.removeEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
|
|
122
|
+
window.removeEventListener(ParaEvent.LOGOUT_EVENT, logoutListener);
|
|
123
|
+
window.removeEventListener(ParaEvent.SIGN_MESSAGE_EVENT, signMessageListener);
|
|
124
|
+
window.removeEventListener(ParaEvent.SIGN_TRANSACTION_EVENT, signTransactionListener);
|
|
125
|
+
window.removeEventListener(ParaEvent.WALLETS_CHANGE_EVENT, walletChangeListener);
|
|
126
|
+
window.removeEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, externalWalletChangeListener);
|
|
127
|
+
window.removeEventListener(ParaEvent.WALLET_CREATED, walletCreatedListener);
|
|
128
|
+
window.removeEventListener(ParaEvent.PREGEN_WALLET_CLAIMED, pregenWalletClaimedListener);
|
|
129
|
+
window.removeEventListener(ParaEvent.GUEST_WALLETS_CREATED, guestWalletsCreatedListener);
|
|
130
|
+
};
|
|
131
|
+
}, [
|
|
132
|
+
loginListener,
|
|
133
|
+
accountSetupListener,
|
|
134
|
+
accountCreationListener,
|
|
135
|
+
logoutListener,
|
|
136
|
+
signMessageListener,
|
|
137
|
+
signTransactionListener,
|
|
138
|
+
walletChangeListener,
|
|
139
|
+
externalWalletChangeListener,
|
|
140
|
+
walletCreatedListener,
|
|
141
|
+
pregenWalletClaimedListener,
|
|
142
|
+
guestWalletsCreatedListener
|
|
143
|
+
]);
|
|
144
|
+
};
|
|
145
|
+
export {
|
|
146
|
+
useEventListeners
|
|
147
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { useStore } from "../../stores/useStore.js";
|
|
4
|
+
const useModal = () => {
|
|
5
|
+
const isOpen = useStore((state) => state.isOpen);
|
|
6
|
+
const setIsOpen = useStore((state) => state.setIsOpen);
|
|
7
|
+
const openModal = () => {
|
|
8
|
+
setIsOpen(true);
|
|
9
|
+
};
|
|
10
|
+
const closeModal = () => {
|
|
11
|
+
setIsOpen(false);
|
|
12
|
+
};
|
|
13
|
+
return { isOpen, openModal, closeModal };
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
useModal
|
|
17
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TWalletType } from '@getpara/web-sdk';
|
|
2
2
|
/**
|
|
3
3
|
* Hook for controlling selected wallet
|
|
4
4
|
*/
|
|
5
5
|
export declare const useWalletState: () => {
|
|
6
6
|
selectedWallet: {
|
|
7
7
|
id: string | undefined;
|
|
8
|
-
type:
|
|
8
|
+
type: "EVM" | "SOLANA" | "COSMOS" | undefined;
|
|
9
9
|
};
|
|
10
10
|
setSelectedWallet: ({ id, type }: {
|
|
11
11
|
id?: string;
|
|
12
|
-
type?:
|
|
12
|
+
type?: TWalletType;
|
|
13
13
|
}) => void;
|
|
14
14
|
updateSelectedWallet: () => void;
|
|
15
15
|
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import "../../../chunk-MMUBH76A.js";
|
|
3
|
+
import { useStore } from "../../stores/useStore.js";
|
|
4
|
+
import { useClient } from "./useClient.js";
|
|
5
|
+
import { useCallback } from "react";
|
|
6
|
+
const useWalletState = () => {
|
|
7
|
+
const client = useClient();
|
|
8
|
+
const selectedWalletId = useStore((state) => state.selectedWalletId);
|
|
9
|
+
const selectedWalletType = useStore((state) => state.selectedWalletType);
|
|
10
|
+
const setStoredSelectedWallet = useStore((state) => state.setSelectedWallet);
|
|
11
|
+
const clearSelectedWallet = useStore((state) => state.clearSelectedWallet);
|
|
12
|
+
const setSelectedWallet = useCallback(
|
|
13
|
+
({ id, type }) => {
|
|
14
|
+
try {
|
|
15
|
+
const validId = client == null ? void 0 : client.findWalletId(id, type ? { type: [type] } : void 0);
|
|
16
|
+
if (validId !== id) {
|
|
17
|
+
clearSelectedWallet();
|
|
18
|
+
} else {
|
|
19
|
+
setStoredSelectedWallet(id, type);
|
|
20
|
+
}
|
|
21
|
+
} catch (e) {
|
|
22
|
+
clearSelectedWallet();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
[client, clearSelectedWallet, setStoredSelectedWallet]
|
|
26
|
+
);
|
|
27
|
+
const updateSelectedWallet = useCallback(() => {
|
|
28
|
+
if (!client) {
|
|
29
|
+
clearSelectedWallet();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!selectedWalletId || !client.findWallet(selectedWalletId)) {
|
|
33
|
+
const defaultWallet = client.findWallet(void 0, void 0, { forbidPregen: true });
|
|
34
|
+
setSelectedWallet({ id: defaultWallet == null ? void 0 : defaultWallet.id, type: defaultWallet == null ? void 0 : defaultWallet.type });
|
|
35
|
+
}
|
|
36
|
+
}, [clearSelectedWallet, setSelectedWallet, client, selectedWalletId]);
|
|
37
|
+
return {
|
|
38
|
+
selectedWallet: {
|
|
39
|
+
id: selectedWalletId,
|
|
40
|
+
type: selectedWalletType
|
|
41
|
+
},
|
|
42
|
+
setSelectedWallet,
|
|
43
|
+
updateSelectedWallet
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
useWalletState
|
|
48
|
+
};
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { BiometricHints } from '@getpara/react-common';
|
|
2
2
|
import { PropsWithChildren } from 'react';
|
|
3
3
|
import { AuthMethod, CoreMethodParams, AuthState, AuthStateSignup, AuthStateLogin } from '@getpara/web-sdk';
|
|
4
|
-
import { ParaModalProps } from '../../modal
|
|
5
|
-
import { TelegramAuthResponse, VerifiedAuth
|
|
4
|
+
import { ParaModalProps } from '../../modal/types/modalProps.js';
|
|
5
|
+
import { TelegramAuthResponse, VerifiedAuth } from '@getpara/user-management-client';
|
|
6
6
|
type Value = {
|
|
7
|
-
signUpOrLogIn:
|
|
8
|
-
|
|
7
|
+
signUpOrLogIn: (_: VerifiedAuth) => void;
|
|
8
|
+
isSignUpOrLogInPending: boolean;
|
|
9
|
+
verifyNewAccount: (_: string) => void;
|
|
10
|
+
isVerifyNewAccountPending: boolean;
|
|
11
|
+
verifyNewAccountError: Error | null;
|
|
9
12
|
verifyOAuth: (_: CoreMethodParams<'verifyOAuth'>['method']) => void;
|
|
10
13
|
verifyFarcaster: () => void;
|
|
11
14
|
verifyTelegram: (_: TelegramAuthResponse) => void;
|
|
12
|
-
verifyExternalWallet: (_: VerifyExternalWalletParams) => void;
|
|
13
15
|
onNewAuthState: (_: AuthState) => void;
|
|
14
16
|
presentSignupUi: (_: AuthMethod, __: AuthStateSignup) => void;
|
|
15
17
|
presentLoginUi: (_: AuthMethod, __: AuthStateLogin) => void;
|
|
16
|
-
|
|
18
|
+
isSetup2faPending: boolean;
|
|
19
|
+
createGuestWallets: () => void;
|
|
20
|
+
isCreateGuestWalletsPending: boolean;
|
|
17
21
|
logout: () => void;
|
|
18
22
|
biometricHints?: BiometricHints;
|
|
19
23
|
};
|