@getpara/react-sdk 0.1.0 → 0.2.1
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/modal/ParaModal.js +47 -16
- package/dist/modal/components/Account/Account.js +3 -2
- package/dist/modal/components/AddFunds/AddFunds.js +3 -2
- package/dist/modal/components/AddFunds/AddFundsAwaiting.js +3 -2
- package/dist/modal/components/AuthInput/AuthInput.js +12 -5
- package/dist/modal/components/BiometricLoginStep/BiometricLoginStep.js +7 -3
- package/dist/modal/components/Controls/Selects.js +6 -4
- package/dist/modal/components/ExternalWalletsWrapper/ExternalWalletsWrapper.js +3 -2
- package/dist/modal/components/Hero/Hero.js +3 -2
- package/dist/modal/components/LoginDoneStep/LoginDoneStep.js +3 -2
- package/dist/modal/components/ModalContent/ModalContent.js +6 -2
- package/dist/modal/components/OAuth/FarcasterOAuthStep.js +3 -2
- package/dist/modal/components/OAuth/OAuth.js +4 -3
- package/dist/modal/components/OAuth/TelegramOAuthStep.js +4 -3
- package/dist/modal/components/Setup2FAStep/Setup2FAStep.js +4 -3
- package/dist/modal/components/VerificationCodeStep/VerificationCodeStep.js +10 -5
- package/dist/modal/components/WalletCard/WalletCard.js +7 -5
- package/dist/modal/components/WalletCreationDoneStep/WalletCreationDoneStep.js +3 -2
- package/dist/modal/constants/constants.d.ts +1 -1
- package/dist/modal/constants/constants.js +1 -1
- package/dist/modal/hooks/useActiveWallet.js +7 -5
- package/dist/modal/providers/ExternalWalletContext.js +3 -2
- package/dist/modal/stores/index.d.ts +0 -1
- package/dist/modal/stores/index.js +0 -1
- package/dist/modal/stores/modal/actions.js +0 -1
- package/dist/modal/stores/modal/useModalStore.d.ts +0 -1
- package/dist/modal/types/modalProps.d.ts +3 -3
- package/dist/provider/ParaProvider.d.ts +2 -0
- package/dist/provider/ParaProvider.js +16 -0
- package/dist/provider/actions/checkIfUserExists.d.ts +9 -0
- package/dist/provider/actions/checkIfUserExists.js +26 -0
- package/dist/provider/actions/createUser.d.ts +12 -0
- package/dist/provider/actions/createUser.js +30 -0
- package/dist/provider/actions/getAccount.d.ts +7 -0
- package/dist/provider/actions/getAccount.js +24 -0
- package/dist/provider/actions/getWallet.d.ts +5 -0
- package/dist/provider/actions/getWallet.js +16 -0
- package/dist/provider/actions/initiateLogin.d.ts +4 -0
- package/dist/provider/actions/initiateLogin.js +23 -0
- package/dist/provider/actions/keepSessionAlive.d.ts +2 -0
- package/dist/provider/actions/keepSessionAlive.js +23 -0
- package/dist/provider/actions/logout.d.ts +2 -0
- package/dist/provider/actions/logout.js +20 -0
- package/dist/provider/actions/signMessage.d.ts +8 -0
- package/dist/provider/actions/signMessage.js +23 -0
- package/dist/provider/actions/signTransaction.d.ts +8 -0
- package/dist/provider/actions/signTransaction.js +23 -0
- package/dist/provider/actions/waitForAccountCreation.d.ts +2 -0
- package/dist/provider/actions/waitForAccountCreation.js +24 -0
- package/dist/provider/actions/waitForLoginAndSetup.d.ts +6 -0
- package/dist/provider/actions/waitForLoginAndSetup.js +27 -0
- package/dist/provider/actions/waitForPasskeyAndCreateWallet.d.ts +2 -0
- package/dist/provider/actions/waitForPasskeyAndCreateWallet.js +24 -0
- package/dist/provider/hooks/index.d.ts +3 -0
- package/dist/provider/hooks/index.js +3 -0
- package/dist/provider/hooks/mutations/index.d.ts +10 -0
- package/dist/provider/hooks/mutations/index.js +10 -0
- package/dist/provider/hooks/mutations/useCheckIfUserExists.d.ts +13 -0
- package/dist/provider/hooks/mutations/useCheckIfUserExists.js +23 -0
- package/dist/provider/hooks/mutations/useCreateUser.d.ts +13 -0
- package/dist/provider/hooks/mutations/useCreateUser.js +23 -0
- package/dist/provider/hooks/mutations/useInitiateLogin.d.ts +14 -0
- package/dist/provider/hooks/mutations/useInitiateLogin.js +23 -0
- package/dist/provider/hooks/mutations/useKeepSessionAlive.d.ts +12 -0
- package/dist/provider/hooks/mutations/useKeepSessionAlive.js +23 -0
- package/dist/provider/hooks/mutations/useLogout.d.ts +12 -0
- package/dist/provider/hooks/mutations/useLogout.js +33 -0
- package/dist/provider/hooks/mutations/useSignMessage.d.ts +15 -0
- package/dist/provider/hooks/mutations/useSignMessage.js +33 -0
- package/dist/provider/hooks/mutations/useSignTransaction.d.ts +14 -0
- package/dist/provider/hooks/mutations/useSignTransaction.js +33 -0
- package/dist/provider/hooks/mutations/useWaitForAccountCreation.d.ts +12 -0
- package/dist/provider/hooks/mutations/useWaitForAccountCreation.js +30 -0
- package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.d.ts +14 -0
- package/dist/provider/hooks/mutations/useWaitForLoginAndSetup.js +30 -0
- package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.d.ts +13 -0
- package/dist/provider/hooks/mutations/useWaitForPasskeyAndCreateWallet.js +30 -0
- package/dist/provider/hooks/queries/index.d.ts +2 -0
- package/dist/provider/hooks/queries/index.js +2 -0
- package/dist/provider/hooks/queries/useAccount.d.ts +10 -0
- package/dist/provider/hooks/queries/useAccount.js +23 -0
- package/dist/provider/hooks/queries/useWallet.d.ts +5 -0
- package/dist/provider/hooks/queries/useWallet.js +24 -0
- package/dist/provider/hooks/utils/index.d.ts +3 -0
- package/dist/provider/hooks/utils/index.js +3 -0
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.d.ts +3 -0
- package/dist/provider/hooks/utils/useAutoSessionKeepAlive.js +79 -0
- package/dist/provider/hooks/utils/useClient.d.ts +4 -0
- package/dist/provider/hooks/utils/useClient.js +8 -0
- package/dist/provider/hooks/utils/useEventListeners.d.ts +2 -0
- package/dist/provider/hooks/utils/useEventListeners.js +87 -0
- package/dist/provider/hooks/utils/useInternalClient.d.ts +5 -0
- package/dist/provider/hooks/utils/useInternalClient.js +9 -0
- package/dist/provider/hooks/utils/useModal.d.ts +8 -0
- package/dist/provider/hooks/utils/useModal.js +15 -0
- package/dist/provider/hooks/utils/useWalletState.d.ts +14 -0
- package/dist/provider/hooks/utils/useWalletState.js +33 -0
- package/dist/provider/index.d.ts +3 -0
- package/dist/provider/index.js +3 -0
- package/dist/provider/stores/getters.d.ts +4 -0
- package/dist/provider/stores/getters.js +5 -0
- package/dist/provider/stores/slices/client.d.ts +3 -0
- package/dist/provider/stores/slices/client.js +4 -0
- package/dist/provider/stores/slices/index.d.ts +3 -0
- package/dist/provider/stores/slices/index.js +3 -0
- package/dist/provider/stores/slices/modal.d.ts +3 -0
- package/dist/provider/stores/slices/modal.js +4 -0
- package/dist/provider/stores/slices/wallet.d.ts +3 -0
- package/dist/provider/stores/slices/wallet.js +6 -0
- package/dist/provider/stores/types.d.ts +16 -0
- package/dist/provider/stores/types.js +1 -0
- package/dist/provider/stores/useStore.d.ts +12 -0
- package/dist/provider/stores/useStore.js +12 -0
- package/dist/provider/types/provider.d.ts +26 -0
- package/dist/provider/types/provider.js +1 -0
- package/dist/provider/types/query.d.ts +3 -0
- package/dist/provider/types/query.js +1 -0
- package/dist/provider/types/utils.d.ts +6 -0
- package/dist/provider/types/utils.js +1 -0
- package/dist/provider/utils/renameMutations.d.ts +2 -0
- package/dist/provider/utils/renameMutations.js +19 -0
- package/package.json +6 -5
|
@@ -0,0 +1,79 @@
|
|
|
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 { useEffect, useRef } from 'react';
|
|
11
|
+
import { useAccount, useClient, useKeepSessionAlive, useLogout } from '../index.js';
|
|
12
|
+
const SESSION_CHECK_INTERVAL = 60000;
|
|
13
|
+
const SESSION_REFRESH_THRESHOLD = 300000;
|
|
14
|
+
export const useAutoSessionKeepAlive = ({ disabled }) => {
|
|
15
|
+
const client = useClient();
|
|
16
|
+
const { data: account } = useAccount();
|
|
17
|
+
const { logoutAsync } = useLogout();
|
|
18
|
+
const { keepSessionAliveAsync } = useKeepSessionAlive();
|
|
19
|
+
const sessionCheckInterval = useRef(null);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!client || disabled) {
|
|
22
|
+
clearSessionMonitoring();
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (account === null || account === void 0 ? void 0 : account.isConnected) {
|
|
26
|
+
setupSessionMonitoring();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
clearSessionMonitoring();
|
|
30
|
+
}
|
|
31
|
+
return () => clearSessionMonitoring();
|
|
32
|
+
}, [client, account, disabled]);
|
|
33
|
+
const getSessionExpiry = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
+
try {
|
|
35
|
+
const sessionCookie = yield client.retrieveSessionCookie();
|
|
36
|
+
if (!sessionCookie)
|
|
37
|
+
return null;
|
|
38
|
+
const expiresMatch = sessionCookie.match(/Expires=([^;]+)/);
|
|
39
|
+
return expiresMatch ? new Date(expiresMatch[1]) : null;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const setupSessionMonitoring = () => {
|
|
46
|
+
clearSessionMonitoring();
|
|
47
|
+
sessionCheckInterval.current = setInterval(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
+
const expiry = yield getSessionExpiry();
|
|
49
|
+
if (!expiry) {
|
|
50
|
+
yield logoutAsync();
|
|
51
|
+
clearSessionMonitoring();
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const timeUntilExpiry = expiry.getTime() - Date.now();
|
|
55
|
+
if (timeUntilExpiry <= 0) {
|
|
56
|
+
yield logoutAsync();
|
|
57
|
+
clearSessionMonitoring();
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (timeUntilExpiry <= SESSION_REFRESH_THRESHOLD) {
|
|
61
|
+
try {
|
|
62
|
+
yield keepSessionAliveAsync();
|
|
63
|
+
setupSessionMonitoring();
|
|
64
|
+
}
|
|
65
|
+
catch (err) {
|
|
66
|
+
console.error('Failed to keep session alive:', err);
|
|
67
|
+
yield logoutAsync();
|
|
68
|
+
clearSessionMonitoring();
|
|
69
|
+
}
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
}), SESSION_CHECK_INTERVAL);
|
|
73
|
+
};
|
|
74
|
+
const clearSessionMonitoring = () => {
|
|
75
|
+
if (sessionCheckInterval.current) {
|
|
76
|
+
clearInterval(sessionCheckInterval.current);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { Callbacks } from '../../types/provider.js';
|
|
2
|
+
export declare const useEventListeners: ({ onLogin, onLogout, onAccountSetup, onAccountCreation, onSignMessage, onSignTransaction, onWalletCreated, onPregenWalletClaimed, onExternalWalletChange, onWalletsChange, }: Callbacks) => void;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useClient, useWalletState } from '../index.js';
|
|
4
|
+
import { ParaEvent, } from '@getpara/web-sdk';
|
|
5
|
+
import { ACCOUNT_BASE_KEY } from '../queries/useAccount.js';
|
|
6
|
+
import { useStore } from '../../stores/useStore.js';
|
|
7
|
+
import { WALLET_BASE_KEY } from '../../hooks/queries/useWallet.js';
|
|
8
|
+
export const useEventListeners = ({ onLogin, onLogout, onAccountSetup, onAccountCreation, onSignMessage, onSignTransaction, onWalletCreated, onPregenWalletClaimed, onExternalWalletChange, onWalletsChange, }) => {
|
|
9
|
+
const queryClient = useQueryClient();
|
|
10
|
+
const client = useClient();
|
|
11
|
+
const clearSelectedWallet = useStore(state => state.clearSelectedWallet);
|
|
12
|
+
const { selectedWallet, setSelectedWallet } = useWalletState();
|
|
13
|
+
const loginListener = (event) => {
|
|
14
|
+
loginOrSetupListener();
|
|
15
|
+
onLogin === null || onLogin === void 0 ? void 0 : onLogin(event);
|
|
16
|
+
};
|
|
17
|
+
const accountSetupListener = (event) => {
|
|
18
|
+
loginOrSetupListener();
|
|
19
|
+
onAccountSetup === null || onAccountSetup === void 0 ? void 0 : onAccountSetup(event);
|
|
20
|
+
};
|
|
21
|
+
const loginOrSetupListener = () => {
|
|
22
|
+
queryClient.invalidateQueries({ queryKey: [ACCOUNT_BASE_KEY], exact: false });
|
|
23
|
+
queryClient.invalidateQueries({ queryKey: [WALLET_BASE_KEY], exact: false });
|
|
24
|
+
};
|
|
25
|
+
const accountCreationListener = (event) => {
|
|
26
|
+
onAccountCreation === null || onAccountCreation === void 0 ? void 0 : onAccountCreation(event);
|
|
27
|
+
};
|
|
28
|
+
const logoutListener = (event) => {
|
|
29
|
+
queryClient.invalidateQueries({ queryKey: [ACCOUNT_BASE_KEY], exact: false });
|
|
30
|
+
clearSelectedWallet();
|
|
31
|
+
onLogout === null || onLogout === void 0 ? void 0 : onLogout(event);
|
|
32
|
+
};
|
|
33
|
+
const signMessageListener = (event) => {
|
|
34
|
+
onSignMessage === null || onSignMessage === void 0 ? void 0 : onSignMessage(event);
|
|
35
|
+
};
|
|
36
|
+
const signTransactionListener = (event) => {
|
|
37
|
+
onSignTransaction === null || onSignTransaction === void 0 ? void 0 : onSignTransaction(event);
|
|
38
|
+
};
|
|
39
|
+
const walletChangeListener = (event) => {
|
|
40
|
+
updateSelectedWallet();
|
|
41
|
+
onWalletsChange === null || onWalletsChange === void 0 ? void 0 : onWalletsChange(event);
|
|
42
|
+
};
|
|
43
|
+
const externalWalletChangeListener = (event) => {
|
|
44
|
+
updateSelectedWallet();
|
|
45
|
+
onExternalWalletChange === null || onExternalWalletChange === void 0 ? void 0 : onExternalWalletChange(event);
|
|
46
|
+
};
|
|
47
|
+
const walletCreatedListener = (event) => {
|
|
48
|
+
onWalletCreated === null || onWalletCreated === void 0 ? void 0 : onWalletCreated(event);
|
|
49
|
+
};
|
|
50
|
+
const pregenWalletClaimedListener = (event) => {
|
|
51
|
+
onPregenWalletClaimed === null || onPregenWalletClaimed === void 0 ? void 0 : onPregenWalletClaimed(event);
|
|
52
|
+
};
|
|
53
|
+
const updateSelectedWallet = () => {
|
|
54
|
+
if (!client) {
|
|
55
|
+
clearSelectedWallet();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
if (!(selectedWallet === null || selectedWallet === void 0 ? void 0 : selectedWallet.id) || !client.findWallet(selectedWallet === null || selectedWallet === void 0 ? void 0 : selectedWallet.id)) {
|
|
59
|
+
const defaultWallet = client.findWallet(undefined, undefined, { forbidPregen: true });
|
|
60
|
+
setSelectedWallet({ id: defaultWallet === null || defaultWallet === void 0 ? void 0 : defaultWallet.id, type: defaultWallet === null || defaultWallet === void 0 ? void 0 : defaultWallet.type });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
useEffect(() => {
|
|
64
|
+
window.addEventListener(ParaEvent.LOGIN_EVENT, loginListener);
|
|
65
|
+
window.addEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
|
|
66
|
+
window.addEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
|
|
67
|
+
window.addEventListener(ParaEvent.LOGOUT_EVENT, logoutListener);
|
|
68
|
+
window.addEventListener(ParaEvent.SIGN_MESSAGE_EVENT, signMessageListener);
|
|
69
|
+
window.addEventListener(ParaEvent.SIGN_TRANSACTION_EVENT, signTransactionListener);
|
|
70
|
+
window.addEventListener(ParaEvent.WALLETS_CHANGE_EVENT, walletChangeListener);
|
|
71
|
+
window.addEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, externalWalletChangeListener);
|
|
72
|
+
window.addEventListener(ParaEvent.WALLET_CREATED, walletCreatedListener);
|
|
73
|
+
window.addEventListener(ParaEvent.PREGEN_WALLET_CLAIMED, pregenWalletClaimedListener);
|
|
74
|
+
return () => {
|
|
75
|
+
window.removeEventListener(ParaEvent.LOGIN_EVENT, loginListener);
|
|
76
|
+
window.removeEventListener(ParaEvent.ACCOUNT_SETUP_EVENT, accountSetupListener);
|
|
77
|
+
window.removeEventListener(ParaEvent.ACCOUNT_CREATION_EVENT, accountCreationListener);
|
|
78
|
+
window.removeEventListener(ParaEvent.LOGOUT_EVENT, logoutListener);
|
|
79
|
+
window.removeEventListener(ParaEvent.SIGN_MESSAGE_EVENT, signMessageListener);
|
|
80
|
+
window.removeEventListener(ParaEvent.SIGN_TRANSACTION_EVENT, signTransactionListener);
|
|
81
|
+
window.removeEventListener(ParaEvent.WALLETS_CHANGE_EVENT, walletChangeListener);
|
|
82
|
+
window.removeEventListener(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, externalWalletChangeListener);
|
|
83
|
+
window.removeEventListener(ParaEvent.WALLET_CREATED, walletCreatedListener);
|
|
84
|
+
window.removeEventListener(ParaEvent.PREGEN_WALLET_CLAIMED, pregenWalletClaimedListener);
|
|
85
|
+
};
|
|
86
|
+
}, [client]);
|
|
87
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// DO NOT EXPORT THIS FROM THE INDEX!
|
|
2
|
+
import { useStore } from '../../stores/useStore.js';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for retrieving the Para internal client
|
|
5
|
+
*/
|
|
6
|
+
export const useInternalClient = () => {
|
|
7
|
+
const client = useStore(state => state.client);
|
|
8
|
+
return client;
|
|
9
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useStore } from '../../stores/useStore.js';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for controlling the Para modal
|
|
4
|
+
*/
|
|
5
|
+
export const useModal = () => {
|
|
6
|
+
const isOpen = useStore(state => state.isOpen);
|
|
7
|
+
const setIsOpen = useStore(state => state.setIsOpen);
|
|
8
|
+
const openModal = () => {
|
|
9
|
+
setIsOpen(true);
|
|
10
|
+
};
|
|
11
|
+
const closeModal = () => {
|
|
12
|
+
setIsOpen(false);
|
|
13
|
+
};
|
|
14
|
+
return { isOpen, openModal, closeModal };
|
|
15
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { WalletType } from '@getpara/web-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Hook for controlling selected wallet
|
|
4
|
+
*/
|
|
5
|
+
export declare const useWalletState: () => {
|
|
6
|
+
selectedWallet: {
|
|
7
|
+
id: string;
|
|
8
|
+
type: WalletType;
|
|
9
|
+
};
|
|
10
|
+
setSelectedWallet: ({ id, type }: {
|
|
11
|
+
id?: string;
|
|
12
|
+
type?: WalletType;
|
|
13
|
+
}) => void;
|
|
14
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useStore } from '../../stores/useStore.js';
|
|
2
|
+
import { useClient } from './useClient.js';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for controlling selected wallet
|
|
5
|
+
*/
|
|
6
|
+
export 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 = ({ id, type }) => {
|
|
13
|
+
try {
|
|
14
|
+
const validId = client.findWalletId(id, { type: [type] });
|
|
15
|
+
if (validId !== id) {
|
|
16
|
+
clearSelectedWallet();
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
setStoredSelectedWallet(id, type);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
clearSelectedWallet();
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
selectedWallet: {
|
|
28
|
+
id: selectedWalletId,
|
|
29
|
+
type: selectedWalletType,
|
|
30
|
+
},
|
|
31
|
+
setSelectedWallet,
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const getClient: () => import("@getpara/web-sdk").ParaWeb;
|
|
2
|
+
export declare const getIsOpen: () => boolean;
|
|
3
|
+
export declare const getSelectedWalletId: () => string;
|
|
4
|
+
export declare const getSelectedWalletType: () => import("@getpara/user-management-client").WalletType;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { useStore } from './useStore.js';
|
|
2
|
+
export const getClient = () => useStore().client;
|
|
3
|
+
export const getIsOpen = () => useStore().isOpen;
|
|
4
|
+
export const getSelectedWalletId = () => useStore().selectedWalletId;
|
|
5
|
+
export const getSelectedWalletType = () => useStore().selectedWalletType;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export const createWalletSlice = set => ({
|
|
2
|
+
selectedWalletId: undefined,
|
|
3
|
+
selectedWalletType: undefined,
|
|
4
|
+
setSelectedWallet: (selectedWalletId, selectedWalletType) => set({ selectedWalletId, selectedWalletType }),
|
|
5
|
+
clearSelectedWallet: () => set({ selectedWalletId: undefined, selectedWalletType: undefined }),
|
|
6
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import ParaWeb, { WalletType } from '@getpara/web-sdk';
|
|
2
|
+
export interface ClientSlice {
|
|
3
|
+
client?: ParaWeb;
|
|
4
|
+
setClient: (_: ParaWeb) => void;
|
|
5
|
+
}
|
|
6
|
+
export interface ModalSlice {
|
|
7
|
+
isOpen: boolean;
|
|
8
|
+
setIsOpen: (_: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export interface WalletSlice {
|
|
11
|
+
selectedWalletId?: string;
|
|
12
|
+
selectedWalletType?: WalletType;
|
|
13
|
+
setSelectedWallet: (_?: string, __?: WalletType) => void;
|
|
14
|
+
clearSelectedWallet: () => void;
|
|
15
|
+
}
|
|
16
|
+
export type Store = ClientSlice & ModalSlice & WalletSlice;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Store } from './types.js';
|
|
2
|
+
export declare const useStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<Store>, "persist"> & {
|
|
3
|
+
persist: {
|
|
4
|
+
setOptions: (options: Partial<import("zustand/middleware").PersistOptions<Store, Pick<Store, "selectedWalletId" | "selectedWalletType">>>) => void;
|
|
5
|
+
clearStorage: () => void;
|
|
6
|
+
rehydrate: () => Promise<void> | void;
|
|
7
|
+
hasHydrated: () => boolean;
|
|
8
|
+
onHydrate: (fn: (state: Store) => void) => () => void;
|
|
9
|
+
onFinishHydration: (fn: (state: Store) => void) => () => void;
|
|
10
|
+
getOptions: () => Partial<import("zustand/middleware").PersistOptions<Store, Pick<Store, "selectedWalletId" | "selectedWalletType">>>;
|
|
11
|
+
};
|
|
12
|
+
}>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { create } from 'zustand';
|
|
2
|
+
import { createClientSlice, createModalSlice, createWalletSlice } from './slices/index.js';
|
|
3
|
+
import { createJSONStorage, persist } from 'zustand/middleware';
|
|
4
|
+
export const useStore = create()(persist((...a) => (Object.assign(Object.assign(Object.assign({}, createClientSlice(...a)), createModalSlice(...a)), createWalletSlice(...a))), {
|
|
5
|
+
version: 1,
|
|
6
|
+
name: '@PARA/web-state',
|
|
7
|
+
storage: createJSONStorage(() => sessionStorage),
|
|
8
|
+
partialize: state => ({
|
|
9
|
+
selectedWalletId: state.selectedWalletId,
|
|
10
|
+
selectedWalletType: state.selectedWalletType,
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AccountCreationEvent, AccountSetupEvent, ConstructorOpts, Environment, ExternalWalletChangeEvent, LoginEvent, LogoutEvent, PregenWalletClaimedEvent, SignMessageEvent, SignTransactionEvent, WalletCreatedEvent, WalletsChangeEvent } from '@getpara/web-sdk';
|
|
2
|
+
import { PropsWithChildren } from 'react';
|
|
3
|
+
export type Callbacks = {
|
|
4
|
+
onLogout?: (event: LogoutEvent) => void;
|
|
5
|
+
onLogin?: (event: LoginEvent) => void;
|
|
6
|
+
onAccountSetup?: (event: AccountSetupEvent) => void;
|
|
7
|
+
onAccountCreation?: (event: AccountCreationEvent) => void;
|
|
8
|
+
onSignMessage?: (event: SignMessageEvent) => void;
|
|
9
|
+
onSignTransaction?: (event: SignTransactionEvent) => void;
|
|
10
|
+
onExternalWalletChange?: (event: ExternalWalletChangeEvent) => void;
|
|
11
|
+
onWalletsChange?: (event: WalletsChangeEvent) => void;
|
|
12
|
+
onWalletCreated?: (event: WalletCreatedEvent) => void;
|
|
13
|
+
onPregenWalletClaimed?: (event: PregenWalletClaimedEvent) => void;
|
|
14
|
+
};
|
|
15
|
+
export type ParaProviderConfig = {
|
|
16
|
+
disableAutoSessionKeepAlive?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export interface ParaProviderProps extends PropsWithChildren {
|
|
19
|
+
paraClientConfig: {
|
|
20
|
+
env: Environment;
|
|
21
|
+
apiKey: string;
|
|
22
|
+
opts?: ConstructorOpts;
|
|
23
|
+
};
|
|
24
|
+
callbacks?: Callbacks;
|
|
25
|
+
config?: ParaProviderConfig;
|
|
26
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
import { Compute, UnionStrictOmit } from './utils.js';
|
|
3
|
+
export type UseMutationReturnType<data = unknown, error = Error, variables = void, context = unknown> = Compute<UnionStrictOmit<UseMutationResult<data, error, variables, context>, 'mutate' | 'mutateAsync'>>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Compute<type> = {
|
|
2
|
+
[key in keyof type]: type[key];
|
|
3
|
+
} & unknown;
|
|
4
|
+
/** Strict version of built-in Omit type */
|
|
5
|
+
export type StrictOmit<type, keys extends keyof type> = Pick<type, Exclude<keyof type, keys>>;
|
|
6
|
+
export type UnionStrictOmit<type, keys extends keyof type> = type extends any ? StrictOmit<type, keys> : never;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { DefaultError, UseMutationResult } from '@tanstack/react-query';
|
|
2
|
+
export declare function renameMutations<TResp = unknown, TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(mutationObj: UseMutationResult<TData, TError, TVariables, TContext>, name: string): TResp;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
export function renameMutations(mutationObj, name) {
|
|
13
|
+
const { mutate: _, mutateAsync: __ } = mutationObj, mutationNoMutate = __rest(mutationObj, ["mutate", "mutateAsync"]);
|
|
14
|
+
const newMutations = {
|
|
15
|
+
[name]: mutationObj.mutate,
|
|
16
|
+
[`${name}Async`]: mutationObj.mutateAsync,
|
|
17
|
+
};
|
|
18
|
+
return Object.assign(Object.assign({}, newMutations), mutationNoMutate);
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getpara/react-sdk",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,9 +12,10 @@
|
|
|
12
12
|
"*.css"
|
|
13
13
|
],
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@getpara/react-common": "0.1
|
|
16
|
-
"@getpara/react-components": "0.
|
|
17
|
-
"@getpara/web-sdk": "0.1
|
|
15
|
+
"@getpara/react-common": "0.2.1",
|
|
16
|
+
"@getpara/react-components": "0.2.0",
|
|
17
|
+
"@getpara/web-sdk": "0.2.1",
|
|
18
|
+
"@tanstack/react-query": "^5.0.0",
|
|
18
19
|
"date-fns": "^3.6.0",
|
|
19
20
|
"detect-browser": "^5.3.0",
|
|
20
21
|
"framer-motion": "11.3.28",
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"resolutions": {
|
|
48
49
|
"styled-components": "^6"
|
|
49
50
|
},
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "dd8c9463981f7dd563f6c925c370c7054ca74adf"
|
|
51
52
|
}
|