@dynamic-labs/sdk-react-core 4.4.3 → 4.4.4

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 (49) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/lib/components/HardwareWalletToggle/HardwareWalletToggle.cjs +12 -11
  6. package/src/lib/components/HardwareWalletToggle/HardwareWalletToggle.js +12 -11
  7. package/src/lib/components/Toggle/Toggle.cjs +1 -5
  8. package/src/lib/components/Toggle/Toggle.d.ts +6 -2
  9. package/src/lib/components/Toggle/Toggle.js +1 -5
  10. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.cjs +1 -1
  11. package/src/lib/context/ConnectWithOtpContext/utils/createSmsHandler.js +1 -1
  12. package/src/lib/context/DynamicContext/DynamicContext.cjs +7 -1
  13. package/src/lib/context/DynamicContext/DynamicContext.js +8 -2
  14. package/src/lib/context/ViewContext/types/index.d.ts +1 -2
  15. package/src/lib/data/api/exchangeRates/exchangeRates.cjs +9 -5
  16. package/src/lib/data/api/exchangeRates/exchangeRates.js +9 -5
  17. package/src/lib/layout/DynamicAuthLayout/Header/header.cjs +2 -6
  18. package/src/lib/layout/DynamicAuthLayout/Header/header.js +2 -6
  19. package/src/lib/store/internalImplementation/store.cjs +1 -0
  20. package/src/lib/store/internalImplementation/store.d.ts +5 -1
  21. package/src/lib/store/internalImplementation/store.js +1 -0
  22. package/src/lib/styles/index.shadow.cjs +1 -1
  23. package/src/lib/styles/index.shadow.js +1 -1
  24. package/src/lib/utils/hooks/multiWallet/useVerifyOnAwaitingSignature/useVerifyOnAwaitingSignature.cjs +5 -0
  25. package/src/lib/utils/hooks/multiWallet/useVerifyOnAwaitingSignature/useVerifyOnAwaitingSignature.js +5 -0
  26. package/src/lib/utils/hooks/useFunding/useConnectWalletForFunding/useConnectWalletForFunding.cjs +25 -7
  27. package/src/lib/utils/hooks/useFunding/useConnectWalletForFunding/useConnectWalletForFunding.js +22 -4
  28. package/src/lib/utils/hooks/useMfaModals/useMfaModals.cjs +12 -12
  29. package/src/lib/utils/hooks/useMfaModals/useMfaModals.js +12 -12
  30. package/src/lib/utils/hooks/useValidateSession/handleStoreVersionChanged/handleStoreVersionChanged.cjs +12 -0
  31. package/src/lib/utils/hooks/useValidateSession/handleStoreVersionChanged/handleStoreVersionChanged.d.ts +7 -0
  32. package/src/lib/utils/hooks/useValidateSession/handleStoreVersionChanged/handleStoreVersionChanged.js +8 -0
  33. package/src/lib/utils/hooks/useValidateSession/handleStoreVersionChanged/index.d.ts +1 -0
  34. package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +5 -3
  35. package/src/lib/utils/hooks/useValidateSession/useValidateSession.d.ts +3 -1
  36. package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +5 -3
  37. package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.cjs +1 -1
  38. package/src/lib/utils/hooks/useWalletItemActions/useHandleWalletItem/useHandleWalletItem.js +1 -1
  39. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.cjs +12 -20
  40. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.d.ts +6 -5
  41. package/src/lib/utils/hooks/useWalletItemActions/useWalletItemActions.js +12 -20
  42. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.cjs +1 -6
  43. package/src/lib/views/MfaChooseDeviceView/MfaChooseDeviceView.js +1 -6
  44. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.cjs +5 -7
  45. package/src/lib/views/MfaSecureDeviceView/MfaSecureDeviceView.js +5 -7
  46. package/src/lib/widgets/DynamicWidget/components/DotsMenu/DotsMenu.cjs +9 -1
  47. package/src/lib/widgets/DynamicWidget/components/DotsMenu/DotsMenu.js +10 -2
  48. package/src/lib/widgets/DynamicWidget/views/ChooseWalletFundingMethod/useFundingMethods/useStartExternalWalletFunding/useStartExternalWalletFunding.cjs +0 -17
  49. package/src/lib/widgets/DynamicWidget/views/ChooseWalletFundingMethod/useFundingMethods/useStartExternalWalletFunding/useStartExternalWalletFunding.js +0 -17
@@ -128,6 +128,11 @@ const useVerifyOnAwaitingSignature = () => {
128
128
  setMultiWalletWidgetState,
129
129
  triggerConnectAndSign,
130
130
  ]);
131
+ // This is the effect that triggers the connect and sign flow
132
+ // when the multi wallet widget is in the awaiting_signature state
133
+ // with linking_new_wallet signature sub state.
134
+ // This is a very, very bad pattern and should be refactored if possible,
135
+ // though that would be a lot of work and this works for now.
131
136
  React.useEffect(() => {
132
137
  if (!legacyIsVerifying &&
133
138
  !isVerifying.current &&
@@ -124,6 +124,11 @@ const useVerifyOnAwaitingSignature = () => {
124
124
  setMultiWalletWidgetState,
125
125
  triggerConnectAndSign,
126
126
  ]);
127
+ // This is the effect that triggers the connect and sign flow
128
+ // when the multi wallet widget is in the awaiting_signature state
129
+ // with linking_new_wallet signature sub state.
130
+ // This is a very, very bad pattern and should be refactored if possible,
131
+ // though that would be a lot of work and this works for now.
127
132
  useEffect(() => {
128
133
  if (!legacyIsVerifying &&
129
134
  !isVerifying.current &&
@@ -33,7 +33,7 @@ var resolvePromiseRef = require('../../../functions/resolvePromiseRef/resolvePro
33
33
  var rejectPromiseRef = require('../../../functions/rejectPromiseRef/rejectPromiseRef.cjs');
34
34
  require('../../../../context/AccessDeniedContext/AccessDeniedContext.cjs');
35
35
  require('../../../../context/AccountExistsContext/AccountExistsContext.cjs');
36
- require('../../../../context/UserWalletsContext/UserWalletsContext.cjs');
36
+ var UserWalletsContext = require('../../../../context/UserWalletsContext/UserWalletsContext.cjs');
37
37
  require('../../../../events/dynamicEvents.cjs');
38
38
  require('../../../../context/VerificationContext/VerificationContext.cjs');
39
39
  require('react-dom');
@@ -52,7 +52,7 @@ require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
52
52
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
53
53
  require('@dynamic-labs/rpc-providers');
54
54
  require('../../../../store/state/loadingAndLifecycle.cjs');
55
- require('../../../../store/state/walletOptions/walletOptions.cjs');
55
+ var walletOptions = require('../../../../store/state/walletOptions/walletOptions.cjs');
56
56
  var useHandleWalletItem = require('../../useWalletItemActions/useHandleWalletItem/useHandleWalletItem.cjs');
57
57
  require('react-i18next');
58
58
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
@@ -100,7 +100,8 @@ var useInternalDynamicContext = require('../../../../context/DynamicContext/useD
100
100
  const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
101
101
  const { primaryWallet, setShowAuthFlow } = useInternalDynamicContext.useInternalDynamicContext();
102
102
  const { clearStackAndPush } = ViewContext.useViewContext();
103
- const { walletOptions } = useWalletOptions.useWalletOptions();
103
+ const userWallets = UserWalletsContext.useUserWallets();
104
+ const { walletOptions: walletOptions$1 } = useWalletOptions.useWalletOptions();
104
105
  const internalConnectionPromiseRef = React.useRef(null);
105
106
  const connectWalletPromiseRef = React.useRef(null);
106
107
  const handleWalletMethod = React.useCallback((props) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -122,20 +123,36 @@ const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
122
123
  rejectPromiseRef.rejectPromiseRef(connectWalletPromiseRef, new utils.DynamicError('User cancelled'));
123
124
  });
124
125
  const getWalletAddress = React.useCallback((walletConnector) => {
125
- const walletOption = walletOptions.find(({ key }) => key === walletConnector.key);
126
+ const walletOption = walletOptions$1.find(({ key }) => key === walletConnector.key);
126
127
  if (!walletOption)
127
128
  return Promise.reject(new utils.DynamicError(`Connect wallet for funding error: wallet option for ${walletConnector.key} not found`));
128
129
  internalConnectionPromiseRef.current = new utils.DeferredPromise();
129
130
  handleWalletItemClick(Object.assign(Object.assign({}, walletOption), { walletConnector }));
130
131
  return internalConnectionPromiseRef.current.promise;
131
- }, [handleWalletItemClick, walletOptions]);
132
- return React.useCallback(() => {
132
+ }, [handleWalletItemClick, walletOptions$1]);
133
+ const hasWalletConnectWallet = userWallets.some((wallet) => wallet.connector.isWalletConnect);
134
+ // WC does not allow multiple sessions, so we have 2 cases here:
135
+ // 1. The user has a linked WalletConnect wallet.
136
+ // In this case, we should not do anything, and our logic will prevent other WCs from being
137
+ // selected for funding.
138
+ // 2. The user does not have a WalletConnect wallet linked.
139
+ // In this case, we should reset the WC session — this is because they might have just
140
+ // previously connected another WC wallet for funding and that session could still be active.
141
+ const resetWalletConnectSession = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
142
+ if (hasWalletConnectWallet)
143
+ return;
144
+ const walletOption = walletOptions.getWalletConnectorOptions().find(({ walletConnector }) => walletConnector.isWalletConnect);
145
+ yield (walletOption === null || walletOption === void 0 ? void 0 : walletOption.walletConnector.endSession());
146
+ yield (walletOption === null || walletOption === void 0 ? void 0 : walletOption.walletConnector.init());
147
+ }), [hasWalletConnectWallet]);
148
+ return React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
133
149
  if (!externalWalletFundingEnabled) {
134
150
  return Promise.reject(new Error('External wallet funding is not enabled'));
135
151
  }
136
152
  if (connectWalletPromiseRef.current) {
137
153
  return connectWalletPromiseRef.current.promise;
138
154
  }
155
+ resetWalletConnectSession();
139
156
  connectWalletPromiseRef.current = new utils.DeferredPromise();
140
157
  clearStackAndPush('external-funding-wallet-list', {
141
158
  onSelectWallet: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ walletConnector }) {
@@ -176,8 +193,9 @@ const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
176
193
  performMultiWalletChecks: false,
177
194
  });
178
195
  return connectWalletPromiseRef.current.promise;
179
- }, [
196
+ }), [
180
197
  externalWalletFundingEnabled,
198
+ resetWalletConnectSession,
181
199
  clearStackAndPush,
182
200
  primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain,
183
201
  setShowAuthFlow,
@@ -29,7 +29,7 @@ import { resolvePromiseRef } from '../../../functions/resolvePromiseRef/resolveP
29
29
  import { rejectPromiseRef } from '../../../functions/rejectPromiseRef/rejectPromiseRef.js';
30
30
  import '../../../../context/AccessDeniedContext/AccessDeniedContext.js';
31
31
  import '../../../../context/AccountExistsContext/AccountExistsContext.js';
32
- import '../../../../context/UserWalletsContext/UserWalletsContext.js';
32
+ import { useUserWallets } from '../../../../context/UserWalletsContext/UserWalletsContext.js';
33
33
  import '../../../../events/dynamicEvents.js';
34
34
  import '../../../../context/VerificationContext/VerificationContext.js';
35
35
  import 'react-dom';
@@ -48,7 +48,7 @@ import '../../../../context/FieldsStateContext/FieldsStateContext.js';
48
48
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
49
49
  import '@dynamic-labs/rpc-providers';
50
50
  import '../../../../store/state/loadingAndLifecycle.js';
51
- import '../../../../store/state/walletOptions/walletOptions.js';
51
+ import { getWalletConnectorOptions } from '../../../../store/state/walletOptions/walletOptions.js';
52
52
  import { useHandleWalletItem } from '../../useWalletItemActions/useHandleWalletItem/useHandleWalletItem.js';
53
53
  import 'react-i18next';
54
54
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
@@ -96,6 +96,7 @@ import { useInternalDynamicContext } from '../../../../context/DynamicContext/us
96
96
  const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
97
97
  const { primaryWallet, setShowAuthFlow } = useInternalDynamicContext();
98
98
  const { clearStackAndPush } = useViewContext();
99
+ const userWallets = useUserWallets();
99
100
  const { walletOptions } = useWalletOptions();
100
101
  const internalConnectionPromiseRef = useRef(null);
101
102
  const connectWalletPromiseRef = useRef(null);
@@ -125,13 +126,29 @@ const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
125
126
  handleWalletItemClick(Object.assign(Object.assign({}, walletOption), { walletConnector }));
126
127
  return internalConnectionPromiseRef.current.promise;
127
128
  }, [handleWalletItemClick, walletOptions]);
128
- return useCallback(() => {
129
+ const hasWalletConnectWallet = userWallets.some((wallet) => wallet.connector.isWalletConnect);
130
+ // WC does not allow multiple sessions, so we have 2 cases here:
131
+ // 1. The user has a linked WalletConnect wallet.
132
+ // In this case, we should not do anything, and our logic will prevent other WCs from being
133
+ // selected for funding.
134
+ // 2. The user does not have a WalletConnect wallet linked.
135
+ // In this case, we should reset the WC session — this is because they might have just
136
+ // previously connected another WC wallet for funding and that session could still be active.
137
+ const resetWalletConnectSession = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
138
+ if (hasWalletConnectWallet)
139
+ return;
140
+ const walletOption = getWalletConnectorOptions().find(({ walletConnector }) => walletConnector.isWalletConnect);
141
+ yield (walletOption === null || walletOption === void 0 ? void 0 : walletOption.walletConnector.endSession());
142
+ yield (walletOption === null || walletOption === void 0 ? void 0 : walletOption.walletConnector.init());
143
+ }), [hasWalletConnectWallet]);
144
+ return useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
129
145
  if (!externalWalletFundingEnabled) {
130
146
  return Promise.reject(new Error('External wallet funding is not enabled'));
131
147
  }
132
148
  if (connectWalletPromiseRef.current) {
133
149
  return connectWalletPromiseRef.current.promise;
134
150
  }
151
+ resetWalletConnectSession();
135
152
  connectWalletPromiseRef.current = new DeferredPromise();
136
153
  clearStackAndPush('external-funding-wallet-list', {
137
154
  onSelectWallet: (_a) => __awaiter(void 0, [_a], void 0, function* ({ walletConnector }) {
@@ -172,8 +189,9 @@ const useConnectWalletForFunding = ({ externalWalletFundingEnabled, }) => {
172
189
  performMultiWalletChecks: false,
173
190
  });
174
191
  return connectWalletPromiseRef.current.promise;
175
- }, [
192
+ }), [
176
193
  externalWalletFundingEnabled,
194
+ resetWalletConnectSession,
177
195
  clearStackAndPush,
178
196
  primaryWallet === null || primaryWallet === void 0 ? void 0 : primaryWallet.chain,
179
197
  setShowAuthFlow,
@@ -4,13 +4,13 @@
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
6
  var React = require('react');
7
- var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
8
7
  require('../../../context/DynamicContext/DynamicContext.cjs');
9
8
  require('@dynamic-labs/sdk-api-core');
10
9
  require('../../../shared/logger.cjs');
11
10
  require('@dynamic-labs/iconic');
12
11
  require('@dynamic-labs/wallet-connector-core');
13
12
  require('react/jsx-runtime');
13
+ var ViewContext = require('../../../context/ViewContext/ViewContext.cjs');
14
14
  require('@dynamic-labs/wallet-book');
15
15
  require('@dynamic-labs/utils');
16
16
  require('../../constants/colors.cjs');
@@ -94,49 +94,49 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
94
94
  const useMfaModals = () => {
95
95
  var _a;
96
96
  const { setShowAuthFlow, projectSettings } = useInternalDynamicContext.useInternalDynamicContext();
97
- const { pushView } = ViewContext.useViewContext();
97
+ const { clearStackAndPush } = ViewContext.useViewContext();
98
98
  const isMfaEnabled = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security.mfa) === null || _a === void 0 ? void 0 : _a.enabled;
99
99
  const setShowMfaChooseType = React.useCallback((value) => {
100
100
  if (value) {
101
101
  if (!isMfaEnabled)
102
102
  return;
103
- pushView('mfa-choose-device');
103
+ clearStackAndPush('mfa-choose-device');
104
104
  }
105
105
  setShowAuthFlow(value, { emitCancelAuth: true });
106
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
106
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
107
107
  const setShowMfaQRCode = React.useCallback((value) => {
108
108
  if (value) {
109
109
  if (!isMfaEnabled)
110
110
  return;
111
111
  // If MFA is enabled, show the MFA setup view and set it as the initial setup
112
- pushView('mfa-secure-device', { isInitialSetup: true });
112
+ clearStackAndPush('mfa-secure-device', { isInitialSetup: true });
113
113
  }
114
114
  setShowAuthFlow(value, { emitCancelAuth: true });
115
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
115
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
116
116
  const setShowOTPVerification = React.useCallback((value) => {
117
117
  if (value) {
118
118
  if (!isMfaEnabled)
119
119
  return;
120
- pushView('mfa-verification');
120
+ clearStackAndPush('mfa-verification');
121
121
  }
122
122
  setShowAuthFlow(value, { emitCancelAuth: true });
123
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
123
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
124
124
  const setShowMfaViewBackupCodes = React.useCallback((value) => {
125
125
  if (value) {
126
126
  if (!isMfaEnabled)
127
127
  return;
128
- pushView('mfa-display-backup-codes');
128
+ clearStackAndPush('mfa-display-backup-codes');
129
129
  }
130
130
  setShowAuthFlow(value, { emitCancelAuth: true });
131
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
131
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
132
132
  const setShowMfaEnterBackupCodes = React.useCallback((value) => {
133
133
  if (value) {
134
134
  if (!isMfaEnabled)
135
135
  return;
136
- pushView('mfa-recovery');
136
+ clearStackAndPush('mfa-recovery');
137
137
  }
138
138
  setShowAuthFlow(value, { emitCancelAuth: true });
139
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
139
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
140
140
  return {
141
141
  setShowMfaChooseType,
142
142
  setShowMfaEnterBackupCodes,
@@ -1,12 +1,12 @@
1
1
  'use client'
2
2
  import { useCallback } from 'react';
3
- import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
4
3
  import '../../../context/DynamicContext/DynamicContext.js';
5
4
  import '@dynamic-labs/sdk-api-core';
6
5
  import '../../../shared/logger.js';
7
6
  import '@dynamic-labs/iconic';
8
7
  import '@dynamic-labs/wallet-connector-core';
9
8
  import 'react/jsx-runtime';
9
+ import { useViewContext } from '../../../context/ViewContext/ViewContext.js';
10
10
  import '@dynamic-labs/wallet-book';
11
11
  import '@dynamic-labs/utils';
12
12
  import '../../constants/colors.js';
@@ -90,49 +90,49 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
90
90
  const useMfaModals = () => {
91
91
  var _a;
92
92
  const { setShowAuthFlow, projectSettings } = useInternalDynamicContext();
93
- const { pushView } = useViewContext();
93
+ const { clearStackAndPush } = useViewContext();
94
94
  const isMfaEnabled = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.security.mfa) === null || _a === void 0 ? void 0 : _a.enabled;
95
95
  const setShowMfaChooseType = useCallback((value) => {
96
96
  if (value) {
97
97
  if (!isMfaEnabled)
98
98
  return;
99
- pushView('mfa-choose-device');
99
+ clearStackAndPush('mfa-choose-device');
100
100
  }
101
101
  setShowAuthFlow(value, { emitCancelAuth: true });
102
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
102
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
103
103
  const setShowMfaQRCode = useCallback((value) => {
104
104
  if (value) {
105
105
  if (!isMfaEnabled)
106
106
  return;
107
107
  // If MFA is enabled, show the MFA setup view and set it as the initial setup
108
- pushView('mfa-secure-device', { isInitialSetup: true });
108
+ clearStackAndPush('mfa-secure-device', { isInitialSetup: true });
109
109
  }
110
110
  setShowAuthFlow(value, { emitCancelAuth: true });
111
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
111
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
112
112
  const setShowOTPVerification = useCallback((value) => {
113
113
  if (value) {
114
114
  if (!isMfaEnabled)
115
115
  return;
116
- pushView('mfa-verification');
116
+ clearStackAndPush('mfa-verification');
117
117
  }
118
118
  setShowAuthFlow(value, { emitCancelAuth: true });
119
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
119
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
120
120
  const setShowMfaViewBackupCodes = useCallback((value) => {
121
121
  if (value) {
122
122
  if (!isMfaEnabled)
123
123
  return;
124
- pushView('mfa-display-backup-codes');
124
+ clearStackAndPush('mfa-display-backup-codes');
125
125
  }
126
126
  setShowAuthFlow(value, { emitCancelAuth: true });
127
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
127
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
128
128
  const setShowMfaEnterBackupCodes = useCallback((value) => {
129
129
  if (value) {
130
130
  if (!isMfaEnabled)
131
131
  return;
132
- pushView('mfa-recovery');
132
+ clearStackAndPush('mfa-recovery');
133
133
  }
134
134
  setShowAuthFlow(value, { emitCancelAuth: true });
135
- }, [isMfaEnabled, setShowAuthFlow, pushView]);
135
+ }, [isMfaEnabled, setShowAuthFlow, clearStackAndPush]);
136
136
  return {
137
137
  setShowMfaChooseType,
138
138
  setShowMfaEnterBackupCodes,
@@ -0,0 +1,12 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const handleStoreVersionChanged = ({ didStoreVersionChangedRef, logout, }) => {
7
+ if (didStoreVersionChangedRef.current) {
8
+ logout('store version changed', {});
9
+ }
10
+ };
11
+
12
+ exports.handleStoreVersionChanged = handleStoreVersionChanged;
@@ -0,0 +1,7 @@
1
+ import { MutableRefObject } from 'react';
2
+ type HandleStoreVersionChangedParams = {
3
+ logout: (reason: string, params: any) => Promise<void>;
4
+ didStoreVersionChangedRef: MutableRefObject<boolean>;
5
+ };
6
+ export declare const handleStoreVersionChanged: ({ didStoreVersionChangedRef, logout, }: HandleStoreVersionChangedParams) => void;
7
+ export {};
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ const handleStoreVersionChanged = ({ didStoreVersionChangedRef, logout, }) => {
3
+ if (didStoreVersionChangedRef.current) {
4
+ logout('store version changed', {});
5
+ }
6
+ };
7
+
8
+ export { handleStoreVersionChanged };
@@ -0,0 +1 @@
1
+ export { handleStoreVersionChanged } from './handleStoreVersionChanged';
@@ -11,8 +11,9 @@ var loadingAndLifecycle = require('../../../store/state/loadingAndLifecycle.cjs'
11
11
  var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
12
12
  var handleStoreAndEnvironmentMismatch = require('./handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.cjs');
13
13
  var handleUserDataOutOfSync = require('./handleUserDataOutOfSync/handleUserDataOutOfSync.cjs');
14
+ var handleStoreVersionChanged = require('./handleStoreVersionChanged/handleStoreVersionChanged.cjs');
14
15
 
15
- const useValidateSession = ({ environmentId, handleLogOut }) => {
16
+ const useValidateSession = ({ environmentId, handleLogOut, didStoreVersionChangedRef, }) => {
16
17
  const logout = React.useCallback(
17
18
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
19
  (reason, params) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
@@ -20,14 +21,15 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
20
21
  return handleLogOut();
21
22
  }), [handleLogOut]);
22
23
  const validateSession = React.useCallback(() => _tslib.__awaiter(void 0, void 0, void 0, function* () {
23
- const params = { environmentId, logout };
24
+ const params = { didStoreVersionChangedRef, environmentId, logout };
24
25
  yield Promise.all([
25
26
  handleStoreAndEnvironmentMismatch.handleStoreAndEnvironmentMismatch(params),
26
27
  handleUserDataOutOfSync.handleUserDataOutOfSync(params),
28
+ handleStoreVersionChanged.handleStoreVersionChanged(params),
27
29
  ]);
28
30
  // Regardless of whether we logged out or not, session validation is now complete
29
31
  loadingAndLifecycle.setLoadingAndLifecycle({ sessionValidation: true });
30
- }), [environmentId, logout]);
32
+ }), [environmentId, logout, didStoreVersionChangedRef]);
31
33
  useEffectOnce.useEffectOnce(() => {
32
34
  validateSession();
33
35
  });
@@ -1,6 +1,8 @@
1
+ import { MutableRefObject } from 'react';
1
2
  type Props = {
2
3
  environmentId: string;
3
4
  handleLogOut: () => Promise<void>;
5
+ didStoreVersionChangedRef: MutableRefObject<boolean>;
4
6
  };
5
- export declare const useValidateSession: ({ environmentId, handleLogOut }: Props) => void;
7
+ export declare const useValidateSession: ({ environmentId, handleLogOut, didStoreVersionChangedRef, }: Props) => void;
6
8
  export {};
@@ -7,8 +7,9 @@ import { setLoadingAndLifecycle } from '../../../store/state/loadingAndLifecycle
7
7
  import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
8
8
  import { handleStoreAndEnvironmentMismatch } from './handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.js';
9
9
  import { handleUserDataOutOfSync } from './handleUserDataOutOfSync/handleUserDataOutOfSync.js';
10
+ import { handleStoreVersionChanged } from './handleStoreVersionChanged/handleStoreVersionChanged.js';
10
11
 
11
- const useValidateSession = ({ environmentId, handleLogOut }) => {
12
+ const useValidateSession = ({ environmentId, handleLogOut, didStoreVersionChangedRef, }) => {
12
13
  const logout = useCallback(
13
14
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
15
  (reason, params) => __awaiter(void 0, void 0, void 0, function* () {
@@ -16,14 +17,15 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
16
17
  return handleLogOut();
17
18
  }), [handleLogOut]);
18
19
  const validateSession = useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
19
- const params = { environmentId, logout };
20
+ const params = { didStoreVersionChangedRef, environmentId, logout };
20
21
  yield Promise.all([
21
22
  handleStoreAndEnvironmentMismatch(params),
22
23
  handleUserDataOutOfSync(params),
24
+ handleStoreVersionChanged(params),
23
25
  ]);
24
26
  // Regardless of whether we logged out or not, session validation is now complete
25
27
  setLoadingAndLifecycle({ sessionValidation: true });
26
- }), [environmentId, logout]);
28
+ }), [environmentId, logout, didStoreVersionChangedRef]);
27
29
  useEffectOnce(() => {
28
30
  validateSession();
29
31
  });
@@ -242,7 +242,7 @@ const useHandleWalletItem = ({ allowAlreadyConnectedWallet, onQrCodeConnect, onC
242
242
  handleAlreadyConnectedWallet(walletConnector);
243
243
  }
244
244
  else if (walletConnector.canConnectViaCustodialService) {
245
- // providers like blocto and dapper
245
+ // providers like coinbase, blocto and dapper
246
246
  handleCustodialWalletClick(walletConnector);
247
247
  }
248
248
  else if (utils.isMobile()) {
@@ -238,7 +238,7 @@ const useHandleWalletItem = ({ allowAlreadyConnectedWallet, onQrCodeConnect, onC
238
238
  handleAlreadyConnectedWallet(walletConnector);
239
239
  }
240
240
  else if (walletConnector.canConnectViaCustodialService) {
241
- // providers like blocto and dapper
241
+ // providers like coinbase, blocto and dapper
242
242
  handleCustodialWalletClick(walletConnector);
243
243
  }
244
244
  else if (isMobile()) {
@@ -99,29 +99,21 @@ const useWalletItemActions = () => {
99
99
  const { onlyConnectUser } = useConnectAndSignSplitSteps.useConnectAndSignSplitSteps();
100
100
  const connectAndSignWallet = useConnectAndSign.useConnectAndSign();
101
101
  const { pushView } = ViewContext.useViewContext();
102
+ const handleExtensionAndCustodial = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ requiresTwoStepAuthentication, walletConnector, }) {
103
+ if (requiresTwoStepAuthentication || authMode === 'connect-only') {
104
+ pushView('pending-connect');
105
+ yield onlyConnectUser({ walletConnector });
106
+ }
107
+ else {
108
+ // See useVerifyOnAwaitingSignature's useEffect for more context.
109
+ setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
110
+ }
111
+ });
102
112
  return useHandleWalletItem.useHandleWalletItem({
103
113
  allowAlreadyConnectedWallet: false,
104
114
  onConnectOnly: onlyConnectUser,
105
- onCustodialWallet: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ requiresTwoStepAuthentication, walletConnector, }) {
106
- if (requiresTwoStepAuthentication) {
107
- yield onlyConnectUser({
108
- walletConnector,
109
- });
110
- }
111
- else {
112
- setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
113
- }
114
- pushView('pending-signature');
115
- }),
116
- onInstalledExtension: (_b) => _tslib.__awaiter(void 0, [_b], void 0, function* ({ walletConnector }) {
117
- if (authMode === 'connect-only') {
118
- pushView('pending-connect');
119
- onlyConnectUser({ walletConnector });
120
- }
121
- else {
122
- setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
123
- }
124
- }),
115
+ onCustodialWallet: handleExtensionAndCustodial,
116
+ onInstalledExtension: handleExtensionAndCustodial,
125
117
  onQrCodeConnect: connectAndSignWallet,
126
118
  });
127
119
  };
@@ -1,9 +1,10 @@
1
+ import { WalletConnectorCore } from '@dynamic-labs/wallet-connector-core';
1
2
  export declare const useWalletItemActions: () => {
2
- handleAlreadyConnectedWallet: (walletConnector: import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector) => Promise<void>;
3
- handleCustodialWalletClick: (walletConnector: import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector) => Promise<void>;
4
- handleInstalledExtensionClick: (walletConnector: import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector) => Promise<void>;
5
- handleMobileWalletClick: (walletConnector: import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector) => Promise<void>;
6
- handleUninstalledClick: (walletConnector: import("dist/packages/wallet-connector-core/src").WalletConnectorCore.WalletConnector) => Promise<void>;
3
+ handleAlreadyConnectedWallet: (walletConnector: WalletConnectorCore.WalletConnector) => Promise<void>;
4
+ handleCustodialWalletClick: (walletConnector: WalletConnectorCore.WalletConnector) => Promise<void>;
5
+ handleInstalledExtensionClick: (walletConnector: WalletConnectorCore.WalletConnector) => Promise<void>;
6
+ handleMobileWalletClick: (walletConnector: WalletConnectorCore.WalletConnector) => Promise<void>;
7
+ handleUninstalledClick: (walletConnector: WalletConnectorCore.WalletConnector) => Promise<void>;
7
8
  handleWalletItemClick: (wallet: import("../../../shared").WalletOption) => Promise<void>;
8
9
  openWallet: import("./useWalletItemActions.types").OpenWalletHandler;
9
10
  };
@@ -95,29 +95,21 @@ const useWalletItemActions = () => {
95
95
  const { onlyConnectUser } = useConnectAndSignSplitSteps();
96
96
  const connectAndSignWallet = useConnectAndSign();
97
97
  const { pushView } = useViewContext();
98
+ const handleExtensionAndCustodial = (_a) => __awaiter(void 0, [_a], void 0, function* ({ requiresTwoStepAuthentication, walletConnector, }) {
99
+ if (requiresTwoStepAuthentication || authMode === 'connect-only') {
100
+ pushView('pending-connect');
101
+ yield onlyConnectUser({ walletConnector });
102
+ }
103
+ else {
104
+ // See useVerifyOnAwaitingSignature's useEffect for more context.
105
+ setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
106
+ }
107
+ });
98
108
  return useHandleWalletItem({
99
109
  allowAlreadyConnectedWallet: false,
100
110
  onConnectOnly: onlyConnectUser,
101
- onCustodialWallet: (_a) => __awaiter(void 0, [_a], void 0, function* ({ requiresTwoStepAuthentication, walletConnector, }) {
102
- if (requiresTwoStepAuthentication) {
103
- yield onlyConnectUser({
104
- walletConnector,
105
- });
106
- }
107
- else {
108
- setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
109
- }
110
- pushView('pending-signature');
111
- }),
112
- onInstalledExtension: (_b) => __awaiter(void 0, [_b], void 0, function* ({ walletConnector }) {
113
- if (authMode === 'connect-only') {
114
- pushView('pending-connect');
115
- onlyConnectUser({ walletConnector });
116
- }
117
- else {
118
- setMultiWalletWidgetState('awaiting_signature', undefined, 'linking_new_wallet');
119
- }
120
- }),
111
+ onCustodialWallet: handleExtensionAndCustodial,
112
+ onInstalledExtension: handleExtensionAndCustodial,
121
113
  onQrCodeConnect: connectAndSignWallet,
122
114
  });
123
115
  };
@@ -105,12 +105,7 @@ const MfaChooseDeviceView = ({ isInitialSetup = true, }) => {
105
105
  const mfaOptions = getMfaOptions.getMfaOptions(isInitialSetup);
106
106
  const handleClick = (option) => {
107
107
  if (option.type === 'backupCode') {
108
- pushView('mfa-recovery', undefined, {
109
- onBackClick: () => {
110
- pushView('mfa-choose-device', { isInitialSetup: false });
111
- return 'override';
112
- },
113
- });
108
+ pushView('mfa-recovery');
114
109
  return;
115
110
  }
116
111
  if (isInitialSetup) {
@@ -101,12 +101,7 @@ const MfaChooseDeviceView = ({ isInitialSetup = true, }) => {
101
101
  const mfaOptions = getMfaOptions(isInitialSetup);
102
102
  const handleClick = (option) => {
103
103
  if (option.type === 'backupCode') {
104
- pushView('mfa-recovery', undefined, {
105
- onBackClick: () => {
106
- pushView('mfa-choose-device', { isInitialSetup: false });
107
- return 'override';
108
- },
109
- });
104
+ pushView('mfa-recovery');
110
105
  return;
111
106
  }
112
107
  if (isInitialSetup) {
@@ -105,13 +105,11 @@ const MfaSecureDeviceView = ({ type, isInitialSetup = false, }) => {
105
105
  const { addDevice } = useMfa.useMfa();
106
106
  const { data, isLoading } = usePromise.usePromise(() => addDevice(type));
107
107
  const onContinue = () => {
108
- // back button on mfa verification view should go back to this view
109
- const onMfaVerificationBackClick = () => {
110
- pushView('mfa-secure-device', { type });
111
- return 'override';
112
- };
113
- pushView('mfa-verification', { deviceId: data === null || data === void 0 ? void 0 : data.id, isInitialSetup, showBackButton: true, type }, {
114
- onBackClick: onMfaVerificationBackClick,
108
+ pushView('mfa-verification', {
109
+ deviceId: data === null || data === void 0 ? void 0 : data.id,
110
+ isInitialSetup,
111
+ showBackButton: true,
112
+ type,
115
113
  });
116
114
  };
117
115
  const onHelpClick = ({ secret, uri }) => {
@@ -101,13 +101,11 @@ const MfaSecureDeviceView = ({ type, isInitialSetup = false, }) => {
101
101
  const { addDevice } = useMfa();
102
102
  const { data, isLoading } = usePromise(() => addDevice(type));
103
103
  const onContinue = () => {
104
- // back button on mfa verification view should go back to this view
105
- const onMfaVerificationBackClick = () => {
106
- pushView('mfa-secure-device', { type });
107
- return 'override';
108
- };
109
- pushView('mfa-verification', { deviceId: data === null || data === void 0 ? void 0 : data.id, isInitialSetup, showBackButton: true, type }, {
110
- onBackClick: onMfaVerificationBackClick,
104
+ pushView('mfa-verification', {
105
+ deviceId: data === null || data === void 0 ? void 0 : data.id,
106
+ isInitialSetup,
107
+ showBackButton: true,
108
+ type,
111
109
  });
112
110
  };
113
111
  const onHelpClick = ({ secret, uri }) => {