@dynamic-labs/sdk-react-core 4.9.2 → 4.9.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 (46) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/package.cjs +2 -2
  3. package/package.js +2 -2
  4. package/package.json +12 -12
  5. package/src/index.cjs +1 -1
  6. package/src/index.js +1 -1
  7. package/src/lib/components/TosAndPp/TosAndPp.cjs +3 -1
  8. package/src/lib/components/TosAndPp/TosAndPp.js +3 -1
  9. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.cjs +1 -2
  10. package/src/lib/context/DynamicContext/hooks/useTieCallbacksToEvents/useTieCallbacksToEvents.js +1 -2
  11. package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.cjs +0 -2
  12. package/src/lib/context/DynamicContext/useCustomerCallbacks/useCustomerCallbacks.js +0 -2
  13. package/src/lib/context/ErrorContext/hooks/useErrorText/useErrorText.cjs +1 -0
  14. package/src/lib/context/ErrorContext/hooks/useErrorText/useErrorText.js +1 -0
  15. package/src/lib/context/PhantomRedirectContext/useResponseHandlers.cjs +1 -0
  16. package/src/lib/context/PhantomRedirectContext/useResponseHandlers.js +1 -0
  17. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.cjs +1 -0
  18. package/src/lib/context/SocialRedirectContext/SocialRedirectContext.js +1 -0
  19. package/src/lib/events/auth.d.ts +0 -5
  20. package/src/lib/locale/en/translation.cjs +1 -0
  21. package/src/lib/locale/en/translation.d.ts +1 -0
  22. package/src/lib/locale/en/translation.js +1 -0
  23. package/src/lib/styles/index.shadow.cjs +1 -1
  24. package/src/lib/styles/index.shadow.js +1 -1
  25. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.cjs +1 -0
  26. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSign/useConnectAndSign.js +1 -0
  27. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.cjs +1 -0
  28. package/src/lib/utils/hooks/authenticationHooks/useConnectAndSignSplitSteps/useConnectAndSignSplitSteps.js +1 -0
  29. package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.cjs +1 -0
  30. package/src/lib/utils/hooks/authenticationHooks/useSignConnectOnlyUser/useSignConnectOnlyUser.js +1 -0
  31. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +8 -8
  32. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +8 -8
  33. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.cjs +1 -3
  34. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.d.ts +1 -2
  35. package/src/lib/utils/hooks/useValidateSession/handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.js +1 -3
  36. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.cjs +3 -5
  37. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.d.ts +1 -2
  38. package/src/lib/utils/hooks/useValidateSession/handleUserDataOutOfSync/handleUserDataOutOfSync.js +3 -5
  39. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.cjs +37 -0
  40. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.d.ts +9 -0
  41. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.js +33 -0
  42. package/src/lib/utils/hooks/useValidateSession/handleWalletInfoOutOfSync/index.d.ts +1 -0
  43. package/src/lib/utils/hooks/useValidateSession/useValidateSession.cjs +2 -6
  44. package/src/lib/utils/hooks/useValidateSession/useValidateSession.js +2 -6
  45. package/src/lib/views/LoginView/useLoginView/useLoginView.cjs +9 -15
  46. package/src/lib/views/LoginView/useLoginView/useLoginView.js +9 -15
@@ -57,6 +57,7 @@ require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
57
57
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
58
58
  require('@dynamic-labs/rpc-providers');
59
59
  require('../../../../store/state/loadingAndLifecycle.cjs');
60
+ require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
60
61
  require('../../../../store/state/walletOptions/walletOptions.cjs');
61
62
  require('react-i18next');
62
63
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
@@ -53,6 +53,7 @@ import '../../../../context/FieldsStateContext/FieldsStateContext.js';
53
53
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
54
54
  import '@dynamic-labs/rpc-providers';
55
55
  import '../../../../store/state/loadingAndLifecycle.js';
56
+ import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
56
57
  import '../../../../store/state/walletOptions/walletOptions.js';
57
58
  import 'react-i18next';
58
59
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
@@ -57,6 +57,7 @@ require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
57
57
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
58
58
  require('@dynamic-labs/rpc-providers');
59
59
  require('../../../../store/state/loadingAndLifecycle.cjs');
60
+ require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
60
61
  require('../../../../store/state/walletOptions/walletOptions.cjs');
61
62
  require('react-i18next');
62
63
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
@@ -53,6 +53,7 @@ import '../../../../context/FieldsStateContext/FieldsStateContext.js';
53
53
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
54
54
  import '@dynamic-labs/rpc-providers';
55
55
  import '../../../../store/state/loadingAndLifecycle.js';
56
+ import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
56
57
  import '../../../../store/state/walletOptions/walletOptions.js';
57
58
  import 'react-i18next';
58
59
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
@@ -51,6 +51,7 @@ require('../../../../context/FieldsStateContext/FieldsStateContext.cjs');
51
51
  require('../../../../context/UserFieldEditorContext/UserFieldEditorContext.cjs');
52
52
  require('@dynamic-labs/rpc-providers');
53
53
  require('../../../../store/state/loadingAndLifecycle.cjs');
54
+ require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
54
55
  require('../../../../store/state/walletOptions/walletOptions.cjs');
55
56
  require('react-i18next');
56
57
  require('../../../../components/Accordion/components/AccordionItem/AccordionItem.cjs');
@@ -47,6 +47,7 @@ import '../../../../context/FieldsStateContext/FieldsStateContext.js';
47
47
  import '../../../../context/UserFieldEditorContext/UserFieldEditorContext.js';
48
48
  import '@dynamic-labs/rpc-providers';
49
49
  import '../../../../store/state/loadingAndLifecycle.js';
50
+ import '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
50
51
  import '../../../../store/state/walletOptions/walletOptions.js';
51
52
  import 'react-i18next';
52
53
  import '../../../../components/Accordion/components/AccordionItem/AccordionItem.js';
@@ -162,23 +162,23 @@ const useEmbeddedWallet = () => {
162
162
  const shouldPromptForKeyExport = React.useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
163
163
  const embeddedWalletSettingVersion = React.useCallback(() => { var _a; return (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion; }, [projectSettings]);
164
164
  const shouldAutoCreateEmbeddedWallet = React.useCallback((verifiedUser) => {
165
- var _a, _b, _c, _d, _e, _f;
165
+ var _a, _b, _c, _d, _e;
166
166
  const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled.isTurnkeyEnabled(projectSettings);
167
- const defaultWalletVersion = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion;
168
167
  const hasPrimaryWallet = primaryWalletId.getPrimaryWalletId();
169
- if (defaultWalletVersion === sdkApiCore.EmbeddedWalletVersionEnum.V3) {
168
+ if (embeddedWalletSettingVersion() === sdkApiCore.EmbeddedWalletVersionEnum.V3 &&
169
+ !verifiedUser) {
170
170
  return false;
171
171
  }
172
172
  if (!hasEmbeddedWalletProviderEnabled || hasPrimaryWallet) {
173
173
  return false;
174
174
  }
175
- // Turnkey specific rules
175
+ // Turnkey and WAAS specific rules
176
176
  if (verifiedUser) {
177
177
  const primaryEmbeddedChain = findPrimaryEmbeddedChain.findPrimaryEmbeddedChain(projectSettings);
178
- const embeddedWalletVerifiedCredentialId = (_b = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
178
+ const embeddedWalletVerifiedCredentialId = (_a = findEmbeddedWalletFromVerifiedCredentials.findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
179
179
  primaryEmbeddedChain,
180
- ])) === null || _b === void 0 ? void 0 : _b.id;
181
- const AAWalletCredentialId = (_d = (_c = verifiedUser.verifiedCredentials) === null || _c === void 0 ? void 0 : _c.find((vc) => vc.walletProvider === sdkApiCore.WalletProviderEnum.SmartContractWallet)) === null || _d === void 0 ? void 0 : _d.id;
180
+ ])) === null || _a === void 0 ? void 0 : _a.id;
181
+ const AAWalletCredentialId = (_c = (_b = verifiedUser.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.find((vc) => vc.walletProvider === sdkApiCore.WalletProviderEnum.SmartContractWallet)) === null || _c === void 0 ? void 0 : _c.id;
182
182
  const targetPrimaryWalletId = AAWalletCredentialId
183
183
  ? AAWalletCredentialId
184
184
  : embeddedWalletVerifiedCredentialId;
@@ -188,7 +188,7 @@ const useEmbeddedWallet = () => {
188
188
  }
189
189
  }
190
190
  if (isTurnkeyEnabled.isTurnkeyEnabled(projectSettings) &&
191
- !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
191
+ !((_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation)) {
192
192
  return false;
193
193
  }
194
194
  return true;
@@ -158,23 +158,23 @@ const useEmbeddedWallet = () => {
158
158
  const shouldPromptForKeyExport = useCallback(() => { var _a; return Boolean((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.promptForKeyExport); }, [projectSettings]);
159
159
  const embeddedWalletSettingVersion = useCallback(() => { var _a; return (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion; }, [projectSettings]);
160
160
  const shouldAutoCreateEmbeddedWallet = useCallback((verifiedUser) => {
161
- var _a, _b, _c, _d, _e, _f;
161
+ var _a, _b, _c, _d, _e;
162
162
  const hasEmbeddedWalletProviderEnabled = isTurnkeyEnabled(projectSettings);
163
- const defaultWalletVersion = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.embeddedWallets) === null || _a === void 0 ? void 0 : _a.defaultWalletVersion;
164
163
  const hasPrimaryWallet = getPrimaryWalletId();
165
- if (defaultWalletVersion === EmbeddedWalletVersionEnum.V3) {
164
+ if (embeddedWalletSettingVersion() === EmbeddedWalletVersionEnum.V3 &&
165
+ !verifiedUser) {
166
166
  return false;
167
167
  }
168
168
  if (!hasEmbeddedWalletProviderEnabled || hasPrimaryWallet) {
169
169
  return false;
170
170
  }
171
- // Turnkey specific rules
171
+ // Turnkey and WAAS specific rules
172
172
  if (verifiedUser) {
173
173
  const primaryEmbeddedChain = findPrimaryEmbeddedChain(projectSettings);
174
- const embeddedWalletVerifiedCredentialId = (_b = findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
174
+ const embeddedWalletVerifiedCredentialId = (_a = findEmbeddedWalletFromVerifiedCredentials(verifiedUser, [
175
175
  primaryEmbeddedChain,
176
- ])) === null || _b === void 0 ? void 0 : _b.id;
177
- const AAWalletCredentialId = (_d = (_c = verifiedUser.verifiedCredentials) === null || _c === void 0 ? void 0 : _c.find((vc) => vc.walletProvider === WalletProviderEnum.SmartContractWallet)) === null || _d === void 0 ? void 0 : _d.id;
176
+ ])) === null || _a === void 0 ? void 0 : _a.id;
177
+ const AAWalletCredentialId = (_c = (_b = verifiedUser.verifiedCredentials) === null || _b === void 0 ? void 0 : _b.find((vc) => vc.walletProvider === WalletProviderEnum.SmartContractWallet)) === null || _c === void 0 ? void 0 : _c.id;
178
178
  const targetPrimaryWalletId = AAWalletCredentialId
179
179
  ? AAWalletCredentialId
180
180
  : embeddedWalletVerifiedCredentialId;
@@ -184,7 +184,7 @@ const useEmbeddedWallet = () => {
184
184
  }
185
185
  }
186
186
  if (isTurnkeyEnabled(projectSettings) &&
187
- !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _e === void 0 ? void 0 : _e.embeddedWallets) === null || _f === void 0 ? void 0 : _f.automaticEmbeddedWalletCreation)) {
187
+ !((_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _d === void 0 ? void 0 : _d.embeddedWallets) === null || _e === void 0 ? void 0 : _e.automaticEmbeddedWalletCreation)) {
188
188
  return false;
189
189
  }
190
190
  return true;
@@ -8,19 +8,17 @@ var dynamicContextProps = require('../../../../store/state/dynamicContextProps/d
8
8
 
9
9
  /**
10
10
  * Detects envId mismtach with store.
11
- * @returns true if there is no mismatch.
12
11
  */
13
12
  const handleStoreAndEnvironmentMismatch = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, }) {
14
13
  const storeEnvId = dynamicContextProps.getEnvironmentId();
15
14
  if (!storeEnvId || environmentId === storeEnvId) {
16
- return true;
15
+ return;
17
16
  }
18
17
  yield logout('store and environment are out of sync', {
19
18
  currentEnvId: environmentId,
20
19
  storedEnvId: storeEnvId,
21
20
  });
22
21
  dynamicContextProps.setEnvironmentId(environmentId);
23
- return false;
24
22
  });
25
23
 
26
24
  exports.handleStoreAndEnvironmentMismatch = handleStoreAndEnvironmentMismatch;
@@ -4,6 +4,5 @@ export type HandleStoreAndEnvironmentMismatchParams = {
4
4
  };
5
5
  /**
6
6
  * Detects envId mismtach with store.
7
- * @returns true if there is no mismatch.
8
7
  */
9
- export declare const handleStoreAndEnvironmentMismatch: ({ environmentId, logout, }: HandleStoreAndEnvironmentMismatchParams) => Promise<boolean>;
8
+ export declare const handleStoreAndEnvironmentMismatch: ({ environmentId, logout, }: HandleStoreAndEnvironmentMismatchParams) => Promise<void>;
@@ -4,19 +4,17 @@ import { getEnvironmentId, setEnvironmentId } from '../../../../store/state/dyna
4
4
 
5
5
  /**
6
6
  * Detects envId mismtach with store.
7
- * @returns true if there is no mismatch.
8
7
  */
9
8
  const handleStoreAndEnvironmentMismatch = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, }) {
10
9
  const storeEnvId = getEnvironmentId();
11
10
  if (!storeEnvId || environmentId === storeEnvId) {
12
- return true;
11
+ return;
13
12
  }
14
13
  yield logout('store and environment are out of sync', {
15
14
  currentEnvId: environmentId,
16
15
  storedEnvId: storeEnvId,
17
16
  });
18
17
  setEnvironmentId(environmentId);
19
- return false;
20
18
  });
21
19
 
22
20
  export { handleStoreAndEnvironmentMismatch };
@@ -14,14 +14,13 @@ var getAuthToken = require('../../../functions/getAuthToken/getAuthToken.cjs');
14
14
 
15
15
  /**
16
16
  * Detects mismatch between user and auth token.
17
- * @returns true if there is no mismatch.
18
17
  */
19
18
  const handleUserDataOutOfSync = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, projectSettings, }) {
20
19
  const cookieEnabled = isCookieEnabled.isCookieEnabled(projectSettings);
21
20
  const authToken = getAuthToken.getAuthToken();
22
21
  const user$2 = user.getUser();
23
22
  if (authToken || !user$2) {
24
- return true;
23
+ return;
25
24
  }
26
25
  if (user$2 && !authToken && cookieEnabled) {
27
26
  try {
@@ -33,16 +32,15 @@ const handleUserDataOutOfSync = (_a) => _tslib.__awaiter(void 0, [_a], void 0, f
33
32
  authToken,
34
33
  user: user$2,
35
34
  });
36
- return false;
35
+ return;
37
36
  }
38
37
  }
39
- return true;
38
+ return;
40
39
  }
41
40
  yield logout('user data out of sync', {
42
41
  authToken,
43
42
  user: user$2,
44
43
  });
45
- return false;
46
44
  });
47
45
 
48
46
  exports.handleUserDataOutOfSync = handleUserDataOutOfSync;
@@ -6,6 +6,5 @@ export type HandleUserDataOutOfSyncParams = {
6
6
  };
7
7
  /**
8
8
  * Detects mismatch between user and auth token.
9
- * @returns true if there is no mismatch.
10
9
  */
11
- export declare const handleUserDataOutOfSync: ({ environmentId, logout, projectSettings, }: HandleUserDataOutOfSyncParams) => Promise<boolean>;
10
+ export declare const handleUserDataOutOfSync: ({ environmentId, logout, projectSettings, }: HandleUserDataOutOfSyncParams) => Promise<void>;
@@ -10,14 +10,13 @@ import { getAuthToken } from '../../../functions/getAuthToken/getAuthToken.js';
10
10
 
11
11
  /**
12
12
  * Detects mismatch between user and auth token.
13
- * @returns true if there is no mismatch.
14
13
  */
15
14
  const handleUserDataOutOfSync = (_a) => __awaiter(void 0, [_a], void 0, function* ({ environmentId, logout, projectSettings, }) {
16
15
  const cookieEnabled = isCookieEnabled(projectSettings);
17
16
  const authToken = getAuthToken();
18
17
  const user = getUser();
19
18
  if (authToken || !user) {
20
- return true;
19
+ return;
21
20
  }
22
21
  if (user && !authToken && cookieEnabled) {
23
22
  try {
@@ -29,16 +28,15 @@ const handleUserDataOutOfSync = (_a) => __awaiter(void 0, [_a], void 0, function
29
28
  authToken,
30
29
  user,
31
30
  });
32
- return false;
31
+ return;
33
32
  }
34
33
  }
35
- return true;
34
+ return;
36
35
  }
37
36
  yield logout('user data out of sync', {
38
37
  authToken,
39
38
  user,
40
39
  });
41
- return false;
42
40
  });
43
41
 
44
42
  export { handleUserDataOutOfSync };
@@ -0,0 +1,37 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../../../../_virtual/_tslib.cjs');
7
+ var user = require('../../../../store/state/user/user.cjs');
8
+ require('@dynamic-labs/utils');
9
+ require('../../../constants/values.cjs');
10
+ require('@dynamic-labs/sdk-api-core');
11
+ require('../../../../store/state/projectSettings/projectSettings.cjs');
12
+ var primaryWalletId = require('../../../../store/state/primaryWalletId/primaryWalletId.cjs');
13
+ var connectedWalletsInfo = require('../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.cjs');
14
+
15
+ /**
16
+ * Detects mismatch between wallet info.
17
+ * If there is primary wallet id, but no user or connected wallets info,
18
+ * it means it's in a bad state and we should log out.
19
+ */
20
+ const handleWalletInfoOutOfSync = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ logout, }) {
21
+ const primaryWalletId$1 = primaryWalletId.getPrimaryWalletId();
22
+ if (!primaryWalletId$1) {
23
+ return;
24
+ }
25
+ const user$1 = user.getUser();
26
+ const connectedWallets = connectedWalletsInfo.getConnectedWalletsInfo();
27
+ if (user$1 || connectedWallets.length > 0) {
28
+ return;
29
+ }
30
+ yield logout('wallet info is out of sync', {
31
+ connectedWallets,
32
+ primaryWalletId: primaryWalletId$1,
33
+ user: user$1,
34
+ });
35
+ });
36
+
37
+ exports.handleWalletInfoOutOfSync = handleWalletInfoOutOfSync;
@@ -0,0 +1,9 @@
1
+ export type HandleWalletInfoOutOfSyncParams = {
2
+ logout: (reason: string, params: any) => Promise<void>;
3
+ };
4
+ /**
5
+ * Detects mismatch between wallet info.
6
+ * If there is primary wallet id, but no user or connected wallets info,
7
+ * it means it's in a bad state and we should log out.
8
+ */
9
+ export declare const handleWalletInfoOutOfSync: ({ logout, }: HandleWalletInfoOutOfSyncParams) => Promise<void>;
@@ -0,0 +1,33 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../../../../_virtual/_tslib.js';
3
+ import { getUser } from '../../../../store/state/user/user.js';
4
+ import '@dynamic-labs/utils';
5
+ import '../../../constants/values.js';
6
+ import '@dynamic-labs/sdk-api-core';
7
+ import '../../../../store/state/projectSettings/projectSettings.js';
8
+ import { getPrimaryWalletId } from '../../../../store/state/primaryWalletId/primaryWalletId.js';
9
+ import { getConnectedWalletsInfo } from '../../../../store/state/connectedWalletsInfo/connectedWalletsInfo.js';
10
+
11
+ /**
12
+ * Detects mismatch between wallet info.
13
+ * If there is primary wallet id, but no user or connected wallets info,
14
+ * it means it's in a bad state and we should log out.
15
+ */
16
+ const handleWalletInfoOutOfSync = (_a) => __awaiter(void 0, [_a], void 0, function* ({ logout, }) {
17
+ const primaryWalletId = getPrimaryWalletId();
18
+ if (!primaryWalletId) {
19
+ return;
20
+ }
21
+ const user = getUser();
22
+ const connectedWallets = getConnectedWalletsInfo();
23
+ if (user || connectedWallets.length > 0) {
24
+ return;
25
+ }
26
+ yield logout('wallet info is out of sync', {
27
+ connectedWallets,
28
+ primaryWalletId,
29
+ user,
30
+ });
31
+ });
32
+
33
+ export { handleWalletInfoOutOfSync };
@@ -0,0 +1 @@
1
+ export * from './handleWalletInfoOutOfSync';
@@ -7,10 +7,10 @@ var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var React = require('react');
8
8
  var logger = require('../../../shared/logger.cjs');
9
9
  var loadingAndLifecycle = require('../../../store/state/loadingAndLifecycle.cjs');
10
- var useDynamicEvents = require('../events/useDynamicEvents/useDynamicEvents.cjs');
11
10
  var projectSettings = require('../../../store/state/projectSettings/projectSettings.cjs');
12
11
  var handleStoreAndEnvironmentMismatch = require('./handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.cjs');
13
12
  var handleUserDataOutOfSync = require('./handleUserDataOutOfSync/handleUserDataOutOfSync.cjs');
13
+ var handleWalletInfoOutOfSync = require('./handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.cjs');
14
14
 
15
15
  const useValidateSession = ({ environmentId, handleLogOut }) => {
16
16
  const didRunRef = React.useRef(false);
@@ -30,6 +30,7 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
30
30
  yield Promise.all([
31
31
  handleStoreAndEnvironmentMismatch.handleStoreAndEnvironmentMismatch(params),
32
32
  handleUserDataOutOfSync.handleUserDataOutOfSync(params),
33
+ handleWalletInfoOutOfSync.handleWalletInfoOutOfSync(params),
33
34
  ]);
34
35
  // Regardless of whether we logged out or not, session validation is now complete
35
36
  loadingAndLifecycle.setLoadingAndLifecycle({ sessionValidation: true });
@@ -40,11 +41,6 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
40
41
  didRunRef.current = true;
41
42
  validateSession(projectSettings$1);
42
43
  }, [validateSession, projectSettings$1]);
43
- useDynamicEvents.useInternalDynamicEvents('triggerSessionValidation', () => {
44
- if (!projectSettings$1)
45
- return;
46
- validateSession(projectSettings$1);
47
- });
48
44
  };
49
45
 
50
46
  exports.useValidateSession = useValidateSession;
@@ -3,10 +3,10 @@ import { __awaiter } from '../../../../../_virtual/_tslib.js';
3
3
  import { useRef, useCallback, useEffect } from 'react';
4
4
  import { logger } from '../../../shared/logger.js';
5
5
  import { setLoadingAndLifecycle } from '../../../store/state/loadingAndLifecycle.js';
6
- import { useInternalDynamicEvents } from '../events/useDynamicEvents/useDynamicEvents.js';
7
6
  import { useProjectSettings } from '../../../store/state/projectSettings/projectSettings.js';
8
7
  import { handleStoreAndEnvironmentMismatch } from './handleStoreAndEnvironmentMismatch/handleStoreAndEnvironmentMismatch.js';
9
8
  import { handleUserDataOutOfSync } from './handleUserDataOutOfSync/handleUserDataOutOfSync.js';
9
+ import { handleWalletInfoOutOfSync } from './handleWalletInfoOutOfSync/handleWalletInfoOutOfSync.js';
10
10
 
11
11
  const useValidateSession = ({ environmentId, handleLogOut }) => {
12
12
  const didRunRef = useRef(false);
@@ -26,6 +26,7 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
26
26
  yield Promise.all([
27
27
  handleStoreAndEnvironmentMismatch(params),
28
28
  handleUserDataOutOfSync(params),
29
+ handleWalletInfoOutOfSync(params),
29
30
  ]);
30
31
  // Regardless of whether we logged out or not, session validation is now complete
31
32
  setLoadingAndLifecycle({ sessionValidation: true });
@@ -36,11 +37,6 @@ const useValidateSession = ({ environmentId, handleLogOut }) => {
36
37
  didRunRef.current = true;
37
38
  validateSession(projectSettings);
38
39
  }, [validateSession, projectSettings]);
39
- useInternalDynamicEvents('triggerSessionValidation', () => {
40
- if (!projectSettings)
41
- return;
42
- validateSession(projectSettings);
43
- });
44
40
  };
45
41
 
46
42
  export { useValidateSession };
@@ -74,6 +74,7 @@ require('react-focus-lock');
74
74
  require('qrcode');
75
75
  require('formik');
76
76
  require('../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.cjs');
77
+ var useWalletList = require('../../../utils/hooks/useWalletList/useWalletList.cjs');
77
78
  require('../../../context/WalletGroupContext/WalletGroupContext.cjs');
78
79
  require('../../../context/IpConfigurationContext/IpConfigurationContext.cjs');
79
80
  require('../../../context/ConnectWithOtpContext/ConnectWithOtpContext.cjs');
@@ -103,21 +104,15 @@ var useInternalDynamicContext = require('../../../context/DynamicContext/useDyna
103
104
  const NUMBER_OF_WALLETS = 3;
104
105
  const useLoginView = () => {
105
106
  const loginView = useViewSettings.useViewSettings(sdkApiCore.SdkViewType.Login);
106
- const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, walletConnectorOptions, walletsFilter, } = useInternalDynamicContext.useInternalDynamicContext();
107
+ const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, walletsFilter, } = useInternalDynamicContext.useInternalDynamicContext();
107
108
  const { t } = reactI18next.useTranslation();
108
109
  const { enabledSocialProviders } = SocialRedirectContext.useSocialRedirectContext();
110
+ const { numberOfWallets } = useWalletList.useWalletList({
111
+ viewWalletsFilter: walletsFilter,
112
+ });
109
113
  const hasSocialProvidersEnabled = Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length);
110
114
  const hasEmailProviderEnabled = isEmailProviderEnabled.isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
111
115
  const hasPhoneProviderEnabled = isPhoneNumberProviderEnabled.isPhoneNumberProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
112
- /** Takes from wallets only those that can be selected in the wallet list by the user.
113
- * Should filter out embedded wallets
114
- * WHY: when we decide whether to show wallets or not, we need to know how many wallets
115
- * will actually be rendered. It would be especially bad to only have for ex "turnkey" in
116
- * wallets and then display an empty wallet list (since turnkey doesn't render)
117
- */
118
- const selectableWallets = (walletsFilter
119
- ? walletsFilter(walletConnectorOptions)
120
- : walletConnectorOptions).filter(({ key }) => key !== 'turnkey');
121
116
  const isWalletOnly = React.useMemo(() => {
122
117
  var _a;
123
118
  if (!projectSettings) {
@@ -158,11 +153,11 @@ const useLoginView = () => {
158
153
  sections.find((section) => section.type === 'wallet')) {
159
154
  logger.logger.error('Failed to render WalletSignInSection - no chains enabled');
160
155
  }
161
- if (selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) {
156
+ if (numberOfWallets > 0) {
162
157
  return sections;
163
158
  }
164
159
  return sections.filter((section) => section.type !== 'wallet');
165
- }, [selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
160
+ }, [numberOfWallets, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
166
161
  /**
167
162
  * returns the login view sections to be displayed in order from projectSettings?.sdk?.views
168
163
  * and has backwards compatibility with project settings design.modal props
@@ -185,8 +180,7 @@ const useLoginView = () => {
185
180
  showPhone: hasPhoneProviderEnabled,
186
181
  showSocial: Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length),
187
182
  // is email only is set in the project settings when the "Email (Web2) only" is toggled on in the dashboard
188
- showWallets: Boolean(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) &&
189
- !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) === null || _f === void 0 ? void 0 : _f.emailOnly),
183
+ showWallets: numberOfWallets > 0 && !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) === null || _f === void 0 ? void 0 : _f.emailOnly),
190
184
  socialAboveEmail,
191
185
  splitEmailAndSocial,
192
186
  web3Layout: authorizationViewDisplayOrder === 'web3',
@@ -216,7 +210,7 @@ const useLoginView = () => {
216
210
  hasPhoneProviderEnabled,
217
211
  loginView === null || loginView === void 0 ? void 0 : loginView.sections,
218
212
  projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal,
219
- selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
213
+ numberOfWallets,
220
214
  t,
221
215
  ]);
222
216
  return {
@@ -70,6 +70,7 @@ import 'react-focus-lock';
70
70
  import 'qrcode';
71
71
  import 'formik';
72
72
  import '../../../utils/hooks/useSubdomainCheck/useSubdomainCheck.js';
73
+ import { useWalletList } from '../../../utils/hooks/useWalletList/useWalletList.js';
73
74
  import '../../../context/WalletGroupContext/WalletGroupContext.js';
74
75
  import '../../../context/IpConfigurationContext/IpConfigurationContext.js';
75
76
  import '../../../context/ConnectWithOtpContext/ConnectWithOtpContext.js';
@@ -99,21 +100,15 @@ import { useInternalDynamicContext } from '../../../context/DynamicContext/useDy
99
100
  const NUMBER_OF_WALLETS = 3;
100
101
  const useLoginView = () => {
101
102
  const loginView = useViewSettings(SdkViewType.Login);
102
- const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, walletConnectorOptions, walletsFilter, } = useInternalDynamicContext();
103
+ const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, walletsFilter, } = useInternalDynamicContext();
103
104
  const { t } = useTranslation();
104
105
  const { enabledSocialProviders } = useSocialRedirectContext();
106
+ const { numberOfWallets } = useWalletList({
107
+ viewWalletsFilter: walletsFilter,
108
+ });
105
109
  const hasSocialProvidersEnabled = Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length);
106
110
  const hasEmailProviderEnabled = isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
107
111
  const hasPhoneProviderEnabled = isPhoneNumberProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
108
- /** Takes from wallets only those that can be selected in the wallet list by the user.
109
- * Should filter out embedded wallets
110
- * WHY: when we decide whether to show wallets or not, we need to know how many wallets
111
- * will actually be rendered. It would be especially bad to only have for ex "turnkey" in
112
- * wallets and then display an empty wallet list (since turnkey doesn't render)
113
- */
114
- const selectableWallets = (walletsFilter
115
- ? walletsFilter(walletConnectorOptions)
116
- : walletConnectorOptions).filter(({ key }) => key !== 'turnkey');
117
112
  const isWalletOnly = useMemo(() => {
118
113
  var _a;
119
114
  if (!projectSettings) {
@@ -154,11 +149,11 @@ const useLoginView = () => {
154
149
  sections.find((section) => section.type === 'wallet')) {
155
150
  logger.error('Failed to render WalletSignInSection - no chains enabled');
156
151
  }
157
- if (selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) {
152
+ if (numberOfWallets > 0) {
158
153
  return sections;
159
154
  }
160
155
  return sections.filter((section) => section.type !== 'wallet');
161
- }, [selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
156
+ }, [numberOfWallets, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
162
157
  /**
163
158
  * returns the login view sections to be displayed in order from projectSettings?.sdk?.views
164
159
  * and has backwards compatibility with project settings design.modal props
@@ -181,8 +176,7 @@ const useLoginView = () => {
181
176
  showPhone: hasPhoneProviderEnabled,
182
177
  showSocial: Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length),
183
178
  // is email only is set in the project settings when the "Email (Web2) only" is toggled on in the dashboard
184
- showWallets: Boolean(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) &&
185
- !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) === null || _f === void 0 ? void 0 : _f.emailOnly),
179
+ showWallets: numberOfWallets > 0 && !((_f = (_e = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _e === void 0 ? void 0 : _e.modal) === null || _f === void 0 ? void 0 : _f.emailOnly),
186
180
  socialAboveEmail,
187
181
  splitEmailAndSocial,
188
182
  web3Layout: authorizationViewDisplayOrder === 'web3',
@@ -212,7 +206,7 @@ const useLoginView = () => {
212
206
  hasPhoneProviderEnabled,
213
207
  loginView === null || loginView === void 0 ? void 0 : loginView.sections,
214
208
  projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal,
215
- selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
209
+ numberOfWallets,
216
210
  t,
217
211
  ]);
218
212
  return {