@dynamic-labs/sdk-react-core 1.0.0-alpha.7 → 1.0.0-alpha.8

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 (93) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +9 -9
  5. package/src/lib/components/NeedHelpSection/NeedHelpSection.cjs +1 -1
  6. package/src/lib/components/NeedHelpSection/NeedHelpSection.js +1 -1
  7. package/src/lib/components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.cjs +68 -0
  8. package/src/lib/components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.d.ts +6 -0
  9. package/src/lib/components/PasskeyCreatedSuccessBanner/PasskeyCreatedSuccessBanner.js +64 -0
  10. package/src/lib/components/PasskeyCreatedSuccessBanner/index.d.ts +1 -0
  11. package/src/lib/components/SecureTurnkeyWalletCard/SecureTurnkeyWalletCard.cjs +24 -0
  12. package/src/lib/components/SecureTurnkeyWalletCard/SecureTurnkeyWalletCard.d.ts +6 -0
  13. package/src/lib/components/SecureTurnkeyWalletCard/SecureTurnkeyWalletCard.js +20 -0
  14. package/src/lib/components/SecureTurnkeyWalletCard/index.d.ts +1 -0
  15. package/src/lib/components/SendBalanceForm/SendBalanceForm.cjs +4 -1
  16. package/src/lib/components/SendBalanceForm/SendBalanceForm.js +4 -1
  17. package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.cjs +5 -2
  18. package/src/lib/components/SyncPasskeyFlow/SyncPasskeyFlow.js +5 -2
  19. package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.cjs +6 -2
  20. package/src/lib/components/TransactionConfirmationPageLayout/TransactionConfirmationPageLayout.js +6 -2
  21. package/src/lib/components/index.d.ts +2 -0
  22. package/src/lib/context/DynamicContext/DynamicContext.cjs +7 -1
  23. package/src/lib/context/DynamicContext/DynamicContext.js +7 -1
  24. package/src/lib/context/DynamicContext/hooks/index.d.ts +1 -0
  25. package/src/lib/context/DynamicContext/hooks/useShowPasskeyCreateSuccess/index.d.ts +1 -0
  26. package/src/lib/context/DynamicContext/hooks/useShowPasskeyCreateSuccess/useShowPasskeyCreateSuccess.cjs +23 -0
  27. package/src/lib/context/DynamicContext/hooks/useShowPasskeyCreateSuccess/useShowPasskeyCreateSuccess.d.ts +4 -0
  28. package/src/lib/context/DynamicContext/hooks/useShowPasskeyCreateSuccess/useShowPasskeyCreateSuccess.js +19 -0
  29. package/src/lib/context/DynamicContext/types/index.d.ts +2 -0
  30. package/src/lib/data/api.cjs +14 -11
  31. package/src/lib/data/api.d.ts +2 -2
  32. package/src/lib/data/api.js +14 -11
  33. package/src/lib/locale/en/translation.cjs +70 -0
  34. package/src/lib/locale/en/translation.d.ts +70 -0
  35. package/src/lib/locale/en/translation.js +70 -0
  36. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.cjs +6 -2
  37. package/src/lib/modals/SignMessageConfirmationModal/SignMessageConfirmationModal.js +6 -2
  38. package/src/lib/styles/index.shadow.cjs +1 -1
  39. package/src/lib/styles/index.shadow.js +1 -1
  40. package/src/lib/utils/hooks/index.d.ts +1 -0
  41. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/index.d.ts +1 -0
  42. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.cjs +83 -0
  43. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.d.ts +15 -0
  44. package/src/lib/utils/hooks/useCreateDynamicEmbeddedWalletMutation/useCreateDynamicEmbeddedWalletMutation.js +79 -0
  45. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.cjs +11 -3
  46. package/src/lib/utils/hooks/useDynamicLayoutData/useDynamicLayoutData.js +11 -3
  47. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.cjs +57 -33
  48. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.d.ts +1 -1
  49. package/src/lib/utils/hooks/useEmbeddedWallet/useEmbeddedWallet.js +57 -33
  50. package/src/lib/utils/hooks/useIsTurnkeyWallet/index.d.ts +1 -0
  51. package/src/lib/utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.cjs +37 -0
  52. package/src/lib/utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.d.ts +6 -0
  53. package/src/lib/utils/hooks/useIsTurnkeyWallet/useIsTurnkeyWallet.js +33 -0
  54. package/src/lib/views/AccountExistsView/AccountExistsView.cjs +1 -1
  55. package/src/lib/views/AccountExistsView/AccountExistsView.js +1 -1
  56. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.cjs +1 -1
  57. package/src/lib/views/EmailWalletOTPVerificationView/EmailWalletOTPVerificationView.js +1 -1
  58. package/src/lib/views/LoginView/sections/SocialSignInSection/MagicSocialSignIn/MagicSocialSignIn.cjs +1 -1
  59. package/src/lib/views/LoginView/sections/SocialSignInSection/MagicSocialSignIn/MagicSocialSignIn.js +1 -1
  60. package/src/lib/views/LoginView/sections/SocialSignInSection/SocialSignInSection.cjs +2 -5
  61. package/src/lib/views/LoginView/sections/SocialSignInSection/SocialSignInSection.js +2 -5
  62. package/src/lib/views/LoginView/useLoginView.cjs +101 -84
  63. package/src/lib/views/LoginView/useLoginView.js +102 -85
  64. package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.cjs +20 -50
  65. package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.d.ts +1 -6
  66. package/src/lib/views/Passkey/PasskeyIntroView/PasskeyIntroView.js +20 -50
  67. package/src/lib/views/Passkey/PasskeyRecovery/BundleValidation/PasskeyBundleRecovery.cjs +7 -2
  68. package/src/lib/views/Passkey/PasskeyRecovery/BundleValidation/PasskeyBundleRecovery.js +7 -2
  69. package/src/lib/views/Passkey/PasskeyRecovery/CompleteRecovery/PasskeyCompleteRecovery.cjs +11 -7
  70. package/src/lib/views/Passkey/PasskeyRecovery/CompleteRecovery/PasskeyCompleteRecovery.js +11 -7
  71. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.cjs +8 -10
  72. package/src/lib/views/Passkey/PasskeyRecovery/InitRecovery/PasskeyInitRecovery.js +8 -10
  73. package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.cjs +56 -0
  74. package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.d.ts +13 -0
  75. package/src/lib/views/Passkey/utils/createPregeneratedWallet/createPregeneratedWallet.js +52 -0
  76. package/src/lib/views/Passkey/utils/createPregeneratedWallet/index.d.ts +1 -0
  77. package/src/lib/views/Passkey/utils/index.d.ts +1 -0
  78. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.cjs +1 -1
  79. package/src/lib/views/TransactionConfirmationView/TransactionConfirmationView.js +1 -1
  80. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.cjs +4 -1
  81. package/src/lib/widgets/DynamicWidget/components/ActiveWalletInformation/ActiveWalletInformation.js +4 -1
  82. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.cjs +2 -1
  83. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetHeader.js +2 -1
  84. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetWalletHeader/DynamicWidgetWalletHeader.cjs +8 -5
  85. package/src/lib/widgets/DynamicWidget/components/DynamicWidgetHeader/DynamicWidgetWalletHeader/DynamicWidgetWalletHeader.js +8 -5
  86. package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.cjs +1 -1
  87. package/src/lib/widgets/DynamicWidget/components/EmailOTPConnectorPendingSignModalContent/EmailOTPConnectorPendingSignModalContent.js +1 -1
  88. package/src/lib/widgets/DynamicWidget/components/EmptyWallets/EmptyWallets.cjs +11 -2
  89. package/src/lib/widgets/DynamicWidget/components/EmptyWallets/EmptyWallets.js +11 -2
  90. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.cjs +2 -1
  91. package/src/lib/widgets/DynamicWidget/views/ManagePasskeysWidgetView/ManagePasskeysWidgetView.js +2 -1
  92. package/src/lib/utils/functions/getEnabledProviders/index.cjs +0 -7
  93. package/src/lib/utils/functions/getEnabledProviders/index.js +0 -3
@@ -28,16 +28,13 @@ const SocialSignInSection = ({ sectionData, collapsedLayout, }) => {
28
28
  numOfItemsToDisplay: sectionData.numOfItemsToDisplay,
29
29
  };
30
30
  const isMagicEnabled = isProviderEnabled(providers, ProviderEnum.MagicLink);
31
- const isDynamicEnabled = isProviderEnabled(providers, ProviderEnum.Dynamic) ||
32
- isProviderEnabled(providers, ProviderEnum.EmailOnly);
33
31
  if (isMagicEnabled &&
34
32
  ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.socialSignIn) === null || _b === void 0 ? void 0 : _b.signInProvider) ===
35
33
  SignInProviderEnum.MagicLink) {
36
34
  return jsx(MagicSocialSignIn, Object.assign({}, componentProps));
37
35
  }
38
- if (isDynamicEnabled &&
39
- ((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.socialSignIn) === null || _c === void 0 ? void 0 : _c.signInProvider) ===
40
- SignInProviderEnum.Dynamic) {
36
+ if (((_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk.socialSignIn) === null || _c === void 0 ? void 0 : _c.signInProvider) ===
37
+ SignInProviderEnum.Dynamic) {
41
38
  return jsx(DynamicSocialSignIn, Object.assign({}, componentProps));
42
39
  }
43
40
  logger.error('Failed to render SocialSignInSection - no sign in provider enabled');
@@ -19,15 +19,20 @@ require('viem');
19
19
  require('@dynamic-labs/utils');
20
20
  require('../../shared/consts/index.cjs');
21
21
  require('@dynamic-labs/multi-wallet');
22
- var index = require('../../utils/functions/getEnabledProviders/index.cjs');
23
22
  var isEmailProviderEnabled = require('../../utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.cjs');
24
23
 
25
24
  /* eslint-disable multiline-comment-style */
26
25
  const NUMBER_OF_WALLETS = 3;
27
26
  const useLoginView = () => {
28
- var _a, _b, _c, _d;
27
+ var _a, _b, _c, _d, _e, _f;
29
28
  const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, wallets, walletsFilter, } = useInternalDynamicContext.useInternalDynamicContext();
29
+ const { t } = reactI18next.useTranslation();
30
30
  const { enabledSocialProviders } = SocialRedirectContext.useSocialRedirectContext();
31
+ const hasSocialProvidersEnabled = Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length);
32
+ const hasEmailProviderEnabled = ((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _a === void 0 ? void 0 : _a.length) &&
33
+ isEmailProviderEnabled.isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
34
+ // is email only is set in the project settings when the "Email (Web2) only" is toggled on in the dashboard
35
+ const isEmailOnly = (_c = (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _b === void 0 ? void 0 : _b.modal) === null || _c === void 0 ? void 0 : _c.emailOnly;
31
36
  /** Takes from wallets only those that can be selected in the wallet list by the user.
32
37
  * Should filter out embedded wallets
33
38
  * WHY: when we decide whether to show wallets or not, we need to know how many wallets
@@ -35,61 +40,91 @@ const useLoginView = () => {
35
40
  * wallets and then display an empty wallet list (since turnkey doesn't render)
36
41
  */
37
42
  const selectableWallets = (walletsFilter ? walletsFilter(wallets) : wallets).filter(({ key }) => key !== 'turnkey');
38
- const { t } = reactI18next.useTranslation();
39
- const hasEnabledProviders = Boolean(index.getEnabledProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers).length);
43
+ const separator = React.useMemo(() => ({
44
+ label: t('dyn_login.separators.default'),
45
+ type: sdkApi.SdkViewSectionType.Separator,
46
+ }), [t]);
40
47
  const isWalletOnly = React.useMemo(() => {
41
- var _a, _b, _c, _d;
48
+ var _a, _b, _c;
42
49
  if (!projectSettings) {
43
50
  return false;
44
51
  }
45
- // toolkit functionality overrides whatever is defined
46
- if (!loginWithEmail) {
52
+ // if both loginWithEmail AND hasSocialProvidersEnabled are false, it's wallet only
53
+ if (!loginWithEmail && !hasSocialProvidersEnabled) {
47
54
  return true;
48
55
  }
49
56
  const loginView = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.views) === null || _b === void 0 ? void 0 : _b.find((view) => view.type === sdkApi.SdkViewType.Login);
50
- // backwards compatibility for those that didn't set up login view sessions
57
+ // backwards compatibility for those that didn't set up login view sections
51
58
  if (!((_c = loginView === null || loginView === void 0 ? void 0 : loginView.sections) === null || _c === void 0 ? void 0 : _c.length)) {
52
- return (!((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _d === void 0 ? void 0 : _d.length) ||
53
- !isEmailProviderEnabled.isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers));
59
+ return !hasEmailProviderEnabled && !hasSocialProvidersEnabled;
54
60
  }
55
61
  return (loginView.sections.length === 1 && loginView.sections[0].type === 'wallet');
56
- }, [projectSettings, loginWithEmail]);
62
+ }, [
63
+ projectSettings,
64
+ loginWithEmail,
65
+ hasSocialProvidersEnabled,
66
+ hasEmailProviderEnabled,
67
+ enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length,
68
+ ]);
57
69
  /**
58
- * build email and social view sections from project settings design.modal props - backwards compatibility
70
+ * build email from project settings design.modal props
59
71
  * @returns SdkViewSection[]
60
72
  */
61
73
  const getEmailViewSectionDefinition = React.useCallback(() => {
62
- var _a, _b;
63
- const loginViewSections = [
74
+ if (!hasEmailProviderEnabled)
75
+ return [];
76
+ return [
64
77
  {
65
78
  type: sdkApi.SdkViewSectionType.Email,
66
79
  },
67
80
  ];
68
- if (enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length) {
69
- const socialSection = {
81
+ }, [hasEmailProviderEnabled]);
82
+ /**
83
+ * build social from project settings design.modal props
84
+ * @returns SdkViewSection[]
85
+ */
86
+ const getSocialViewSectionDefinition = React.useCallback(() => {
87
+ if (!(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length))
88
+ return [];
89
+ return [
90
+ {
70
91
  numOfItemsToDisplay: 5,
71
92
  type: sdkApi.SdkViewSectionType.Social,
72
- };
73
- loginViewSections.push(socialSection);
74
- if ((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _a === void 0 ? void 0 : _a.splitEmailAndSocial) {
75
- loginViewSections.splice(1, 0, {
76
- label: t('dyn_login.separators.default'),
77
- type: sdkApi.SdkViewSectionType.Separator,
78
- });
79
- // eslint-disable-next-line prefer-destructuring
80
- socialSection.defaultItem = enabledSocialProviders[0];
81
- }
82
- }
83
- if ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _b === void 0 ? void 0 : _b.socialAboveEmail) {
84
- loginViewSections.reverse();
85
- }
86
- return loginViewSections;
93
+ },
94
+ ];
95
+ }, [enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length]);
96
+ const getWalletViewSectionDefinition = React.useCallback(() => {
97
+ var _a, _b;
98
+ if (!(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length))
99
+ return [];
100
+ const numOfItemsToDisplay = ((_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _a === void 0 ? void 0 : _a.modal) === null || _b === void 0 ? void 0 : _b.showWalletsButton)
101
+ ? 0
102
+ : NUMBER_OF_WALLETS;
103
+ return [
104
+ {
105
+ numOfItemsToDisplay,
106
+ type: sdkApi.SdkViewSectionType.Wallet,
107
+ },
108
+ ];
87
109
  }, [
88
- enabledSocialProviders,
89
- (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _a === void 0 ? void 0 : _a.socialAboveEmail,
90
- (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _b === void 0 ? void 0 : _b.splitEmailAndSocial,
91
- t,
110
+ (_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _d === void 0 ? void 0 : _d.modal) === null || _e === void 0 ? void 0 : _e.showWalletsButton,
111
+ selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
92
112
  ]);
113
+ const applyLoginModalSettings = React.useCallback((emailAndSocialSections) => {
114
+ if (emailAndSocialSections.length < 2) {
115
+ return emailAndSocialSections;
116
+ }
117
+ const { splitEmailAndSocial, socialAboveEmail } = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) || {};
118
+ if (splitEmailAndSocial) {
119
+ emailAndSocialSections.splice(1, 0, separator);
120
+ // eslint-disable-next-line prefer-destructuring
121
+ emailAndSocialSections[2].defaultItem = enabledSocialProviders[0];
122
+ }
123
+ if (socialAboveEmail) {
124
+ emailAndSocialSections.reverse();
125
+ }
126
+ return emailAndSocialSections;
127
+ }, [enabledSocialProviders, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal, separator]);
93
128
  // TODO: https://linear.app/dynamic-labs/issue/GVTY-212/rethink-or-implement-toolkit-template-for-email-wallet-order
94
129
  /**
95
130
  * remove wallet view section from projectSettings?.sdk?.views if no wallet defined
@@ -109,78 +144,60 @@ const useLoginView = () => {
109
144
  }
110
145
  return sections.filter((section) => section.type !== 'wallet');
111
146
  }, [selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
112
- const addSeparator = React.useCallback((index) => {
113
- // if not the first index, no separator is needed
114
- // if the first index but does not have wallets or providers,
115
- // it'll show only one view section - no separator is needed
116
- if (index !== 0 || !(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) || !hasEnabledProviders) {
117
- return [];
118
- }
119
- return [
120
- {
121
- label: t('dyn_login.separators.default'),
122
- type: sdkApi.SdkViewSectionType.Separator,
123
- },
124
- ];
125
- }, [hasEnabledProviders, selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, t]);
126
147
  /**
127
148
  * build login view sections array from project settings design.modal props - backwards compatibility
128
149
  * @returns SdkViewSection[]
129
150
  */
130
- const buildLoginSections = React.useCallback(() => {
131
- let loginViewSections = [];
132
- authorizationViewDisplayOrder === null || authorizationViewDisplayOrder === void 0 ? void 0 : authorizationViewDisplayOrder.forEach((loginItem, index) => {
133
- var _a, _b;
134
- if (loginItem === 'email' &&
135
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) &&
136
- isEmailProviderEnabled.isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers)) {
137
- loginViewSections = loginViewSections.concat(getEmailViewSectionDefinition(),
138
- // add separator if wallets defined
139
- addSeparator(index));
151
+ const buildLoginSections = React.useCallback((buildOrder) => {
152
+ const loginViewSections = [];
153
+ buildOrder === null || buildOrder === void 0 ? void 0 : buildOrder.forEach((loginItem) => {
154
+ // Add a separator if there are sections already
155
+ if (loginViewSections.length)
156
+ loginViewSections.push(separator);
157
+ if (loginItem === 'email') {
158
+ // In the past, the email and social sections were combined into one section,
159
+ // so we need to check for that case and add the social section if needed for backwards compatibility
160
+ // if email was just pushed to the loginViewSections array and social is not defined in the buildOrder,
161
+ // then we need to add social (if social is enabled)
162
+ const emailAndSocialSections = [
163
+ ...getEmailViewSectionDefinition(),
164
+ ...getSocialViewSectionDefinition(),
165
+ ];
166
+ loginViewSections.push(...applyLoginModalSettings(emailAndSocialSections));
140
167
  }
141
- if (loginItem === 'wallet' && (selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length)) {
142
- // if showWalletsButton is true, it should show "Connec with Wallet" button
143
- const numOfItemsToDisplay = ((_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _a === void 0 ? void 0 : _a.modal) === null || _b === void 0 ? void 0 : _b.showWalletsButton)
144
- ? 0
145
- : NUMBER_OF_WALLETS;
146
- loginViewSections = loginViewSections.concat([
147
- {
148
- numOfItemsToDisplay,
149
- type: sdkApi.SdkViewSectionType.Wallet,
150
- },
151
- ],
152
- // add separator if email providers defined
153
- addSeparator(index));
168
+ if (loginItem === 'wallet') {
169
+ loginViewSections.push(...getWalletViewSectionDefinition());
154
170
  }
155
171
  });
156
172
  return loginViewSections;
157
173
  }, [
158
- addSeparator,
159
- authorizationViewDisplayOrder,
174
+ applyLoginModalSettings,
160
175
  getEmailViewSectionDefinition,
161
- (_d = (_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _c === void 0 ? void 0 : _c.modal) === null || _d === void 0 ? void 0 : _d.showWalletsButton,
162
- projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers,
163
- selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
176
+ getSocialViewSectionDefinition,
177
+ getWalletViewSectionDefinition,
178
+ separator,
164
179
  ]);
165
180
  /**
166
181
  * returns the login view sections to be displayed in order from projectSettings?.sdk?.views
167
182
  * and has backwards compatibility with project settings design.modal props
168
183
  */
169
184
  const logingViewSections = React.useMemo(() => {
170
- var _a, _b, _c, _d, _e;
185
+ var _a, _b, _c;
171
186
  const loginView = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.views) === null || _b === void 0 ? void 0 : _b.find((view) => view.type === sdkApi.SdkViewType.Login);
172
187
  if ((_c = loginView === null || loginView === void 0 ? void 0 : loginView.sections) === null || _c === void 0 ? void 0 : _c.length) {
173
188
  return filterLoginViewSections(loginView === null || loginView === void 0 ? void 0 : loginView.sections);
174
189
  }
175
- if ((_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _d === void 0 ? void 0 : _d.modal) === null || _e === void 0 ? void 0 : _e.emailOnly) {
176
- return getEmailViewSectionDefinition();
190
+ let viewOrder = authorizationViewDisplayOrder;
191
+ if (isEmailOnly) {
192
+ viewOrder = ['email'];
177
193
  }
178
- return buildLoginSections();
194
+ return buildLoginSections(viewOrder);
179
195
  }, [
180
- projectSettings,
181
- getEmailViewSectionDefinition,
182
- filterLoginViewSections,
196
+ (_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _f === void 0 ? void 0 : _f.views,
197
+ authorizationViewDisplayOrder,
198
+ isEmailOnly,
183
199
  buildLoginSections,
200
+ filterLoginViewSections,
184
201
  ]);
185
202
  return {
186
203
  isWalletOnly,
@@ -1,6 +1,6 @@
1
1
  import { useMemo, useCallback } from 'react';
2
2
  import { useTranslation } from 'react-i18next';
3
- import { SdkViewType, SdkViewSectionType } from '@dynamic-labs/sdk-api';
3
+ import { SdkViewSectionType, SdkViewType } from '@dynamic-labs/sdk-api';
4
4
  import { useInternalDynamicContext } from '../../context/DynamicContext/useInternalDynamicContext.js';
5
5
  import { useSocialRedirectContext } from '../../context/SocialRedirectContext/SocialRedirectContext.js';
6
6
  import { logger } from '../../shared/logger.js';
@@ -15,15 +15,20 @@ import 'viem';
15
15
  import '@dynamic-labs/utils';
16
16
  import '../../shared/consts/index.js';
17
17
  import '@dynamic-labs/multi-wallet';
18
- import { getEnabledProviders } from '../../utils/functions/getEnabledProviders/index.js';
19
18
  import { isEmailProviderEnabled } from '../../utils/functions/isEmailProviderEnabled/isEmailProviderEnabled.js';
20
19
 
21
20
  /* eslint-disable multiline-comment-style */
22
21
  const NUMBER_OF_WALLETS = 3;
23
22
  const useLoginView = () => {
24
- var _a, _b, _c, _d;
23
+ var _a, _b, _c, _d, _e, _f;
25
24
  const { projectSettings, authorizationViewDisplayOrder, loginWithEmail, wallets, walletsFilter, } = useInternalDynamicContext();
25
+ const { t } = useTranslation();
26
26
  const { enabledSocialProviders } = useSocialRedirectContext();
27
+ const hasSocialProvidersEnabled = Boolean(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length);
28
+ const hasEmailProviderEnabled = ((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _a === void 0 ? void 0 : _a.length) &&
29
+ isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers);
30
+ // is email only is set in the project settings when the "Email (Web2) only" is toggled on in the dashboard
31
+ const isEmailOnly = (_c = (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _b === void 0 ? void 0 : _b.modal) === null || _c === void 0 ? void 0 : _c.emailOnly;
27
32
  /** Takes from wallets only those that can be selected in the wallet list by the user.
28
33
  * Should filter out embedded wallets
29
34
  * WHY: when we decide whether to show wallets or not, we need to know how many wallets
@@ -31,61 +36,91 @@ const useLoginView = () => {
31
36
  * wallets and then display an empty wallet list (since turnkey doesn't render)
32
37
  */
33
38
  const selectableWallets = (walletsFilter ? walletsFilter(wallets) : wallets).filter(({ key }) => key !== 'turnkey');
34
- const { t } = useTranslation();
35
- const hasEnabledProviders = Boolean(getEnabledProviders(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers).length);
39
+ const separator = useMemo(() => ({
40
+ label: t('dyn_login.separators.default'),
41
+ type: SdkViewSectionType.Separator,
42
+ }), [t]);
36
43
  const isWalletOnly = useMemo(() => {
37
- var _a, _b, _c, _d;
44
+ var _a, _b, _c;
38
45
  if (!projectSettings) {
39
46
  return false;
40
47
  }
41
- // toolkit functionality overrides whatever is defined
42
- if (!loginWithEmail) {
48
+ // if both loginWithEmail AND hasSocialProvidersEnabled are false, it's wallet only
49
+ if (!loginWithEmail && !hasSocialProvidersEnabled) {
43
50
  return true;
44
51
  }
45
52
  const loginView = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.views) === null || _b === void 0 ? void 0 : _b.find((view) => view.type === SdkViewType.Login);
46
- // backwards compatibility for those that didn't set up login view sessions
53
+ // backwards compatibility for those that didn't set up login view sections
47
54
  if (!((_c = loginView === null || loginView === void 0 ? void 0 : loginView.sections) === null || _c === void 0 ? void 0 : _c.length)) {
48
- return (!((_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) === null || _d === void 0 ? void 0 : _d.length) ||
49
- !isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers));
55
+ return !hasEmailProviderEnabled && !hasSocialProvidersEnabled;
50
56
  }
51
57
  return (loginView.sections.length === 1 && loginView.sections[0].type === 'wallet');
52
- }, [projectSettings, loginWithEmail]);
58
+ }, [
59
+ projectSettings,
60
+ loginWithEmail,
61
+ hasSocialProvidersEnabled,
62
+ hasEmailProviderEnabled,
63
+ enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length,
64
+ ]);
53
65
  /**
54
- * build email and social view sections from project settings design.modal props - backwards compatibility
66
+ * build email from project settings design.modal props
55
67
  * @returns SdkViewSection[]
56
68
  */
57
69
  const getEmailViewSectionDefinition = useCallback(() => {
58
- var _a, _b;
59
- const loginViewSections = [
70
+ if (!hasEmailProviderEnabled)
71
+ return [];
72
+ return [
60
73
  {
61
74
  type: SdkViewSectionType.Email,
62
75
  },
63
76
  ];
64
- if (enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length) {
65
- const socialSection = {
77
+ }, [hasEmailProviderEnabled]);
78
+ /**
79
+ * build social from project settings design.modal props
80
+ * @returns SdkViewSection[]
81
+ */
82
+ const getSocialViewSectionDefinition = useCallback(() => {
83
+ if (!(enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length))
84
+ return [];
85
+ return [
86
+ {
66
87
  numOfItemsToDisplay: 5,
67
88
  type: SdkViewSectionType.Social,
68
- };
69
- loginViewSections.push(socialSection);
70
- if ((_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _a === void 0 ? void 0 : _a.splitEmailAndSocial) {
71
- loginViewSections.splice(1, 0, {
72
- label: t('dyn_login.separators.default'),
73
- type: SdkViewSectionType.Separator,
74
- });
75
- // eslint-disable-next-line prefer-destructuring
76
- socialSection.defaultItem = enabledSocialProviders[0];
77
- }
78
- }
79
- if ((_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _b === void 0 ? void 0 : _b.socialAboveEmail) {
80
- loginViewSections.reverse();
81
- }
82
- return loginViewSections;
89
+ },
90
+ ];
91
+ }, [enabledSocialProviders === null || enabledSocialProviders === void 0 ? void 0 : enabledSocialProviders.length]);
92
+ const getWalletViewSectionDefinition = useCallback(() => {
93
+ var _a, _b;
94
+ if (!(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length))
95
+ return [];
96
+ const numOfItemsToDisplay = ((_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _a === void 0 ? void 0 : _a.modal) === null || _b === void 0 ? void 0 : _b.showWalletsButton)
97
+ ? 0
98
+ : NUMBER_OF_WALLETS;
99
+ return [
100
+ {
101
+ numOfItemsToDisplay,
102
+ type: SdkViewSectionType.Wallet,
103
+ },
104
+ ];
83
105
  }, [
84
- enabledSocialProviders,
85
- (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _a === void 0 ? void 0 : _a.socialAboveEmail,
86
- (_b = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) === null || _b === void 0 ? void 0 : _b.splitEmailAndSocial,
87
- t,
106
+ (_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _d === void 0 ? void 0 : _d.modal) === null || _e === void 0 ? void 0 : _e.showWalletsButton,
107
+ selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
88
108
  ]);
109
+ const applyLoginModalSettings = useCallback((emailAndSocialSections) => {
110
+ if (emailAndSocialSections.length < 2) {
111
+ return emailAndSocialSections;
112
+ }
113
+ const { splitEmailAndSocial, socialAboveEmail } = (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal) || {};
114
+ if (splitEmailAndSocial) {
115
+ emailAndSocialSections.splice(1, 0, separator);
116
+ // eslint-disable-next-line prefer-destructuring
117
+ emailAndSocialSections[2].defaultItem = enabledSocialProviders[0];
118
+ }
119
+ if (socialAboveEmail) {
120
+ emailAndSocialSections.reverse();
121
+ }
122
+ return emailAndSocialSections;
123
+ }, [enabledSocialProviders, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design.modal, separator]);
89
124
  // TODO: https://linear.app/dynamic-labs/issue/GVTY-212/rethink-or-implement-toolkit-template-for-email-wallet-order
90
125
  /**
91
126
  * remove wallet view section from projectSettings?.sdk?.views if no wallet defined
@@ -105,78 +140,60 @@ const useLoginView = () => {
105
140
  }
106
141
  return sections.filter((section) => section.type !== 'wallet');
107
142
  }, [selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.chains]);
108
- const addSeparator = useCallback((index) => {
109
- // if not the first index, no separator is needed
110
- // if the first index but does not have wallets or providers,
111
- // it'll show only one view section - no separator is needed
112
- if (index !== 0 || !(selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length) || !hasEnabledProviders) {
113
- return [];
114
- }
115
- return [
116
- {
117
- label: t('dyn_login.separators.default'),
118
- type: SdkViewSectionType.Separator,
119
- },
120
- ];
121
- }, [hasEnabledProviders, selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length, t]);
122
143
  /**
123
144
  * build login view sections array from project settings design.modal props - backwards compatibility
124
145
  * @returns SdkViewSection[]
125
146
  */
126
- const buildLoginSections = useCallback(() => {
127
- let loginViewSections = [];
128
- authorizationViewDisplayOrder === null || authorizationViewDisplayOrder === void 0 ? void 0 : authorizationViewDisplayOrder.forEach((loginItem, index) => {
129
- var _a, _b;
130
- if (loginItem === 'email' &&
131
- (projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers) &&
132
- isEmailProviderEnabled(projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers)) {
133
- loginViewSections = loginViewSections.concat(getEmailViewSectionDefinition(),
134
- // add separator if wallets defined
135
- addSeparator(index));
147
+ const buildLoginSections = useCallback((buildOrder) => {
148
+ const loginViewSections = [];
149
+ buildOrder === null || buildOrder === void 0 ? void 0 : buildOrder.forEach((loginItem) => {
150
+ // Add a separator if there are sections already
151
+ if (loginViewSections.length)
152
+ loginViewSections.push(separator);
153
+ if (loginItem === 'email') {
154
+ // In the past, the email and social sections were combined into one section,
155
+ // so we need to check for that case and add the social section if needed for backwards compatibility
156
+ // if email was just pushed to the loginViewSections array and social is not defined in the buildOrder,
157
+ // then we need to add social (if social is enabled)
158
+ const emailAndSocialSections = [
159
+ ...getEmailViewSectionDefinition(),
160
+ ...getSocialViewSectionDefinition(),
161
+ ];
162
+ loginViewSections.push(...applyLoginModalSettings(emailAndSocialSections));
136
163
  }
137
- if (loginItem === 'wallet' && (selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length)) {
138
- // if showWalletsButton is true, it should show "Connec with Wallet" button
139
- const numOfItemsToDisplay = ((_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _a === void 0 ? void 0 : _a.modal) === null || _b === void 0 ? void 0 : _b.showWalletsButton)
140
- ? 0
141
- : NUMBER_OF_WALLETS;
142
- loginViewSections = loginViewSections.concat([
143
- {
144
- numOfItemsToDisplay,
145
- type: SdkViewSectionType.Wallet,
146
- },
147
- ],
148
- // add separator if email providers defined
149
- addSeparator(index));
164
+ if (loginItem === 'wallet') {
165
+ loginViewSections.push(...getWalletViewSectionDefinition());
150
166
  }
151
167
  });
152
168
  return loginViewSections;
153
169
  }, [
154
- addSeparator,
155
- authorizationViewDisplayOrder,
170
+ applyLoginModalSettings,
156
171
  getEmailViewSectionDefinition,
157
- (_d = (_c = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _c === void 0 ? void 0 : _c.modal) === null || _d === void 0 ? void 0 : _d.showWalletsButton,
158
- projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.providers,
159
- selectableWallets === null || selectableWallets === void 0 ? void 0 : selectableWallets.length,
172
+ getSocialViewSectionDefinition,
173
+ getWalletViewSectionDefinition,
174
+ separator,
160
175
  ]);
161
176
  /**
162
177
  * returns the login view sections to be displayed in order from projectSettings?.sdk?.views
163
178
  * and has backwards compatibility with project settings design.modal props
164
179
  */
165
180
  const logingViewSections = useMemo(() => {
166
- var _a, _b, _c, _d, _e;
181
+ var _a, _b, _c;
167
182
  const loginView = (_b = (_a = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _a === void 0 ? void 0 : _a.views) === null || _b === void 0 ? void 0 : _b.find((view) => view.type === SdkViewType.Login);
168
183
  if ((_c = loginView === null || loginView === void 0 ? void 0 : loginView.sections) === null || _c === void 0 ? void 0 : _c.length) {
169
184
  return filterLoginViewSections(loginView === null || loginView === void 0 ? void 0 : loginView.sections);
170
185
  }
171
- if ((_e = (_d = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.design) === null || _d === void 0 ? void 0 : _d.modal) === null || _e === void 0 ? void 0 : _e.emailOnly) {
172
- return getEmailViewSectionDefinition();
186
+ let viewOrder = authorizationViewDisplayOrder;
187
+ if (isEmailOnly) {
188
+ viewOrder = ['email'];
173
189
  }
174
- return buildLoginSections();
190
+ return buildLoginSections(viewOrder);
175
191
  }, [
176
- projectSettings,
177
- getEmailViewSectionDefinition,
178
- filterLoginViewSections,
192
+ (_f = projectSettings === null || projectSettings === void 0 ? void 0 : projectSettings.sdk) === null || _f === void 0 ? void 0 : _f.views,
193
+ authorizationViewDisplayOrder,
194
+ isEmailOnly,
179
195
  buildLoginSections,
196
+ filterLoginViewSections,
180
197
  ]);
181
198
  return {
182
199
  isWalletOnly,