@dynamic-labs/sdk-react-core 2.2.5 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +13 -13
  5. package/src/index.cjs +1 -1
  6. package/src/index.js +1 -1
  7. package/src/lib/context/DynamicContext/DynamicContext.cjs +1 -0
  8. package/src/lib/context/DynamicContext/DynamicContext.js +1 -0
  9. package/src/lib/styles/index.shadow.cjs +1 -1
  10. package/src/lib/styles/index.shadow.js +1 -1
  11. package/src/lib/utils/functions/getPlatformForConnector/getPlatformForConnector.cjs +10 -0
  12. package/src/lib/utils/functions/getPlatformForConnector/getPlatformForConnector.d.ts +3 -0
  13. package/src/lib/utils/functions/getPlatformForConnector/getPlatformForConnector.js +6 -0
  14. package/src/lib/utils/functions/getPlatformForConnector/index.d.ts +1 -0
  15. package/src/lib/utils/functions/index.d.ts +1 -0
  16. package/src/lib/utils/functions/walletListBuilder/utils/applyMultiWalletFilters/applyMultiWalletFilters.cjs +2 -2
  17. package/src/lib/utils/functions/walletListBuilder/utils/applyMultiWalletFilters/applyMultiWalletFilters.d.ts +3 -1
  18. package/src/lib/utils/functions/walletListBuilder/utils/applyMultiWalletFilters/applyMultiWalletFilters.js +2 -2
  19. package/src/lib/utils/functions/walletListBuilder/utils/staticLinkedWalletFilter/staticLinkedWalletFilter.cjs +5 -12
  20. package/src/lib/utils/functions/walletListBuilder/utils/staticLinkedWalletFilter/staticLinkedWalletFilter.d.ts +2 -1
  21. package/src/lib/utils/functions/walletListBuilder/utils/staticLinkedWalletFilter/staticLinkedWalletFilter.js +5 -12
  22. package/src/lib/utils/functions/walletListBuilder/walletListBuilder.cjs +1 -0
  23. package/src/lib/utils/functions/walletListBuilder/walletListBuilder.js +1 -0
  24. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.cjs +2 -2
  25. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.d.ts +3 -1
  26. package/src/lib/utils/hooks/useWalletConnectors/useWalletConnectors.js +2 -2
  27. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.cjs +14 -7
  28. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.d.ts +3 -2
  29. package/src/lib/utils/hooks/useWalletsConnectionState/useWalletsConnectionState.js +14 -7
  30. package/src/lib/widgets/DynamicWidget/prompts/DetectedNewWalletModal/DetectedNewWalletModal.cjs +8 -5
  31. package/src/lib/widgets/DynamicWidget/prompts/DetectedNewWalletModal/DetectedNewWalletModal.js +8 -5
  32. package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.cjs +1 -1
  33. package/src/lib/widgets/DynamicWidget/prompts/PendingAccountSwitchModal/PendingAccountSwitchModal.js +1 -1
  34. package/src/lib/shared/assets/prompt-account-switch.cjs +0 -64
  35. package/src/lib/shared/assets/prompt-account-switch.js +0 -40
@@ -0,0 +1,10 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var utils = require('@dynamic-labs/utils');
7
+
8
+ const getPlatformForConnector = (connector) => utils.isMobile() || connector.isWalletConnect ? 'mobile' : 'browserExtension';
9
+
10
+ exports.getPlatformForConnector = getPlatformForConnector;
@@ -0,0 +1,3 @@
1
+ import { WalletSchema } from '@dynamic-labs/wallet-book';
2
+ import { WalletConnector } from '../../../..';
3
+ export declare const getPlatformForConnector: (connector: WalletConnector) => keyof NonNullable<WalletSchema['walletLimitations']>;
@@ -0,0 +1,6 @@
1
+ 'use client'
2
+ import { isMobile } from '@dynamic-labs/utils';
3
+
4
+ const getPlatformForConnector = (connector) => isMobile() || connector.isWalletConnect ? 'mobile' : 'browserExtension';
5
+
6
+ export { getPlatformForConnector };
@@ -0,0 +1 @@
1
+ export * from './getPlatformForConnector';
@@ -79,3 +79,4 @@ export * from './getExpiresAt';
79
79
  export * from './getSupportedCountriesForVerificationFromProjectSettings';
80
80
  export * from './getDefaultCountriesIfEmpty';
81
81
  export * from './logVerboseTroubleshootingMessage';
82
+ export * from './getPlatformForConnector';
@@ -7,7 +7,7 @@ var filterConnectedWallets = require('../filterConnectedWallets/filterConnectedW
7
7
  var staticLinkedWalletFilter = require('../staticLinkedWalletFilter/staticLinkedWalletFilter.cjs');
8
8
  var filterWalletConnectWallets = require('../filterWalletConnectWallets/filterWalletConnectWallets.cjs');
9
9
 
10
- const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, }) => {
10
+ const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, walletBook, }) => {
11
11
  const walletList = filterWalletConnectWallets.filterWalletConnectWallets({
12
12
  userWallets,
13
13
  walletOptions,
@@ -18,7 +18,7 @@ const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, }) => {
18
18
  walletOptions: walletList,
19
19
  });
20
20
  }
21
- return staticLinkedWalletFilter.staticWalletFilter(userWallets, walletList);
21
+ return staticLinkedWalletFilter.staticWalletFilter(userWallets, walletList, walletBook);
22
22
  };
23
23
 
24
24
  exports.applyMultiWalletFilters = applyMultiWalletFilters;
@@ -1,6 +1,8 @@
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
1
2
  import { AuthModeType, Wallet, WalletOption } from '../../../../../shared';
2
- export declare const applyMultiWalletFilters: ({ authMode, userWallets, walletOptions, }: {
3
+ export declare const applyMultiWalletFilters: ({ authMode, userWallets, walletOptions, walletBook, }: {
3
4
  authMode: AuthModeType;
4
5
  userWallets: Wallet[];
5
6
  walletOptions: WalletOption[];
7
+ walletBook: WalletBookSchema;
6
8
  }) => WalletOption[];
@@ -3,7 +3,7 @@ import { filterConnectedWallets } from '../filterConnectedWallets/filterConnecte
3
3
  import { staticWalletFilter } from '../staticLinkedWalletFilter/staticLinkedWalletFilter.js';
4
4
  import { filterWalletConnectWallets } from '../filterWalletConnectWallets/filterWalletConnectWallets.js';
5
5
 
6
- const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, }) => {
6
+ const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, walletBook, }) => {
7
7
  const walletList = filterWalletConnectWallets({
8
8
  userWallets,
9
9
  walletOptions,
@@ -14,7 +14,7 @@ const applyMultiWalletFilters = ({ authMode, userWallets, walletOptions, }) => {
14
14
  walletOptions: walletList,
15
15
  });
16
16
  }
17
- return staticWalletFilter(userWallets, walletList);
17
+ return staticWalletFilter(userWallets, walletList, walletBook);
18
18
  };
19
19
 
20
20
  export { applyMultiWalletFilters };
@@ -3,22 +3,15 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- /**
7
- * These wallets do not fire events when switching accounts, so we should filter
8
- * them out of the wallet list if they are already linked to the user profile.
9
- */
10
- const staticListToFilter = [
11
- 'xverse',
12
- 'magiceden',
13
- 'magicedenbtc',
14
- 'magicedensol',
15
- ];
6
+ var walletBook = require('@dynamic-labs/wallet-book');
7
+ var getPlatformForConnector = require('../../../getPlatformForConnector/getPlatformForConnector.cjs');
8
+
16
9
  /**
17
10
  * This function is a helper to filter out wallets that should not appear in the wallet list
18
11
  * if they are already linked to the user profile.
19
12
  */
20
- const staticWalletFilter = (linkedWallets, walletOptions) => walletOptions.filter((walletOption) => {
21
- if (!staticListToFilter.includes(walletOption.key)) {
13
+ const staticWalletFilter = (linkedWallets, walletOptions, walletBook$1) => walletOptions.filter((walletOption) => {
14
+ if (walletBook.isWalletEventSupported(walletBook.findWalletBookWallet(walletBook$1, walletOption.key), 'accountChanged', getPlatformForConnector.getPlatformForConnector(walletOption.walletConnector))) {
22
15
  return true;
23
16
  }
24
17
  if (linkedWallets.some((wallet) => wallet.connector.key === walletOption.key)) {
@@ -1,6 +1,7 @@
1
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
1
2
  import { Wallet, WalletOption } from '../../../../../shared';
2
3
  /**
3
4
  * This function is a helper to filter out wallets that should not appear in the wallet list
4
5
  * if they are already linked to the user profile.
5
6
  */
6
- export declare const staticWalletFilter: (linkedWallets: Wallet[], walletOptions: WalletOption[]) => WalletOption[];
7
+ export declare const staticWalletFilter: (linkedWallets: Wallet[], walletOptions: WalletOption[], walletBook: WalletBookSchema) => WalletOption[];
@@ -1,20 +1,13 @@
1
1
  'use client'
2
- /**
3
- * These wallets do not fire events when switching accounts, so we should filter
4
- * them out of the wallet list if they are already linked to the user profile.
5
- */
6
- const staticListToFilter = [
7
- 'xverse',
8
- 'magiceden',
9
- 'magicedenbtc',
10
- 'magicedensol',
11
- ];
2
+ import { isWalletEventSupported, findWalletBookWallet } from '@dynamic-labs/wallet-book';
3
+ import { getPlatformForConnector } from '../../../getPlatformForConnector/getPlatformForConnector.js';
4
+
12
5
  /**
13
6
  * This function is a helper to filter out wallets that should not appear in the wallet list
14
7
  * if they are already linked to the user profile.
15
8
  */
16
- const staticWalletFilter = (linkedWallets, walletOptions) => walletOptions.filter((walletOption) => {
17
- if (!staticListToFilter.includes(walletOption.key)) {
9
+ const staticWalletFilter = (linkedWallets, walletOptions, walletBook) => walletOptions.filter((walletOption) => {
10
+ if (isWalletEventSupported(findWalletBookWallet(walletBook, walletOption.key), 'accountChanged', getPlatformForConnector(walletOption.walletConnector))) {
18
11
  return true;
19
12
  }
20
13
  if (linkedWallets.some((wallet) => wallet.connector.key === walletOption.key)) {
@@ -66,6 +66,7 @@ const walletListBuilder = ({ authMode, userWallets, multiWallet, numberOfWallets
66
66
  walletList = applyMultiWalletFilters.applyMultiWalletFilters({
67
67
  authMode,
68
68
  userWallets,
69
+ walletBook,
69
70
  walletOptions: walletList,
70
71
  });
71
72
  }
@@ -62,6 +62,7 @@ const walletListBuilder = ({ authMode, userWallets, multiWallet, numberOfWallets
62
62
  walletList = applyMultiWalletFilters({
63
63
  authMode,
64
64
  userWallets,
65
+ walletBook,
65
66
  walletOptions: walletList,
66
67
  });
67
68
  }
@@ -32,7 +32,7 @@ var reconnectSocialWallet = require('./reconnectSocialWallet.cjs');
32
32
  var createLinkedWalletsFromWalletOptions = require('./utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.cjs');
33
33
  var updateUserWalletsFromLinkedWallets = require('./utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.cjs');
34
34
 
35
- const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, }) => {
35
+ const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, walletBook, }) => {
36
36
  const [showQrcodeModal, setShowQrcodeModal] = React.useState(false);
37
37
  const linkedWallets = React.useMemo(() => {
38
38
  if (!user) {
@@ -75,7 +75,7 @@ const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOption
75
75
  React.useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
76
76
  wallet.connector.initEventListener();
77
77
  }), [walletsBasedOnAuthMode]);
78
- const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode);
78
+ const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState.useWalletsConnectionState(walletsBasedOnAuthMode, walletBook, primaryWalletId, authMode);
79
79
  const wallets = React.useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletsMap[getWalletIdentifier.getWalletIdentifier(wallet)]) }))), [connectedWalletsMap, walletsBasedOnAuthMode]);
80
80
  logVerboseTroubleshootingMessage.logVerboseTroubleshootingMessage('wallets', wallets);
81
81
  logVerboseTroubleshootingMessage.logVerboseTroubleshootingMessage('didConnectedStateLoad', didConnectedStateLoad);
@@ -1,5 +1,6 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  import { UserProfile } from '@dynamic-labs/types';
3
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
4
  import { AuthModeType, MultiWalletWidgetState, Wallet, WalletOption } from '../../../shared';
4
5
  import { MultiWalletWidgetStateSetter } from '../multiWallet';
5
6
  type Props = {
@@ -14,6 +15,7 @@ type Props = {
14
15
  primaryWalletId: string | undefined;
15
16
  user?: UserProfile;
16
17
  canHaveMultipleWalletsConnected?: boolean;
18
+ walletBook: WalletBookSchema;
17
19
  };
18
20
  export interface UseWalletConnectors {
19
21
  didConnectedStateLoad: boolean;
@@ -24,5 +26,5 @@ export interface UseWalletConnectors {
24
26
  showQrcodeModal: boolean;
25
27
  wallets: Wallet[];
26
28
  }
27
- export declare const useWalletConnectors: ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, }: Props) => UseWalletConnectors;
29
+ export declare const useWalletConnectors: ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, walletBook, }: Props) => UseWalletConnectors;
28
30
  export {};
@@ -28,7 +28,7 @@ import { reconnectSocialWallet } from './reconnectSocialWallet.js';
28
28
  import { createLinkedWalletsFromWalletOptions } from './utils/createLinkedWalletsFromWalletOptions/createLinkedWalletsFromWalletOptions.js';
29
29
  import { updateUserWalletsFromLinkedWallets } from './utils/updateUserWalletsFromLinkedWallets/updateUserWalletsFromLinkedWallets.js';
30
30
 
31
- const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, }) => {
31
+ const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOptions, multiWalletWidgetState, setDesktopUri, setMultiWalletWidgetState, setQrcodeUri, primaryWalletId, setPrimaryWalletId, user, canHaveMultipleWalletsConnected, walletBook, }) => {
32
32
  const [showQrcodeModal, setShowQrcodeModal] = useState(false);
33
33
  const linkedWallets = useMemo(() => {
34
34
  if (!user) {
@@ -71,7 +71,7 @@ const useWalletConnectors = ({ authMode, connectedWallets, walletConnectorOption
71
71
  useEffect(() => walletsBasedOnAuthMode.forEach((wallet) => {
72
72
  wallet.connector.initEventListener();
73
73
  }), [walletsBasedOnAuthMode]);
74
- const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode);
74
+ const { connectedWalletsMap, didConnectedStateLoad } = useWalletsConnectionState(walletsBasedOnAuthMode, walletBook, primaryWalletId, authMode);
75
75
  const wallets = useMemo(() => walletsBasedOnAuthMode.map((wallet) => (Object.assign(Object.assign({}, wallet), { connected: Boolean(connectedWalletsMap[getWalletIdentifier(wallet)]) }))), [connectedWalletsMap, walletsBasedOnAuthMode]);
76
76
  logVerboseTroubleshootingMessage('wallets', wallets);
77
77
  logVerboseTroubleshootingMessage('didConnectedStateLoad', didConnectedStateLoad);
@@ -6,12 +6,12 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var React = require('react');
8
8
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
9
+ var walletBook = require('@dynamic-labs/wallet-book');
9
10
  require('@dynamic-labs/sdk-api-core');
10
11
  require('../../../shared/logger.cjs');
11
12
  require('@dynamic-labs/iconic');
12
13
  require('react/jsx-runtime');
13
14
  require('../../../context/ViewContext/ViewContext.cjs');
14
- require('@dynamic-labs/wallet-book');
15
15
  require('../../constants/colors.cjs');
16
16
  require('../../constants/values.cjs');
17
17
  require('../../../shared/utils/classes/storage/localStorage.cjs');
@@ -27,6 +27,7 @@ require('viem/chains');
27
27
  require('../../../config/ApiEndpoint.cjs');
28
28
  require('@dynamic-labs/store');
29
29
  require('../../../locale/locale.cjs');
30
+ var getPlatformForConnector = require('../../functions/getPlatformForConnector/getPlatformForConnector.cjs');
30
31
  require('../../../events/dynamicEvents.cjs');
31
32
  var useWalletConnectorEvent = require('../events/useWalletConnectorEvent/useWalletConnectorEvent.cjs');
32
33
  var useWindowEvent = require('../events/useWindowEvent/useWindowEvent.cjs');
@@ -35,14 +36,17 @@ var useWindowEvent = require('../events/useWindowEvent/useWindowEvent.cjs');
35
36
  * For the given wallet array, this returns an object mapping from each wallet's
36
37
  * identifier to whether its connector recognizes it as currently connected or not.
37
38
  */
38
- const getConnectedWalletsMap = (wallets) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
39
+ const getConnectedWalletsMap = (wallets, walletBook$1, primaryWalletId) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
39
40
  const newMap = {};
40
- yield Promise.all(wallets.map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
41
+ yield Promise.all(wallets
42
+ .filter((wallet) => wallet.id === primaryWalletId ||
43
+ walletBook.isWalletMethodSupported(walletBook.findWalletBookWallet(walletBook$1, wallet.key), 'getConnectedAccounts', getPlatformForConnector.getPlatformForConnector(wallet.connector)))
44
+ .map((wallet) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
41
45
  newMap[getWalletIdentifier.getWalletIdentifier(wallet)] = yield isWalletConnected.isWalletConnected(wallet);
42
46
  })));
43
47
  return newMap;
44
48
  });
45
- const useWalletsConnectionState = (wallets) => {
49
+ const useWalletsConnectionState = (wallets, walletBook, primaryWalletId, authMode) => {
46
50
  const [connectedWalletsMap, setConnectedWalletsMap] = React.useState({});
47
51
  /**
48
52
  * Whether the connection map has been loaded off of the current wallet array.
@@ -59,7 +63,7 @@ const useWalletsConnectionState = (wallets) => {
59
63
  const incomingWalletSwitchAddress = React.useRef(undefined);
60
64
  const computeConnectedStateForWallets = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
61
65
  didConnectedStateLoad.current = false;
62
- const newMap = yield getConnectedWalletsMap(wallets);
66
+ const newMap = yield getConnectedWalletsMap(wallets, walletBook, primaryWalletId);
63
67
  if (Object.values(newMap).length === 0) {
64
68
  setConnectedWalletsMap({});
65
69
  return;
@@ -75,7 +79,7 @@ const useWalletsConnectionState = (wallets) => {
75
79
  return;
76
80
  }
77
81
  setConnectedWalletsMap(newMap);
78
- }), [wallets]);
82
+ }), [primaryWalletId, walletBook, wallets]);
79
83
  /** A string that is unique for each possible value of the wallets prop */
80
84
  const walletsHash = wallets.map(getWalletIdentifier.getWalletIdentifier).join('-');
81
85
  const connectors = wallets.map(({ connector }) => connector);
@@ -92,6 +96,9 @@ const useWalletsConnectionState = (wallets) => {
92
96
  useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'accountChange', onAccountChange);
93
97
  useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'disconnect', handleEvent);
94
98
  useWalletConnectorEvent.useWalletConnectorEvent(connectors, 'chainChange', handleEvent);
99
+ const computeConnectedStateKey = authMode === 'connect-and-sign'
100
+ ? `${primaryWalletId}-${walletsHash}`
101
+ : walletsHash;
95
102
  React.useEffect(() => {
96
103
  computeConnectedStateForWallets();
97
104
  },
@@ -100,7 +107,7 @@ const useWalletsConnectionState = (wallets) => {
100
107
  * wallets change.
101
108
  */
102
109
  // eslint-disable-next-line react-hooks/exhaustive-deps
103
- [walletsHash]);
110
+ [computeConnectedStateKey]);
104
111
  /**
105
112
  * This is a workaround to detect when the user switches to another tab/extension
106
113
  * and then comes back to the dapp.
@@ -1,9 +1,10 @@
1
1
  import { MutableRefObject } from 'react';
2
- import { Wallet } from '../../../shared';
2
+ import { WalletBookSchema } from '@dynamic-labs/wallet-book';
3
+ import { AuthModeType, Wallet } from '../../../shared';
3
4
  type ConnectedWalletsMap = {
4
5
  [address: string]: boolean;
5
6
  };
6
- type WalletsConnectionStateHook = (wallets: Wallet[]) => {
7
+ type WalletsConnectionStateHook = (wallets: Wallet[], walletBook: WalletBookSchema, primaryWalletId: string | undefined, authMode: AuthModeType) => {
7
8
  connectedWalletsMap: ConnectedWalletsMap;
8
9
  didConnectedStateLoad: MutableRefObject<boolean>;
9
10
  };
@@ -2,12 +2,12 @@
2
2
  import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
3
  import { useState, useRef, useCallback, useEffect } from 'react';
4
4
  import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
5
+ import { isWalletMethodSupported, findWalletBookWallet } from '@dynamic-labs/wallet-book';
5
6
  import '@dynamic-labs/sdk-api-core';
6
7
  import '../../../shared/logger.js';
7
8
  import '@dynamic-labs/iconic';
8
9
  import 'react/jsx-runtime';
9
10
  import '../../../context/ViewContext/ViewContext.js';
10
- import '@dynamic-labs/wallet-book';
11
11
  import '../../constants/colors.js';
12
12
  import '../../constants/values.js';
13
13
  import '../../../shared/utils/classes/storage/localStorage.js';
@@ -23,6 +23,7 @@ import 'viem/chains';
23
23
  import '../../../config/ApiEndpoint.js';
24
24
  import '@dynamic-labs/store';
25
25
  import '../../../locale/locale.js';
26
+ import { getPlatformForConnector } from '../../functions/getPlatformForConnector/getPlatformForConnector.js';
26
27
  import '../../../events/dynamicEvents.js';
27
28
  import { useWalletConnectorEvent } from '../events/useWalletConnectorEvent/useWalletConnectorEvent.js';
28
29
  import { useWindowEvent } from '../events/useWindowEvent/useWindowEvent.js';
@@ -31,14 +32,17 @@ import { useWindowEvent } from '../events/useWindowEvent/useWindowEvent.js';
31
32
  * For the given wallet array, this returns an object mapping from each wallet's
32
33
  * identifier to whether its connector recognizes it as currently connected or not.
33
34
  */
34
- const getConnectedWalletsMap = (wallets) => __awaiter(void 0, void 0, void 0, function* () {
35
+ const getConnectedWalletsMap = (wallets, walletBook, primaryWalletId) => __awaiter(void 0, void 0, void 0, function* () {
35
36
  const newMap = {};
36
- yield Promise.all(wallets.map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
37
+ yield Promise.all(wallets
38
+ .filter((wallet) => wallet.id === primaryWalletId ||
39
+ isWalletMethodSupported(findWalletBookWallet(walletBook, wallet.key), 'getConnectedAccounts', getPlatformForConnector(wallet.connector)))
40
+ .map((wallet) => __awaiter(void 0, void 0, void 0, function* () {
37
41
  newMap[getWalletIdentifier(wallet)] = yield isWalletConnected(wallet);
38
42
  })));
39
43
  return newMap;
40
44
  });
41
- const useWalletsConnectionState = (wallets) => {
45
+ const useWalletsConnectionState = (wallets, walletBook, primaryWalletId, authMode) => {
42
46
  const [connectedWalletsMap, setConnectedWalletsMap] = useState({});
43
47
  /**
44
48
  * Whether the connection map has been loaded off of the current wallet array.
@@ -55,7 +59,7 @@ const useWalletsConnectionState = (wallets) => {
55
59
  const incomingWalletSwitchAddress = useRef(undefined);
56
60
  const computeConnectedStateForWallets = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
57
61
  didConnectedStateLoad.current = false;
58
- const newMap = yield getConnectedWalletsMap(wallets);
62
+ const newMap = yield getConnectedWalletsMap(wallets, walletBook, primaryWalletId);
59
63
  if (Object.values(newMap).length === 0) {
60
64
  setConnectedWalletsMap({});
61
65
  return;
@@ -71,7 +75,7 @@ const useWalletsConnectionState = (wallets) => {
71
75
  return;
72
76
  }
73
77
  setConnectedWalletsMap(newMap);
74
- }), [wallets]);
78
+ }), [primaryWalletId, walletBook, wallets]);
75
79
  /** A string that is unique for each possible value of the wallets prop */
76
80
  const walletsHash = wallets.map(getWalletIdentifier).join('-');
77
81
  const connectors = wallets.map(({ connector }) => connector);
@@ -88,6 +92,9 @@ const useWalletsConnectionState = (wallets) => {
88
92
  useWalletConnectorEvent(connectors, 'accountChange', onAccountChange);
89
93
  useWalletConnectorEvent(connectors, 'disconnect', handleEvent);
90
94
  useWalletConnectorEvent(connectors, 'chainChange', handleEvent);
95
+ const computeConnectedStateKey = authMode === 'connect-and-sign'
96
+ ? `${primaryWalletId}-${walletsHash}`
97
+ : walletsHash;
91
98
  useEffect(() => {
92
99
  computeConnectedStateForWallets();
93
100
  },
@@ -96,7 +103,7 @@ const useWalletsConnectionState = (wallets) => {
96
103
  * wallets change.
97
104
  */
98
105
  // eslint-disable-next-line react-hooks/exhaustive-deps
99
- [walletsHash]);
106
+ [computeConnectedStateKey]);
100
107
  /**
101
108
  * This is a workaround to detect when the user switches to another tab/extension
102
109
  * and then comes back to the dapp.
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var jsxRuntime = require('react/jsx-runtime');
7
7
  var reactI18next = require('react-i18next');
8
+ var walletBook = require('@dynamic-labs/wallet-book');
8
9
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
9
10
  require('../../../../components/Alert/Alert.cjs');
10
11
  require('react');
@@ -17,8 +18,6 @@ require('../../../../shared/logger.cjs');
17
18
  require('@dynamic-labs/iconic');
18
19
  require('@dynamic-labs/wallet-connector-core');
19
20
  require('../../../../context/ViewContext/ViewContext.cjs');
20
- var promptAccountSwitch = require('../../../../shared/assets/prompt-account-switch.cjs');
21
- require('@dynamic-labs/wallet-book');
22
21
  require('../../../../utils/constants/colors.cjs');
23
22
  require('../../../../utils/constants/values.cjs');
24
23
  require('../../../../shared/utils/classes/storage/localStorage.cjs');
@@ -63,6 +62,8 @@ require('../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
63
62
  var PromptModal = require('../../components/PromptModal/PromptModal.cjs');
64
63
  var WidgetPortal = require('../../components/WidgetPortal/WidgetPortal.cjs');
65
64
  var useCloseMultiWalletPrompt = require('../../hooks/useCloseMultiWalletPrompt/useCloseMultiWalletPrompt.cjs');
65
+ var DefaultPromptModal = require('../DefaultPromptModal/DefaultPromptModal.cjs');
66
+ var Divider = require('../../../../components/Divider/Divider.cjs');
66
67
  require('../../context/DynamicWidgetContext.cjs');
67
68
  require('../../../../components/IconButton/IconButton.cjs');
68
69
  require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
@@ -75,6 +76,7 @@ require('../../../../context/PasskeyContext/PasskeyContext.cjs');
75
76
  require('../../views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.cjs');
76
77
  require('../../../../components/InlineWidget/InlineWidget.cjs');
77
78
  require('../../../../components/IsBrowser/IsBrowser.cjs');
79
+ var LogoutButton = require('../../../../components/LogoutButton/LogoutButton.cjs');
78
80
  require('../../../../components/Popper/Popper/Popper.cjs');
79
81
  require('../../../../components/Popper/PopperContext/PopperContext.cjs');
80
82
  require('react-focus-lock');
@@ -85,16 +87,17 @@ require('@hcaptcha/react-hcaptcha');
85
87
  require('../../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
86
88
 
87
89
  const DetectedNewWalletContent = () => {
90
+ var _a;
88
91
  const { t } = reactI18next.useTranslation();
89
92
  const { setMultiWalletWidgetState, primaryWallet } = useInternalDynamicContext.useInternalDynamicContext();
90
93
  const handleClick = () => {
91
94
  setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
92
95
  };
93
- return (jsxRuntime.jsxs("div", { className: 'detected-new-wallet-modal__content', children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'primary', children: t('dyn_detected_new_wallet.title') }), jsxRuntime.jsx(promptAccountSwitch.ReactComponent, {}), jsxRuntime.jsx(Typography.Typography, { variant: 'body_small', color: 'secondary', children: t('dyn_detected_new_wallet.description', {
96
+ return (jsxRuntime.jsxs(DefaultPromptModal.DefaultPromptLayout, { dataTestId: 'detected-new-wallet-modal', icon: jsxRuntime.jsx(walletBook.WalletIcon, { walletKey: (_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) === null || _a === void 0 ? void 0 : _a.key }), title: t('dyn_detected_new_wallet.title'), children: [jsxRuntime.jsx(Typography.Typography, { variant: 'body_normal', color: 'secondary', weight: 'regular', "data-testid": 'content', children: t('dyn_detected_new_wallet.description', {
94
97
  walletName: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.name,
95
- }) }), jsxRuntime.jsx(TypographyButton.TypographyButton, { expanded: true, onClick: handleClick, typographyProps: {
98
+ }) }), jsxRuntime.jsx(TypographyButton.TypographyButton, { buttonClassName: 'detected-new-wallet-modal__confirm-button', expanded: true, onClick: handleClick, typographyProps: {
96
99
  variant: 'button_secondary',
97
- }, children: t('dyn_detected_new_wallet.confirm_button') })] }));
100
+ }, children: t('dyn_detected_new_wallet.confirm_button') }), jsxRuntime.jsx(Divider.Divider, { fullWidth: true, text: 'Or' }), jsxRuntime.jsx(LogoutButton.LogoutButton, { isTextButton: false, buttonClassName: 'detected-new-wallet-modal__log-out-button' })] }));
98
101
  };
99
102
  const DetectedNewWalletWidgetPortal = () => (jsxRuntime.jsx(WidgetPortal.WidgetPortal, { onClose: useCloseMultiWalletPrompt.useCloseMultiWalletPrompt(), children: jsxRuntime.jsx(DetectedNewWalletContent, {}) }));
100
103
  const DetectedNewWalletModal = () => (jsxRuntime.jsx(PromptModal.PromptModal, { onClose: useCloseMultiWalletPrompt.useCloseMultiWalletPrompt(), children: jsxRuntime.jsx(DetectedNewWalletContent, {}) }));
@@ -1,6 +1,7 @@
1
1
  'use client'
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import { useTranslation } from 'react-i18next';
4
+ import { WalletIcon } from '@dynamic-labs/wallet-book';
4
5
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
5
6
  import '../../../../components/Alert/Alert.js';
6
7
  import 'react';
@@ -13,8 +14,6 @@ import '../../../../shared/logger.js';
13
14
  import '@dynamic-labs/iconic';
14
15
  import '@dynamic-labs/wallet-connector-core';
15
16
  import '../../../../context/ViewContext/ViewContext.js';
16
- import { ReactComponent as SvgPromptAccountSwitch } from '../../../../shared/assets/prompt-account-switch.js';
17
- import '@dynamic-labs/wallet-book';
18
17
  import '../../../../utils/constants/colors.js';
19
18
  import '../../../../utils/constants/values.js';
20
19
  import '../../../../shared/utils/classes/storage/localStorage.js';
@@ -59,6 +58,8 @@ import '../../components/DynamicWidgetHeader/DynamicWidgetHeader.js';
59
58
  import { PromptModal } from '../../components/PromptModal/PromptModal.js';
60
59
  import { WidgetPortal } from '../../components/WidgetPortal/WidgetPortal.js';
61
60
  import { useCloseMultiWalletPrompt } from '../../hooks/useCloseMultiWalletPrompt/useCloseMultiWalletPrompt.js';
61
+ import { DefaultPromptLayout } from '../DefaultPromptModal/DefaultPromptModal.js';
62
+ import { Divider } from '../../../../components/Divider/Divider.js';
62
63
  import '../../context/DynamicWidgetContext.js';
63
64
  import '../../../../components/IconButton/IconButton.js';
64
65
  import '../../../../components/MenuList/Dropdown/Dropdown.js';
@@ -71,6 +72,7 @@ import '../../../../context/PasskeyContext/PasskeyContext.js';
71
72
  import '../../views/ManagePasskeysWidgetView/PasskeyCard/PasskeyCard.js';
72
73
  import '../../../../components/InlineWidget/InlineWidget.js';
73
74
  import '../../../../components/IsBrowser/IsBrowser.js';
75
+ import { LogoutButton } from '../../../../components/LogoutButton/LogoutButton.js';
74
76
  import '../../../../components/Popper/Popper/Popper.js';
75
77
  import '../../../../components/Popper/PopperContext/PopperContext.js';
76
78
  import 'react-focus-lock';
@@ -81,16 +83,17 @@ import '@hcaptcha/react-hcaptcha';
81
83
  import '../../../../context/IpConfigurationContext/IpConfigurationContext.js';
82
84
 
83
85
  const DetectedNewWalletContent = () => {
86
+ var _a;
84
87
  const { t } = useTranslation();
85
88
  const { setMultiWalletWidgetState, primaryWallet } = useInternalDynamicContext();
86
89
  const handleClick = () => {
87
90
  setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
88
91
  };
89
- return (jsxs("div", { className: 'detected-new-wallet-modal__content', children: [jsx(Typography, { variant: 'body_normal', color: 'primary', children: t('dyn_detected_new_wallet.title') }), jsx(SvgPromptAccountSwitch, {}), jsx(Typography, { variant: 'body_small', color: 'secondary', children: t('dyn_detected_new_wallet.description', {
92
+ return (jsxs(DefaultPromptLayout, { dataTestId: 'detected-new-wallet-modal', icon: jsx(WalletIcon, { walletKey: (_a = primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector) === null || _a === void 0 ? void 0 : _a.key }), title: t('dyn_detected_new_wallet.title'), children: [jsx(Typography, { variant: 'body_normal', color: 'secondary', weight: 'regular', "data-testid": 'content', children: t('dyn_detected_new_wallet.description', {
90
93
  walletName: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector.name,
91
- }) }), jsx(TypographyButton, { expanded: true, onClick: handleClick, typographyProps: {
94
+ }) }), jsx(TypographyButton, { buttonClassName: 'detected-new-wallet-modal__confirm-button', expanded: true, onClick: handleClick, typographyProps: {
92
95
  variant: 'button_secondary',
93
- }, children: t('dyn_detected_new_wallet.confirm_button') })] }));
96
+ }, children: t('dyn_detected_new_wallet.confirm_button') }), jsx(Divider, { fullWidth: true, text: 'Or' }), jsx(LogoutButton, { isTextButton: false, buttonClassName: 'detected-new-wallet-modal__log-out-button' })] }));
94
97
  };
95
98
  const DetectedNewWalletWidgetPortal = () => (jsx(WidgetPortal, { onClose: useCloseMultiWalletPrompt(), children: jsx(DetectedNewWalletContent, {}) }));
96
99
  const DetectedNewWalletModal = () => (jsx(PromptModal, { onClose: useCloseMultiWalletPrompt(), children: jsx(DetectedNewWalletContent, {}) }));
@@ -75,8 +75,8 @@ require('../../../../context/PasskeyContext/PasskeyContext.cjs');
75
75
  require('../../components/DynamicWidgetHeader/DynamicWidgetHeader.cjs');
76
76
  var PromptModal = require('../../components/PromptModal/PromptModal.cjs');
77
77
  var WidgetPortal = require('../../components/WidgetPortal/WidgetPortal.cjs');
78
- var useConnectedAccountWallet = require('../../../../utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.cjs');
79
78
  var DefaultPromptModal = require('../DefaultPromptModal/DefaultPromptModal.cjs');
79
+ var useConnectedAccountWallet = require('../../../../utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.cjs');
80
80
  var SwitchAccountView = require('./SwitchAccountView/SwitchAccountView.cjs');
81
81
  var SwitchOrUseActiveAccountView = require('./SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.cjs');
82
82
  require('../../context/DynamicWidgetContext.cjs');
@@ -71,8 +71,8 @@ import '../../../../context/PasskeyContext/PasskeyContext.js';
71
71
  import '../../components/DynamicWidgetHeader/DynamicWidgetHeader.js';
72
72
  import { PromptModal } from '../../components/PromptModal/PromptModal.js';
73
73
  import { WidgetPortal } from '../../components/WidgetPortal/WidgetPortal.js';
74
- import { useConnectedAccountWallet } from '../../../../utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.js';
75
74
  import { DefaultPromptLayout } from '../DefaultPromptModal/DefaultPromptModal.js';
75
+ import { useConnectedAccountWallet } from '../../../../utils/hooks/useConnectedAccountWallet/useConnectedAccountWallet.js';
76
76
  import { SwitchAccountView } from './SwitchAccountView/SwitchAccountView.js';
77
77
  import { SwitchOrUseActiveAccountView } from './SwitchOrUseActiveAccountView/SwitchOrUseActiveAccountView.js';
78
78
  import '../../context/DynamicWidgetContext.js';
@@ -1,64 +0,0 @@
1
- 'use client'
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var React = require('react');
7
-
8
- function _interopNamespace(e) {
9
- if (e && e.__esModule) return e;
10
- var n = Object.create(null);
11
- if (e) {
12
- Object.keys(e).forEach(function (k) {
13
- if (k !== 'default') {
14
- var d = Object.getOwnPropertyDescriptor(e, k);
15
- Object.defineProperty(n, k, d.get ? d : {
16
- enumerable: true,
17
- get: function () { return e[k]; }
18
- });
19
- }
20
- });
21
- }
22
- n["default"] = e;
23
- return Object.freeze(n);
24
- }
25
-
26
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
-
28
- var _path, _path2, _path3, _path4;
29
- var _excluded = ["title", "titleId"];
30
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
31
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
32
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
33
- var SvgPromptAccountSwitch = function SvgPromptAccountSwitch(_ref) {
34
- var title = _ref.title,
35
- titleId = _ref.titleId,
36
- props = _objectWithoutProperties(_ref, _excluded);
37
- return /*#__PURE__*/React__namespace.createElement("svg", _extends({
38
- width: 40,
39
- height: 40,
40
- viewBox: "0 0 42 42",
41
- fill: "none",
42
- xmlns: "http://www.w3.org/2000/svg",
43
- "aria-labelledby": titleId
44
- }, props), title ? /*#__PURE__*/React__namespace.createElement("title", {
45
- id: titleId
46
- }, title) : null, _path || (_path = /*#__PURE__*/React__namespace.createElement("path", {
47
- d: "M31.583 11.75a7.617 7.617 0 0 0-1.25-.083H13.667c-.467 0-.917.033-1.35.1.233-.467.566-.9.966-1.3L18.7 5.033a5.875 5.875 0 0 1 8.267 0l2.916 2.95a5.623 5.623 0 0 1 1.7 3.767Z",
48
- fill: "#2660FF"
49
- })), _path2 || (_path2 = /*#__PURE__*/React__namespace.createElement("path", {
50
- opacity: 0.4,
51
- d: "M38.667 20v8.333c0 5-3.334 8.334-8.334 8.334H14.717a5.988 5.988 0 0 0 1.316-1.567c.617-1 .967-2.184.967-3.434A6.665 6.665 0 0 0 10.333 25c-2 0-3.783.883-5 2.267V20c0-4.534 2.734-7.7 6.984-8.233.433-.067.883-.1 1.35-.1h16.666c.434 0 .85.016 1.25.083 4.3.5 7.084 3.683 7.084 8.25Z",
52
- fill: "#2660FF"
53
- })), _path3 || (_path3 = /*#__PURE__*/React__namespace.createElement("path", {
54
- d: "M38.667 20.833h-5a3.343 3.343 0 0 0-3.334 3.334c0 1.833 1.5 3.333 3.334 3.333h5",
55
- fill: "#2660FF"
56
- })), _path4 || (_path4 = /*#__PURE__*/React__namespace.createElement("path", {
57
- fillRule: "evenodd",
58
- clipRule: "evenodd",
59
- d: "M10.333 25a6.667 6.667 0 1 0 0 13.333 6.667 6.667 0 0 0 0-13.333ZM2 31.667a8.333 8.333 0 1 1 16.667 0 8.333 8.333 0 0 1-16.667 0Zm8.577-3.09a.833.833 0 0 1 1.179 0l2.5 2.5a.833.833 0 0 1 0 1.18l-2.5 2.5a.833.833 0 0 1-1.179-1.18l1.078-1.077H7a.833.833 0 0 1 0-1.666h4.655l-1.078-1.078a.833.833 0 0 1 0-1.178Z",
60
- fill: "#2660FF"
61
- })));
62
- };
63
-
64
- exports.ReactComponent = SvgPromptAccountSwitch;