@dynamic-labs/sdk-react-core 0.19.5 → 0.19.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 +24 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -9
- package/src/index.cjs +2 -0
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -0
- package/src/lib/Main.cjs +1 -0
- package/src/lib/Main.js +1 -0
- package/src/lib/components/Accordion/components/AccordionItem/AccordionItem.cjs +1 -1
- package/src/lib/components/Accordion/components/AccordionItem/AccordionItem.js +1 -1
- package/src/lib/components/AnimatePresence/AnimatePresence.cjs +1 -1
- package/src/lib/components/AnimatePresence/AnimatePresence.js +1 -1
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.cjs +1 -1
- package/src/lib/components/AuthProviderIcon/AuthProviderIcon.js +1 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.cjs +1 -1
- package/src/lib/components/MenuList/Dropdown/Dropdown.js +1 -1
- package/src/lib/components/Modal/Modal.cjs +1 -1
- package/src/lib/components/Modal/Modal.js +1 -1
- package/src/lib/components/NeedHelpSection/NeedHelpSection.cjs +5 -4
- package/src/lib/components/NeedHelpSection/NeedHelpSection.js +5 -4
- package/src/lib/components/NetworkPicker/NetworkPicker.cjs +11 -9
- package/src/lib/components/NetworkPicker/NetworkPicker.d.ts +2 -1
- package/src/lib/components/NetworkPicker/NetworkPicker.js +11 -9
- package/src/lib/components/OverlayCard/OverlayCard.cjs +1 -1
- package/src/lib/components/OverlayCard/OverlayCard.js +1 -1
- package/src/lib/components/Portal/Portal.cjs +1 -1
- package/src/lib/components/Portal/Portal.js +1 -1
- package/src/lib/components/SendBalancePageLayout/components/TokenBalanceCard/TokenBalanceCard.cjs +2 -1
- package/src/lib/components/SendBalancePageLayout/components/TokenBalanceCard/TokenBalanceCard.js +2 -1
- package/src/lib/components/SocialSignIn/SocialSignIn.cjs +1 -1
- package/src/lib/components/SocialSignIn/SocialSignIn.js +1 -1
- package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.cjs +1 -1
- package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.js +1 -1
- package/src/lib/components/Tooltip/Tooltip.cjs +1 -1
- package/src/lib/components/Tooltip/Tooltip.js +1 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.cjs +1 -1
- package/src/lib/components/TransactionStatusLayout/TransactionStatusLayout.js +1 -1
- package/src/lib/components/Transition/VerticalDrawerTransition/VerticalDrawerTransition.cjs +1 -1
- package/src/lib/components/Transition/VerticalDrawerTransition/VerticalDrawerTransition.js +1 -1
- package/src/lib/components/UserAddress/UserAddress.cjs +1 -1
- package/src/lib/components/UserAddress/UserAddress.js +1 -1
- package/src/lib/context/DynamicContext/DynamicContext.cjs +16 -13
- package/src/lib/context/DynamicContext/DynamicContext.js +16 -13
- package/src/lib/context/DynamicContext/useCustomerCallbacks/types.d.ts +3 -5
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerAuthFlowCallbacks.cjs +1 -1
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerAuthFlowCallbacks.js +1 -1
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.cjs +5 -24
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.d.ts +1 -1
- package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.js +5 -24
- package/src/lib/context/MockContext/MockContext.cjs +1 -0
- package/src/lib/context/MockContext/MockContext.js +1 -0
- package/src/lib/context/QrCodeContext/QrCodeContext.cjs +1 -1
- package/src/lib/context/QrCodeContext/QrCodeContext.js +1 -1
- package/src/lib/context/SendBalanceContext/SendBalanceContext.cjs +1 -1
- package/src/lib/context/SendBalanceContext/SendBalanceContext.js +1 -1
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +16 -2
- package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +17 -3
- package/src/lib/context/UserFieldEditorContext/UserFieldEditorContext.cjs +1 -1
- package/src/lib/context/UserFieldEditorContext/UserFieldEditorContext.js +1 -1
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.cjs +1 -0
- package/src/lib/layout/DynamicUserProfileLayout/DynamicUserProfileLayout.js +1 -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/utils/groupWalletOptions/groupWalletOptions.cjs +5 -3
- package/src/lib/utils/functions/walletListBuilder/utils/groupWalletOptions/groupWalletOptions.js +5 -3
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.cjs +8 -9
- package/src/lib/utils/hooks/useConnectedWalletsNetworkValidation/useConnectedWalletsNetworkValidation.js +8 -9
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.cjs +34 -5
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.d.ts +33 -1
- package/src/lib/utils/hooks/useWalletConnectorEvent/useWalletConnectorEvent.js +34 -5
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +19 -18
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +2 -1
- package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +19 -18
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.cjs +1 -1
- package/src/lib/utils/hooks/useWalletUiUtils/useWalletUiUtils.js +1 -1
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +32 -8
- package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +33 -9
- package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +1 -1
- package/src/lib/views/CollectUserDataView/CollectUserDataView.js +1 -1
- package/src/lib/views/EmailVerification/EmailVerification.cjs +2 -5
- package/src/lib/views/EmailVerification/EmailVerification.js +2 -5
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +9 -3
- package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +9 -3
- package/src/lib/views/LoginView/useLoginView.cjs +5 -0
- package/src/lib/views/LoginView/useLoginView.js +5 -0
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.cjs +6 -3
- package/src/lib/views/NetworkNotSupported/NetworkNotSupported.js +6 -3
- package/src/lib/views/QrCodeView/QRCode.cjs +1 -1
- package/src/lib/views/QrCodeView/QRCode.js +1 -1
- package/src/lib/views/QrCodeView/QrCodeView.cjs +1 -1
- package/src/lib/views/QrCodeView/QrCodeView.js +1 -1
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.cjs +1 -1
- package/src/lib/views/SendBalanceView/components/TransactionStage/TransactionStage.js +1 -1
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +1 -1
- package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +1 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.cjs +1 -1
- package/src/lib/views/TransactionConfirmationView/hooks/useTransactionGas/useTransactionGas.js +1 -1
- package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedUserProfile/DynamicEmbeddedUserProfile.cjs +1 -0
- package/src/lib/widgets/DynamicEmbeddedWidget/DynamicEmbeddedUserProfile/DynamicEmbeddedUserProfile.js +1 -0
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +1 -1
- 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/DynamicUserProfile/DynamicUserProfile.cjs +1 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicUserProfile/DynamicUserProfile.js +1 -0
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js +1 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetVariants/variants/DynamicWidgetDropdown/DynamicWidgetDropdown.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/components/DynamicWidgetVariants/variants/DynamicWidgetDropdown/DynamicWidgetDropdown.js +1 -1
- package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.cjs +6 -2
- package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.js +6 -2
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.cjs +1 -1
- package/src/lib/widgets/DynamicWidget/context/DynamicWidgetContext.js +1 -1
- package/src/lib/widgets/DynamicWidget/helpers/helpers.cjs +7 -7
- package/src/lib/widgets/DynamicWidget/helpers/helpers.d.ts +1 -1
- package/src/lib/widgets/DynamicWidget/helpers/helpers.js +7 -7
|
@@ -3,13 +3,42 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var React = require('react');
|
|
6
|
-
var useIsomorphicLayoutEffect = require('../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.cjs');
|
|
7
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Hook for handling events from a WalletConnector or an array of WalletConnectors.
|
|
9
|
+
* This hook allows you to specify an event to listen to and a handler function that will be called
|
|
10
|
+
* whenever the event is emitted. The handler will receive the event arguments followed by the instance
|
|
11
|
+
* of the WalletConnector that emitted the event.
|
|
12
|
+
*
|
|
13
|
+
* @template Event - The type of the event to listen for, which should be a key of WalletConnectorEventTypes.
|
|
14
|
+
*
|
|
15
|
+
* @param eventEmitters - The WalletConnector instance(s) to attach the event listener to.
|
|
16
|
+
* If an array is provided, the event listener is attached to all provided connectors.
|
|
17
|
+
* @param eventName - The name of the event to listen for.
|
|
18
|
+
* @param handler - The callback function to execute when the event is emitted.
|
|
19
|
+
* The arguments to the callback are the arguments emitted with the event, followed by the WalletConnector instance
|
|
20
|
+
* that emitted the event.
|
|
21
|
+
*
|
|
22
|
+
* @returns {void} This hook does not return anything.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // Example usage of useWalletConnectorEvent
|
|
26
|
+
* const { primaryWallet } = useDynamicContext();
|
|
27
|
+
*
|
|
28
|
+
* useWalletConnectorEvent(
|
|
29
|
+
* primaryWallet?.connector,
|
|
30
|
+
* 'accountChange',
|
|
31
|
+
* ({ accounts }, connector) => {
|
|
32
|
+
* console.group('accountChange');
|
|
33
|
+
* console.log('accounts', accounts);
|
|
34
|
+
* console.log('connector that emitted', connector);
|
|
35
|
+
* console.groupEnd();
|
|
36
|
+
* },
|
|
37
|
+
* );
|
|
38
|
+
*/
|
|
8
39
|
const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
|
|
9
40
|
const callbackRef = React.useRef(handler);
|
|
10
|
-
|
|
11
|
-
callbackRef.current = handler;
|
|
12
|
-
}, [handler]);
|
|
41
|
+
callbackRef.current = handler;
|
|
13
42
|
React.useEffect(() => {
|
|
14
43
|
if (!eventEmitters)
|
|
15
44
|
return;
|
|
@@ -24,7 +53,7 @@ const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
|
|
|
24
53
|
const uniqueEventEmitters = Array.from(new Set(eventEmittersArray));
|
|
25
54
|
const unsubscribeCallbacks = uniqueEventEmitters.map((emitter) => {
|
|
26
55
|
const callback = (...args) => {
|
|
27
|
-
callbackRef.current(
|
|
56
|
+
callbackRef.current(...args, emitter);
|
|
28
57
|
};
|
|
29
58
|
emitter.on(eventName, callback);
|
|
30
59
|
return () => emitter.off(eventName, callback);
|
|
@@ -8,5 +8,37 @@ type ArgumentMap<T extends object> = {
|
|
|
8
8
|
[K in keyof T]: T[K] extends (...args: any[]) => void ? Parameters<T[K]> : T[K] extends any[] ? T[K] : any[];
|
|
9
9
|
};
|
|
10
10
|
type EventArg<Event extends keyof WalletConnectorEventTypes> = ArgumentMap<WalletConnectorEventTypes>[Extract<Event, keyof WalletConnectorEventTypes>];
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Hook for handling events from a WalletConnector or an array of WalletConnectors.
|
|
13
|
+
* This hook allows you to specify an event to listen to and a handler function that will be called
|
|
14
|
+
* whenever the event is emitted. The handler will receive the event arguments followed by the instance
|
|
15
|
+
* of the WalletConnector that emitted the event.
|
|
16
|
+
*
|
|
17
|
+
* @template Event - The type of the event to listen for, which should be a key of WalletConnectorEventTypes.
|
|
18
|
+
*
|
|
19
|
+
* @param eventEmitters - The WalletConnector instance(s) to attach the event listener to.
|
|
20
|
+
* If an array is provided, the event listener is attached to all provided connectors.
|
|
21
|
+
* @param eventName - The name of the event to listen for.
|
|
22
|
+
* @param handler - The callback function to execute when the event is emitted.
|
|
23
|
+
* The arguments to the callback are the arguments emitted with the event, followed by the WalletConnector instance
|
|
24
|
+
* that emitted the event.
|
|
25
|
+
*
|
|
26
|
+
* @returns {void} This hook does not return anything.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // Example usage of useWalletConnectorEvent
|
|
30
|
+
* const { primaryWallet } = useDynamicContext();
|
|
31
|
+
*
|
|
32
|
+
* useWalletConnectorEvent(
|
|
33
|
+
* primaryWallet?.connector,
|
|
34
|
+
* 'accountChange',
|
|
35
|
+
* ({ accounts }, connector) => {
|
|
36
|
+
* console.group('accountChange');
|
|
37
|
+
* console.log('accounts', accounts);
|
|
38
|
+
* console.log('connector that emitted', connector);
|
|
39
|
+
* console.groupEnd();
|
|
40
|
+
* },
|
|
41
|
+
* );
|
|
42
|
+
*/
|
|
43
|
+
export declare const useWalletConnectorEvent: <Event_1 extends keyof WalletConnectorEventTypes = keyof WalletConnectorEventTypes>(eventEmitters: WalletConnector | WalletConnector[] | undefined, eventName: Event_1, handler: (...args: [...EventArg<Event_1>, import("@dynamic-labs/wallet-connector-core").WalletConnectorCore.WalletConnector]) => void) => void;
|
|
12
44
|
export {};
|
|
@@ -1,11 +1,40 @@
|
|
|
1
1
|
import { useRef, useEffect } from 'react';
|
|
2
|
-
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect/useIsomorphicLayoutEffect.js';
|
|
3
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Hook for handling events from a WalletConnector or an array of WalletConnectors.
|
|
5
|
+
* This hook allows you to specify an event to listen to and a handler function that will be called
|
|
6
|
+
* whenever the event is emitted. The handler will receive the event arguments followed by the instance
|
|
7
|
+
* of the WalletConnector that emitted the event.
|
|
8
|
+
*
|
|
9
|
+
* @template Event - The type of the event to listen for, which should be a key of WalletConnectorEventTypes.
|
|
10
|
+
*
|
|
11
|
+
* @param eventEmitters - The WalletConnector instance(s) to attach the event listener to.
|
|
12
|
+
* If an array is provided, the event listener is attached to all provided connectors.
|
|
13
|
+
* @param eventName - The name of the event to listen for.
|
|
14
|
+
* @param handler - The callback function to execute when the event is emitted.
|
|
15
|
+
* The arguments to the callback are the arguments emitted with the event, followed by the WalletConnector instance
|
|
16
|
+
* that emitted the event.
|
|
17
|
+
*
|
|
18
|
+
* @returns {void} This hook does not return anything.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* // Example usage of useWalletConnectorEvent
|
|
22
|
+
* const { primaryWallet } = useDynamicContext();
|
|
23
|
+
*
|
|
24
|
+
* useWalletConnectorEvent(
|
|
25
|
+
* primaryWallet?.connector,
|
|
26
|
+
* 'accountChange',
|
|
27
|
+
* ({ accounts }, connector) => {
|
|
28
|
+
* console.group('accountChange');
|
|
29
|
+
* console.log('accounts', accounts);
|
|
30
|
+
* console.log('connector that emitted', connector);
|
|
31
|
+
* console.groupEnd();
|
|
32
|
+
* },
|
|
33
|
+
* );
|
|
34
|
+
*/
|
|
4
35
|
const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
|
|
5
36
|
const callbackRef = useRef(handler);
|
|
6
|
-
|
|
7
|
-
callbackRef.current = handler;
|
|
8
|
-
}, [handler]);
|
|
37
|
+
callbackRef.current = handler;
|
|
9
38
|
useEffect(() => {
|
|
10
39
|
if (!eventEmitters)
|
|
11
40
|
return;
|
|
@@ -20,7 +49,7 @@ const useWalletConnectorEvent = (eventEmitters, eventName, handler) => {
|
|
|
20
49
|
const uniqueEventEmitters = Array.from(new Set(eventEmittersArray));
|
|
21
50
|
const unsubscribeCallbacks = uniqueEventEmitters.map((emitter) => {
|
|
22
51
|
const callback = (...args) => {
|
|
23
|
-
callbackRef.current(
|
|
52
|
+
callbackRef.current(...args, emitter);
|
|
24
53
|
};
|
|
25
54
|
emitter.on(eventName, callback);
|
|
26
55
|
return () => emitter.off(eventName, callback);
|
|
@@ -43,7 +43,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
43
43
|
logger.logger.debug('primary wallet disconnect');
|
|
44
44
|
handleLogOut();
|
|
45
45
|
});
|
|
46
|
-
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', (
|
|
46
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', ({ chain }) => {
|
|
47
47
|
logger.logger.debug('primary wallet chain change', { chain });
|
|
48
48
|
if (!primaryWallet) {
|
|
49
49
|
return;
|
|
@@ -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', (
|
|
60
|
+
useWalletConnectorEvent.useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', ({ accounts }) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
61
61
|
logger.logger.debug('primary wallet account change', {
|
|
62
62
|
accounts,
|
|
63
63
|
});
|
|
@@ -114,35 +114,36 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
114
114
|
}
|
|
115
115
|
return Array.from(allWalletConnectors);
|
|
116
116
|
}, [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* () {
|
|
117
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', (_, changedConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
118
118
|
logger.logger.debug('secondary wallet account change');
|
|
119
119
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
120
|
-
|
|
120
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
121
|
+
for (const wallet of affectedWallets)
|
|
122
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
121
123
|
return;
|
|
122
124
|
}
|
|
123
125
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
124
126
|
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
125
127
|
}
|
|
126
|
-
yield computeConnectedStateForWallets();
|
|
127
128
|
}));
|
|
128
|
-
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', (_, changedConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
129
130
|
logger.logger.debug('secondary wallet chain change');
|
|
130
|
-
//
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
131
|
+
// Get all wallets with this connector
|
|
132
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
133
|
+
for (const wallet of affectedWallets)
|
|
134
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
135
135
|
}));
|
|
136
|
-
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
136
|
+
useWalletConnectorEvent.useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
137
137
|
logger.logger.debug('secondary wallet disconnect');
|
|
138
138
|
// argent sends a disconnect event when the user adds a new account
|
|
139
|
-
if (authMode === 'connect-only'
|
|
140
|
-
|
|
141
|
-
secondaryWallets
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
if (authMode === 'connect-only') {
|
|
140
|
+
// Get all wallets with this connector
|
|
141
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === affectedConnector.key);
|
|
142
|
+
for (const wallet of affectedWallets) {
|
|
143
|
+
if (wallet.connector.key === 'argentx')
|
|
144
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
145
|
+
}
|
|
144
146
|
}
|
|
145
|
-
computeConnectedStateForWallets();
|
|
146
147
|
});
|
|
147
148
|
const handleAccountChangeWhenAwaitingAccountSwitch = React.useCallback((isPrimaryWallet, newAddress) => {
|
|
148
149
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import type { WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
3
3
|
import { AuthModeType, MultiWalletWidgetState, UserProfile, Wallet, WalletWithAction } from '../../../shared';
|
|
4
4
|
import { MultiWalletWidgetStateSetter } from '../multiWallet';
|
|
5
|
+
import { IDynamicContext } from '../../../context/DynamicContext/types';
|
|
5
6
|
export type UseWalletEventListenersArgs = {
|
|
6
7
|
computeConnectedStateForWallets(): Promise<void>;
|
|
7
8
|
handleLogOut(): Promise<void>;
|
|
@@ -13,7 +14,7 @@ export type UseWalletEventListenersArgs = {
|
|
|
13
14
|
selectedWalletWithAction: WalletWithAction | null;
|
|
14
15
|
setMultiWalletWidgetState: MultiWalletWidgetStateSetter;
|
|
15
16
|
setPrimaryWalletId(walletId: string): void;
|
|
16
|
-
setSelectedWalletConnector
|
|
17
|
+
setSelectedWalletConnector: IDynamicContext['setSelectedWalletConnector'];
|
|
17
18
|
setSelectedWalletWithAction(walletWithAction: WalletWithAction | null): void;
|
|
18
19
|
user: UserProfile | undefined;
|
|
19
20
|
authMode: AuthModeType;
|
|
@@ -39,7 +39,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
39
39
|
logger.debug('primary wallet disconnect');
|
|
40
40
|
handleLogOut();
|
|
41
41
|
});
|
|
42
|
-
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', (
|
|
42
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'chainChange', ({ chain }) => {
|
|
43
43
|
logger.debug('primary wallet chain change', { chain });
|
|
44
44
|
if (!primaryWallet) {
|
|
45
45
|
return;
|
|
@@ -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', (
|
|
56
|
+
useWalletConnectorEvent(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, 'accountChange', ({ accounts }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
57
|
logger.debug('primary wallet account change', {
|
|
58
58
|
accounts,
|
|
59
59
|
});
|
|
@@ -110,35 +110,36 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
|
|
|
110
110
|
}
|
|
111
111
|
return Array.from(allWalletConnectors);
|
|
112
112
|
}, [secondaryWallets, selectedWalletConnector, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
|
|
113
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
113
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'accountChange', (_, changedConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
114
|
logger.debug('secondary wallet account change');
|
|
115
115
|
if (authMode === 'connect-only' && secondaryWallets.length) {
|
|
116
|
-
|
|
116
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
117
|
+
for (const wallet of affectedWallets)
|
|
118
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
119
121
|
if (multiWalletWidgetState === 'awaiting_account_switch') {
|
|
120
122
|
handleAccountChangeWhenAwaitingAccountSwitch(false, (selectedWalletWithAction === null || selectedWalletWithAction === void 0 ? void 0 : selectedWalletWithAction.wallet.address) || '');
|
|
121
123
|
}
|
|
122
|
-
yield computeConnectedStateForWallets();
|
|
123
124
|
}));
|
|
124
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'chainChange', (_, changedConnector) => __awaiter(void 0, void 0, void 0, function* () {
|
|
125
126
|
logger.debug('secondary wallet chain change');
|
|
126
|
-
//
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
|
|
127
|
+
// Get all wallets with this connector
|
|
128
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === changedConnector.key);
|
|
129
|
+
for (const wallet of affectedWallets)
|
|
130
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
131
131
|
}));
|
|
132
|
-
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', () => {
|
|
132
|
+
useWalletConnectorEvent(uniqueNonPrimaryWallets, 'disconnect', (affectedConnector) => {
|
|
133
133
|
logger.debug('secondary wallet disconnect');
|
|
134
134
|
// argent sends a disconnect event when the user adds a new account
|
|
135
|
-
if (authMode === 'connect-only'
|
|
136
|
-
|
|
137
|
-
secondaryWallets
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
if (authMode === 'connect-only') {
|
|
136
|
+
// Get all wallets with this connector
|
|
137
|
+
const affectedWallets = secondaryWallets.filter(({ connector }) => connector.key === affectedConnector.key);
|
|
138
|
+
for (const wallet of affectedWallets) {
|
|
139
|
+
if (wallet.connector.key === 'argentx')
|
|
140
|
+
refreshConnectedWallet(wallet.id, wallet.connector);
|
|
141
|
+
}
|
|
140
142
|
}
|
|
141
|
-
computeConnectedStateForWallets();
|
|
142
143
|
});
|
|
143
144
|
const handleAccountChangeWhenAwaitingAccountSwitch = useCallback((isPrimaryWallet, newAddress) => {
|
|
144
145
|
const linkedSecondaryWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
|
|
@@ -45,6 +45,7 @@ require('../../../components/Alert/Alert.cjs');
|
|
|
45
45
|
require('../../../components/Popper/Popper/Popper.cjs');
|
|
46
46
|
require('../../../components/Popper/PopperContext/PopperContext.cjs');
|
|
47
47
|
require('formik');
|
|
48
|
+
require('i18next');
|
|
48
49
|
require('../../../components/InlineWidget/InlineWidget.cjs');
|
|
49
50
|
require('../../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
50
51
|
require('../../../components/OverlayCard/OverlayCard.context.cjs');
|
|
@@ -54,7 +55,6 @@ require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
|
|
|
54
55
|
require('../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
|
|
55
56
|
require('qrcode');
|
|
56
57
|
require('../../../context/LoadingContext/LoadingContext.cjs');
|
|
57
|
-
require('i18next');
|
|
58
58
|
require('../../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
59
59
|
require('../../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.cjs');
|
|
60
60
|
require('../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
|
|
@@ -41,6 +41,7 @@ import '../../../components/Alert/Alert.js';
|
|
|
41
41
|
import '../../../components/Popper/Popper/Popper.js';
|
|
42
42
|
import '../../../components/Popper/PopperContext/PopperContext.js';
|
|
43
43
|
import 'formik';
|
|
44
|
+
import 'i18next';
|
|
44
45
|
import '../../../components/InlineWidget/InlineWidget.js';
|
|
45
46
|
import '../../../components/MenuList/Dropdown/Dropdown.js';
|
|
46
47
|
import '../../../components/OverlayCard/OverlayCard.context.js';
|
|
@@ -50,7 +51,6 @@ import '../../../context/WalletGroupContext/WalletGroupContext.js';
|
|
|
50
51
|
import '../../../widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js';
|
|
51
52
|
import 'qrcode';
|
|
52
53
|
import '../../../context/LoadingContext/LoadingContext.js';
|
|
53
|
-
import 'i18next';
|
|
54
54
|
import '../../../widgets/DynamicWidget/context/DynamicWidgetContext.js';
|
|
55
55
|
import '../../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.js';
|
|
56
56
|
import '../../../widgets/DynamicWidget/views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
|
|
@@ -18,6 +18,8 @@ require('@dynamic-labs/utils');
|
|
|
18
18
|
require('../../../shared/consts/index.cjs');
|
|
19
19
|
require('@dynamic-labs/multi-wallet');
|
|
20
20
|
var isWalletConnected = require('../../functions/isWalletConnected/isWalletConnected.cjs');
|
|
21
|
+
var useEventListener = require('../useEventListener/useEventListener.cjs');
|
|
22
|
+
var useWalletConnectorEvent = require('../useWalletConnectorEvent/useWalletConnectorEvent.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,12 +55,25 @@ 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
78
|
computeConnectedStateForWallets,
|
|
55
79
|
connectedWalletMap: state.connectedWalletsMap,
|
|
@@ -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';
|
|
@@ -14,6 +14,8 @@ import '@dynamic-labs/utils';
|
|
|
14
14
|
import '../../../shared/consts/index.js';
|
|
15
15
|
import '@dynamic-labs/multi-wallet';
|
|
16
16
|
import { isWalletConnected } from '../../functions/isWalletConnected/isWalletConnected.js';
|
|
17
|
+
import { useEventListener } from '../useEventListener/useEventListener.js';
|
|
18
|
+
import { useWalletConnectorEvent } from '../useWalletConnectorEvent/useWalletConnectorEvent.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,12 +51,25 @@ 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
74
|
computeConnectedStateForWallets,
|
|
51
75
|
connectedWalletMap: state.connectedWalletsMap,
|
|
@@ -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, { evmNetworks: evmNetworks, currentNetwork: network, 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, { evmNetworks: evmNetworks, currentNetwork: network, 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) ||
|
|
@@ -94,7 +94,7 @@ const EmailVerification = () => {
|
|
|
94
94
|
const { view, setView, goToInitialView } = ViewContext.useViewContext();
|
|
95
95
|
const { error, setError, setErrorMessage } = ErrorContext.useErrorContext();
|
|
96
96
|
const { setExistentAccountData } = AccountExistsContext.useAccountExistsContext();
|
|
97
|
-
const { environmentId, onboardingOnlyJwt, handleLogOut, authToken, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, setIsVerificationInProgress, projectSettings, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
97
|
+
const { environmentId, onboardingOnlyJwt, handleLogOut, authToken, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, setIsVerificationInProgress, projectSettings, internalEvents, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
98
98
|
const { email, verificationUUID, setVerificationUUID } = EmailVerificationContext.useEmailVerificationContext();
|
|
99
99
|
const { loading, setLoading } = LoadingContext.useLoadingContext();
|
|
100
100
|
const { t } = reactI18next.useTranslation();
|
|
@@ -108,10 +108,7 @@ const EmailVerification = () => {
|
|
|
108
108
|
useOnUnmount.useOnUnmount(() => {
|
|
109
109
|
if (!callCallbackOnUnmount.current)
|
|
110
110
|
return;
|
|
111
|
-
|
|
112
|
-
? 'emailVerificationSuccess'
|
|
113
|
-
: 'emailVerificationFailure';
|
|
114
|
-
setCallback(callback, { email: email !== null && email !== void 0 ? email : '' });
|
|
111
|
+
internalEvents.current.emit('emailVerificationResult', isValidatedRef.current, email !== null && email !== void 0 ? email : '');
|
|
115
112
|
});
|
|
116
113
|
useEffectOnce.useEffectOnce(() => {
|
|
117
114
|
// Set verification in progress
|
|
@@ -90,7 +90,7 @@ const EmailVerification = () => {
|
|
|
90
90
|
const { view, setView, goToInitialView } = useViewContext();
|
|
91
91
|
const { error, setError, setErrorMessage } = useErrorContext();
|
|
92
92
|
const { setExistentAccountData } = useAccountExistsContext();
|
|
93
|
-
const { environmentId, onboardingOnlyJwt, handleLogOut, authToken, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, setIsVerificationInProgress, projectSettings, } = useInternalDynamicContext();
|
|
93
|
+
const { environmentId, onboardingOnlyJwt, handleLogOut, authToken, setOnboardingOnlyJwt, setShowAuthFlow, setCallback, setIsVerificationInProgress, projectSettings, internalEvents, } = useInternalDynamicContext();
|
|
94
94
|
const { email, verificationUUID, setVerificationUUID } = useEmailVerificationContext();
|
|
95
95
|
const { loading, setLoading } = useLoadingContext();
|
|
96
96
|
const { t } = useTranslation();
|
|
@@ -104,10 +104,7 @@ const EmailVerification = () => {
|
|
|
104
104
|
useOnUnmount(() => {
|
|
105
105
|
if (!callCallbackOnUnmount.current)
|
|
106
106
|
return;
|
|
107
|
-
|
|
108
|
-
? 'emailVerificationSuccess'
|
|
109
|
-
: 'emailVerificationFailure';
|
|
110
|
-
setCallback(callback, { email: email !== null && email !== void 0 ? email : '' });
|
|
107
|
+
internalEvents.current.emit('emailVerificationResult', isValidatedRef.current, email !== null && email !== void 0 ? email : '');
|
|
111
108
|
});
|
|
112
109
|
useEffectOnce(() => {
|
|
113
110
|
// Set verification in progress
|
|
@@ -38,6 +38,7 @@ require('../../components/Popper/Popper/Popper.cjs');
|
|
|
38
38
|
require('../../components/Popper/PopperContext/PopperContext.cjs');
|
|
39
39
|
require('formik');
|
|
40
40
|
require('yup');
|
|
41
|
+
require('i18next');
|
|
41
42
|
require('../../components/InlineWidget/InlineWidget.cjs');
|
|
42
43
|
require('../../components/MenuList/Dropdown/Dropdown.cjs');
|
|
43
44
|
require('../../components/OverlayCard/OverlayCard.context.cjs');
|
|
@@ -50,7 +51,6 @@ require('../../context/CaptchaContext/CaptchaContext.cjs');
|
|
|
50
51
|
require('../../context/EmailVerificationContext/EmailVerificationContext.cjs');
|
|
51
52
|
require('qrcode');
|
|
52
53
|
require('../../context/LoadingContext/LoadingContext.cjs');
|
|
53
|
-
require('i18next');
|
|
54
54
|
require('../../widgets/DynamicWidget/context/DynamicWidgetContext.cjs');
|
|
55
55
|
require('../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.cjs');
|
|
56
56
|
require('@dynamic-labs/types');
|
|
@@ -63,7 +63,7 @@ const EmailWalletOTPVerificationView = () => {
|
|
|
63
63
|
const { setView } = ViewContext.useViewContext();
|
|
64
64
|
const [error, setError] = React.useState();
|
|
65
65
|
const { t } = reactI18next.useTranslation();
|
|
66
|
-
const { selectedWalletConnector: emailWalletConnector, clearStatesOnBackClick, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
66
|
+
const { selectedWalletConnector: emailWalletConnector, clearStatesOnBackClick, internalEvents, } = useInternalDynamicContext.useInternalDynamicContext();
|
|
67
67
|
if (!emailWalletConnector ||
|
|
68
68
|
!walletConnectorCore.isEmailOTPWalletConnector(emailWalletConnector)) {
|
|
69
69
|
throw new Error('Current wallet is not EmailWalletConnector');
|
|
@@ -78,7 +78,13 @@ const EmailWalletOTPVerificationView = () => {
|
|
|
78
78
|
setView('login-with-email-or-wallet');
|
|
79
79
|
};
|
|
80
80
|
const { data: isValid, isLoading, mutate: onSubmit, } = useMutation.useMutation((otp) => emailWalletConnector.verifyOneTimePassword(otp), {
|
|
81
|
-
onFailure: (error) =>
|
|
81
|
+
onFailure: (error) => {
|
|
82
|
+
setError(error);
|
|
83
|
+
internalEvents.current.emit('emailVerificationResult', false, email);
|
|
84
|
+
},
|
|
85
|
+
onSuccess: () => {
|
|
86
|
+
internalEvents.current.emit('emailVerificationResult', true, email);
|
|
87
|
+
},
|
|
82
88
|
});
|
|
83
89
|
return (jsxRuntime.jsx(OTPVerificationView.OTPVerificationView, { email: email, error: error, onClickBack: handleBackClick, isLoading: isLoading, onPinComplete: onSubmit, isValid: isValid === true, onPinChange: () => setError(undefined), onClickEditEmail: handleBackClick, successBannerText: t('dyn_otp_verification.banner_text') }));
|
|
84
90
|
};
|