@dynamic-labs/sdk-react-core 4.88.1 → 4.88.3

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 (47) hide show
  1. package/CHANGELOG.md +18 -153
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +12 -12
  5. package/src/lib/components/WalletConnectorEvents/WalletConnectorEvents.cjs +6 -0
  6. package/src/lib/components/WalletConnectorEvents/WalletConnectorEvents.js +6 -0
  7. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.cjs +8 -0
  8. package/src/lib/context/ConnectWithOtpContext/ConnectWithOtpProvider.js +8 -0
  9. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/index.d.ts +1 -0
  10. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.cjs +48 -0
  11. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.d.ts +16 -0
  12. package/src/lib/context/ConnectWithOtpContext/hooks/useRestoreOtpVerificationState/useRestoreOtpVerificationState.js +44 -0
  13. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.cjs +88 -0
  14. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.d.ts +16 -0
  15. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/buildEmailOtpHandler.js +84 -0
  16. package/src/lib/context/ConnectWithOtpContext/utils/buildEmailOtpHandler/index.d.ts +1 -0
  17. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.cjs +67 -0
  18. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.d.ts +17 -0
  19. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/buildSmsOtpHandler.js +63 -0
  20. package/src/lib/context/ConnectWithOtpContext/utils/buildSmsOtpHandler/index.d.ts +1 -0
  21. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.cjs +23 -47
  22. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.d.ts +1 -1
  23. package/src/lib/context/ConnectWithOtpContext/utils/createEmailHandler.js +23 -47
  24. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.cjs +19 -34
  25. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.d.ts +1 -1
  26. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.js +19 -34
  27. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/index.d.ts +2 -0
  28. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.cjs +60 -0
  29. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.d.ts +30 -0
  30. package/src/lib/context/ConnectWithOtpContext/utils/otpVerificationStorage/otpVerificationStorage.js +54 -0
  31. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +3 -3
  32. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +4 -4
  33. package/src/lib/utils/hooks/useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.cjs +10 -2
  34. package/src/lib/utils/hooks/useCreateWalletConnectorOptions/useCreateWalletConnectorOptions.js +10 -2
  35. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.cjs +11 -10
  36. package/src/lib/utils/hooks/useDynamicWaas/useDynamicWaas.js +12 -11
  37. package/src/lib/utils/hooks/useReconcileInstalledWallets/index.d.ts +1 -0
  38. package/src/lib/utils/hooks/useReconcileInstalledWallets/useReconcileInstalledWallets.cjs +69 -0
  39. package/src/lib/utils/hooks/useReconcileInstalledWallets/useReconcileInstalledWallets.d.ts +7 -0
  40. package/src/lib/utils/hooks/useReconcileInstalledWallets/useReconcileInstalledWallets.js +65 -0
  41. package/src/lib/utils/hooks/useWalletList/buildWalletsList.cjs +42 -0
  42. package/src/lib/utils/hooks/useWalletList/buildWalletsList.d.ts +17 -0
  43. package/src/lib/utils/hooks/useWalletList/buildWalletsList.js +38 -0
  44. package/src/lib/utils/hooks/useWalletList/useWalletList.cjs +27 -26
  45. package/src/lib/utils/hooks/useWalletList/useWalletList.js +27 -26
  46. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +26 -21
  47. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +26 -21
@@ -0,0 +1,38 @@
1
+ 'use client'
2
+ import { pipe } from '@dynamic-labs/utils';
3
+ import { FilterBridgeChainsName } from '../../functions/walletFilters/index.js';
4
+ import { walletListBuilder } from '../../functions/walletListBuilder/walletListBuilder.js';
5
+ import { getEffectiveRecommendedWallets } from './utils/getEffectiveRecommendedWallets/getEffectiveRecommendedWallets.js';
6
+ import { getEffectiveWalletFilter } from './utils/getEffectiveWalletFilter/getEffectiveWalletFilter.js';
7
+
8
+ const buildWalletsList = ({ bridgeChainsToConnect, defaultNumberOfWalletsToShow, isWalletConnectList, lastUsedWalletKey, multiWallet, recommendedWallets, searchFilter, selectedTabSettings, userWallets, viewWalletsFilter, walletConnectorOptions, walletGroups, walletsFilter, }) => {
9
+ const getFilteredBridgeChains = (bridgeChainsToConnect === null || bridgeChainsToConnect === void 0 ? void 0 : bridgeChainsToConnect.length) &&
10
+ FilterBridgeChainsName(bridgeChainsToConnect[0].chain);
11
+ const filteredBridgeChains = getFilteredBridgeChains && getFilteredBridgeChains(walletConnectorOptions);
12
+ const effectiveRecommendedWallets = getEffectiveRecommendedWallets(selectedTabSettings, recommendedWallets);
13
+ const effectiveWalletsFilter = getEffectiveWalletFilter(selectedTabSettings, walletsFilter);
14
+ const { numberOfWallets, walletsList } = walletListBuilder({
15
+ groupWallets: true,
16
+ inputList: filteredBridgeChains || walletConnectorOptions,
17
+ isWalletConnectList,
18
+ lastUsedWalletKey,
19
+ multiWallet,
20
+ numberOfWalletsToShow: defaultNumberOfWalletsToShow,
21
+ recommendedWallets: effectiveRecommendedWallets,
22
+ searchFilter,
23
+ showMoreWalletsWithFilter: true,
24
+ userWallets,
25
+ walletGroups,
26
+ // use both filters if available, else use the viewWalletsFilter or effectiveWalletsFilter
27
+ walletsFilter: viewWalletsFilter && effectiveWalletsFilter
28
+ ? pipe(viewWalletsFilter).pipe(effectiveWalletsFilter)
29
+ : viewWalletsFilter || effectiveWalletsFilter,
30
+ });
31
+ return {
32
+ numberOfWallets,
33
+ recommendedWallets: effectiveRecommendedWallets,
34
+ walletsList,
35
+ };
36
+ };
37
+
38
+ export { buildWalletsList };
@@ -3,47 +3,48 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var utils = require('@dynamic-labs/utils');
6
+ var React = require('react');
7
7
  require('../../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
8
8
  var useInternalDynamicContext = require('../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
9
9
  var UserWalletsContext = require('../../../context/UserWalletsContext/UserWalletsContext.cjs');
10
10
  var walletOptions = require('../../../store/state/walletOptions/walletOptions.cjs');
11
- var index = require('../../functions/walletFilters/index.cjs');
12
- var walletListBuilder = require('../../functions/walletListBuilder/walletListBuilder.cjs');
13
- var getEffectiveRecommendedWallets = require('./utils/getEffectiveRecommendedWallets/getEffectiveRecommendedWallets.cjs');
14
- var getEffectiveWalletFilter = require('./utils/getEffectiveWalletFilter/getEffectiveWalletFilter.cjs');
11
+ var buildWalletsList = require('./buildWalletsList.cjs');
15
12
 
16
13
  const useWalletList = ({ isWalletConnectList = false, viewWalletsFilter, searchFilter, lastUsedWalletKey, }) => {
17
14
  const { walletsFilter, walletConnectorOptions, defaultNumberOfWalletsToShow, bridgeChainsToConnect, multiWallet, recommendedWallets, selectedTabSettings, } = useInternalDynamicContext.useInternalDynamicContext();
18
15
  const { userWallets } = UserWalletsContext.useInternalUserWallets();
19
16
  const walletGroups = walletOptions.useWalletGroups();
20
- const getFilteredBridgeChains = (bridgeChainsToConnect === null || bridgeChainsToConnect === void 0 ? void 0 : bridgeChainsToConnect.length) &&
21
- index.FilterBridgeChainsName(bridgeChainsToConnect[0].chain);
22
- const filteredBridgeChains = getFilteredBridgeChains && getFilteredBridgeChains(walletConnectorOptions);
23
- const effectiveRecommendedWallets = getEffectiveRecommendedWallets.getEffectiveRecommendedWallets(selectedTabSettings, recommendedWallets);
24
- const effectiveWalletsFilter = getEffectiveWalletFilter.getEffectiveWalletFilter(selectedTabSettings, walletsFilter);
25
- const { numberOfWallets, walletsList } = walletListBuilder.walletListBuilder({
26
- groupWallets: true,
27
- inputList: filteredBridgeChains || walletConnectorOptions,
17
+ // Run the heavy list build once per real input change, not on every render —
18
+ // a modal close animation re-renders this hundreds of times.
19
+ return React.useMemo(() => buildWalletsList.buildWalletsList({
20
+ bridgeChainsToConnect,
21
+ defaultNumberOfWalletsToShow,
28
22
  isWalletConnectList,
29
23
  lastUsedWalletKey,
30
24
  multiWallet,
31
- numberOfWalletsToShow: defaultNumberOfWalletsToShow,
32
- recommendedWallets: effectiveRecommendedWallets,
25
+ recommendedWallets,
33
26
  searchFilter,
34
- showMoreWalletsWithFilter: true,
27
+ selectedTabSettings,
35
28
  userWallets,
29
+ viewWalletsFilter,
30
+ walletConnectorOptions,
36
31
  walletGroups,
37
- // use both filters if available, else use the viewWalletsFilter or effectiveWalletsFilter
38
- walletsFilter: viewWalletsFilter && effectiveWalletsFilter
39
- ? utils.pipe(viewWalletsFilter).pipe(effectiveWalletsFilter)
40
- : viewWalletsFilter || effectiveWalletsFilter,
41
- });
42
- return {
43
- numberOfWallets,
44
- recommendedWallets: effectiveRecommendedWallets,
45
- walletsList,
46
- };
32
+ walletsFilter,
33
+ }), [
34
+ bridgeChainsToConnect,
35
+ defaultNumberOfWalletsToShow,
36
+ isWalletConnectList,
37
+ lastUsedWalletKey,
38
+ multiWallet,
39
+ recommendedWallets,
40
+ searchFilter,
41
+ selectedTabSettings,
42
+ userWallets,
43
+ viewWalletsFilter,
44
+ walletConnectorOptions,
45
+ walletGroups,
46
+ walletsFilter,
47
+ ]);
47
48
  };
48
49
 
49
50
  exports.useWalletList = useWalletList;
@@ -1,45 +1,46 @@
1
1
  'use client'
2
- import { pipe } from '@dynamic-labs/utils';
2
+ import { useMemo } from 'react';
3
3
  import '../../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
4
4
  import { useInternalDynamicContext } from '../../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
5
5
  import { useInternalUserWallets } from '../../../context/UserWalletsContext/UserWalletsContext.js';
6
6
  import { useWalletGroups } from '../../../store/state/walletOptions/walletOptions.js';
7
- import { FilterBridgeChainsName } from '../../functions/walletFilters/index.js';
8
- import { walletListBuilder } from '../../functions/walletListBuilder/walletListBuilder.js';
9
- import { getEffectiveRecommendedWallets } from './utils/getEffectiveRecommendedWallets/getEffectiveRecommendedWallets.js';
10
- import { getEffectiveWalletFilter } from './utils/getEffectiveWalletFilter/getEffectiveWalletFilter.js';
7
+ import { buildWalletsList } from './buildWalletsList.js';
11
8
 
12
9
  const useWalletList = ({ isWalletConnectList = false, viewWalletsFilter, searchFilter, lastUsedWalletKey, }) => {
13
10
  const { walletsFilter, walletConnectorOptions, defaultNumberOfWalletsToShow, bridgeChainsToConnect, multiWallet, recommendedWallets, selectedTabSettings, } = useInternalDynamicContext();
14
11
  const { userWallets } = useInternalUserWallets();
15
12
  const walletGroups = useWalletGroups();
16
- const getFilteredBridgeChains = (bridgeChainsToConnect === null || bridgeChainsToConnect === void 0 ? void 0 : bridgeChainsToConnect.length) &&
17
- FilterBridgeChainsName(bridgeChainsToConnect[0].chain);
18
- const filteredBridgeChains = getFilteredBridgeChains && getFilteredBridgeChains(walletConnectorOptions);
19
- const effectiveRecommendedWallets = getEffectiveRecommendedWallets(selectedTabSettings, recommendedWallets);
20
- const effectiveWalletsFilter = getEffectiveWalletFilter(selectedTabSettings, walletsFilter);
21
- const { numberOfWallets, walletsList } = walletListBuilder({
22
- groupWallets: true,
23
- inputList: filteredBridgeChains || walletConnectorOptions,
13
+ // Run the heavy list build once per real input change, not on every render —
14
+ // a modal close animation re-renders this hundreds of times.
15
+ return useMemo(() => buildWalletsList({
16
+ bridgeChainsToConnect,
17
+ defaultNumberOfWalletsToShow,
24
18
  isWalletConnectList,
25
19
  lastUsedWalletKey,
26
20
  multiWallet,
27
- numberOfWalletsToShow: defaultNumberOfWalletsToShow,
28
- recommendedWallets: effectiveRecommendedWallets,
21
+ recommendedWallets,
29
22
  searchFilter,
30
- showMoreWalletsWithFilter: true,
23
+ selectedTabSettings,
31
24
  userWallets,
25
+ viewWalletsFilter,
26
+ walletConnectorOptions,
32
27
  walletGroups,
33
- // use both filters if available, else use the viewWalletsFilter or effectiveWalletsFilter
34
- walletsFilter: viewWalletsFilter && effectiveWalletsFilter
35
- ? pipe(viewWalletsFilter).pipe(effectiveWalletsFilter)
36
- : viewWalletsFilter || effectiveWalletsFilter,
37
- });
38
- return {
39
- numberOfWallets,
40
- recommendedWallets: effectiveRecommendedWallets,
41
- walletsList,
42
- };
28
+ walletsFilter,
29
+ }), [
30
+ bridgeChainsToConnect,
31
+ defaultNumberOfWalletsToShow,
32
+ isWalletConnectList,
33
+ lastUsedWalletKey,
34
+ multiWallet,
35
+ recommendedWallets,
36
+ searchFilter,
37
+ selectedTabSettings,
38
+ userWallets,
39
+ viewWalletsFilter,
40
+ walletConnectorOptions,
41
+ walletGroups,
42
+ walletsFilter,
43
+ ]);
43
44
  };
44
45
 
45
46
  export { useWalletList };
@@ -10,7 +10,6 @@ var reactI18next = require('react-i18next');
10
10
  var bs58 = require('bs58');
11
11
  var walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
12
12
  var utils = require('@dynamic-labs/utils');
13
- var sdkApiCore = require('@dynamic-labs/sdk-api-core');
14
13
  require('../../context/DynamicContext/useDynamicContext/useDynamicContext.cjs');
15
14
  var useInternalDynamicContext = require('../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.cjs');
16
15
  require('../../events/dynamicEvents.cjs');
@@ -22,6 +21,7 @@ var logger = require('../../shared/logger.cjs');
22
21
  require('@dynamic-labs/wallet-book');
23
22
  require('../../utils/constants/colors.cjs');
24
23
  require('../../utils/constants/values.cjs');
24
+ require('@dynamic-labs/sdk-api-core');
25
25
  require('../../shared/consts/index.cjs');
26
26
  require('@dynamic-labs/multi-wallet');
27
27
  require('react-international-phone');
@@ -138,6 +138,12 @@ var SimulationStatus;
138
138
  const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation, onClickBack, walletConnector, onClickClose, title, displayPoweredByDynamicFooter = false, copykey, hideModal, currentToken, isNativeToken, transactionValue, isModal, sendBalanceTransaction, }) => {
139
139
  var _a, _b, _c;
140
140
  const { primaryWallet, environmentId } = useInternalDynamicContext.useInternalDynamicContext();
141
+ // The connector that is actually signing this transaction. A transaction can
142
+ // be sent from a non-primary wallet (e.g. an EVM wallet while the primary
143
+ // wallet is BTC), so chain, key and simulation must be derived from this
144
+ // connector and never from primaryWallet, which would resolve the wrong
145
+ // chain/wallet and fail simulation.
146
+ const activeConnector = walletConnector !== null && walletConnector !== void 0 ? walletConnector : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
141
147
  const projectSettings = useProjectSettings.useProjectSettings();
142
148
  const svmGasSponsorshipEnabled = (_c = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.embeddedWallets) === null || _b === void 0 ? void 0 : _b.svmGasSponsorshipEnabled) !== null && _c !== void 0 ? _c : false;
143
149
  const [isGasSponsored, setIsGasSponsored] = React.useState(false);
@@ -147,12 +153,12 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
147
153
  const { currency } = useFetchCurrency.useFetchCurrency(walletConnector);
148
154
  // Update the chainId access to handle undefined case
149
155
  const chainId = React.useMemo(() => {
150
- if (!(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector)) {
156
+ if (!activeConnector) {
151
157
  return undefined;
152
158
  }
153
- const connector = primaryWallet.connector;
159
+ const connector = activeConnector;
154
160
  return connector._selectedChainId || connector.lastUsedChainId;
155
- }, [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
161
+ }, [activeConnector]);
156
162
  const [simulationState, setSimulationState] = React.useState({
157
163
  status: SimulationStatus.LOADING,
158
164
  });
@@ -161,7 +167,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
161
167
  const [preSubmitValidationError, setPreSubmitValidationError] = React.useState(undefined);
162
168
  const isFetchingSimulationRef = React.useRef(false);
163
169
  const fetchSimulationResult = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
164
- var _d, _e, _f, _g, _h, _j, _k;
170
+ var _d, _e, _f, _g, _h, _j;
165
171
  if (simulationState.status !== SimulationStatus.LOADING) {
166
172
  return;
167
173
  }
@@ -175,14 +181,14 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
175
181
  isFetchingSimulationRef.current = false;
176
182
  return;
177
183
  }
178
- if (!primaryWallet ||
184
+ if (!activeConnector ||
179
185
  (!chainId &&
180
- (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) !== 'SOL' &&
181
- (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) !== 'TON')) {
186
+ activeConnector.connectedChain !== 'SOL' &&
187
+ activeConnector.connectedChain !== 'TON')) {
182
188
  logger.logger.error('[TransactionConfirmationView] Simulation failed:', {
183
- chain: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain,
189
+ chain: activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.connectedChain,
184
190
  chainId,
185
- primaryWallet,
191
+ walletConnector: activeConnector,
186
192
  });
187
193
  setSimulationState({ status: SimulationStatus.FAILED });
188
194
  isFetchingSimulationRef.current = false;
@@ -190,8 +196,8 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
190
196
  }
191
197
  try {
192
198
  let result;
193
- if (primaryWallet.connector.key === 'zerodev') {
194
- const connector = primaryWallet.connector;
199
+ if (activeConnector.key === 'zerodev') {
200
+ const connector = activeConnector;
195
201
  const { userOperation, sponsored } = yield connector.getCurrentUserOperation(transaction);
196
202
  setIsGasSponsored(sponsored);
197
203
  setIsGasSponsoredLoading(false);
@@ -252,7 +258,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
252
258
  return;
253
259
  }
254
260
  }
255
- if (!result && ((_k = primaryWallet.connector) === null || _k === void 0 ? void 0 : _k.key) !== 'zerodev') {
261
+ if (!result && activeConnector.key !== 'zerodev') {
256
262
  logger.logger.warn('[TransactionConfirmationView] Simulation failed: No result');
257
263
  setSimulationState({ status: SimulationStatus.FAILED });
258
264
  return;
@@ -271,7 +277,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
271
277
  }), [
272
278
  sendBalanceTransaction,
273
279
  hideModal,
274
- primaryWallet,
280
+ activeConnector,
275
281
  chainId,
276
282
  environmentId,
277
283
  transaction,
@@ -285,7 +291,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
285
291
  return;
286
292
  }
287
293
  fetchSimulationResult();
288
- }, [fetchSimulationResult, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, simulationState.status]);
294
+ }, [fetchSimulationResult, activeConnector, simulationState.status]);
289
295
  // Check destination account for chains that require it (e.g., Stellar)
290
296
  React.useEffect(() => {
291
297
  const checkDestination = () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -303,10 +309,9 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
303
309
  * to reflect the new fee on the UI
304
310
  */
305
311
  const fetchTransactionFee = React.useCallback(() => {
306
- var _a;
307
- if (((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) === sdkApiCore.ChainEnum.Sol &&
312
+ if (((activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.connectedChain) === 'SOL' &&
308
313
  transaction.fee.gas !== undefined) ||
309
- (primaryWallet && ((_a = primaryWallet.connector) === null || _a === void 0 ? void 0 : _a.key) === 'zerodev')) {
314
+ (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key) === 'zerodev') {
310
315
  return;
311
316
  }
312
317
  if (transaction.fetchFee) {
@@ -331,7 +336,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
331
336
  });
332
337
  }
333
338
  }
334
- }, [primaryWallet, transaction, update]);
339
+ }, [activeConnector, transaction, update]);
335
340
  React.useEffect(() => {
336
341
  // If SVM gas sponsorship is enabled in project settings, treat as sponsored
337
342
  // before the fee payer is actually replaced (which happens at send time)
@@ -489,7 +494,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
489
494
  transactionSignature: transactionSignatureForLink,
490
495
  transactionValue,
491
496
  walletConnector,
492
- walletKey: (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.key) || '',
497
+ walletKey: (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key) || '',
493
498
  });
494
499
  }, [
495
500
  total,
@@ -513,7 +518,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
513
518
  transaction,
514
519
  isGasSponsored,
515
520
  isGasSponsoredLoading,
516
- primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.key,
521
+ activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key,
517
522
  simulationState.result,
518
523
  sendBalanceTransaction,
519
524
  fetchTransactionFee,
@@ -6,7 +6,6 @@ import { useTranslation } from 'react-i18next';
6
6
  import bs58 from 'bs58';
7
7
  import { isAccountAbstractionConnector } from '@dynamic-labs/wallet-connector-core';
8
8
  import { TransactionGasCannotBeSponsoredError } from '@dynamic-labs/utils';
9
- import { ChainEnum } from '@dynamic-labs/sdk-api-core';
10
9
  import '../../context/DynamicContext/useDynamicContext/useDynamicContext.js';
11
10
  import { useInternalDynamicContext } from '../../context/DynamicContext/useDynamicContext/useInternalDynamicContext/useInternalDynamicContext.js';
12
11
  import '../../events/dynamicEvents.js';
@@ -18,6 +17,7 @@ import { logger } from '../../shared/logger.js';
18
17
  import '@dynamic-labs/wallet-book';
19
18
  import '../../utils/constants/colors.js';
20
19
  import '../../utils/constants/values.js';
20
+ import '@dynamic-labs/sdk-api-core';
21
21
  import '../../shared/consts/index.js';
22
22
  import '@dynamic-labs/multi-wallet';
23
23
  import 'react-international-phone';
@@ -130,6 +130,12 @@ var SimulationStatus;
130
130
  const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation, onClickBack, walletConnector, onClickClose, title, displayPoweredByDynamicFooter = false, copykey, hideModal, currentToken, isNativeToken, transactionValue, isModal, sendBalanceTransaction, }) => {
131
131
  var _a, _b, _c;
132
132
  const { primaryWallet, environmentId } = useInternalDynamicContext();
133
+ // The connector that is actually signing this transaction. A transaction can
134
+ // be sent from a non-primary wallet (e.g. an EVM wallet while the primary
135
+ // wallet is BTC), so chain, key and simulation must be derived from this
136
+ // connector and never from primaryWallet, which would resolve the wrong
137
+ // chain/wallet and fail simulation.
138
+ const activeConnector = walletConnector !== null && walletConnector !== void 0 ? walletConnector : primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector;
133
139
  const projectSettings = useProjectSettings();
134
140
  const svmGasSponsorshipEnabled = (_c = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.embeddedWallets) === null || _b === void 0 ? void 0 : _b.svmGasSponsorshipEnabled) !== null && _c !== void 0 ? _c : false;
135
141
  const [isGasSponsored, setIsGasSponsored] = useState(false);
@@ -139,12 +145,12 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
139
145
  const { currency } = useFetchCurrency(walletConnector);
140
146
  // Update the chainId access to handle undefined case
141
147
  const chainId = useMemo(() => {
142
- if (!(primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector)) {
148
+ if (!activeConnector) {
143
149
  return undefined;
144
150
  }
145
- const connector = primaryWallet.connector;
151
+ const connector = activeConnector;
146
152
  return connector._selectedChainId || connector.lastUsedChainId;
147
- }, [primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector]);
153
+ }, [activeConnector]);
148
154
  const [simulationState, setSimulationState] = useState({
149
155
  status: SimulationStatus.LOADING,
150
156
  });
@@ -153,7 +159,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
153
159
  const [preSubmitValidationError, setPreSubmitValidationError] = useState(undefined);
154
160
  const isFetchingSimulationRef = useRef(false);
155
161
  const fetchSimulationResult = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
156
- var _d, _e, _f, _g, _h, _j, _k;
162
+ var _d, _e, _f, _g, _h, _j;
157
163
  if (simulationState.status !== SimulationStatus.LOADING) {
158
164
  return;
159
165
  }
@@ -167,14 +173,14 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
167
173
  isFetchingSimulationRef.current = false;
168
174
  return;
169
175
  }
170
- if (!primaryWallet ||
176
+ if (!activeConnector ||
171
177
  (!chainId &&
172
- (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) !== 'SOL' &&
173
- (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) !== 'TON')) {
178
+ activeConnector.connectedChain !== 'SOL' &&
179
+ activeConnector.connectedChain !== 'TON')) {
174
180
  logger.error('[TransactionConfirmationView] Simulation failed:', {
175
- chain: primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain,
181
+ chain: activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.connectedChain,
176
182
  chainId,
177
- primaryWallet,
183
+ walletConnector: activeConnector,
178
184
  });
179
185
  setSimulationState({ status: SimulationStatus.FAILED });
180
186
  isFetchingSimulationRef.current = false;
@@ -182,8 +188,8 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
182
188
  }
183
189
  try {
184
190
  let result;
185
- if (primaryWallet.connector.key === 'zerodev') {
186
- const connector = primaryWallet.connector;
191
+ if (activeConnector.key === 'zerodev') {
192
+ const connector = activeConnector;
187
193
  const { userOperation, sponsored } = yield connector.getCurrentUserOperation(transaction);
188
194
  setIsGasSponsored(sponsored);
189
195
  setIsGasSponsoredLoading(false);
@@ -244,7 +250,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
244
250
  return;
245
251
  }
246
252
  }
247
- if (!result && ((_k = primaryWallet.connector) === null || _k === void 0 ? void 0 : _k.key) !== 'zerodev') {
253
+ if (!result && activeConnector.key !== 'zerodev') {
248
254
  logger.warn('[TransactionConfirmationView] Simulation failed: No result');
249
255
  setSimulationState({ status: SimulationStatus.FAILED });
250
256
  return;
@@ -263,7 +269,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
263
269
  }), [
264
270
  sendBalanceTransaction,
265
271
  hideModal,
266
- primaryWallet,
272
+ activeConnector,
267
273
  chainId,
268
274
  environmentId,
269
275
  transaction,
@@ -277,7 +283,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
277
283
  return;
278
284
  }
279
285
  fetchSimulationResult();
280
- }, [fetchSimulationResult, primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.connector, simulationState.status]);
286
+ }, [fetchSimulationResult, activeConnector, simulationState.status]);
281
287
  // Check destination account for chains that require it (e.g., Stellar)
282
288
  useEffect(() => {
283
289
  const checkDestination = () => __awaiter(void 0, void 0, void 0, function* () {
@@ -295,10 +301,9 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
295
301
  * to reflect the new fee on the UI
296
302
  */
297
303
  const fetchTransactionFee = useCallback(() => {
298
- var _a;
299
- if (((primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain) === ChainEnum.Sol &&
304
+ if (((activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.connectedChain) === 'SOL' &&
300
305
  transaction.fee.gas !== undefined) ||
301
- (primaryWallet && ((_a = primaryWallet.connector) === null || _a === void 0 ? void 0 : _a.key) === 'zerodev')) {
306
+ (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key) === 'zerodev') {
302
307
  return;
303
308
  }
304
309
  if (transaction.fetchFee) {
@@ -323,7 +328,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
323
328
  });
324
329
  }
325
330
  }
326
- }, [primaryWallet, transaction, update]);
331
+ }, [activeConnector, transaction, update]);
327
332
  useEffect(() => {
328
333
  // If SVM gas sponsorship is enabled in project settings, treat as sponsored
329
334
  // before the fee payer is actually replaced (which happens at send time)
@@ -481,7 +486,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
481
486
  transactionSignature: transactionSignatureForLink,
482
487
  transactionValue,
483
488
  walletConnector,
484
- walletKey: (primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.key) || '',
489
+ walletKey: (activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key) || '',
485
490
  });
486
491
  }, [
487
492
  total,
@@ -505,7 +510,7 @@ const TransactionConfirmationView = ({ transaction, onError, onSuccess, mutation
505
510
  transaction,
506
511
  isGasSponsored,
507
512
  isGasSponsoredLoading,
508
- primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.key,
513
+ activeConnector === null || activeConnector === void 0 ? void 0 : activeConnector.key,
509
514
  simulationState.result,
510
515
  sendBalanceTransaction,
511
516
  fetchTransactionFee,