@dynamic-labs/sdk-react-core 0.18.0-RC.7 → 0.18.0-RC.8
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/CHANGELOG.md +23 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +8 -8
- package/src/index.cjs +2 -0
- package/src/index.js +1 -0
- package/src/lib/components/NetworkPicker/NetworkPicker.cjs +26 -1
- package/src/lib/components/NetworkPicker/NetworkPicker.js +26 -1
- package/src/lib/components/NetworkPicker/components/Network/Network.cjs +3 -1
- package/src/lib/components/NetworkPicker/components/Network/Network.d.ts +2 -1
- package/src/lib/components/NetworkPicker/components/Network/Network.js +3 -1
- package/src/lib/components/NetworkPicker/components/NetworkAction/NetworkAction.cjs +6 -1
- package/src/lib/components/NetworkPicker/components/NetworkAction/NetworkAction.d.ts +2 -1
- package/src/lib/components/NetworkPicker/components/NetworkAction/NetworkAction.js +6 -1
- package/src/lib/components/TosAndPp/TosAndPp.cjs +1 -1
- package/src/lib/components/TosAndPp/TosAndPp.js +1 -1
- package/src/lib/components/Transition/transition.type.d.ts +3 -3
- package/src/lib/context/DynamicContext/DynamicContext.cjs +20 -4
- package/src/lib/context/DynamicContext/DynamicContext.d.ts +4 -1
- package/src/lib/context/DynamicContext/DynamicContext.js +21 -5
- package/src/lib/context/ErrorContext/ErrorContext.cjs +6 -0
- package/src/lib/context/ErrorContext/ErrorContext.js +6 -0
- package/src/lib/shared/utils/hooks/index.d.ts +1 -0
- package/src/lib/shared/utils/hooks/useMediaQuery/index.d.ts +1 -0
- package/src/lib/shared/utils/hooks/useMediaQuery/useMediaQuery.cjs +31 -0
- package/src/lib/shared/utils/hooks/useMediaQuery/useMediaQuery.d.ts +1 -0
- package/src/lib/shared/utils/hooks/useMediaQuery/useMediaQuery.js +27 -0
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/walletListBuilder/walletListBuilder.cjs +1 -1
- package/src/lib/utils/functions/walletListBuilder/walletListBuilder.js +1 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +2 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +2 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.cjs +3 -1
- package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.js +3 -1
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs +13 -0
- package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js +13 -0
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/useColorSchemePreference/useColorSchemePreference.cjs +16 -18
- package/src/lib/utils/hooks/useColorSchemePreference/useColorSchemePreference.js +16 -18
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +20 -6
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.d.ts +14 -2
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +20 -6
- package/src/lib/utils/hooks/useCountdown/useCountdown.cjs +39 -0
- package/src/lib/utils/hooks/useCountdown/useCountdown.d.ts +11 -0
- package/src/lib/utils/hooks/useCountdown/useCountdown.js +35 -0
- package/src/lib/utils/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs +10 -0
- package/src/lib/utils/hooks/useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js +6 -0
- package/src/lib/utils/hooks/useKeyboardEventListener/useKeyboardEventListener.cjs +6 -8
- package/src/lib/utils/hooks/useKeyboardEventListener/useKeyboardEventListener.js +7 -9
- package/src/lib/utils/hooks/useRpcProviders/useRpcProviders.cjs +6 -28
- package/src/lib/utils/hooks/useRpcProviders/useRpcProviders.d.ts +0 -1
- package/src/lib/utils/hooks/useRpcProviders/useRpcProviders.js +7 -29
- package/src/lib/utils/hooks/useTimeout/useTimeout.cjs +27 -0
- package/src/lib/utils/hooks/useTimeout/useTimeout.js +23 -0
- package/src/lib/utils/hooks/useTransition/useTransition.cjs +16 -24
- package/src/lib/utils/hooks/useTransition/useTransition.d.ts +3 -3
- package/src/lib/utils/hooks/useTransition/useTransition.js +17 -25
- package/src/lib/utils/hooks/useTransitionEvents/useTransitionEvents.cjs +11 -9
- package/src/lib/utils/hooks/useTransitionEvents/useTransitionEvents.js +11 -9
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.cjs +3 -1
- package/src/lib/utils/hooks/useVerifyWallet/useVerifyWallet.js +3 -1
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +1 -0
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +1 -0
- package/src/lib/utils/hooks/useWallets/useWallets.cjs +4 -1
- package/src/lib/utils/hooks/useWallets/useWallets.d.ts +2 -1
- package/src/lib/utils/hooks/useWallets/useWallets.js +4 -1
- package/src/lib/views/EmailUpdate/EmailUpdate.cjs +2 -1
- package/src/lib/views/EmailUpdate/EmailUpdate.js +2 -1
- package/src/lib/views/EmailVerification/EmailVerification.cjs +12 -21
- package/src/lib/views/EmailVerification/EmailVerification.js +13 -22
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.cjs +2 -1
- package/src/lib/views/LoginWithEmailView/components/LoginWithEmailForm/LoginWithEmailForm.js +2 -1
- package/src/lib/views/QrCodeView/QRCode.cjs +36 -4
- package/src/lib/views/QrCodeView/QRCode.js +37 -5
- package/src/lib/views/QrCodeView/QrCodeView.cjs +3 -6
- package/src/lib/views/QrCodeView/QrCodeView.js +3 -6
- package/src/lib/views/TransactionConfirmationView/helpers/transactionErrorMessage.cjs +15 -0
- package/src/lib/views/TransactionConfirmationView/helpers/transactionErrorMessage.js +15 -0
- package/src/lib/views/WalletList/data.cjs +2 -1
- package/src/lib/views/WalletList/data.js +2 -1
|
@@ -1,23 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import '@dynamic-labs/sdk-api';
|
|
2
|
+
import '../../../shared/logger.js';
|
|
3
|
+
import '@dynamic-labs/iconic';
|
|
4
|
+
import '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import 'react/jsx-runtime';
|
|
6
|
+
import '../../../context/ViewContext/ViewContext.js';
|
|
7
|
+
import 'react';
|
|
8
|
+
import '@dynamic-labs/wallet-book';
|
|
9
|
+
import '@dynamic-labs/utils';
|
|
10
|
+
import '../../constants/colors.js';
|
|
11
|
+
import '../../../shared/utils/classes/storage/localStorage.js';
|
|
12
|
+
import 'ethers';
|
|
13
|
+
import { useMediaQuery } from '../../../shared/utils/hooks/useMediaQuery/useMediaQuery.js';
|
|
14
|
+
import '../../../shared/consts/index.js';
|
|
2
15
|
|
|
3
16
|
const useColorSchemePreference = () => {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
: 'light');
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const listener = (e) => {
|
|
9
|
-
setPreference(e.matches ? 'dark' : 'light');
|
|
10
|
-
};
|
|
11
|
-
window
|
|
12
|
-
.matchMedia('(prefers-color-scheme: dark)')
|
|
13
|
-
.addEventListener('change', listener);
|
|
14
|
-
return () => {
|
|
15
|
-
window
|
|
16
|
-
.matchMedia('(prefers-color-scheme: dark)')
|
|
17
|
-
.removeEventListener('change', listener);
|
|
18
|
-
};
|
|
19
|
-
}, []);
|
|
20
|
-
return preference;
|
|
17
|
+
const isDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
|
|
18
|
+
return isDarkMode ? 'dark' : 'light';
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
export { useColorSchemePreference };
|
|
@@ -23,7 +23,7 @@ var api = require('../../../data/api.cjs');
|
|
|
23
23
|
require('@dynamic-labs/multi-wallet');
|
|
24
24
|
var shouldManuallyReconnectOnRefresh = require('../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.cjs');
|
|
25
25
|
|
|
26
|
-
const useConnectWallet = (
|
|
26
|
+
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, user, }) => {
|
|
27
27
|
const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage.useLocalStorage(localStorage.CONNECTED_WALLETS_INFO, []);
|
|
28
28
|
const [connectedWallet, setConnectedWallet] = React.useState(null);
|
|
29
29
|
const [connectedWallets, setConnectedWallets] = React.useState([]);
|
|
@@ -37,9 +37,11 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
37
37
|
});
|
|
38
38
|
setConnectedWallets((currentWallets) => {
|
|
39
39
|
const exists = currentWallets.some((currentWallet) => walletConnectorCore.isSameAddress(currentWallet.address, address, chain));
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
// when we connect first wallet, it should be set as a primary wallet
|
|
41
|
+
const shouldSetPrimaryWalletId = authMode === 'connect-only' &&
|
|
42
|
+
currentWallets.length === 0 &&
|
|
43
|
+
!primaryWalletId;
|
|
44
|
+
if (shouldSetPrimaryWalletId) {
|
|
43
45
|
setPrimaryWalletId(`connect-only-wallet-${0}`);
|
|
44
46
|
}
|
|
45
47
|
if (exists) {
|
|
@@ -65,6 +67,7 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
65
67
|
...currentWallets,
|
|
66
68
|
{
|
|
67
69
|
chain,
|
|
70
|
+
id: `connect-only-wallet-${id}`,
|
|
68
71
|
name: walletConnector.name,
|
|
69
72
|
provider: getWalletProvider.getWalletProvider(walletConnector),
|
|
70
73
|
walletPublicKey: address,
|
|
@@ -72,6 +75,16 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
72
75
|
];
|
|
73
76
|
});
|
|
74
77
|
}, [authMode, primaryWalletId, setConnectedWalletsInfo, setPrimaryWalletId]);
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
const found = connectedWalletsInfo.find((connectedWalletInfo) => connectedWalletInfo.id !== primaryWalletId);
|
|
80
|
+
// when primaryWalletId is defined, but it does not exist in
|
|
81
|
+
// connectedWalletInfo that means we're out of sync and we want to remove all connected wallets data
|
|
82
|
+
if (primaryWalletId && !found && !user) {
|
|
83
|
+
removeConnectedWalletsInfo();
|
|
84
|
+
setConnectedWallets([]);
|
|
85
|
+
clearPrimaryWalletId();
|
|
86
|
+
}
|
|
87
|
+
}, []);
|
|
75
88
|
const connectWalletByAddressAndChain = React.useCallback((name, address, chain, id) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
76
89
|
const walletConnector = walletConnectorCore.getWalletConnectorByName(wallets.map((wallet) => wallet.walletConnector), name);
|
|
77
90
|
if (walletConnector) {
|
|
@@ -93,9 +106,10 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
93
106
|
}
|
|
94
107
|
}), [setConnectedStates, wallets]);
|
|
95
108
|
React.useEffect(() => {
|
|
96
|
-
|
|
109
|
+
const shouldUpdateConnectedWalletsState = authMode === 'connect-only' &&
|
|
97
110
|
connectedWalletsInfo.length &&
|
|
98
|
-
!connectedWallets.length
|
|
111
|
+
!connectedWallets.length;
|
|
112
|
+
if (shouldUpdateConnectedWalletsState) {
|
|
99
113
|
connectedWalletsInfo.forEach(({ name, walletPublicKey, chain }, id) => {
|
|
100
114
|
if (chain) {
|
|
101
115
|
connectWalletByAddressAndChain(name, walletPublicKey, chain, id);
|
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { Chain, FetchPublicAddressOpts, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
-
import { AuthModeType, Wallet, WalletOption } from '../../../shared';
|
|
3
|
+
import { AuthModeType, UserProfile, Wallet, WalletOption } from '../../../shared';
|
|
4
4
|
export type ConnectedWalletConnectorType = {
|
|
5
5
|
chain: Chain | undefined;
|
|
6
6
|
name: string;
|
|
7
7
|
provider: string;
|
|
8
8
|
walletPublicKey: string;
|
|
9
|
+
id: string;
|
|
9
10
|
};
|
|
10
|
-
|
|
11
|
+
type Props = {
|
|
12
|
+
authMode: AuthModeType;
|
|
13
|
+
clearPrimaryWalletId: () => void;
|
|
14
|
+
enableVisitTrackingOnConnectOnly: boolean;
|
|
15
|
+
environmentId: string;
|
|
16
|
+
primaryWalletId: string | undefined;
|
|
17
|
+
setPrimaryWalletId: (walletId: string) => void;
|
|
18
|
+
wallets: WalletOption[];
|
|
19
|
+
user: UserProfile | undefined;
|
|
20
|
+
};
|
|
21
|
+
export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, user, }: Props) => {
|
|
11
22
|
connectWallet: (walletConnector: WalletConnector, fetchPublicAddressOpts?: FetchPublicAddressOpts) => Promise<string>;
|
|
12
23
|
connectWalletByAddressAndChain: (name: string, address: string, chain: Chain, id?: number) => Promise<void>;
|
|
13
24
|
connectedWallet: Wallet | null;
|
|
@@ -17,3 +28,4 @@ export declare const useConnectWallet: (wallets: WalletOption[], authMode: AuthM
|
|
|
17
28
|
setConnectedWallet: import("react").Dispatch<import("react").SetStateAction<Wallet | null>>;
|
|
18
29
|
setConnectedWallets: import("react").Dispatch<import("react").SetStateAction<[] | Wallet[]>>;
|
|
19
30
|
};
|
|
31
|
+
export {};
|
|
@@ -19,7 +19,7 @@ import { createVisit } from '../../../data/api.js';
|
|
|
19
19
|
import '@dynamic-labs/multi-wallet';
|
|
20
20
|
import { shouldManuallyReconnectOnRefresh } from '../../functions/shouldManuallyReconnectOnRefresh/shouldManuallyReconnectOnRefresh.js';
|
|
21
21
|
|
|
22
|
-
const useConnectWallet = (
|
|
22
|
+
const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingOnConnectOnly, environmentId, primaryWalletId, setPrimaryWalletId, wallets, user, }) => {
|
|
23
23
|
const [connectedWalletsInfo, setConnectedWalletsInfo, removeConnectedWalletsInfo,] = useLocalStorage(CONNECTED_WALLETS_INFO, []);
|
|
24
24
|
const [connectedWallet, setConnectedWallet] = useState(null);
|
|
25
25
|
const [connectedWallets, setConnectedWallets] = useState([]);
|
|
@@ -33,9 +33,11 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
33
33
|
});
|
|
34
34
|
setConnectedWallets((currentWallets) => {
|
|
35
35
|
const exists = currentWallets.some((currentWallet) => isSameAddress(currentWallet.address, address, chain));
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
// when we connect first wallet, it should be set as a primary wallet
|
|
37
|
+
const shouldSetPrimaryWalletId = authMode === 'connect-only' &&
|
|
38
|
+
currentWallets.length === 0 &&
|
|
39
|
+
!primaryWalletId;
|
|
40
|
+
if (shouldSetPrimaryWalletId) {
|
|
39
41
|
setPrimaryWalletId(`connect-only-wallet-${0}`);
|
|
40
42
|
}
|
|
41
43
|
if (exists) {
|
|
@@ -61,6 +63,7 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
61
63
|
...currentWallets,
|
|
62
64
|
{
|
|
63
65
|
chain,
|
|
66
|
+
id: `connect-only-wallet-${id}`,
|
|
64
67
|
name: walletConnector.name,
|
|
65
68
|
provider: getWalletProvider(walletConnector),
|
|
66
69
|
walletPublicKey: address,
|
|
@@ -68,6 +71,16 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
68
71
|
];
|
|
69
72
|
});
|
|
70
73
|
}, [authMode, primaryWalletId, setConnectedWalletsInfo, setPrimaryWalletId]);
|
|
74
|
+
useEffect(() => {
|
|
75
|
+
const found = connectedWalletsInfo.find((connectedWalletInfo) => connectedWalletInfo.id !== primaryWalletId);
|
|
76
|
+
// when primaryWalletId is defined, but it does not exist in
|
|
77
|
+
// connectedWalletInfo that means we're out of sync and we want to remove all connected wallets data
|
|
78
|
+
if (primaryWalletId && !found && !user) {
|
|
79
|
+
removeConnectedWalletsInfo();
|
|
80
|
+
setConnectedWallets([]);
|
|
81
|
+
clearPrimaryWalletId();
|
|
82
|
+
}
|
|
83
|
+
}, []);
|
|
71
84
|
const connectWalletByAddressAndChain = useCallback((name, address, chain, id) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
85
|
const walletConnector = getWalletConnectorByName(wallets.map((wallet) => wallet.walletConnector), name);
|
|
73
86
|
if (walletConnector) {
|
|
@@ -89,9 +102,10 @@ const useConnectWallet = (wallets, authMode, environmentId, enableVisitTrackingO
|
|
|
89
102
|
}
|
|
90
103
|
}), [setConnectedStates, wallets]);
|
|
91
104
|
useEffect(() => {
|
|
92
|
-
|
|
105
|
+
const shouldUpdateConnectedWalletsState = authMode === 'connect-only' &&
|
|
93
106
|
connectedWalletsInfo.length &&
|
|
94
|
-
!connectedWallets.length
|
|
107
|
+
!connectedWallets.length;
|
|
108
|
+
if (shouldUpdateConnectedWalletsState) {
|
|
95
109
|
connectedWalletsInfo.forEach(({ name, walletPublicKey, chain }, id) => {
|
|
96
110
|
if (chain) {
|
|
97
111
|
connectWalletByAddressAndChain(name, walletPublicKey, chain, id);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
const useCountdown = ({ callback, seconds }) => {
|
|
8
|
+
const [remainingSeconds, setRemainingSeconds] = React.useState(seconds);
|
|
9
|
+
const timeoutRef = React.useRef();
|
|
10
|
+
const startCountdown = () => {
|
|
11
|
+
if (timeoutRef.current) {
|
|
12
|
+
return setRemainingSeconds(seconds);
|
|
13
|
+
}
|
|
14
|
+
runCountdown();
|
|
15
|
+
};
|
|
16
|
+
const stopCountdown = () => {
|
|
17
|
+
clearTimeout(timeoutRef.current);
|
|
18
|
+
timeoutRef.current = undefined;
|
|
19
|
+
};
|
|
20
|
+
const runCountdown = () => {
|
|
21
|
+
timeoutRef.current = setTimeout(() => {
|
|
22
|
+
setRemainingSeconds((prevSeconds) => prevSeconds - 1);
|
|
23
|
+
}, 1000);
|
|
24
|
+
};
|
|
25
|
+
React.useEffect(() => {
|
|
26
|
+
if (!timeoutRef.current)
|
|
27
|
+
return;
|
|
28
|
+
if (remainingSeconds <= 0) {
|
|
29
|
+
if (callback)
|
|
30
|
+
callback();
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
runCountdown();
|
|
34
|
+
return () => clearTimeout(timeoutRef.current);
|
|
35
|
+
}, [remainingSeconds, callback]);
|
|
36
|
+
return { remainingSeconds, startCountdown, stopCountdown };
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
exports.useCountdown = useCountdown;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
type Prop = {
|
|
2
|
+
callback?: () => void;
|
|
3
|
+
seconds: number;
|
|
4
|
+
};
|
|
5
|
+
export interface UseCountdown {
|
|
6
|
+
remainingSeconds: number;
|
|
7
|
+
startCountdown: () => void;
|
|
8
|
+
stopCountdown: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const useCountdown: ({ callback, seconds }: Prop) => UseCountdown;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { useState, useRef, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useCountdown = ({ callback, seconds }) => {
|
|
4
|
+
const [remainingSeconds, setRemainingSeconds] = useState(seconds);
|
|
5
|
+
const timeoutRef = useRef();
|
|
6
|
+
const startCountdown = () => {
|
|
7
|
+
if (timeoutRef.current) {
|
|
8
|
+
return setRemainingSeconds(seconds);
|
|
9
|
+
}
|
|
10
|
+
runCountdown();
|
|
11
|
+
};
|
|
12
|
+
const stopCountdown = () => {
|
|
13
|
+
clearTimeout(timeoutRef.current);
|
|
14
|
+
timeoutRef.current = undefined;
|
|
15
|
+
};
|
|
16
|
+
const runCountdown = () => {
|
|
17
|
+
timeoutRef.current = setTimeout(() => {
|
|
18
|
+
setRemainingSeconds((prevSeconds) => prevSeconds - 1);
|
|
19
|
+
}, 1000);
|
|
20
|
+
};
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (!timeoutRef.current)
|
|
23
|
+
return;
|
|
24
|
+
if (remainingSeconds <= 0) {
|
|
25
|
+
if (callback)
|
|
26
|
+
callback();
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
runCountdown();
|
|
30
|
+
return () => clearTimeout(timeoutRef.current);
|
|
31
|
+
}, [remainingSeconds, callback]);
|
|
32
|
+
return { remainingSeconds, startCountdown, stopCountdown };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { useCountdown };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
// https://usehooks-ts.com/react-hook/use-isomorphic-layout-effect
|
|
8
|
+
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
9
|
+
|
|
10
|
+
exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
|
|
@@ -5,19 +5,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
|
|
7
7
|
const useKeyboardEventListener = ({ disabled, inputKey, onKeyPressed, }) => {
|
|
8
|
-
const handleKeydown = React.useCallback((evt) => {
|
|
9
|
-
if (disabled)
|
|
10
|
-
return;
|
|
11
|
-
if (evt.key === inputKey) {
|
|
12
|
-
onKeyPressed();
|
|
13
|
-
}
|
|
14
|
-
}, [disabled, inputKey, onKeyPressed]);
|
|
15
8
|
React.useEffect(() => {
|
|
9
|
+
const handleKeydown = (evt) => {
|
|
10
|
+
if (disabled || evt.key !== inputKey)
|
|
11
|
+
return;
|
|
12
|
+
onKeyPressed();
|
|
13
|
+
};
|
|
16
14
|
document.addEventListener('keydown', handleKeydown);
|
|
17
15
|
return () => {
|
|
18
16
|
document.removeEventListener('keydown', handleKeydown);
|
|
19
17
|
};
|
|
20
|
-
}, [
|
|
18
|
+
}, [disabled, inputKey, onKeyPressed]);
|
|
21
19
|
};
|
|
22
20
|
|
|
23
21
|
exports.useKeyboardEventListener = useKeyboardEventListener;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
2
|
|
|
3
3
|
const useKeyboardEventListener = ({ disabled, inputKey, onKeyPressed, }) => {
|
|
4
|
-
const handleKeydown = useCallback((evt) => {
|
|
5
|
-
if (disabled)
|
|
6
|
-
return;
|
|
7
|
-
if (evt.key === inputKey) {
|
|
8
|
-
onKeyPressed();
|
|
9
|
-
}
|
|
10
|
-
}, [disabled, inputKey, onKeyPressed]);
|
|
11
4
|
useEffect(() => {
|
|
5
|
+
const handleKeydown = (evt) => {
|
|
6
|
+
if (disabled || evt.key !== inputKey)
|
|
7
|
+
return;
|
|
8
|
+
onKeyPressed();
|
|
9
|
+
};
|
|
12
10
|
document.addEventListener('keydown', handleKeydown);
|
|
13
11
|
return () => {
|
|
14
12
|
document.removeEventListener('keydown', handleKeydown);
|
|
15
13
|
};
|
|
16
|
-
}, [
|
|
14
|
+
}, [disabled, inputKey, onKeyPressed]);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
17
|
export { useKeyboardEventListener };
|
|
@@ -18,45 +18,23 @@ require('ethers');
|
|
|
18
18
|
require('../../../shared/consts/index.cjs');
|
|
19
19
|
|
|
20
20
|
const useRpcProviders = ({ networkConfigurations, }) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const [solanaDefaultProvider, setSolanaDefaultProvider] = React.useState();
|
|
24
|
-
React.useEffect(() => {
|
|
21
|
+
let providers, evmDefaultProvider, solanaDefaultProvider;
|
|
22
|
+
if (networkConfigurations) {
|
|
25
23
|
try {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
24
|
+
providers = rpcProviders.ChainRpcProviders.getProviders(networkConfigurations);
|
|
25
|
+
evmDefaultProvider = rpcProviders.ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, 1);
|
|
26
|
+
solanaDefaultProvider = rpcProviders.ChainRpcProviders.getSolanaRpcProviderByChainId(networkConfigurations, '101');
|
|
29
27
|
}
|
|
30
28
|
catch (error) {
|
|
31
29
|
logger.logger.error(error);
|
|
32
30
|
}
|
|
33
|
-
}
|
|
31
|
+
}
|
|
34
32
|
const getEvmRpcProviderByChainId = React.useCallback((chainId) => {
|
|
35
33
|
if (!networkConfigurations) {
|
|
36
34
|
return undefined;
|
|
37
35
|
}
|
|
38
36
|
return rpcProviders.ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, chainId);
|
|
39
37
|
}, [networkConfigurations]);
|
|
40
|
-
React.useEffect(() => {
|
|
41
|
-
try {
|
|
42
|
-
if (networkConfigurations) {
|
|
43
|
-
setEvmDefaultProvider(rpcProviders.ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, 1));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (error) {
|
|
47
|
-
logger.logger.error(error);
|
|
48
|
-
}
|
|
49
|
-
}, [networkConfigurations]);
|
|
50
|
-
React.useEffect(() => {
|
|
51
|
-
try {
|
|
52
|
-
if (networkConfigurations) {
|
|
53
|
-
setSolanaDefaultProvider(rpcProviders.ChainRpcProviders.getSolanaRpcProviderByChainId(networkConfigurations, '101'));
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
catch (error) {
|
|
57
|
-
logger.logger.error(error);
|
|
58
|
-
}
|
|
59
|
-
}, [networkConfigurations]);
|
|
60
38
|
return {
|
|
61
39
|
evmDefaultProvider,
|
|
62
40
|
evmProviders: providers === null || providers === void 0 ? void 0 : providers.evm,
|
|
@@ -2,7 +2,6 @@ import { NetworkConfigurationMap } from '@dynamic-labs/types';
|
|
|
2
2
|
import { DynamicRPCProviders } from '../../../shared';
|
|
3
3
|
type Props = {
|
|
4
4
|
networkConfigurations: NetworkConfigurationMap | undefined;
|
|
5
|
-
networkId: string | number | undefined;
|
|
6
5
|
};
|
|
7
6
|
export declare const useRpcProviders: ({ networkConfigurations, }: Props) => DynamicRPCProviders;
|
|
8
7
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
2
|
import { ChainRpcProviders } from '@dynamic-labs/rpc-providers';
|
|
3
3
|
import '@dynamic-labs/sdk-api';
|
|
4
4
|
import { logger } from '../../../shared/logger.js';
|
|
@@ -14,45 +14,23 @@ import 'ethers';
|
|
|
14
14
|
import '../../../shared/consts/index.js';
|
|
15
15
|
|
|
16
16
|
const useRpcProviders = ({ networkConfigurations, }) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const [solanaDefaultProvider, setSolanaDefaultProvider] = useState();
|
|
20
|
-
useEffect(() => {
|
|
17
|
+
let providers, evmDefaultProvider, solanaDefaultProvider;
|
|
18
|
+
if (networkConfigurations) {
|
|
21
19
|
try {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
providers = ChainRpcProviders.getProviders(networkConfigurations);
|
|
21
|
+
evmDefaultProvider = ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, 1);
|
|
22
|
+
solanaDefaultProvider = ChainRpcProviders.getSolanaRpcProviderByChainId(networkConfigurations, '101');
|
|
25
23
|
}
|
|
26
24
|
catch (error) {
|
|
27
25
|
logger.error(error);
|
|
28
26
|
}
|
|
29
|
-
}
|
|
27
|
+
}
|
|
30
28
|
const getEvmRpcProviderByChainId = useCallback((chainId) => {
|
|
31
29
|
if (!networkConfigurations) {
|
|
32
30
|
return undefined;
|
|
33
31
|
}
|
|
34
32
|
return ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, chainId);
|
|
35
33
|
}, [networkConfigurations]);
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
try {
|
|
38
|
-
if (networkConfigurations) {
|
|
39
|
-
setEvmDefaultProvider(ChainRpcProviders.getEvmProviderByChainId(networkConfigurations, 1));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
catch (error) {
|
|
43
|
-
logger.error(error);
|
|
44
|
-
}
|
|
45
|
-
}, [networkConfigurations]);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
try {
|
|
48
|
-
if (networkConfigurations) {
|
|
49
|
-
setSolanaDefaultProvider(ChainRpcProviders.getSolanaRpcProviderByChainId(networkConfigurations, '101'));
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (error) {
|
|
53
|
-
logger.error(error);
|
|
54
|
-
}
|
|
55
|
-
}, [networkConfigurations]);
|
|
56
34
|
return {
|
|
57
35
|
evmDefaultProvider,
|
|
58
36
|
evmProviders: providers === null || providers === void 0 ? void 0 : providers.evm,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs');
|
|
7
|
+
|
|
8
|
+
// https://usehooks-ts.com/react-hook/use-timeout
|
|
9
|
+
const useTimeout = (callback, delay) => {
|
|
10
|
+
const savedCallback = React.useRef(callback);
|
|
11
|
+
// Remember the latest callback if it changes.
|
|
12
|
+
useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
|
|
13
|
+
savedCallback.current = callback;
|
|
14
|
+
}, [callback]);
|
|
15
|
+
// Set up the timeout.
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
// Don't schedule if no delay is specified.
|
|
18
|
+
// Note: 0 is a valid value for delay.
|
|
19
|
+
if (!delay && delay !== 0) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const id = setTimeout(() => savedCallback.current(), delay);
|
|
23
|
+
return () => clearTimeout(id);
|
|
24
|
+
}, [delay]);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
exports.useTimeout = useTimeout;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useRef, useEffect } from 'react';
|
|
2
|
+
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js';
|
|
3
|
+
|
|
4
|
+
// https://usehooks-ts.com/react-hook/use-timeout
|
|
5
|
+
const useTimeout = (callback, delay) => {
|
|
6
|
+
const savedCallback = useRef(callback);
|
|
7
|
+
// Remember the latest callback if it changes.
|
|
8
|
+
useIsomorphicLayoutEffect(() => {
|
|
9
|
+
savedCallback.current = callback;
|
|
10
|
+
}, [callback]);
|
|
11
|
+
// Set up the timeout.
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
// Don't schedule if no delay is specified.
|
|
14
|
+
// Note: 0 is a valid value for delay.
|
|
15
|
+
if (!delay && delay !== 0) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const id = setTimeout(() => savedCallback.current(), delay);
|
|
19
|
+
return () => clearTimeout(id);
|
|
20
|
+
}, [delay]);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export { useTimeout };
|
|
@@ -10,22 +10,22 @@ var useTransitionEvents = require('../useTransitionEvents/useTransitionEvents.cj
|
|
|
10
10
|
const DEFAULT_DURATION = 100;
|
|
11
11
|
// The hook inspired by https://github.com/reactjs/react-transition-group/blob/master/src/Transition.js
|
|
12
12
|
const useTransition = (_a) => {
|
|
13
|
-
var { isShown, inDuration, outDuration, duration = DEFAULT_DURATION,
|
|
14
|
-
const
|
|
13
|
+
var { isShown, inDuration, outDuration, duration = DEFAULT_DURATION, delay, inDelay, outDelay, animateOnMount = true } = _a, events = _tslib.__rest(_a, ["isShown", "inDuration", "outDuration", "duration", "delay", "inDelay", "outDelay", "animateOnMount"]);
|
|
14
|
+
const initialStage = animateOnMount ? 'UNMOUNT' : 'ENTERED';
|
|
15
15
|
const animationFrameTimeoutIdRef = React.useRef({ id: -1 });
|
|
16
16
|
const timeoutIdRef = React.useRef({ id: -1 });
|
|
17
|
-
const [stage, setStage] = React.useState(
|
|
17
|
+
const [stage, setStage] = React.useState(initialStage);
|
|
18
18
|
const [mount, setMount] = React.useState(!animateOnMount);
|
|
19
19
|
const [currentDuration, setCurrentDuration] = React.useState(duration);
|
|
20
|
-
const
|
|
21
|
-
if (
|
|
22
|
-
timeoutIdRef.current = animationFrameTimeout.animationFrameTimeout(
|
|
20
|
+
const performTransition = (runTransition, transitionDelay) => {
|
|
21
|
+
if (transitionDelay) {
|
|
22
|
+
timeoutIdRef.current = animationFrameTimeout.animationFrameTimeout(runTransition, transitionDelay);
|
|
23
23
|
}
|
|
24
24
|
else {
|
|
25
|
-
|
|
25
|
+
runTransition();
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
const performEnter = React.useCallback(() =>
|
|
28
|
+
const performEnter = React.useCallback(() => {
|
|
29
29
|
const animationDuration = inDuration || duration;
|
|
30
30
|
setCurrentDuration(animationDuration);
|
|
31
31
|
setMount(true);
|
|
@@ -33,8 +33,8 @@ const useTransition = (_a) => {
|
|
|
33
33
|
animationFrameTimeoutIdRef.current = animationFrameTimeout.animationFrameTimeout(() => {
|
|
34
34
|
setStage('ENTERED');
|
|
35
35
|
}, animationDuration);
|
|
36
|
-
}
|
|
37
|
-
const performExit = React.useCallback(() =>
|
|
36
|
+
}, [duration, inDuration]);
|
|
37
|
+
const performExit = React.useCallback(() => {
|
|
38
38
|
const animationDuration = outDuration || duration;
|
|
39
39
|
setCurrentDuration(animationDuration);
|
|
40
40
|
setStage('EXITING');
|
|
@@ -42,29 +42,21 @@ const useTransition = (_a) => {
|
|
|
42
42
|
setMount(false);
|
|
43
43
|
setStage('UNMOUNT');
|
|
44
44
|
}, animationDuration);
|
|
45
|
-
}
|
|
45
|
+
}, [duration, outDuration]);
|
|
46
46
|
React.useEffect(() => {
|
|
47
47
|
if (isShown && stage !== 'ENTERED') {
|
|
48
|
-
const
|
|
49
|
-
|
|
48
|
+
const enterDelay = inDelay || delay;
|
|
49
|
+
performTransition(performEnter, enterDelay);
|
|
50
50
|
}
|
|
51
51
|
else if (!isShown && stage !== 'UNMOUNT') {
|
|
52
|
-
const
|
|
53
|
-
|
|
52
|
+
const exitDelay = outDelay || delay;
|
|
53
|
+
performTransition(performExit, exitDelay);
|
|
54
54
|
}
|
|
55
55
|
return () => {
|
|
56
56
|
animationFrameTimeout.clearAnimationFrameTimeout(animationFrameTimeoutIdRef.current);
|
|
57
57
|
animationFrameTimeout.clearAnimationFrameTimeout(timeoutIdRef.current);
|
|
58
58
|
};
|
|
59
|
-
}, [
|
|
60
|
-
inTimeout,
|
|
61
|
-
outTimeout,
|
|
62
|
-
performEnter,
|
|
63
|
-
performExit,
|
|
64
|
-
isShown,
|
|
65
|
-
timeout,
|
|
66
|
-
stage,
|
|
67
|
-
]);
|
|
59
|
+
}, [inDelay, outDelay, performEnter, performExit, isShown, delay, stage]);
|
|
68
60
|
useTransitionEvents.useTransitionEvents(stage, events);
|
|
69
61
|
return { currentDuration, mount, stage };
|
|
70
62
|
};
|
|
@@ -8,11 +8,11 @@ export type UseTransitionProps = {
|
|
|
8
8
|
animateOnMount?: boolean;
|
|
9
9
|
duration?: number;
|
|
10
10
|
inDuration?: number;
|
|
11
|
-
|
|
11
|
+
inDelay?: number;
|
|
12
12
|
isShown?: boolean;
|
|
13
13
|
outDuration?: number;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
outDelay?: number;
|
|
15
|
+
delay?: number;
|
|
16
16
|
};
|
|
17
17
|
export type Props = UseTransitionProps & UseTransitionEvents;
|
|
18
18
|
export type TransitionStage = 'ENTERED' | 'ENTERING' | 'EXITING' | 'UNMOUNT';
|