@dynamic-labs/sdk-react-core 4.79.2 → 4.81.0

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 (101) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +13 -13
  5. package/src/lib/Main.cjs +2 -2
  6. package/src/lib/Main.js +2 -2
  7. package/src/lib/client/extension/deprecated/mfa/verifyTotpMfaDevice/verifyTotpMfaDevice.d.ts +1 -1
  8. package/src/lib/components/LogoutButton/LogoutButton.cjs +2 -2
  9. package/src/lib/components/LogoutButton/LogoutButton.js +2 -2
  10. package/src/lib/components/SendBalanceForm/SendBalanceForm.cjs +63 -3
  11. package/src/lib/components/SendBalanceForm/SendBalanceForm.js +63 -3
  12. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/TransactionModeSegmentedControl.cjs +40 -0
  13. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/TransactionModeSegmentedControl.d.ts +16 -0
  14. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/TransactionModeSegmentedControl.js +36 -0
  15. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/icons.cjs +17 -0
  16. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/icons.d.ts +8 -0
  17. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/icons.js +12 -0
  18. package/src/lib/components/SendBalanceForm/TransactionModeSegmentedControl/index.d.ts +1 -0
  19. package/src/lib/context/DynamicContext/DynamicContext.cjs +6 -4
  20. package/src/lib/context/DynamicContext/DynamicContext.js +6 -4
  21. package/src/lib/context/DynamicContext/hooks/useHandleLogout/index.d.ts +1 -0
  22. package/src/lib/context/DynamicContext/hooks/useHandleLogout/types.d.ts +9 -0
  23. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.cjs +25 -12
  24. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.d.ts +5 -3
  25. package/src/lib/context/DynamicContext/hooks/useHandleLogout/useHandleLogout.js +24 -11
  26. package/src/lib/context/DynamicContext/hooks/useRemoveWallet/useRemoveWallet.cjs +3 -3
  27. package/src/lib/context/DynamicContext/hooks/useRemoveWallet/useRemoveWallet.d.ts +3 -2
  28. package/src/lib/context/DynamicContext/hooks/useRemoveWallet/useRemoveWallet.js +3 -3
  29. package/src/lib/context/DynamicContext/types/IDynamicContext.d.ts +2 -0
  30. package/src/lib/context/DynamicContext/types/IInternalDynamicContext.d.ts +8 -1
  31. package/src/lib/events/auth.d.ts +2 -1
  32. package/src/lib/styles/index.shadow.cjs +1 -1
  33. package/src/lib/styles/index.shadow.js +1 -1
  34. package/src/lib/utils/hooks/useAleoShieldedBalances/index.d.ts +1 -0
  35. package/src/lib/utils/hooks/useAleoShieldedBalances/useAleoShieldedBalances.cjs +372 -0
  36. package/src/lib/utils/hooks/useAleoShieldedBalances/useAleoShieldedBalances.d.ts +24 -0
  37. package/src/lib/utils/hooks/useAleoShieldedBalances/useAleoShieldedBalances.js +368 -0
  38. package/src/lib/utils/hooks/useDeleteUserAccount/useDeleteUserAccount.cjs +2 -2
  39. package/src/lib/utils/hooks/useDeleteUserAccount/useDeleteUserAccount.js +2 -2
  40. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +1 -0
  41. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +1 -0
  42. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +1 -0
  43. package/src/lib/utils/hooks/useEmbeddedWalletSessionKeys/useEmbeddedWalletSessionKeys.cjs +1 -1
  44. package/src/lib/utils/hooks/useEmbeddedWalletSessionKeys/useEmbeddedWalletSessionKeys.js +1 -1
  45. package/src/lib/utils/hooks/useUserAuth/useUserAuth.cjs +3 -3
  46. package/src/lib/utils/hooks/useUserAuth/useUserAuth.js +3 -3
  47. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.cjs +1 -1
  48. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.d.ts +2 -1
  49. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.js +1 -1
  50. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.cjs +3 -1
  51. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.d.ts +2 -2
  52. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.js +3 -1
  53. package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +3 -3
  54. package/src/lib/utils/hooks/useValidateSession/useValidateSession.d.ts +3 -3
  55. package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +3 -3
  56. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.cjs +2 -2
  57. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.d.ts +3 -2
  58. package/src/lib/utils/hooks/useWalletEventListeners/useWalletEventListeners.js +2 -2
  59. package/src/lib/views/BackupUnsuccessfulView/BackupUnsuccessfulView.cjs +5 -5
  60. package/src/lib/views/BackupUnsuccessfulView/BackupUnsuccessfulView.js +5 -5
  61. package/src/lib/views/CollectUserDataView/CollectUserDataView.cjs +2 -2
  62. package/src/lib/views/CollectUserDataView/CollectUserDataView.js +2 -2
  63. package/src/lib/views/CollectUserDataViewNoWallet/CollectUserDataViewNoWallet.cjs +2 -2
  64. package/src/lib/views/CollectUserDataViewNoWallet/CollectUserDataViewNoWallet.js +2 -2
  65. package/src/lib/views/DeviceRegistrationView/DeviceRegistrationView.cjs +2 -2
  66. package/src/lib/views/DeviceRegistrationView/DeviceRegistrationView.js +2 -2
  67. package/src/lib/views/EmailVerification/EmailVerification.cjs +2 -2
  68. package/src/lib/views/EmailVerification/EmailVerification.js +2 -2
  69. package/src/lib/views/EmbeddedDeleteView/EmbeddedDeleteView.cjs +2 -2
  70. package/src/lib/views/EmbeddedDeleteView/EmbeddedDeleteView.js +2 -2
  71. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.cjs +7 -7
  72. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.js +7 -7
  73. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.cjs +7 -7
  74. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.js +7 -7
  75. package/src/lib/views/MfaVerificationView/MfaVerificationView.cjs +5 -5
  76. package/src/lib/views/MfaVerificationView/MfaVerificationView.js +5 -5
  77. package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +2 -2
  78. package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +2 -2
  79. package/src/lib/views/SendBalanceView/SendBalanceView.cjs +53 -0
  80. package/src/lib/views/SendBalanceView/SendBalanceView.js +53 -0
  81. package/src/lib/views/SmsVerification/SmsVerification.cjs +2 -2
  82. package/src/lib/views/SmsVerification/SmsVerification.js +2 -2
  83. package/src/lib/views/WalletDelegation/WalletDelegationView/WalletDelegationView.cjs +2 -2
  84. package/src/lib/views/WalletDelegation/WalletDelegationView/WalletDelegationView.js +2 -2
  85. package/src/lib/views/WalletLockedView/WalletLockedView.cjs +2 -2
  86. package/src/lib/views/WalletLockedView/WalletLockedView.js +2 -2
  87. package/src/lib/views/WalletUsedView/WalletUsedView.cjs +2 -2
  88. package/src/lib/views/WalletUsedView/WalletUsedView.js +2 -2
  89. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/ActiveWalletBalance.cjs +191 -11
  90. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/ActiveWalletBalance.js +191 -11
  91. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/TokenBalanceItem.cjs +5 -2
  92. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/TokenBalanceItem.d.ts +10 -1
  93. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/TokenBalanceItem.js +5 -2
  94. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceItem/index.d.ts +1 -0
  95. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceList/TokenBalanceList.cjs +2 -2
  96. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceList/TokenBalanceList.d.ts +3 -1
  97. package/src/lib/widgets/DynamicWidget/components/ActiveWalletBalance/TokenBalanceList/TokenBalanceList.js +2 -2
  98. package/src/lib/widgets/DynamicWidget/components/SingleWalletButtons/SingleWalletButtons.cjs +2 -2
  99. package/src/lib/widgets/DynamicWidget/components/SingleWalletButtons/SingleWalletButtons.js +2 -2
  100. package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.cjs +2 -2
  101. package/src/lib/widgets/DynamicWidget/views/SettingsView/SettingsView.js +2 -2
@@ -370,7 +370,7 @@ const InnerDynamicContextProvider = (props) => {
370
370
  }
371
371
  });
372
372
  };
373
- const handleLogOut = useHandleLogout({
373
+ const { handleLogOut, handleLogOutWithReason } = useHandleLogout({
374
374
  bridgeChains,
375
375
  clearAllWalletConnectSessions,
376
376
  connectedWallets,
@@ -392,7 +392,7 @@ const InnerDynamicContextProvider = (props) => {
392
392
  });
393
393
  useValidateSession({
394
394
  environmentId,
395
- handleLogOut,
395
+ handleLogOutWithReason,
396
396
  });
397
397
  // For some reason, calling useNonce in useGlobalLoading causes errors
398
398
  const nonce = useNonce();
@@ -418,7 +418,7 @@ const InnerDynamicContextProvider = (props) => {
418
418
  // Listen for wallet deep link returns and emit events (mobile only)
419
419
  useWalletReturnRoute();
420
420
  const removeWallet = useRemoveWallet({
421
- handleLogOut,
421
+ handleLogOutWithReason,
422
422
  secondaryWallets,
423
423
  setPrimaryWallet,
424
424
  });
@@ -433,7 +433,7 @@ const InnerDynamicContextProvider = (props) => {
433
433
  useWalletEventListeners({
434
434
  detectNewWalletsForLinking,
435
435
  disconnectWallet,
436
- handleLogOut,
436
+ handleLogOutWithReason,
437
437
  multiWallet,
438
438
  multiWalletWidgetState,
439
439
  primaryWallet,
@@ -534,6 +534,7 @@ const InnerDynamicContextProvider = (props) => {
534
534
  getConnectedWalletById,
535
535
  getNameService,
536
536
  handleLogOut,
537
+ handleLogOutWithReason,
537
538
  handlers,
538
539
  i18nSDKInstance,
539
540
  isBridgeFlow,
@@ -649,6 +650,7 @@ const InnerDynamicContextProvider = (props) => {
649
650
  getConnectedWalletById,
650
651
  getNameService,
651
652
  handleLogOut,
653
+ handleLogOutWithReason,
652
654
  removeWallet,
653
655
  handlers,
654
656
  i18nSDKInstance,
@@ -1 +1,2 @@
1
1
  export * from './useHandleLogout';
2
+ export type { SdkLogoutReason } from './types';
@@ -1,4 +1,5 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
+ import { LogoutReason } from '@dynamic-labs-sdk/client';
2
3
  import { AuthMode, UserProfile } from '@dynamic-labs/types';
3
4
  import { WalletConnector } from '@dynamic-labs/wallet-connector-core';
4
5
  import { DynamicEventsCallbacks, Wallet } from '../../../../shared';
@@ -6,6 +7,14 @@ import { MultiWalletWidgetStateSetter } from '../../../../utils/hooks/multiWalle
6
7
  import { ChainsToConnect } from '../../types';
7
8
  import { SetShowAuthFlow } from '../useShowAuthFlow';
8
9
  import { SetSelectedWalletConnectorKey } from '../useSelectedWalletConnector/SetSelectedWalletConnectorKey.type';
10
+ /**
11
+ * Diagnostic reason tag for a logout. Widens the official LogoutReason union
12
+ * from @dynamic-labs-sdk/client with SDK-invented strings so each internal
13
+ * logout call site can be attributed in Datadog. Cast to LogoutReason at the
14
+ * boundary inside handleLogOutWithReason (the client SDK forwards unknown
15
+ * strings through to Datadog as-is).
16
+ */
17
+ export type SdkLogoutReason = LogoutReason | 'auth-cancelled' | 'last-wallet-removed' | 'network-unsupported' | 'wallet-info-out-of-sync' | 'token-expired-validate-session' | 'embedded-wallet-session-key-invalid' | 'storage-parse-failure' | 'mfa-verification-cancelled' | 'mfa-choose-device-cancelled' | 'mfa-secure-device-cancelled' | 'backup-unsuccessful' | 'user-data-collection-cancelled' | 'store-environment-mismatch' | 'primary-wallet-disconnected';
9
18
  export type UseHandleLogoutParams = {
10
19
  clearAllWalletConnectSessions: () => void;
11
20
  bridgeChains: ChainsToConnect[] | undefined;
@@ -5,7 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
7
  var React = require('react');
8
- var client = require('@dynamic-labs-sdk/client');
8
+ var client$1 = require('@dynamic-labs-sdk/client');
9
+ var core = require('@dynamic-labs-sdk/client/core');
9
10
  var utils = require('@dynamic-labs/utils');
10
11
  require('@dynamic-labs/iconic');
11
12
  require('@dynamic-labs/wallet-connector-core');
@@ -29,8 +30,7 @@ require('../../../ErrorContext/ErrorContext.cjs');
29
30
  require('@dynamic-labs/multi-wallet');
30
31
  require('react-international-phone');
31
32
  require('../../../../store/state/nonce/nonce.cjs');
32
- require('@dynamic-labs-sdk/client/core');
33
- require('eventemitter3');
33
+ var client = require('../../../../client/client.cjs');
34
34
  require('../../../../config/ApiEndpoint.cjs');
35
35
  require('../../../../events/dynamicEvents.cjs');
36
36
  require('@dynamic-labs/locale');
@@ -111,6 +111,8 @@ require('../../../../store/state/multichainBalances.cjs');
111
111
  require('@dynamic-labs/store');
112
112
  require('../../../../shared/utils/functions/getInitialUrl/getInitialUrl.cjs');
113
113
 
114
+ const PUBLIC_LOGOUT_REASON = 'user-intent';
115
+ const STORAGE_PARSE_FAILURE_REASON = 'storage-parse-failure';
114
116
  const useHandleLogout = (params) => {
115
117
  const paramsRef = React.useRef(params);
116
118
  paramsRef.current = params;
@@ -124,8 +126,9 @@ const useHandleLogout = (params) => {
124
126
  ];
125
127
  logger.logger.logVerboseTroubleshootingMessage('useHandleLogout called', {
126
128
  params: paramsRef.current,
129
+ reason,
127
130
  });
128
- utils.tracing.logEvent('logout', 'useHandleLogout called');
131
+ utils.tracing.logEvent('logout', `useHandleLogout called (reason=${reason})`);
129
132
  p.setSelectedWalletConnectorKey(null);
130
133
  p.clearAllWalletConnectSessions();
131
134
  p.setShowDynamicUserProfile(false);
@@ -149,13 +152,23 @@ const useHandleLogout = (params) => {
149
152
  primaryWalletId.resetPrimaryWalletId();
150
153
  p.removeConnectedNameService();
151
154
  p.removeSessionStorageSessionKeys();
152
- yield Promise.all(activeConnectors.map((connector) => connector.endSession(reason)));
155
+ yield Promise.all(
156
+ // Narrow to the client-SDK LogoutReason at the connector boundary. SDK-invented
157
+ // reasons flow through untyped; connectors ignore values they don't recognize.
158
+ activeConnectors.map((connector) => connector.endSession(reason)));
153
159
  }), []);
154
- const logout = React.useCallback((reason) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
155
- yield client.logout();
160
+ const handleLogOutWithReason = React.useCallback((reason) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
161
+ if (typeof reason !== 'string') {
162
+ throw new Error('Invalid reason');
163
+ }
164
+ // Cast to LogoutReason here — this is the one place unsound widening meets
165
+ // the client SDK's narrow union. The client SDK forwards the string to
166
+ // Datadog as-is; unknown values are logged, not parsed.
167
+ yield core.logoutWithReason({ reason: reason }, client.getDynamicClient());
156
168
  yield logoutReactSdk(reason);
157
169
  }), [logoutReactSdk]);
158
- React.useEffect(() => client.onEvent({
170
+ const handleLogOut = React.useCallback(() => handleLogOutWithReason(PUBLIC_LOGOUT_REASON), [handleLogOutWithReason]);
171
+ React.useEffect(() => client$1.onEvent({
159
172
  event: 'logout',
160
173
  listener: (metadata) => {
161
174
  logoutReactSdk(metadata === null || metadata === void 0 ? void 0 : metadata.reason);
@@ -163,15 +176,15 @@ const useHandleLogout = (params) => {
163
176
  }), [logoutReactSdk]);
164
177
  /** Trigger a logout when the SDK failed to load data from storage */
165
178
  React.useEffect(() => {
166
- const handler = () => logout();
179
+ const handler = () => handleLogOutWithReason(STORAGE_PARSE_FAILURE_REASON);
167
180
  utils.StorageService.events.on('parseFailure', handler);
168
181
  return () => {
169
182
  utils.StorageService.events.off('parseFailure', handler);
170
183
  };
171
- }, [logout]);
184
+ }, [handleLogOutWithReason]);
172
185
  /** Allows triggering a logout from anywhere in the code */
173
- useDynamicEvents.useInternalDynamicEvents('triggerLogout', () => logout());
174
- return logout;
186
+ useDynamicEvents.useInternalDynamicEvents('triggerLogout', (reason) => handleLogOutWithReason(reason));
187
+ return { handleLogOut, handleLogOutWithReason };
175
188
  };
176
189
 
177
190
  exports.useHandleLogout = useHandleLogout;
@@ -1,3 +1,5 @@
1
- import { LogoutReason } from '@dynamic-labs-sdk/client';
2
- import { UseHandleLogoutParams } from './types';
3
- export declare const useHandleLogout: (params: UseHandleLogoutParams) => (reason?: LogoutReason) => Promise<void>;
1
+ import { SdkLogoutReason, UseHandleLogoutParams } from './types';
2
+ export declare const useHandleLogout: (params: UseHandleLogoutParams) => {
3
+ handleLogOut: () => Promise<void>;
4
+ handleLogOutWithReason: (reason: SdkLogoutReason) => Promise<void>;
5
+ };
@@ -1,7 +1,8 @@
1
1
  'use client'
2
2
  import { __awaiter } from '../../../../../../_virtual/_tslib.js';
3
3
  import { useRef, useCallback, useEffect } from 'react';
4
- import { logout, onEvent } from '@dynamic-labs-sdk/client';
4
+ import { onEvent } from '@dynamic-labs-sdk/client';
5
+ import { logoutWithReason } from '@dynamic-labs-sdk/client/core';
5
6
  import { tracing, StorageService } from '@dynamic-labs/utils';
6
7
  import '@dynamic-labs/iconic';
7
8
  import '@dynamic-labs/wallet-connector-core';
@@ -25,8 +26,7 @@ import '../../../ErrorContext/ErrorContext.js';
25
26
  import '@dynamic-labs/multi-wallet';
26
27
  import 'react-international-phone';
27
28
  import '../../../../store/state/nonce/nonce.js';
28
- import '@dynamic-labs-sdk/client/core';
29
- import 'eventemitter3';
29
+ import { getDynamicClient } from '../../../../client/client.js';
30
30
  import '../../../../config/ApiEndpoint.js';
31
31
  import '../../../../events/dynamicEvents.js';
32
32
  import '@dynamic-labs/locale';
@@ -107,6 +107,8 @@ import '../../../../store/state/multichainBalances.js';
107
107
  import '@dynamic-labs/store';
108
108
  import '../../../../shared/utils/functions/getInitialUrl/getInitialUrl.js';
109
109
 
110
+ const PUBLIC_LOGOUT_REASON = 'user-intent';
111
+ const STORAGE_PARSE_FAILURE_REASON = 'storage-parse-failure';
110
112
  const useHandleLogout = (params) => {
111
113
  const paramsRef = useRef(params);
112
114
  paramsRef.current = params;
@@ -120,8 +122,9 @@ const useHandleLogout = (params) => {
120
122
  ];
121
123
  logger.logVerboseTroubleshootingMessage('useHandleLogout called', {
122
124
  params: paramsRef.current,
125
+ reason,
123
126
  });
124
- tracing.logEvent('logout', 'useHandleLogout called');
127
+ tracing.logEvent('logout', `useHandleLogout called (reason=${reason})`);
125
128
  p.setSelectedWalletConnectorKey(null);
126
129
  p.clearAllWalletConnectSessions();
127
130
  p.setShowDynamicUserProfile(false);
@@ -145,12 +148,22 @@ const useHandleLogout = (params) => {
145
148
  resetPrimaryWalletId();
146
149
  p.removeConnectedNameService();
147
150
  p.removeSessionStorageSessionKeys();
148
- yield Promise.all(activeConnectors.map((connector) => connector.endSession(reason)));
151
+ yield Promise.all(
152
+ // Narrow to the client-SDK LogoutReason at the connector boundary. SDK-invented
153
+ // reasons flow through untyped; connectors ignore values they don't recognize.
154
+ activeConnectors.map((connector) => connector.endSession(reason)));
149
155
  }), []);
150
- const logout$1 = useCallback((reason) => __awaiter(void 0, void 0, void 0, function* () {
151
- yield logout();
156
+ const handleLogOutWithReason = useCallback((reason) => __awaiter(void 0, void 0, void 0, function* () {
157
+ if (typeof reason !== 'string') {
158
+ throw new Error('Invalid reason');
159
+ }
160
+ // Cast to LogoutReason here — this is the one place unsound widening meets
161
+ // the client SDK's narrow union. The client SDK forwards the string to
162
+ // Datadog as-is; unknown values are logged, not parsed.
163
+ yield logoutWithReason({ reason: reason }, getDynamicClient());
152
164
  yield logoutReactSdk(reason);
153
165
  }), [logoutReactSdk]);
166
+ const handleLogOut = useCallback(() => handleLogOutWithReason(PUBLIC_LOGOUT_REASON), [handleLogOutWithReason]);
154
167
  useEffect(() => onEvent({
155
168
  event: 'logout',
156
169
  listener: (metadata) => {
@@ -159,15 +172,15 @@ const useHandleLogout = (params) => {
159
172
  }), [logoutReactSdk]);
160
173
  /** Trigger a logout when the SDK failed to load data from storage */
161
174
  useEffect(() => {
162
- const handler = () => logout$1();
175
+ const handler = () => handleLogOutWithReason(STORAGE_PARSE_FAILURE_REASON);
163
176
  StorageService.events.on('parseFailure', handler);
164
177
  return () => {
165
178
  StorageService.events.off('parseFailure', handler);
166
179
  };
167
- }, [logout$1]);
180
+ }, [handleLogOutWithReason]);
168
181
  /** Allows triggering a logout from anywhere in the code */
169
- useInternalDynamicEvents('triggerLogout', () => logout$1());
170
- return logout$1;
182
+ useInternalDynamicEvents('triggerLogout', (reason) => handleLogOutWithReason(reason));
183
+ return { handleLogOut, handleLogOutWithReason };
171
184
  };
172
185
 
173
186
  export { useHandleLogout };
@@ -33,7 +33,7 @@ var wallets = require('../../../../data/api/wallets/wallets.cjs');
33
33
  var authMode = require('../../../../store/state/authMode/authMode.cjs');
34
34
  var UserWalletsContext = require('../../../UserWalletsContext/UserWalletsContext.cjs');
35
35
 
36
- const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, }) => {
36
+ const useRemoveWallet = ({ secondaryWallets, handleLogOutWithReason, setPrimaryWallet, }) => {
37
37
  const { removedWalletsIds, userWallets } = UserWalletsContext.useInternalUserWallets();
38
38
  const connectedWalletsInfo$1 = connectedWalletsInfo.useConnectedWalletsInfo();
39
39
  const nextWalletId = React.useMemo(() => (secondaryWallets[0] ? secondaryWallets[0].id : undefined), [secondaryWallets]);
@@ -74,7 +74,7 @@ const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, })
74
74
  }
75
75
  // If there are no wallets left and no user (connect-only), we need to log out
76
76
  if (!user && !nextWalletId) {
77
- handleLogOut();
77
+ yield handleLogOutWithReason('last-wallet-removed');
78
78
  return;
79
79
  }
80
80
  const numberOfWalletsWithSameConnector = userWallets.filter(({ connector }) => connector.key === wallet.connector.key).length;
@@ -88,7 +88,7 @@ const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, })
88
88
  nextWalletId,
89
89
  removedWalletsIds,
90
90
  setPrimaryWallet,
91
- handleLogOut,
91
+ handleLogOutWithReason,
92
92
  ]);
93
93
  return callback;
94
94
  };
@@ -1,7 +1,8 @@
1
1
  import { Wallet } from '../../../../shared/types/wallets';
2
+ import { SdkLogoutReason } from '../useHandleLogout';
2
3
  export type UseRemoveWalletProps = {
3
4
  secondaryWallets: Wallet[];
4
- handleLogOut: () => void;
5
+ handleLogOutWithReason: (reason: SdkLogoutReason) => Promise<void>;
5
6
  setPrimaryWallet: (walletId: string) => void;
6
7
  };
7
- export declare const useRemoveWallet: ({ secondaryWallets, handleLogOut, setPrimaryWallet, }: UseRemoveWalletProps) => (walletId: string, clearStackAndPushInitialView?: () => void) => Promise<void>;
8
+ export declare const useRemoveWallet: ({ secondaryWallets, handleLogOutWithReason, setPrimaryWallet, }: UseRemoveWalletProps) => (walletId: string, clearStackAndPushInitialView?: () => void) => Promise<void>;
@@ -29,7 +29,7 @@ import { unlinkWallet } from '../../../../data/api/wallets/wallets.js';
29
29
  import { getAuthMode } from '../../../../store/state/authMode/authMode.js';
30
30
  import { useInternalUserWallets } from '../../../UserWalletsContext/UserWalletsContext.js';
31
31
 
32
- const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, }) => {
32
+ const useRemoveWallet = ({ secondaryWallets, handleLogOutWithReason, setPrimaryWallet, }) => {
33
33
  const { removedWalletsIds, userWallets } = useInternalUserWallets();
34
34
  const connectedWalletsInfo = useConnectedWalletsInfo();
35
35
  const nextWalletId = useMemo(() => (secondaryWallets[0] ? secondaryWallets[0].id : undefined), [secondaryWallets]);
@@ -70,7 +70,7 @@ const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, })
70
70
  }
71
71
  // If there are no wallets left and no user (connect-only), we need to log out
72
72
  if (!user && !nextWalletId) {
73
- handleLogOut();
73
+ yield handleLogOutWithReason('last-wallet-removed');
74
74
  return;
75
75
  }
76
76
  const numberOfWalletsWithSameConnector = userWallets.filter(({ connector }) => connector.key === wallet.connector.key).length;
@@ -84,7 +84,7 @@ const useRemoveWallet = ({ secondaryWallets, handleLogOut, setPrimaryWallet, })
84
84
  nextWalletId,
85
85
  removedWalletsIds,
86
86
  setPrimaryWallet,
87
- handleLogOut,
87
+ handleLogOutWithReason,
88
88
  ]);
89
89
  return callback;
90
90
  };
@@ -13,6 +13,7 @@ import { ConnectWalletOptions } from '../../../utils/hooks/useConnectWallet/useC
13
13
  import { ThemeData, ThemeSetting } from '../../ThemeContext';
14
14
  import { DisplayOrder, SetDisplayOrderPriority, SetShowAuthFlow } from '../hooks';
15
15
  import { SetCallbackType } from '../useCustomerCallbacks';
16
+ import { SdkLogoutReason } from '../hooks/useHandleLogout/types';
16
17
  import { SetSelectedWalletConnectorKey } from '../hooks/useSelectedWalletConnector/SetSelectedWalletConnectorKey.type';
17
18
  import { SettingsOverrides } from './SettingsOverrides';
18
19
  import { SocialSettings } from './SocialSettings';
@@ -64,6 +65,7 @@ export interface IDynamicContext {
64
65
  getConnectedWalletById: (walletId: string) => Wallet | undefined;
65
66
  getNameService: (address?: string) => Promise<NameServiceData | undefined>;
66
67
  handleLogOut: () => Promise<void>;
68
+ handleLogOutWithReason: (reason: SdkLogoutReason) => Promise<void>;
67
69
  removeWallet: (walletId: string, clearStackAndPushInitialView?: () => void) => Promise<void>;
68
70
  handlers?: DynamicHandlers;
69
71
  isBridgeFlow: boolean;
@@ -1,9 +1,16 @@
1
+ import { SdkLogoutReason } from '../hooks/useHandleLogout';
1
2
  import { IDynamicContext } from './IDynamicContext';
2
3
  /**
3
4
  * Allows deprecating specific methods that we should avoid using internally
4
5
  * without deprecating them publicly as well.
5
6
  */
6
- export type IInternalDynamicContext = Omit<IDynamicContext, 'user' | 'cspNonce' | 'cssOverrides' | 'accessDeniedButton' | 'accessDeniedMessagePrimary' | 'accessDeniedMessageSecondary' | 'appLogoUrl' | 'appName' | 'bridgeChains' | 'customPrivacyPolicy' | 'customTermsOfServices' | 'debugError' | 'defaultNumberOfWalletsToShow' | 'defaultPhoneInputIso2' | 'detectNewWalletsForLinking' | 'displaySiweStatement' | 'enableConnectOnlyFallback' | 'events' | 'handlers' | 'mobileExperience' | 'networkValidationMode' | 'newToWeb3WalletChainMap' | 'notInTheListImageUrl' | 'onboardingImageUrl' | 'overrides' | 'policiesConsentInnerComponent' | 'privacyPolicyUrl' | 'recommendedWallets' | 'redirectUrl' | 'shadowDOMEnabled' | 'showLockedWalletView' | 'siweStatement' | 'socialMediaIconUrl' | 'socialMediaLinkText' | 'socialMediaUrl' | 'socialProvidersFilter' | 'termsOfServiceUrl' | 'theme' | 'walletsFilter'> & {
7
+ export type IInternalDynamicContext = Omit<IDynamicContext, 'handleLogOut' | 'user' | 'cspNonce' | 'cssOverrides' | 'accessDeniedButton' | 'accessDeniedMessagePrimary' | 'accessDeniedMessageSecondary' | 'appLogoUrl' | 'appName' | 'bridgeChains' | 'customPrivacyPolicy' | 'customTermsOfServices' | 'debugError' | 'defaultNumberOfWalletsToShow' | 'defaultPhoneInputIso2' | 'detectNewWalletsForLinking' | 'displaySiweStatement' | 'enableConnectOnlyFallback' | 'events' | 'handlers' | 'mobileExperience' | 'networkValidationMode' | 'newToWeb3WalletChainMap' | 'notInTheListImageUrl' | 'onboardingImageUrl' | 'overrides' | 'policiesConsentInnerComponent' | 'privacyPolicyUrl' | 'recommendedWallets' | 'redirectUrl' | 'shadowDOMEnabled' | 'showLockedWalletView' | 'siweStatement' | 'socialMediaIconUrl' | 'socialMediaLinkText' | 'socialMediaUrl' | 'socialProvidersFilter' | 'termsOfServiceUrl' | 'theme' | 'walletsFilter'> & {
8
+ /**
9
+ * Reason-tagged logout for internal SDK call sites. Every internal logout
10
+ * must carry a reason so Datadog can attribute it. The no-arg public
11
+ * `handleLogOut` is intentionally omitted from this view.
12
+ */
13
+ handleLogOutWithReason: (reason: SdkLogoutReason) => Promise<void>;
7
14
  /**
8
15
  * @deprecated please call useOnboardingCompleteUser() OR useUser() instead.
9
16
  * | `useOnboardingCompleteUser` only returns the user if it's not missing KYC or MFA.
@@ -1,5 +1,6 @@
1
1
  import type { LogoutEventMetadata } from '@dynamic-labs-sdk/client';
2
2
  import { AuthEventPayload } from '@dynamic-labs/types';
3
+ import { SdkLogoutReason } from '../context/DynamicContext/hooks/useHandleLogout';
3
4
  export type AuthEvents = {
4
5
  /**
5
6
  * Informs an auth attempt failed.
@@ -15,7 +16,7 @@ export type AuthEvents = {
15
16
  authInit: (method: AuthEventPayload) => void;
16
17
  logout: (metadata?: LogoutEventMetadata) => void;
17
18
  /** This event is used to trigger logout to be called, DO NOT listen to it. Listen to "logout" instead */
18
- triggerLogout: () => void;
19
+ triggerLogout: (reason: SdkLogoutReason) => void;
19
20
  /**
20
21
  * Emitted when the user succesfully completes an MFA challenge
21
22
  */