@dynamic-labs/sdk-react-core 1.0.0-alpha.6 → 1.0.0-alpha.7
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 +20 -0
- package/package.cjs +2 -2
- package/package.js +2 -2
- package/package.json +10 -10
- package/src/index.cjs +4 -2
- package/src/index.d.ts +1 -1
- package/src/index.js +2 -1
- package/src/lib/Main.cjs +18 -21
- package/src/lib/Main.js +18 -21
- package/src/lib/components/NeedHelpSection/NeedHelpSection.cjs +84 -5
- package/src/lib/components/NeedHelpSection/NeedHelpSection.js +85 -6
- package/src/lib/components/NetworkPicker/NetworkPicker.cjs +8 -6
- package/src/lib/components/NetworkPicker/NetworkPicker.d.ts +2 -1
- package/src/lib/components/NetworkPicker/NetworkPicker.js +8 -6
- package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -4
- package/src/lib/context/DynamicContext/DynamicContext.js +1 -4
- package/src/lib/context/DynamicContext/types/index.d.ts +0 -1
- package/src/lib/data/api.cjs +2 -1
- package/src/lib/data/api.js +2 -1
- package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +9 -11
- package/src/lib/layout/DynamicAuthLayout/Header/header.js +10 -12
- package/src/lib/locale/en/translation.cjs +7 -3
- package/src/lib/locale/en/translation.d.ts +6 -2
- package/src/lib/locale/en/translation.js +7 -3
- package/src/lib/modals/SignMessageConfirmationModal/getProperErrorMessage.cjs +1 -1
- package/src/lib/modals/SignMessageConfirmationModal/getProperErrorMessage.js +1 -1
- package/src/lib/styles/index.shadow.cjs +1 -1
- package/src/lib/styles/index.shadow.js +1 -1
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.cjs +1 -1
- package/src/lib/utils/functions/findTurnkeyWallet/findTurnkeyWallet.js +1 -1
- package/src/lib/utils/hooks/index.d.ts +1 -0
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.cjs +1 -6
- package/src/lib/utils/hooks/multiWallet/useSyncPrimaryWallet/useSyncPrimaryWallet.js +1 -6
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.cjs +3 -0
- package/src/lib/utils/hooks/useConnectWallet/useConnectWallet.js +3 -0
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.cjs +7 -8
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.js +7 -8
- package/src/lib/utils/hooks/useEventListener/useEventListener.cjs +2 -1
- package/src/lib/utils/hooks/useEventListener/useEventListener.js +2 -1
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +9 -5
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.d.ts +0 -1
- package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +10 -6
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +20 -21
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +1 -2
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +20 -21
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +32 -9
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.d.ts +0 -1
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +33 -10
- package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +1 -1
- package/src/lib/views/CollectUserDataView/CollectUserDataView.js +1 -1
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +6 -3
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +6 -3
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +1 -1
- package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +1 -1
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.cjs +1 -1
- package/src/lib/views/Passkey/utils/passkeyRecovery/passkeyRecovery.js +1 -1
- package/src/lib/views/QrCodeView/QrCodeContainer/QrCodeContainer.cjs +1 -1
- package/src/lib/views/QrCodeView/QrCodeContainer/QrCodeContainer.js +1 -1
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +11 -1
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +11 -1
- package/src/lib/views/TransactionConfirmationView/helpers/transactionErrorMessage.cjs +3 -0
- package/src/lib/views/TransactionConfirmationView/helpers/transactionErrorMessage.js +4 -1
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +3 -3
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +3 -3
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.cjs +2 -2
- package/src/lib/widgets/DynamicWidget/components/DynamicNav/DynamicNav.js +2 -2
- package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.cjs +1 -2
- package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.js +1 -2
- package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.cjs +1 -2
- package/src/lib/widgets/DynamicWidget/components/Wallet/Wallet.js +1 -2
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.cjs +1 -3
- package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.js +1 -3
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/prompts/QrCodeModalView/QrCodeModalView.js +1 -1
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs +16 -6
- package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js +16 -6
|
@@ -19,10 +19,12 @@ require('../../../shared/consts/index.cjs');
|
|
|
19
19
|
require('@dynamic-labs/multi-wallet');
|
|
20
20
|
var isProgrammableNetworkSwitchSupported = require('../../functions/isProgrammableNetworkSwitchSupported/isProgrammableNetworkSwitchSupported.cjs');
|
|
21
21
|
var isSupportedNetwork = require('../../functions/isSupportedNetwork/isSupportedNetwork.cjs');
|
|
22
|
+
var useIsLoggedIn = require('../useIsLoggedIn/useIsLoggedIn.cjs');
|
|
22
23
|
|
|
23
24
|
const useConnectedWalletsNetworkValidation = () => {
|
|
24
|
-
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnectorKey, setShowAuthFlow,
|
|
25
|
+
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnectorKey, setShowAuthFlow, bridgeChainsToConnect, sdkHasLoaded, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
25
26
|
const { setView } = ViewContext.useViewContext();
|
|
27
|
+
const isLoggedIn = useIsLoggedIn.useIsLoggedIn();
|
|
26
28
|
React.useEffect(() => {
|
|
27
29
|
/**
|
|
28
30
|
* This check was added to prevent the "wrong network" modal from appearing
|
|
@@ -33,7 +35,7 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
33
35
|
* extra popup because handleLogOut flips sdkHasLoaded to false, so on the
|
|
34
36
|
* next render it will already be false.
|
|
35
37
|
*/
|
|
36
|
-
if (!sdkHasLoaded) {
|
|
38
|
+
if (!sdkHasLoaded || !isLoggedIn) {
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
39
41
|
const connectedWalletsWithInvalidNetwork = connectedWallets.filter((connectedWallet) => {
|
|
@@ -57,14 +59,10 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
57
59
|
const networkNotSupportedView = isProgrammableNetworkSwitchSupported.isProgrammableNetworkSwitchSupported(connectedWalletWithInvalidNetwork.connector)
|
|
58
60
|
? 'network-not-supported'
|
|
59
61
|
: 'network-not-supported-manual';
|
|
60
|
-
if
|
|
61
|
-
|
|
62
|
-
}
|
|
62
|
+
// Doesn't rerender if it's already true
|
|
63
|
+
setShowAuthFlow(true);
|
|
63
64
|
setView(networkNotSupportedView);
|
|
64
65
|
}
|
|
65
|
-
// we need it to remove 'showAuthFlow' property. we don't want to react to it,
|
|
66
|
-
// because closing modal on network switch causes it to re-open
|
|
67
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
68
66
|
}, [
|
|
69
67
|
sdkHasLoaded,
|
|
70
68
|
connectedWallets,
|
|
@@ -73,6 +71,7 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
73
71
|
setShowAuthFlow,
|
|
74
72
|
setView,
|
|
75
73
|
bridgeChainsToConnect,
|
|
74
|
+
isLoggedIn,
|
|
76
75
|
]);
|
|
77
76
|
};
|
|
78
77
|
|
|
@@ -15,10 +15,12 @@ import '../../../shared/consts/index.js';
|
|
|
15
15
|
import '@dynamic-labs/multi-wallet';
|
|
16
16
|
import { isProgrammableNetworkSwitchSupported } from '../../functions/isProgrammableNetworkSwitchSupported/isProgrammableNetworkSwitchSupported.js';
|
|
17
17
|
import { isSupportedNetwork } from '../../functions/isSupportedNetwork/isSupportedNetwork.js';
|
|
18
|
+
import { useIsLoggedIn } from '../useIsLoggedIn/useIsLoggedIn.js';
|
|
18
19
|
|
|
19
20
|
const useConnectedWalletsNetworkValidation = () => {
|
|
20
|
-
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnectorKey, setShowAuthFlow,
|
|
21
|
+
const { connectedWallets, selectedWalletConnector, setSelectedWalletConnectorKey, setShowAuthFlow, bridgeChainsToConnect, sdkHasLoaded, } = useInternalDynamicContext();
|
|
21
22
|
const { setView } = useViewContext();
|
|
23
|
+
const isLoggedIn = useIsLoggedIn();
|
|
22
24
|
useEffect(() => {
|
|
23
25
|
/**
|
|
24
26
|
* This check was added to prevent the "wrong network" modal from appearing
|
|
@@ -29,7 +31,7 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
29
31
|
* extra popup because handleLogOut flips sdkHasLoaded to false, so on the
|
|
30
32
|
* next render it will already be false.
|
|
31
33
|
*/
|
|
32
|
-
if (!sdkHasLoaded) {
|
|
34
|
+
if (!sdkHasLoaded || !isLoggedIn) {
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
35
37
|
const connectedWalletsWithInvalidNetwork = connectedWallets.filter((connectedWallet) => {
|
|
@@ -53,14 +55,10 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
53
55
|
const networkNotSupportedView = isProgrammableNetworkSwitchSupported(connectedWalletWithInvalidNetwork.connector)
|
|
54
56
|
? 'network-not-supported'
|
|
55
57
|
: 'network-not-supported-manual';
|
|
56
|
-
if
|
|
57
|
-
|
|
58
|
-
}
|
|
58
|
+
// Doesn't rerender if it's already true
|
|
59
|
+
setShowAuthFlow(true);
|
|
59
60
|
setView(networkNotSupportedView);
|
|
60
61
|
}
|
|
61
|
-
// we need it to remove 'showAuthFlow' property. we don't want to react to it,
|
|
62
|
-
// because closing modal on network switch causes it to re-open
|
|
63
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
64
62
|
}, [
|
|
65
63
|
sdkHasLoaded,
|
|
66
64
|
connectedWallets,
|
|
@@ -69,6 +67,7 @@ const useConnectedWalletsNetworkValidation = () => {
|
|
|
69
67
|
setShowAuthFlow,
|
|
70
68
|
setView,
|
|
71
69
|
bridgeChainsToConnect,
|
|
70
|
+
isLoggedIn,
|
|
72
71
|
]);
|
|
73
72
|
};
|
|
74
73
|
|
|
@@ -7,6 +7,7 @@ var React = require('react');
|
|
|
7
7
|
const useEventListener = (eventName, handler) => {
|
|
8
8
|
// Create a ref that stores handler
|
|
9
9
|
const savedHandler = React.useRef(handler);
|
|
10
|
+
savedHandler.current = handler;
|
|
10
11
|
React.useEffect(() => {
|
|
11
12
|
// Define the listening target
|
|
12
13
|
const targetElement = window;
|
|
@@ -19,7 +20,7 @@ const useEventListener = (eventName, handler) => {
|
|
|
19
20
|
return () => {
|
|
20
21
|
targetElement.removeEventListener(eventName, listener);
|
|
21
22
|
};
|
|
22
|
-
}, [eventName]);
|
|
23
|
+
}, [eventName, handler]);
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
exports.useEventListener = useEventListener;
|
|
@@ -3,6 +3,7 @@ import { useRef, useEffect } from 'react';
|
|
|
3
3
|
const useEventListener = (eventName, handler) => {
|
|
4
4
|
// Create a ref that stores handler
|
|
5
5
|
const savedHandler = useRef(handler);
|
|
6
|
+
savedHandler.current = handler;
|
|
6
7
|
useEffect(() => {
|
|
7
8
|
// Define the listening target
|
|
8
9
|
const targetElement = window;
|
|
@@ -15,7 +16,7 @@ const useEventListener = (eventName, handler) => {
|
|
|
15
16
|
return () => {
|
|
16
17
|
targetElement.removeEventListener(eventName, listener);
|
|
17
18
|
};
|
|
18
|
-
}, [eventName]);
|
|
19
|
+
}, [eventName, handler]);
|
|
19
20
|
};
|
|
20
21
|
|
|
21
22
|
export { useEventListener };
|
|
@@ -42,6 +42,14 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
42
42
|
if (authMode === 'connect-and-sign' && (user || onboardingOnlyJwt)) {
|
|
43
43
|
return linkedWallets;
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* This is to handle users in connect-only who are signing in with social/email
|
|
47
|
+
* with an embedded wallet
|
|
48
|
+
*/
|
|
49
|
+
if (authMode === 'connect-only' &&
|
|
50
|
+
linkedWallets.find((wallet) => walletConnectorCore.isEmbeddedConnector(wallet.connector))) {
|
|
51
|
+
return linkedWallets;
|
|
52
|
+
}
|
|
45
53
|
return connectedWallets;
|
|
46
54
|
}, [authMode, connectedWallets, linkedWallets, user, onboardingOnlyJwt]);
|
|
47
55
|
/**
|
|
@@ -54,11 +62,8 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
54
62
|
React.useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
|
|
55
63
|
wallet.connector.initEventListener();
|
|
56
64
|
}), [walletsBasedOnAuthMode]);
|
|
57
|
-
const { connectedWalletMap,
|
|
65
|
+
const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
|
|
58
66
|
const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
|
|
59
|
-
React.useEffect(() => {
|
|
60
|
-
computeConnectedStateForWallets();
|
|
61
|
-
}, [primaryWalletId, computeConnectedStateForWallets]);
|
|
62
67
|
const getPrimaryWallet = React.useCallback(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
63
68
|
const getSecondaryWallets = React.useCallback(() => canHaveMultipleWalletsConnected
|
|
64
69
|
? wallets.filter((wallet) => wallet.id !== primaryWalletId)
|
|
@@ -159,7 +164,6 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
159
164
|
]);
|
|
160
165
|
const walletConnectors = wallets.map((wallet) => wallet.connector);
|
|
161
166
|
return {
|
|
162
|
-
computeConnectedStateForWallets,
|
|
163
167
|
didConnectedStateLoad,
|
|
164
168
|
getPrimaryWallet,
|
|
165
169
|
getSecondaryWallets,
|
|
@@ -18,7 +18,6 @@ type Props = {
|
|
|
18
18
|
canHaveMultipleWalletsConnected?: boolean;
|
|
19
19
|
};
|
|
20
20
|
export interface UseWalletConnectors {
|
|
21
|
-
computeConnectedStateForWallets: () => Promise<void>;
|
|
22
21
|
didConnectedStateLoad: boolean;
|
|
23
22
|
getPrimaryWallet: () => Wallet | null;
|
|
24
23
|
getSecondaryWallets: () => Wallet[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
2
|
import { useState, useMemo, useEffect, useCallback } from 'react';
|
|
3
|
-
import { isEmailWalletConnector, isSocialWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
|
+
import { isEmbeddedConnector, isEmailWalletConnector, isSocialWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { DynamicError } from '@dynamic-labs/utils';
|
|
5
5
|
import '@dynamic-labs/sdk-api';
|
|
6
6
|
import { logger } from '../../../shared/logger.js';
|
|
@@ -38,6 +38,14 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
38
38
|
if (authMode === 'connect-and-sign' && (user || onboardingOnlyJwt)) {
|
|
39
39
|
return linkedWallets;
|
|
40
40
|
}
|
|
41
|
+
/**
|
|
42
|
+
* This is to handle users in connect-only who are signing in with social/email
|
|
43
|
+
* with an embedded wallet
|
|
44
|
+
*/
|
|
45
|
+
if (authMode === 'connect-only' &&
|
|
46
|
+
linkedWallets.find((wallet) => isEmbeddedConnector(wallet.connector))) {
|
|
47
|
+
return linkedWallets;
|
|
48
|
+
}
|
|
41
49
|
return connectedWallets;
|
|
42
50
|
}, [authMode, connectedWallets, linkedWallets, user, onboardingOnlyJwt]);
|
|
43
51
|
/**
|
|
@@ -50,11 +58,8 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
50
58
|
useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
|
|
51
59
|
wallet.connector.initEventListener();
|
|
52
60
|
}), [walletsBasedOnAuthMode]);
|
|
53
|
-
const { connectedWalletMap,
|
|
61
|
+
const { connectedWalletMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode);
|
|
54
62
|
const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletMap[wallet.id]) }))), [connectedWalletMap, walletsBasedOnAuthMode]);
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
computeConnectedStateForWallets();
|
|
57
|
-
}, [primaryWalletId, computeConnectedStateForWallets]);
|
|
58
63
|
const getPrimaryWallet = useCallback(() => { var _a; return (_a = wallets.find((wallet) => wallet.id === primaryWalletId)) !== null && _a !== void 0 ? _a : null; }, [primaryWalletId, wallets]);
|
|
59
64
|
const getSecondaryWallets = useCallback(() => canHaveMultipleWalletsConnected
|
|
60
65
|
? wallets.filter((wallet) => wallet.id !== primaryWalletId)
|
|
@@ -155,7 +160,6 @@ const useWalletConnectors = ({ authMode, authToken, connectedWallets, wallets: a
|
|
|
155
160
|
]);
|
|
156
161
|
const walletConnectors = wallets.map((wallet) => wallet.connector);
|
|
157
162
|
return {
|
|
158
|
-
computeConnectedStateForWallets,
|
|
159
163
|
didConnectedStateLoad,
|
|
160
164
|
getPrimaryWallet,
|
|
161
165
|
getSecondaryWallets,
|
|
@@ -18,7 +18,7 @@ require('@dynamic-labs/utils');
|
|
|
18
18
|
require('../../../shared/consts/index.cjs');
|
|
19
19
|
var useWalletConnectorEvent = require('../useWalletConnectorEvent/useWalletConnectorEvent.cjs');
|
|
20
20
|
|
|
21
|
-
const useWalletEventListeners = ({
|
|
21
|
+
const useWalletEventListeners = ({ handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnectorKey, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }) => {
|
|
22
22
|
const [loadingNetwork, setLoadingNetwork] = React.useState(true);
|
|
23
23
|
const [network, setNetwork] = React.useState(undefined);
|
|
24
24
|
React.useEffect(() => {
|
|
@@ -57,7 +57,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
57
57
|
setNetwork(parseInt(chain));
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
-
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) =>
|
|
60
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) => {
|
|
61
61
|
logger.logger.debug('primary wallet account change', {
|
|
62
62
|
accounts,
|
|
63
63
|
});
|
|
@@ -91,7 +91,6 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
91
91
|
if (user) {
|
|
92
92
|
setMultiWalletWidgetState('detected_new_wallet');
|
|
93
93
|
setSelectedWalletConnectorKey(primaryWallet.connector.key);
|
|
94
|
-
yield computeConnectedStateForWallets();
|
|
95
94
|
return;
|
|
96
95
|
}
|
|
97
96
|
}
|
|
@@ -99,8 +98,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
99
98
|
logger.logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
100
99
|
setMultiWalletWidgetState('idle');
|
|
101
100
|
}
|
|
102
|
-
|
|
103
|
-
}));
|
|
101
|
+
});
|
|
104
102
|
const uniqueNonPrimaryWallets = React.useMemo(() => {
|
|
105
103
|
const primaryConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
|
|
106
104
|
const secondaryConnectors = secondaryWallets.map(({ connector }) => connector);
|
|
@@ -114,35 +112,36 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
114
112
|
}
|
|
115
113
|
return Array.from(allWalletConnectors);
|
|
116
114
|
}, [secondaryWallets, selectedWalletConnector, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
|
|
117
|
-
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', (changedConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
118
116
|
logger.logger.debug('secondary wallet account change');
|
|
119
117
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
120
|
-
|
|
118
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
119
|
+
for (const wallet of affectedWallets)
|
|
120
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
121
121
|
return;
|
|
122
122
|
}
|
|
123
123
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
124
124
|
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
125
125
|
}
|
|
126
|
-
yield computeConnectedStateForWallets();
|
|
127
126
|
}));
|
|
128
|
-
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
127
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', (changedConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
129
128
|
logger.logger.debug('secondary wallet chain change');
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
129
|
+
// Get all wallets with this connector
|
|
130
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
131
|
+
for (const wallet of affectedWallets)
|
|
132
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
135
133
|
}));
|
|
136
|
-
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
134
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
137
135
|
logger.logger.debug('secondary wallet disconnect');
|
|
138
136
|
// argent sends a disconnect event when the user adds a new account
|
|
139
|
-
if (authMode === 'connect-only'
|
|
140
|
-
|
|
141
|
-
secondaryWallets
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
if (authMode === 'connect-only') {
|
|
138
|
+
// Get all wallets with this connector
|
|
139
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === affectedConnector.key);
|
|
140
|
+
for (const wallet of affectedWallets) {
|
|
141
|
+
if (wallet.connector.key === 'argentx')
|
|
142
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
143
|
+
}
|
|
144
144
|
}
|
|
145
|
-
computeConnectedStateForWallets();
|
|
146
145
|
});
|
|
147
146
|
const handleAccountChangeWhenAwaitingAccountSwitch = React.useCallback((isPrimaryWallet, newAddress) => {
|
|
148
147
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -4,7 +4,6 @@ import { AuthModeType, MultiWalletWidgetState, UserProfile, Wallet, WalletWithAc
|
|
|
4
4
|
import { MultiWalletWidgetStateSetter } from '../multiWallet';
|
|
5
5
|
import { IDynamicContext } from '../../../context/DynamicContext/types';
|
|
6
6
|
export type UseWalletEventListenersArgs = {
|
|
7
|
-
computeConnectedStateForWallets(): Promise<void>;
|
|
8
7
|
handleLogOut(): Promise<void>;
|
|
9
8
|
multiWallet: boolean;
|
|
10
9
|
multiWalletWidgetState: MultiWalletWidgetState;
|
|
@@ -20,7 +19,7 @@ export type UseWalletEventListenersArgs = {
|
|
|
20
19
|
authMode: AuthModeType;
|
|
21
20
|
refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector, shouldCallCallback?: boolean) => Promise<void>;
|
|
22
21
|
};
|
|
23
|
-
export declare const useWalletEventListeners: ({
|
|
22
|
+
export declare const useWalletEventListeners: ({ handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnectorKey, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }: UseWalletEventListenersArgs) => {
|
|
24
23
|
loadingNetwork: boolean;
|
|
25
24
|
network: string | number | undefined;
|
|
26
25
|
setNetwork: import("react").Dispatch<import("react").SetStateAction<string | number | undefined>>;
|
|
@@ -14,7 +14,7 @@ import '@dynamic-labs/utils';
|
|
|
14
14
|
import '../../../shared/consts/index.js';
|
|
15
15
|
import { useWalletConnectorEvent } from '../useWalletConnectorEvent/useWalletConnectorEvent.js';
|
|
16
16
|
|
|
17
|
-
const useWalletEventListeners = ({
|
|
17
|
+
const useWalletEventListeners = ({ handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnectorKey, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }) => {
|
|
18
18
|
const [loadingNetwork, setLoadingNetwork] = useState(true);
|
|
19
19
|
const [network, setNetwork] = useState(undefined);
|
|
20
20
|
useEffect(() => {
|
|
@@ -53,7 +53,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
53
53
|
setNetwork(parseInt(chain));
|
|
54
54
|
}
|
|
55
55
|
});
|
|
56
|
-
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) =>
|
|
56
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', (_, { accounts }) => {
|
|
57
57
|
logger.debug('primary wallet account change', {
|
|
58
58
|
accounts,
|
|
59
59
|
});
|
|
@@ -87,7 +87,6 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
87
87
|
if (user) {
|
|
88
88
|
setMultiWalletWidgetState('detected_new_wallet');
|
|
89
89
|
setSelectedWalletConnectorKey(primaryWallet.connector.key);
|
|
90
|
-
yield computeConnectedStateForWallets();
|
|
91
90
|
return;
|
|
92
91
|
}
|
|
93
92
|
}
|
|
@@ -95,8 +94,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
95
94
|
logger.error(`Unexpected multiWalletWidgetState (${multiWalletWidgetState}) and onAccountChange combination. Resetting state to idle.`);
|
|
96
95
|
setMultiWalletWidgetState('idle');
|
|
97
96
|
}
|
|
98
|
-
|
|
99
|
-
}));
|
|
97
|
+
});
|
|
100
98
|
const uniqueNonPrimaryWallets = useMemo(() => {
|
|
101
99
|
const primaryConnector = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
|
|
102
100
|
const secondaryConnectors = secondaryWallets.map(({ connector }) => connector);
|
|
@@ -110,35 +108,36 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
110
108
|
}
|
|
111
109
|
return Array.from(allWalletConnectors);
|
|
112
110
|
}, [secondaryWallets, selectedWalletConnector, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
|
|
113
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', (changedConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
112
|
logger.debug('secondary wallet account change');
|
|
115
113
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
116
|
-
|
|
114
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
115
|
+
for (const wallet of affectedWallets)
|
|
116
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
117
117
|
return;
|
|
118
118
|
}
|
|
119
119
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
120
120
|
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
121
121
|
}
|
|
122
|
-
yield computeConnectedStateForWallets();
|
|
123
122
|
}));
|
|
124
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', (changedConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
124
|
logger.debug('secondary wallet chain change');
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
125
|
+
// Get all wallets with this connector
|
|
126
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
127
|
+
for (const wallet of affectedWallets)
|
|
128
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
131
129
|
}));
|
|
132
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
130
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
133
131
|
logger.debug('secondary wallet disconnect');
|
|
134
132
|
// argent sends a disconnect event when the user adds a new account
|
|
135
|
-
if (authMode === 'connect-only'
|
|
136
|
-
|
|
137
|
-
secondaryWallets
|
|
138
|
-
|
|
139
|
-
|
|
133
|
+
if (authMode === 'connect-only') {
|
|
134
|
+
// Get all wallets with this connector
|
|
135
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === affectedConnector.key);
|
|
136
|
+
for (const wallet of affectedWallets) {
|
|
137
|
+
if (wallet.connector.key === 'argentx')
|
|
138
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
139
|
+
}
|
|
140
140
|
}
|
|
141
|
-
computeConnectedStateForWallets();
|
|
142
141
|
});
|
|
143
142
|
const handleAccountChangeWhenAwaitingAccountSwitch = useCallback((isPrimaryWallet, newAddress) => {
|
|
144
143
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -16,8 +16,10 @@ require('../../../shared/utils/classes/storage/localStorage.cjs');
|
|
|
16
16
|
require('viem');
|
|
17
17
|
require('@dynamic-labs/utils');
|
|
18
18
|
require('../../../shared/consts/index.cjs');
|
|
19
|
+
var useWalletConnectorEvent = require('../useWalletConnectorEvent/useWalletConnectorEvent.cjs');
|
|
19
20
|
require('@dynamic-labs/multi-wallet');
|
|
20
21
|
var isWalletConnected = require('../../functions/isWalletConnected/isWalletConnected.cjs');
|
|
22
|
+
var useEventListener = require('../useEventListener/useEventListener.cjs');
|
|
21
23
|
|
|
22
24
|
const connectedWalletStateReducer = (state, connectedWalletsMap) => {
|
|
23
25
|
const isConnectedWalletsMapEmpty = Object.values(connectedWalletsMap).length === 0;
|
|
@@ -26,14 +28,23 @@ const connectedWalletStateReducer = (state, connectedWalletsMap) => {
|
|
|
26
28
|
}
|
|
27
29
|
return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: true });
|
|
28
30
|
};
|
|
29
|
-
const useWalletsConnectionState = (
|
|
31
|
+
const useWalletsConnectionState = (wallets) => {
|
|
30
32
|
const [state, setState] = React.useReducer(connectedWalletStateReducer, {
|
|
31
33
|
connectedWalletsMap: {},
|
|
32
34
|
didLoad: false,
|
|
33
35
|
});
|
|
36
|
+
const refreshKey = wallets.map(({ id }) => id).join('-');
|
|
37
|
+
const connectors = wallets.map(({ connector }) => connector);
|
|
34
38
|
const lastCallTimestamp = React.useRef(0);
|
|
35
39
|
const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
|
|
40
|
+
const connectedWalletsMap = {};
|
|
41
|
+
yield Promise.all(wallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
+
connectedWalletsMap[wallet.id] = yield isWalletConnected.isWalletConnected(wallet);
|
|
43
|
+
})));
|
|
44
|
+
setState(connectedWalletsMap);
|
|
45
|
+
}), [wallets]);
|
|
46
|
+
const handleOnEventUpdate = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
if (!wallets.length)
|
|
37
48
|
return;
|
|
38
49
|
const callTimestamp = new Date().getTime();
|
|
39
50
|
const diffFromLastCall = callTimestamp - lastCallTimestamp.current;
|
|
@@ -44,14 +55,26 @@ const useWalletsConnectionState = (linkedWallets) => {
|
|
|
44
55
|
logger.logger.warn('computeConnectedStateForWallets: skipping due too many calls.');
|
|
45
56
|
return;
|
|
46
57
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
58
|
+
computeConnectedStateForWallets();
|
|
59
|
+
}), [computeConnectedStateForWallets, wallets.length]);
|
|
60
|
+
useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'accountChange', handleOnEventUpdate);
|
|
61
|
+
useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'disconnect', handleOnEventUpdate);
|
|
62
|
+
useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'chainChange', handleOnEventUpdate);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
computeConnectedStateForWallets();
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* This is using a custom key to force the useEffect to run only when a connector is
|
|
68
|
+
* added or removed from the connectors list.
|
|
69
|
+
*/
|
|
70
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
71
|
+
[refreshKey]);
|
|
72
|
+
/**
|
|
73
|
+
* This is a workaround to detect when the user switches to another tab/extension
|
|
74
|
+
* and then comes back to the dapp.
|
|
75
|
+
*/
|
|
76
|
+
useEventListener.useEventListener('focus', computeConnectedStateForWallets);
|
|
53
77
|
return {
|
|
54
|
-
computeConnectedStateForWallets,
|
|
55
78
|
connectedWalletMap: state.connectedWalletsMap,
|
|
56
79
|
didConnectedStateLoad: state.didLoad,
|
|
57
80
|
};
|
|
@@ -6,7 +6,6 @@ type ConnectedState = {
|
|
|
6
6
|
};
|
|
7
7
|
};
|
|
8
8
|
type WalletsConnectionStateHook = (wallets: Wallet[]) => {
|
|
9
|
-
computeConnectedStateForWallets: () => Promise<void>;
|
|
10
9
|
connectedWalletMap: ConnectedState['connectedWalletsMap'];
|
|
11
10
|
didConnectedStateLoad: ConnectedState['didLoad'];
|
|
12
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
2
|
-
import { useReducer, useRef, useCallback } from 'react';
|
|
2
|
+
import { useReducer, useRef, useCallback, useEffect } from 'react';
|
|
3
3
|
import '@dynamic-labs/sdk-api';
|
|
4
4
|
import { logger } from '../../../shared/logger.js';
|
|
5
5
|
import '@dynamic-labs/iconic';
|
|
@@ -12,8 +12,10 @@ import '../../../shared/utils/classes/storage/localStorage.js';
|
|
|
12
12
|
import 'viem';
|
|
13
13
|
import '@dynamic-labs/utils';
|
|
14
14
|
import '../../../shared/consts/index.js';
|
|
15
|
+
import { useWalletConnectorEvent } from '../useWalletConnectorEvent/useWalletConnectorEvent.js';
|
|
15
16
|
import '@dynamic-labs/multi-wallet';
|
|
16
17
|
import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
|
|
18
|
+
import { useEventListener } from '../useEventListener/useEventListener.js';
|
|
17
19
|
|
|
18
20
|
const connectedWalletStateReducer = (state, connectedWalletsMap) => {
|
|
19
21
|
const isConnectedWalletsMapEmpty = Object.values(connectedWalletsMap).length === 0;
|
|
@@ -22,14 +24,23 @@ const connectedWalletStateReducer = (state, connectedWalletsMap) => {
|
|
|
22
24
|
}
|
|
23
25
|
return Object.assign(Object.assign({}, state), { connectedWalletsMap, didLoad: true });
|
|
24
26
|
};
|
|
25
|
-
const useWalletsConnectionState = (
|
|
27
|
+
const useWalletsConnectionState = (wallets) => {
|
|
26
28
|
const [state, setState] = useReducer(connectedWalletStateReducer, {
|
|
27
29
|
connectedWalletsMap: {},
|
|
28
30
|
didLoad: false,
|
|
29
31
|
});
|
|
32
|
+
const refreshKey = wallets.map(({ id }) => id).join('-');
|
|
33
|
+
const connectors = wallets.map(({ connector }) => connector);
|
|
30
34
|
const lastCallTimestamp = useRef(0);
|
|
31
35
|
const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
32
|
-
|
|
36
|
+
const connectedWalletsMap = {};
|
|
37
|
+
yield Promise.all(wallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
|
|
38
|
+
connectedWalletsMap[wallet.id] = yield isWalletConnected(wallet);
|
|
39
|
+
})));
|
|
40
|
+
setState(connectedWalletsMap);
|
|
41
|
+
}), [wallets]);
|
|
42
|
+
const handleOnEventUpdate = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
if (!wallets.length)
|
|
33
44
|
return;
|
|
34
45
|
const callTimestamp = new Date().getTime();
|
|
35
46
|
const diffFromLastCall = callTimestamp - lastCallTimestamp.current;
|
|
@@ -40,14 +51,26 @@ const useWalletsConnectionState = (linkedWallets) => {
|
|
|
40
51
|
logger.warn('computeConnectedStateForWallets: skipping due too many calls.');
|
|
41
52
|
return;
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
54
|
+
computeConnectedStateForWallets();
|
|
55
|
+
}), [computeConnectedStateForWallets, wallets.length]);
|
|
56
|
+
useWalletConnectorEvent(connectors, 'accountChange', handleOnEventUpdate);
|
|
57
|
+
useWalletConnectorEvent(connectors, 'disconnect', handleOnEventUpdate);
|
|
58
|
+
useWalletConnectorEvent(connectors, 'chainChange', handleOnEventUpdate);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
computeConnectedStateForWallets();
|
|
61
|
+
},
|
|
62
|
+
/**
|
|
63
|
+
* This is using a custom key to force the useEffect to run only when a connector is
|
|
64
|
+
* added or removed from the connectors list.
|
|
65
|
+
*/
|
|
66
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
+
[refreshKey]);
|
|
68
|
+
/**
|
|
69
|
+
* This is a workaround to detect when the user switches to another tab/extension
|
|
70
|
+
* and then comes back to the dapp.
|
|
71
|
+
*/
|
|
72
|
+
useEventListener('focus', computeConnectedStateForWallets);
|
|
49
73
|
return {
|
|
50
|
-
computeConnectedStateForWallets,
|
|
51
74
|
connectedWalletMap: state.connectedWalletsMap,
|
|
52
75
|
didConnectedStateLoad: state.didLoad,
|
|
53
76
|
};
|
|
@@ -83,7 +83,7 @@ const CollectUserDataView = () => {
|
|
|
83
83
|
const evmNetworks = walletConnector.evmNetworks || [];
|
|
84
84
|
const _isSupportedNetwork = !network || isSupportedNetwork.isSupportedNetwork({ network, walletConnector });
|
|
85
85
|
const walletAddress = (_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.verifiedCredentials.find((verifiedCredential) => verifiedCredential.id === userProfile.lastVerifiedCredentialId)) === null || _a === void 0 ? void 0 : _a.address;
|
|
86
|
-
return (jsxRuntime.jsxs("div", { className: 'collect-user-data', "data-testid": 'collect-user-data-view', children: [jsxRuntime.jsxs("div", { className: 'collect-user-data__network-container', children: [jsxRuntime.jsxs("div", { className: 'collect-user-data__img-container', children: [(nameService === null || nameService === void 0 ? void 0 : nameService.avatar) ? (jsxRuntime.jsx("img", { src: nameService.avatar, alt: '', className: 'collect-user-data__img collect-user-data__img--rounded' })) : (jsxRuntime.jsx(AuthProviderIcon.AuthProviderIcon, { jwt: onboardingOnlyJwt, iconSize: 28 })), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', weight: 'medium', className: 'collect-user-data__wallet-address', children: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || shortenWalletAddress.shortenWalletAddress(walletAddress, 3, 3) })] }), jsxRuntime.jsx(NetworkPicker.NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, showNetworkName: true, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, buttonClassName: 'collect-user-data__network-picker-button', mainClassName: 'collect-user-data__network-picker' })] }), onboardingImageUrl && (jsxRuntime.jsx("img", { className: 'collect-user-data__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { withIcon: false, className: 'collect-user-data__error--not-supported', children: t('dyn_collect_user_data.not_supported_network.error_message') })), jsxRuntime.jsxs("div", { className: classNames.classNames('collect-user-data__form', {
|
|
86
|
+
return (jsxRuntime.jsxs("div", { className: 'collect-user-data', "data-testid": 'collect-user-data-view', children: [jsxRuntime.jsxs("div", { className: 'collect-user-data__network-container', children: [jsxRuntime.jsxs("div", { className: 'collect-user-data__img-container', children: [(nameService === null || nameService === void 0 ? void 0 : nameService.avatar) ? (jsxRuntime.jsx("img", { src: nameService.avatar, alt: '', className: 'collect-user-data__img collect-user-data__img--rounded' })) : (jsxRuntime.jsx(AuthProviderIcon.AuthProviderIcon, { jwt: onboardingOnlyJwt, iconSize: 28 })), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', weight: 'medium', className: 'collect-user-data__wallet-address', children: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || shortenWalletAddress.shortenWalletAddress(walletAddress, 3, 3) })] }), jsxRuntime.jsx(NetworkPicker.NetworkPicker, { currentNetwork: network, evmNetworks: evmNetworks, connector: walletConnector, showNetworkName: true, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, buttonClassName: 'collect-user-data__network-picker-button', mainClassName: 'collect-user-data__network-picker' })] }), onboardingImageUrl && (jsxRuntime.jsx("img", { className: 'collect-user-data__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsxRuntime.jsx(ErrorContainer.ErrorContainer, { withIcon: false, className: 'collect-user-data__error--not-supported', children: t('dyn_collect_user_data.not_supported_network.error_message') })), jsxRuntime.jsxs("div", { className: classNames.classNames('collect-user-data__form', {
|
|
87
87
|
'collect-user-data__form--error': !_isSupportedNetwork,
|
|
88
88
|
}), children: [jsxRuntime.jsx("div", { className: 'collect-user-data__success-icon', children: jsxRuntime.jsx(Icon.Icon, { color: 'text-primary', size: 'large', children: jsxRuntime.jsx(checkConnection.ReactComponent, {}) }) }), jsxRuntime.jsx(OnboardingUserDataForm.OnboardingUserDataForm, { disableSubmit: !_isSupportedNetwork, userProfile: userProfile, children: !_isSupportedNetwork ? (jsxRuntime.jsxs("div", { className: 'collect-user-data__welcome-container', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'title', color: 'primary', className: 'collect-user-data__welcome-title', children: t('dyn_collect_user_data.not_supported_network.title') }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: t('dyn_collect_user_data.not_supported_network.description') })] })) : (jsxRuntime.jsxs("div", { className: 'collect-user-data__welcome-container', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'title', color: 'primary', className: 'collect-user-data__welcome-title', children: (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general.collectUserDataWelcomeHeader) ||
|
|
89
89
|
t('dyn_collect_user_data.greeting', { appName }) }), jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general.collectUserDataWelcomeMessage) ||
|
|
@@ -79,7 +79,7 @@ const CollectUserDataView = () => {
|
|
|
79
79
|
const evmNetworks = walletConnector.evmNetworks || [];
|
|
80
80
|
const _isSupportedNetwork = !network || isSupportedNetwork({ network, walletConnector });
|
|
81
81
|
const walletAddress = (_a = userProfile === null || userProfile === void 0 ? void 0 : userProfile.verifiedCredentials.find((verifiedCredential) => verifiedCredential.id === userProfile.lastVerifiedCredentialId)) === null || _a === void 0 ? void 0 : _a.address;
|
|
82
|
-
return (jsxs("div", { className: 'collect-user-data', "data-testid": 'collect-user-data-view', children: [jsxs("div", { className: 'collect-user-data__network-container', children: [jsxs("div", { className: 'collect-user-data__img-container', children: [(nameService === null || nameService === void 0 ? void 0 : nameService.avatar) ? (jsx("img", { src: nameService.avatar, alt: '', className: 'collect-user-data__img collect-user-data__img--rounded' })) : (jsx(AuthProviderIcon, { jwt: onboardingOnlyJwt, iconSize: 28 })), jsx(Typography, { variant: 'body_normal', color: 'primary', weight: 'medium', className: 'collect-user-data__wallet-address', children: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || shortenWalletAddress(walletAddress, 3, 3) })] }), jsx(NetworkPicker, { evmNetworks: evmNetworks, connector: walletConnector, showNetworkName: true, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, buttonClassName: 'collect-user-data__network-picker-button', mainClassName: 'collect-user-data__network-picker' })] }), onboardingImageUrl && (jsx("img", { className: 'collect-user-data__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsx(ErrorContainer, { withIcon: false, className: 'collect-user-data__error--not-supported', children: t('dyn_collect_user_data.not_supported_network.error_message') })), jsxs("div", { className: classNames('collect-user-data__form', {
|
|
82
|
+
return (jsxs("div", { className: 'collect-user-data', "data-testid": 'collect-user-data-view', children: [jsxs("div", { className: 'collect-user-data__network-container', children: [jsxs("div", { className: 'collect-user-data__img-container', children: [(nameService === null || nameService === void 0 ? void 0 : nameService.avatar) ? (jsx("img", { src: nameService.avatar, alt: '', className: 'collect-user-data__img collect-user-data__img--rounded' })) : (jsx(AuthProviderIcon, { jwt: onboardingOnlyJwt, iconSize: 28 })), jsx(Typography, { variant: 'body_normal', color: 'primary', weight: 'medium', className: 'collect-user-data__wallet-address', children: (nameService === null || nameService === void 0 ? void 0 : nameService.name) || shortenWalletAddress(walletAddress, 3, 3) })] }), jsx(NetworkPicker, { currentNetwork: network, evmNetworks: evmNetworks, connector: walletConnector, showNetworkName: true, isNetworkPickerOpen: isNetworkPickerOpen, setIsNetworkPickerOpen: setIsNetworkPickerOpen, buttonClassName: 'collect-user-data__network-picker-button', mainClassName: 'collect-user-data__network-picker' })] }), onboardingImageUrl && (jsx("img", { className: 'collect-user-data__main-img', src: onboardingImageUrl, alt: 'onboarding' })), !_isSupportedNetwork && (jsx(ErrorContainer, { withIcon: false, className: 'collect-user-data__error--not-supported', children: t('dyn_collect_user_data.not_supported_network.error_message') })), jsxs("div", { className: classNames('collect-user-data__form', {
|
|
83
83
|
'collect-user-data__form--error': !_isSupportedNetwork,
|
|
84
84
|
}), children: [jsx("div", { className: 'collect-user-data__success-icon', children: jsx(Icon, { color: 'text-primary', size: 'large', children: jsx(SvgCheckConnection, {}) }) }), jsx(OnboardingUserDataForm, { disableSubmit: !_isSupportedNetwork, userProfile: userProfile, children: !_isSupportedNetwork ? (jsxs("div", { className: 'collect-user-data__welcome-container', children: [jsx(Typography, { variant: 'title', color: 'primary', className: 'collect-user-data__welcome-title', children: t('dyn_collect_user_data.not_supported_network.title') }), jsx(Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: t('dyn_collect_user_data.not_supported_network.description') })] })) : (jsxs("div", { className: 'collect-user-data__welcome-container', children: [jsx(Typography, { variant: 'title', color: 'primary', className: 'collect-user-data__welcome-title', children: (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general.collectUserDataWelcomeHeader) ||
|
|
85
85
|
t('dyn_collect_user_data.greeting', { appName }) }), jsx(Typography, { variant: 'body_normal', weight: 'regular', color: 'secondary', children: (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.general.collectUserDataWelcomeMessage) ||
|