@dynamic-labs/sdk-react-core 0.18.0-RC.23 → 0.18.0-RC.24

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 CHANGED
@@ -1,4 +1,16 @@
1
1
 
2
+ ## [0.18.0-RC.24](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.23...v0.18.0-RC.24) (2023-08-01)
3
+
4
+
5
+ ### Features
6
+
7
+ * **QNTM-156:** onBeforeConnectSuccessConfirmation on account change ([#2782](https://github.com/dynamic-labs/DynamicAuth/issues/2782)) ([eeabcd0](https://github.com/dynamic-labs/DynamicAuth/commit/eeabcd07889b7284680dc92a83bfa1b8321fa0f5))
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * **bridge:** reordering not mess connected wallets ([#2758](https://github.com/dynamic-labs/DynamicAuth/issues/2758)) ([2cdc240](https://github.com/dynamic-labs/DynamicAuth/commit/2cdc240b1f5b401880d776174646ebc9383506d2))
13
+
2
14
  ## [0.18.0-RC.23](https://github.com/dynamic-labs/DynamicAuth/compare/v0.18.0-RC.22...v0.18.0-RC.23) (2023-07-31)
3
15
 
4
16
 
package/package.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "0.18.0-RC.23";
5
+ var version = "0.18.0-RC.24";
6
6
  var dependencies = {
7
7
  "react-focus-lock": "2.9.2",
8
8
  "@dynamic-labs/iconic": "0.1.23",
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
- var version = "0.18.0-RC.23";
1
+ var version = "0.18.0-RC.24";
2
2
  var dependencies = {
3
3
  "react-focus-lock": "2.9.2",
4
4
  "@dynamic-labs/iconic": "0.1.23",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/sdk-react-core",
3
- "version": "0.18.0-RC.23",
3
+ "version": "0.18.0-RC.24",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/dynamic-labs/DynamicAuth.git",
@@ -16,13 +16,13 @@
16
16
  "formik": "2.2.9",
17
17
  "qrcode": "1.5.1",
18
18
  "ethers": "5.7.2",
19
- "@dynamic-labs/logger": "0.18.0-RC.23",
20
- "@dynamic-labs/multi-wallet": "0.18.0-RC.23",
21
- "@dynamic-labs/rpc-providers": "0.18.0-RC.23",
22
- "@dynamic-labs/types": "0.18.0-RC.23",
23
- "@dynamic-labs/utils": "0.18.0-RC.23",
24
- "@dynamic-labs/wallet-book": "0.18.0-RC.23",
25
- "@dynamic-labs/wallet-connector-core": "0.18.0-RC.23"
19
+ "@dynamic-labs/logger": "0.18.0-RC.24",
20
+ "@dynamic-labs/multi-wallet": "0.18.0-RC.24",
21
+ "@dynamic-labs/rpc-providers": "0.18.0-RC.24",
22
+ "@dynamic-labs/types": "0.18.0-RC.24",
23
+ "@dynamic-labs/utils": "0.18.0-RC.24",
24
+ "@dynamic-labs/wallet-book": "0.18.0-RC.24",
25
+ "@dynamic-labs/wallet-connector-core": "0.18.0-RC.24"
26
26
  },
27
27
  "devDependencies": {
28
28
  "semver": "7.3.8"
@@ -21,7 +21,6 @@ var localStorage = require('../../shared/utils/classes/storage/localStorage.cjs'
21
21
  require('ethers');
22
22
  var useLocalStorage = require('../../shared/utils/hooks/useLocalStorage/useLocalStorage.cjs');
23
23
  var useGlobalLoading = require('../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.cjs');
24
- var useEffectOnce = require('../../shared/utils/hooks/useEffectOnce/useEffectOnce.cjs');
25
24
  require('../../shared/consts/index.cjs');
26
25
  require('react-dom');
27
26
  require('react-focus-lock');
@@ -80,7 +79,6 @@ require('../../views/CollectUserDataView/fieldsConfig.cjs');
80
79
  require('../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.cjs');
81
80
  var FundingWidget = require('../../widgets/FundingWidget/FundingWidget.cjs');
82
81
  var DynamicBridgeWidgetContext = require('../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.cjs');
83
- require('../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.cjs');
84
82
  var EmailVerificationContext = require('../EmailVerificationContext/EmailVerificationContext.cjs');
85
83
  var FundingContext = require('../FundingContext/FundingContext.cjs');
86
84
  var SendBalanceContext = require('../SendBalanceContext/SendBalanceContext.cjs');
@@ -199,10 +197,10 @@ const DynamicContextProvider = ({ children, theme, settings, }) => {
199
197
  setShowAuthFlow,
200
198
  wallets,
201
199
  });
202
- useEffectOnce.useEffectOnce(() => {
200
+ React.useEffect(() => {
203
201
  const missingChains = getMissingChains.getMissingChains(walletsByChain, connectedWalletsInfo);
204
202
  setWalletsToConnectByChain(missingChains);
205
- });
203
+ }, [walletsByChain]);
206
204
  const [selectedWalletConnector, setSelectedWalletConnector] = React.useState(null);
207
205
  //selected wallet to perform an action (become primary, unlink, etc)
208
206
  const [selectedWalletWithAction, setSelectedWalletWithAction] = React.useState(null);
@@ -1,6 +1,6 @@
1
1
  import { __awaiter } from '../../../../_virtual/_tslib.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { createContext, useState, useCallback, useEffect, useMemo } from 'react';
3
+ import { createContext, useState, useEffect, useCallback, useMemo } from 'react';
4
4
  import { ICONIC_SPRITE_URL } from '@dynamic-labs/iconic';
5
5
  import { MissingEnvironmentIdError } from '@dynamic-labs/utils';
6
6
  import { useWalletBookCdn, getWalletBookCdnUrl, WalletBookContextProvider } from '@dynamic-labs/wallet-book';
@@ -17,7 +17,6 @@ import { LocalStorage } from '../../shared/utils/classes/storage/localStorage.js
17
17
  import 'ethers';
18
18
  import { useLocalStorage } from '../../shared/utils/hooks/useLocalStorage/useLocalStorage.js';
19
19
  import { useGlobalLoading } from '../../shared/utils/hooks/useGlobalLoading/useGlobalLoading.js';
20
- import { useEffectOnce } from '../../shared/utils/hooks/useEffectOnce/useEffectOnce.js';
21
20
  import '../../shared/consts/index.js';
22
21
  import 'react-dom';
23
22
  import 'react-focus-lock';
@@ -76,7 +75,6 @@ import '../../views/CollectUserDataView/fieldsConfig.js';
76
75
  import '../../components/UserProfile/parts/UserProfileField/components/VerifiedEmailIcon/VerifiedEmailIcon.js';
77
76
  import { FundingWidget } from '../../widgets/FundingWidget/FundingWidget.js';
78
77
  import { DynamicBridgeWidgetContextProvider } from '../../widgets/DynamicBridgeWidget/context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.js';
79
- import '../../widgets/DynamicBridgeWidget/views/WalletsView/components/SecondaryWallets/SecondaryWallets.js';
80
78
  import { EmailVerificationContextProvider } from '../EmailVerificationContext/EmailVerificationContext.js';
81
79
  import { FundingContextProvider } from '../FundingContext/FundingContext.js';
82
80
  import { SendBalanceContextProvider } from '../SendBalanceContext/SendBalanceContext.js';
@@ -195,10 +193,10 @@ const DynamicContextProvider = ({ children, theme, settings, }) => {
195
193
  setShowAuthFlow,
196
194
  wallets,
197
195
  });
198
- useEffectOnce(() => {
196
+ useEffect(() => {
199
197
  const missingChains = getMissingChains(walletsByChain, connectedWalletsInfo);
200
198
  setWalletsToConnectByChain(missingChains);
201
- });
199
+ }, [walletsByChain]);
202
200
  const [selectedWalletConnector, setSelectedWalletConnector] = useState(null);
203
201
  //selected wallet to perform an action (become primary, unlink, etc)
204
202
  const [selectedWalletWithAction, setSelectedWalletWithAction] = useState(null);
@@ -102,7 +102,7 @@ export type OnAuthSuccess = (params: {
102
102
  export type OnConnectSuccess = (params: {
103
103
  walletConnector: WalletConnector | null;
104
104
  }) => void;
105
- export type OnBeforeConnectSuccessConfirmation = (walletAddress: string) => Promise<boolean>;
105
+ export type OnBeforeConnectSuccessConfirmation = (wallet: Partial<Wallet>) => Promise<boolean>;
106
106
  export type OnUserProfileUpdate = (user: UserProfile) => void;
107
107
  export type MultiWalletWidgetState = 'idle' | 'awaiting_account_switch' | 'awaiting_connection' | 'awaiting_signature' | 'detected_new_wallet';
108
108
  export type AccountSwitchState = 'idle' | 'linking_new_wallet' | 'switching_primary' | 'primary_not_connected';
@@ -102,11 +102,23 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
102
102
  return Promise.resolve();
103
103
  };
104
104
  // Updates connected wallet (network and address) and verifies connected wallet connection
105
- const refreshConnectedWallet = (walletId, walletConnector) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
105
+ const refreshConnectedWallet = (walletId, walletConnector, shouldCallCallback = false) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
106
106
  if (shouldManuallyReconnectOnRefresh.shouldManuallyReconnectOnRefresh(walletConnector)) {
107
107
  yield walletConnector.connect();
108
108
  }
109
109
  const currentWalletConnectorAddress = yield walletConnector.fetchPublicAddress();
110
+ if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
111
+ const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
112
+ address: currentWalletConnectorAddress,
113
+ chain: walletConnector.connectedChain,
114
+ connector: walletConnector,
115
+ });
116
+ if (!shouldProceedWithConnection) {
117
+ walletConnectorCore.logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
118
+ setShowAuthFlow(false);
119
+ return;
120
+ }
121
+ }
110
122
  if (!currentWalletConnectorAddress) {
111
123
  walletConnectorCore.logger.error('Could not refresh the wallet. The wallet address is not available');
112
124
  return;
@@ -127,7 +139,11 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
127
139
  throw error;
128
140
  }
129
141
  if (onBeforeConnectSuccessConfirmation) {
130
- const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation(publicWalletAddress);
142
+ const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
143
+ address: publicWalletAddress,
144
+ chain: walletConnector.connectedChain,
145
+ connector: walletConnector,
146
+ });
131
147
  if (!shouldProceedWithConnection) {
132
148
  walletConnectorCore.logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
133
149
  setShowAuthFlow(false);
@@ -26,7 +26,7 @@ export declare const useConnectWallet: ({ authMode, clearPrimaryWalletId, enable
26
26
  connectedWallets: Wallet[];
27
27
  connectedWalletsInfo: ConnectedWalletConnectorType[] | [];
28
28
  getConnectedWalletById: (walletId: string) => Wallet | undefined;
29
- refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
29
+ refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector, shouldCallCallback?: boolean) => Promise<void>;
30
30
  removeConnectedWalletsInfo: () => void;
31
31
  unlinkConnectedWallet: (walletId: string) => void;
32
32
  };
@@ -98,11 +98,23 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
98
98
  return Promise.resolve();
99
99
  };
100
100
  // Updates connected wallet (network and address) and verifies connected wallet connection
101
- const refreshConnectedWallet = (walletId, walletConnector) => __awaiter(void 0, void 0, void 0, function* () {
101
+ const refreshConnectedWallet = (walletId, walletConnector, shouldCallCallback = false) => __awaiter(void 0, void 0, void 0, function* () {
102
102
  if (shouldManuallyReconnectOnRefresh(walletConnector)) {
103
103
  yield walletConnector.connect();
104
104
  }
105
105
  const currentWalletConnectorAddress = yield walletConnector.fetchPublicAddress();
106
+ if (onBeforeConnectSuccessConfirmation && shouldCallCallback) {
107
+ const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
108
+ address: currentWalletConnectorAddress,
109
+ chain: walletConnector.connectedChain,
110
+ connector: walletConnector,
111
+ });
112
+ if (!shouldProceedWithConnection) {
113
+ logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
114
+ setShowAuthFlow(false);
115
+ return;
116
+ }
117
+ }
106
118
  if (!currentWalletConnectorAddress) {
107
119
  logger.error('Could not refresh the wallet. The wallet address is not available');
108
120
  return;
@@ -123,7 +135,11 @@ const useConnectWallet = ({ authMode, clearPrimaryWalletId, enableVisitTrackingO
123
135
  throw error;
124
136
  }
125
137
  if (onBeforeConnectSuccessConfirmation) {
126
- const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation(publicWalletAddress);
138
+ const shouldProceedWithConnection = yield onBeforeConnectSuccessConfirmation({
139
+ address: publicWalletAddress,
140
+ chain: walletConnector.connectedChain,
141
+ connector: walletConnector,
142
+ });
127
143
  if (!shouldProceedWithConnection) {
128
144
  logger.info('Connection was not established because onBeforeConnectSuccessConfirmation returned false');
129
145
  setShowAuthFlow(false);
@@ -96,7 +96,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
96
96
  const [newAddress] = accounts;
97
97
  const newWallet = secondaryWallets.find((wallet) => walletConnectorCore.isSameAddress(wallet.address, newAddress, wallet.chain));
98
98
  if (authMode === 'connect-only') {
99
- refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
99
+ refreshConnectedWallet(primaryWallet.id, primaryWallet.connector, true);
100
100
  return;
101
101
  }
102
102
  if (walletConnectorCore.isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
@@ -160,7 +160,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
160
160
  const secondaryListeners = {
161
161
  onAccountChange: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
162
162
  if (authMode === 'connect-only' && secondaryWallets.length) {
163
- refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
163
+ refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector, true);
164
164
  return;
165
165
  }
166
166
  if (multiWalletWidgetState === 'awaiting_account_switch') {
@@ -17,7 +17,7 @@ export type UseWalletEventListenersArgs = {
17
17
  setSelectedWalletWithAction(walletWithAction: WalletWithAction | null): void;
18
18
  user: UserProfile | undefined;
19
19
  authMode: AuthModeType;
20
- refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector) => Promise<void>;
20
+ refreshConnectedWallet: (walletId: string, walletConnector: WalletConnector, shouldCallCallback?: boolean) => Promise<void>;
21
21
  };
22
22
  export declare const useWalletEventListeners: ({ computeConnectedStateForWallets, handleLogOut, multiWallet, multiWalletWidgetState, primaryWallet, secondaryWallets, selectedWalletConnector, selectedWalletWithAction, setSelectedWalletConnector, setSelectedWalletWithAction, setMultiWalletWidgetState, user, setPrimaryWalletId, authMode, refreshConnectedWallet, }: UseWalletEventListenersArgs) => {
23
23
  loadingNetwork: boolean;
@@ -92,7 +92,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
92
92
  const [newAddress] = accounts;
93
93
  const newWallet = secondaryWallets.find((wallet) => isSameAddress(wallet.address, newAddress, wallet.chain));
94
94
  if (authMode === 'connect-only') {
95
- refreshConnectedWallet(primaryWallet.id, primaryWallet.connector);
95
+ refreshConnectedWallet(primaryWallet.id, primaryWallet.connector, true);
96
96
  return;
97
97
  }
98
98
  if (isSameAddress(newAddress, primaryWallet.address, primaryWallet.chain)) {
@@ -156,7 +156,7 @@ const useWalletEventListeners = ({ computeConnectedStateForWallets, handleLogOut
156
156
  const secondaryListeners = {
157
157
  onAccountChange: () => __awaiter(void 0, void 0, void 0, function* () {
158
158
  if (authMode === 'connect-only' && secondaryWallets.length) {
159
- refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector);
159
+ refreshConnectedWallet(secondaryWallets[0].id, secondaryWallets[0].connector, true);
160
160
  return;
161
161
  }
162
162
  if (multiWalletWidgetState === 'awaiting_account_switch') {
@@ -50,7 +50,7 @@ var DynamicBridgeUserProfile = require('./components/DynamicBridgeUserProfile/Dy
50
50
  var DynamicBridgeWidgetContext = require('./context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.cjs');
51
51
 
52
52
  const DynamicBridgeWidget = ({ className, variant = 'modal', }) => {
53
- const { showAuthFlow, setShowBridgeWidget, walletsByChain, setShowAuthFlow, getConnectedWalletById, } = useInternalDynamicContext.useInternalDynamicContext();
53
+ const { showAuthFlow, setShowBridgeWidget, walletsByChain, setShowAuthFlow, connectedWallets, } = useInternalDynamicContext.useInternalDynamicContext();
54
54
  const { widgetRef, inlineControlsRef } = DynamicBridgeWidgetContext.useDynamicBridgeWidgetContext();
55
55
  const closeOnOutsideClick = React.useCallback((e) => {
56
56
  var _a;
@@ -62,11 +62,11 @@ const DynamicBridgeWidget = ({ className, variant = 'modal', }) => {
62
62
  }
63
63
  }, [inlineControlsRef, variant, showAuthFlow, setShowBridgeWidget]);
64
64
  index.useOnClickOutside(widgetRef, closeOnOutsideClick);
65
- return (jsxRuntime.jsx(IsBrowser.IsBrowser, { children: jsxRuntime.jsxs(ShadowDOM.ShadowDOM, Object.assign({ id: 'dynamic-bridge-widget', className: 'dynamic-widget__container' }, { children: [jsxRuntime.jsx(InlineWidget.InlineWidget, Object.assign({ ref: inlineControlsRef, className: className, dataTestId: 'BridgeWidgetNav' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }, index) => {
65
+ return (jsxRuntime.jsx(IsBrowser.IsBrowser, { children: jsxRuntime.jsxs(ShadowDOM.ShadowDOM, Object.assign({ id: 'dynamic-bridge-widget', className: 'dynamic-widget__container' }, { children: [jsxRuntime.jsx(InlineWidget.InlineWidget, Object.assign({ ref: inlineControlsRef, className: className, dataTestId: 'BridgeWidgetNav' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
66
66
  const ChainIcon = getChainIcon.getChainIcon(chain);
67
- const wallet = getConnectedWalletById(`connect-wallet-${index}`);
68
- if (wallet) {
69
- return (jsxRuntime.jsx(InlineWidgetButton.InlineWidgetButton, Object.assign({ icon: jsxRuntime.jsx(ChainIcon, {}), onClick: () => setShowBridgeWidget(true) }, { children: shortenWalletAddress.shortenWalletAddress(wallet.address, 3, 3) }), chain));
67
+ const connectedChainWallets = connectedWallets.filter(({ chain: connectedChain }) => connectedChain === chain);
68
+ if (connectedChainWallets.length > 0) {
69
+ return connectedChainWallets.map((wallet) => (jsxRuntime.jsx(InlineWidgetButton.InlineWidgetButton, Object.assign({ icon: jsxRuntime.jsx(ChainIcon, {}), onClick: () => setShowBridgeWidget(true) }, { children: shortenWalletAddress.shortenWalletAddress(wallet.address, 3, 3) }), wallet.id)));
70
70
  }
71
71
  return (jsxRuntime.jsx(InlineWidgetButton.InlineWidgetButton, Object.assign({ icon: jsxRuntime.jsx(ChainIcon, {}), onClick: () => setShowAuthFlow(true) }, { children: "Connect wallet" }), chain));
72
72
  }) })), jsxRuntime.jsx(DynamicBridgeUserProfile.DynamicBridgeUserProfile, { variant: variant })] })) }));
@@ -46,7 +46,7 @@ import { DynamicBridgeUserProfile } from './components/DynamicBridgeUserProfile/
46
46
  import { useDynamicBridgeWidgetContext } from './context/DynamicBridgeWidgetContext/DynamicBridgeWidgetContext.js';
47
47
 
48
48
  const DynamicBridgeWidget = ({ className, variant = 'modal', }) => {
49
- const { showAuthFlow, setShowBridgeWidget, walletsByChain, setShowAuthFlow, getConnectedWalletById, } = useInternalDynamicContext();
49
+ const { showAuthFlow, setShowBridgeWidget, walletsByChain, setShowAuthFlow, connectedWallets, } = useInternalDynamicContext();
50
50
  const { widgetRef, inlineControlsRef } = useDynamicBridgeWidgetContext();
51
51
  const closeOnOutsideClick = useCallback((e) => {
52
52
  var _a;
@@ -58,11 +58,11 @@ const DynamicBridgeWidget = ({ className, variant = 'modal', }) => {
58
58
  }
59
59
  }, [inlineControlsRef, variant, showAuthFlow, setShowBridgeWidget]);
60
60
  useOnClickOutside(widgetRef, closeOnOutsideClick);
61
- return (jsx(IsBrowser, { children: jsxs(ShadowDOM, Object.assign({ id: 'dynamic-bridge-widget', className: 'dynamic-widget__container' }, { children: [jsx(InlineWidget, Object.assign({ ref: inlineControlsRef, className: className, dataTestId: 'BridgeWidgetNav' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }, index) => {
61
+ return (jsx(IsBrowser, { children: jsxs(ShadowDOM, Object.assign({ id: 'dynamic-bridge-widget', className: 'dynamic-widget__container' }, { children: [jsx(InlineWidget, Object.assign({ ref: inlineControlsRef, className: className, dataTestId: 'BridgeWidgetNav' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
62
62
  const ChainIcon = getChainIcon(chain);
63
- const wallet = getConnectedWalletById(`connect-wallet-${index}`);
64
- if (wallet) {
65
- return (jsx(InlineWidgetButton, Object.assign({ icon: jsx(ChainIcon, {}), onClick: () => setShowBridgeWidget(true) }, { children: shortenWalletAddress(wallet.address, 3, 3) }), chain));
63
+ const connectedChainWallets = connectedWallets.filter(({ chain: connectedChain }) => connectedChain === chain);
64
+ if (connectedChainWallets.length > 0) {
65
+ return connectedChainWallets.map((wallet) => (jsx(InlineWidgetButton, Object.assign({ icon: jsx(ChainIcon, {}), onClick: () => setShowBridgeWidget(true) }, { children: shortenWalletAddress(wallet.address, 3, 3) }), wallet.id)));
66
66
  }
67
67
  return (jsx(InlineWidgetButton, Object.assign({ icon: jsx(ChainIcon, {}), onClick: () => setShowAuthFlow(true) }, { children: "Connect wallet" }), chain));
68
68
  }) })), jsx(DynamicBridgeUserProfile, { variant: variant })] })) }));
@@ -4,7 +4,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var jsxRuntime = require('react/jsx-runtime');
6
6
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
7
- var DynamicWidgetFooter = require('../../../DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.cjs');
8
7
  require('react');
9
8
  require('@dynamic-labs/sdk-api');
10
9
  require('../../../../shared/logger.cjs');
@@ -44,20 +43,24 @@ require('formik');
44
43
  require('yup');
45
44
  require('../../../../components/InlineWidget/InlineWidget.cjs');
46
45
  require('../../../../components/MenuList/Dropdown/Dropdown.cjs');
46
+ var Balance = require('../../../DynamicWidget/components/Balance/Balance.cjs');
47
+ var DynamicWidgetFooter = require('../../../DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.cjs');
47
48
  var DynamicBridgeWalletCard = require('../../components/DynamicBridgeWalletCard/DynamicBridgeWalletCard.cjs');
48
49
  var DynamicBridgeWalletCardBody = require('../../components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.cjs');
49
- var Balance = require('../../../DynamicWidget/components/Balance/Balance.cjs');
50
50
  var DynamicBridgeWidgetEmptyCard = require('../../components/DynamicBridgeWidgetEmptyCard/DynamicBridgeWidgetEmptyCard.cjs');
51
- var SecondaryWallets = require('./components/SecondaryWallets/SecondaryWallets.cjs');
52
51
 
53
52
  const WalletsView = () => {
54
- const { unlinkConnectedWallet, walletsByChain, getConnectedWalletById } = useInternalDynamicContext.useInternalDynamicContext();
55
- const firstWallet = getConnectedWalletById('connect-wallet-0');
56
- const PrimaryWalletChainIcon = firstWallet && getChainIcon.getChainIcon(firstWallet.chain);
57
- const primaryWalletChainInfo = firstWallet && walletConnectorCore.getChainInfo(firstWallet.chain);
58
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs("div", Object.assign({ className: 'dynamic-bridge-widget-wallets-view' }, { children: [firstWallet && PrimaryWalletChainIcon && (jsxRuntime.jsx(DynamicBridgeWalletCard.DynamicBridgeWalletCard, Object.assign({ networkIcon: jsxRuntime.jsx(PrimaryWalletChainIcon, {}), networkName: primaryWalletChainInfo === null || primaryWalletChainInfo === void 0 ? void 0 : primaryWalletChainInfo.displayName }, { children: jsxRuntime.jsx(DynamicBridgeWalletCardBody.DynamicBridgeWalletCardBody, { walletName: firstWallet.connector.name, walletAddress: firstWallet.address, walletBalance:
59
- // eslint-disable-next-line react/jsx-wrap-multilines
60
- jsxRuntime.jsx(Balance.Balance, { address: firstWallet.address, connector: firstWallet.connector, network: firstWallet.chain }), onUnlinkClick: () => unlinkConnectedWallet(firstWallet.id) }) }))), !firstWallet && (jsxRuntime.jsx(DynamicBridgeWidgetEmptyCard.DynamicBridgeWidgetEmptyCard, { chain: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain[0].chain })), jsxRuntime.jsx(SecondaryWallets.MemoSecondaryWallets, {})] })), jsxRuntime.jsx(DynamicWidgetFooter.DynamicWidgetFooter, { children: jsxRuntime.jsx(LogoutButton.LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
53
+ const { unlinkConnectedWallet, walletsByChain, connectedWallets } = useInternalDynamicContext.useInternalDynamicContext();
54
+ return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("div", Object.assign({ className: 'dynamic-bridge-widget-wallets-view' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
55
+ const chainWallets = connectedWallets.filter(({ chain: walletChain }) => chain === walletChain);
56
+ // "Connect wallet" for empty chains
57
+ if (!chainWallets.length)
58
+ return jsxRuntime.jsx(DynamicBridgeWidgetEmptyCard.DynamicBridgeWidgetEmptyCard, { chain: chain });
59
+ const WalletIcon = getChainIcon.getChainIcon(chain);
60
+ const walletInfo = walletConnectorCore.getChainInfo(chain);
61
+ // Wallets info for chains with connected wallets
62
+ return chainWallets.map(({ connector, address, id }) => (jsxRuntime.jsx(DynamicBridgeWalletCard.DynamicBridgeWalletCard, Object.assign({ networkIcon: jsxRuntime.jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName }, { children: jsxRuntime.jsx(DynamicBridgeWalletCardBody.DynamicBridgeWalletCardBody, { walletName: connector.name, walletAddress: address, walletBalance: jsxRuntime.jsx(Balance.Balance, { address: address, connector: connector, network: chain }), onUnlinkClick: () => unlinkConnectedWallet(id) }) }), id)));
63
+ }) })), jsxRuntime.jsx(DynamicWidgetFooter.DynamicWidgetFooter, { children: jsxRuntime.jsx(LogoutButton.LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
61
64
  };
62
65
 
63
66
  exports.WalletsView = WalletsView;
@@ -1,6 +1,5 @@
1
1
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
2
2
  import { getChainInfo } from '@dynamic-labs/wallet-connector-core';
3
- import { DynamicWidgetFooter } from '../../../DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.js';
4
3
  import 'react';
5
4
  import '@dynamic-labs/sdk-api';
6
5
  import '../../../../shared/logger.js';
@@ -40,20 +39,24 @@ import 'formik';
40
39
  import 'yup';
41
40
  import '../../../../components/InlineWidget/InlineWidget.js';
42
41
  import '../../../../components/MenuList/Dropdown/Dropdown.js';
42
+ import { Balance } from '../../../DynamicWidget/components/Balance/Balance.js';
43
+ import { DynamicWidgetFooter } from '../../../DynamicWidget/components/DynamicWidgetFooter/DynamicWidgetFooter.js';
43
44
  import { DynamicBridgeWalletCard } from '../../components/DynamicBridgeWalletCard/DynamicBridgeWalletCard.js';
44
45
  import { DynamicBridgeWalletCardBody } from '../../components/DynamicBridgeWalletCardBody/DynamicBridgeWalletCardBody.js';
45
- import { Balance } from '../../../DynamicWidget/components/Balance/Balance.js';
46
46
  import { DynamicBridgeWidgetEmptyCard } from '../../components/DynamicBridgeWidgetEmptyCard/DynamicBridgeWidgetEmptyCard.js';
47
- import { MemoSecondaryWallets } from './components/SecondaryWallets/SecondaryWallets.js';
48
47
 
49
48
  const WalletsView = () => {
50
- const { unlinkConnectedWallet, walletsByChain, getConnectedWalletById } = useInternalDynamicContext();
51
- const firstWallet = getConnectedWalletById('connect-wallet-0');
52
- const PrimaryWalletChainIcon = firstWallet && getChainIcon(firstWallet.chain);
53
- const primaryWalletChainInfo = firstWallet && getChainInfo(firstWallet.chain);
54
- return (jsxs(Fragment, { children: [jsxs("div", Object.assign({ className: 'dynamic-bridge-widget-wallets-view' }, { children: [firstWallet && PrimaryWalletChainIcon && (jsx(DynamicBridgeWalletCard, Object.assign({ networkIcon: jsx(PrimaryWalletChainIcon, {}), networkName: primaryWalletChainInfo === null || primaryWalletChainInfo === void 0 ? void 0 : primaryWalletChainInfo.displayName }, { children: jsx(DynamicBridgeWalletCardBody, { walletName: firstWallet.connector.name, walletAddress: firstWallet.address, walletBalance:
55
- // eslint-disable-next-line react/jsx-wrap-multilines
56
- jsx(Balance, { address: firstWallet.address, connector: firstWallet.connector, network: firstWallet.chain }), onUnlinkClick: () => unlinkConnectedWallet(firstWallet.id) }) }))), !firstWallet && (jsx(DynamicBridgeWidgetEmptyCard, { chain: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain[0].chain })), jsx(MemoSecondaryWallets, {})] })), jsx(DynamicWidgetFooter, { children: jsx(LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
49
+ const { unlinkConnectedWallet, walletsByChain, connectedWallets } = useInternalDynamicContext();
50
+ return (jsxs(Fragment, { children: [jsx("div", Object.assign({ className: 'dynamic-bridge-widget-wallets-view' }, { children: walletsByChain === null || walletsByChain === void 0 ? void 0 : walletsByChain.map(({ chain }) => {
51
+ const chainWallets = connectedWallets.filter(({ chain: walletChain }) => chain === walletChain);
52
+ // "Connect wallet" for empty chains
53
+ if (!chainWallets.length)
54
+ return jsx(DynamicBridgeWidgetEmptyCard, { chain: chain });
55
+ const WalletIcon = getChainIcon(chain);
56
+ const walletInfo = getChainInfo(chain);
57
+ // Wallets info for chains with connected wallets
58
+ return chainWallets.map(({ connector, address, id }) => (jsx(DynamicBridgeWalletCard, Object.assign({ networkIcon: jsx(WalletIcon, {}), networkName: walletInfo === null || walletInfo === void 0 ? void 0 : walletInfo.displayName }, { children: jsx(DynamicBridgeWalletCardBody, { walletName: connector.name, walletAddress: address, walletBalance: jsx(Balance, { address: address, connector: connector, network: chain }), onUnlinkClick: () => unlinkConnectedWallet(id) }) }), id)));
59
+ }) })), jsx(DynamicWidgetFooter, { children: jsx(LogoutButton, { buttonClassName: 'dynamic-bridge-widget-wallets-view__logout-button', isTextButton: true }) })] }));
57
60
  };
58
61
 
59
62
  export { WalletsView, WalletsView as default };