@web3auth/modal 9.6.0 → 10.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/dist/lib.cjs/node_modules/style-inject/dist/style-inject.es.js +28 -0
  2. package/dist/lib.cjs/{config.js → packages/modal/src/config.js} +14 -14
  3. package/dist/lib.cjs/{index.js → packages/modal/src/index.js} +7 -0
  4. package/dist/lib.cjs/{modalManager.js → packages/modal/src/modalManager.js} +92 -92
  5. package/dist/lib.cjs/packages/modal/src/react/Web3AuthProvider.js +15 -0
  6. package/dist/lib.cjs/packages/modal/src/react/context/Web3AuthInnerContext.js +225 -0
  7. package/dist/lib.cjs/packages/modal/src/react/hooks/useWeb3Auth.js +15 -0
  8. package/dist/lib.cjs/packages/modal/src/react/index.js +12 -0
  9. package/dist/lib.cjs/packages/modal/src/ui/assets/arrow-left-dark.svg.js +7 -0
  10. package/dist/lib.cjs/packages/modal/src/ui/assets/arrow-left-light.svg.js +7 -0
  11. package/dist/lib.cjs/packages/modal/src/ui/assets/x-dark.svg.js +7 -0
  12. package/dist/lib.cjs/packages/modal/src/ui/assets/x-light.svg.js +7 -0
  13. package/dist/lib.cjs/packages/modal/src/ui/components/AdapterLoader.js +108 -0
  14. package/dist/lib.cjs/packages/modal/src/ui/components/Button/Button.js +34 -0
  15. package/dist/lib.cjs/packages/modal/src/ui/components/Button/styles.css.js +8 -0
  16. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletButton.js +44 -0
  17. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletConnect.js +67 -0
  18. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +34 -0
  19. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletHeader.js +46 -0
  20. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallet/ExternalWalletInstall.js +167 -0
  21. package/dist/lib.cjs/packages/modal/src/ui/components/ExternalWallets.js +273 -0
  22. package/dist/lib.cjs/packages/modal/src/ui/components/Footer.js +20 -0
  23. package/dist/lib.cjs/packages/modal/src/ui/components/Header.js +81 -0
  24. package/dist/lib.cjs/packages/modal/src/ui/components/Icon.js +73 -0
  25. package/dist/lib.cjs/packages/modal/src/ui/components/Image.js +51 -0
  26. package/dist/lib.cjs/packages/modal/src/ui/components/Loader.js +59 -0
  27. package/dist/lib.cjs/packages/modal/src/ui/components/Modal.js +244 -0
  28. package/dist/lib.cjs/packages/modal/src/ui/components/SelfCustodyViaWeb3Auth.js +30 -0
  29. package/dist/lib.cjs/packages/modal/src/ui/components/SocialLoginPasswordless.js +141 -0
  30. package/dist/lib.cjs/packages/modal/src/ui/components/SocialLogins.js +148 -0
  31. package/dist/lib.cjs/packages/modal/src/ui/components/WalletConnect.js +84 -0
  32. package/dist/lib.cjs/packages/modal/src/ui/config.js +17 -0
  33. package/dist/lib.cjs/packages/modal/src/ui/context/ThemeContext.js +9 -0
  34. package/dist/lib.cjs/packages/modal/src/ui/css/web3auth.css.js +8 -0
  35. package/dist/lib.cjs/packages/modal/src/ui/i18n/dutch.json.js +84 -0
  36. package/dist/lib.cjs/packages/modal/src/ui/i18n/english.json.js +84 -0
  37. package/dist/lib.cjs/packages/modal/src/ui/i18n/french.json.js +82 -0
  38. package/dist/lib.cjs/packages/modal/src/ui/i18n/german.json.js +84 -0
  39. package/dist/lib.cjs/packages/modal/src/ui/i18n/japanese.json.js +84 -0
  40. package/dist/lib.cjs/packages/modal/src/ui/i18n/korean.json.js +84 -0
  41. package/dist/lib.cjs/packages/modal/src/ui/i18n/mandarin.json.js +84 -0
  42. package/dist/lib.cjs/packages/modal/src/ui/i18n/portuguese.json.js +84 -0
  43. package/dist/lib.cjs/packages/modal/src/ui/i18n/spanish.json.js +84 -0
  44. package/dist/lib.cjs/packages/modal/src/ui/i18n/turkish.json.js +84 -0
  45. package/dist/lib.cjs/packages/modal/src/ui/interfaces.js +26 -0
  46. package/dist/lib.cjs/packages/modal/src/ui/localeImport.js +25 -0
  47. package/dist/lib.cjs/packages/modal/src/ui/loginModal.js +309 -0
  48. package/dist/lib.cjs/packages/modal/src/ui/utils.js +71 -0
  49. package/dist/lib.cjs/packages/modal/src/vue/Web3AuthProvider.js +234 -0
  50. package/dist/lib.cjs/packages/modal/src/vue/composables/useWeb3Auth.js +12 -0
  51. package/dist/lib.cjs/packages/modal/src/vue/index.js +9 -0
  52. package/dist/lib.esm/node_modules/style-inject/dist/style-inject.es.js +26 -0
  53. package/dist/lib.esm/{config.js → packages/modal/src/config.js} +1 -1
  54. package/dist/lib.esm/{index.js → packages/modal/src/index.js} +1 -0
  55. package/dist/lib.esm/{modalManager.js → packages/modal/src/modalManager.js} +5 -5
  56. package/dist/lib.esm/packages/modal/src/react/Web3AuthProvider.js +13 -0
  57. package/dist/lib.esm/packages/modal/src/react/context/Web3AuthInnerContext.js +222 -0
  58. package/dist/lib.esm/packages/modal/src/react/hooks/useWeb3Auth.js +13 -0
  59. package/dist/lib.esm/packages/modal/src/react/index.js +3 -0
  60. package/dist/lib.esm/packages/modal/src/ui/assets/arrow-left-dark.svg.js +5 -0
  61. package/dist/lib.esm/packages/modal/src/ui/assets/arrow-left-light.svg.js +5 -0
  62. package/dist/lib.esm/packages/modal/src/ui/assets/x-dark.svg.js +5 -0
  63. package/dist/lib.esm/packages/modal/src/ui/assets/x-light.svg.js +5 -0
  64. package/dist/lib.esm/packages/modal/src/ui/components/AdapterLoader.js +106 -0
  65. package/dist/lib.esm/packages/modal/src/ui/components/Button/Button.js +32 -0
  66. package/dist/lib.esm/packages/modal/src/ui/components/Button/styles.css.js +6 -0
  67. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletButton.js +42 -0
  68. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletConnect.js +65 -0
  69. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletDetails.js +32 -0
  70. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletHeader.js +44 -0
  71. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallet/ExternalWalletInstall.js +165 -0
  72. package/dist/lib.esm/packages/modal/src/ui/components/ExternalWallets.js +271 -0
  73. package/dist/lib.esm/packages/modal/src/ui/components/Footer.js +18 -0
  74. package/dist/lib.esm/packages/modal/src/ui/components/Header.js +79 -0
  75. package/dist/lib.esm/packages/modal/src/ui/components/Icon.js +71 -0
  76. package/dist/lib.esm/packages/modal/src/ui/components/Image.js +49 -0
  77. package/dist/lib.esm/packages/modal/src/ui/components/Loader.js +57 -0
  78. package/dist/lib.esm/packages/modal/src/ui/components/Modal.js +242 -0
  79. package/dist/lib.esm/packages/modal/src/ui/components/SelfCustodyViaWeb3Auth.js +28 -0
  80. package/dist/lib.esm/packages/modal/src/ui/components/SocialLoginPasswordless.js +139 -0
  81. package/dist/lib.esm/packages/modal/src/ui/components/SocialLogins.js +146 -0
  82. package/dist/lib.esm/packages/modal/src/ui/components/WalletConnect.js +82 -0
  83. package/dist/lib.esm/packages/modal/src/ui/config.js +13 -0
  84. package/dist/lib.esm/packages/modal/src/ui/context/ThemeContext.js +7 -0
  85. package/dist/lib.esm/packages/modal/src/ui/css/web3auth.css.js +6 -0
  86. package/dist/lib.esm/packages/modal/src/ui/i18n/dutch.json.js +79 -0
  87. package/dist/lib.esm/packages/modal/src/ui/i18n/english.json.js +79 -0
  88. package/dist/lib.esm/packages/modal/src/ui/i18n/french.json.js +77 -0
  89. package/dist/lib.esm/packages/modal/src/ui/i18n/german.json.js +79 -0
  90. package/dist/lib.esm/packages/modal/src/ui/i18n/japanese.json.js +79 -0
  91. package/dist/lib.esm/packages/modal/src/ui/i18n/korean.json.js +79 -0
  92. package/dist/lib.esm/packages/modal/src/ui/i18n/mandarin.json.js +79 -0
  93. package/dist/lib.esm/packages/modal/src/ui/i18n/portuguese.json.js +79 -0
  94. package/dist/lib.esm/packages/modal/src/ui/i18n/spanish.json.js +79 -0
  95. package/dist/lib.esm/packages/modal/src/ui/i18n/turkish.json.js +79 -0
  96. package/dist/lib.esm/packages/modal/src/ui/interfaces.js +20 -0
  97. package/dist/lib.esm/packages/modal/src/ui/localeImport.js +23 -0
  98. package/dist/lib.esm/packages/modal/src/ui/loginModal.js +307 -0
  99. package/dist/lib.esm/packages/modal/src/ui/utils.js +65 -0
  100. package/dist/lib.esm/packages/modal/src/vue/Web3AuthProvider.js +232 -0
  101. package/dist/lib.esm/packages/modal/src/vue/composables/useWeb3Auth.js +10 -0
  102. package/dist/lib.esm/packages/modal/src/vue/index.js +2 -0
  103. package/dist/modal.cjs.js +5703 -420
  104. package/dist/modal.umd.min.js +1 -1
  105. package/dist/modal.umd.min.js.LICENSE.txt +54 -0
  106. package/dist/types/index.d.ts +1 -0
  107. package/dist/types/interface.d.ts +1 -1
  108. package/dist/types/modalManager.d.ts +2 -3
  109. package/dist/types/react/Web3AuthProvider.d.ts +3 -0
  110. package/dist/types/react/context/Web3AuthInnerContext.d.ts +4 -0
  111. package/dist/types/react/context/index.d.ts +1 -0
  112. package/dist/types/react/hooks/index.d.ts +1 -0
  113. package/dist/types/react/hooks/useWeb3Auth.d.ts +2 -0
  114. package/dist/types/react/index.d.ts +4 -0
  115. package/dist/types/react/interfaces.d.ts +18 -0
  116. package/dist/types/ui/components/AdapterLoader.d.ts +11 -0
  117. package/dist/types/ui/components/Button/Button.d.ts +16 -0
  118. package/dist/types/ui/components/Button/index.d.ts +1 -0
  119. package/dist/types/ui/components/ExternalWallet/ExternalWalletButton.d.ts +7 -0
  120. package/dist/types/ui/components/ExternalWallet/ExternalWalletConnect.d.ts +9 -0
  121. package/dist/types/ui/components/ExternalWallet/ExternalWalletDetails.d.ts +9 -0
  122. package/dist/types/ui/components/ExternalWallet/ExternalWalletHeader.d.ts +8 -0
  123. package/dist/types/ui/components/ExternalWallet/ExternalWalletInstall.d.ts +8 -0
  124. package/dist/types/ui/components/ExternalWallets.d.ts +17 -0
  125. package/dist/types/ui/components/Footer.d.ts +1 -0
  126. package/dist/types/ui/components/Header.d.ts +8 -0
  127. package/dist/types/ui/components/Icon.d.ts +9 -0
  128. package/dist/types/ui/components/Image.d.ts +12 -0
  129. package/dist/types/ui/components/Loader.d.ts +10 -0
  130. package/dist/types/ui/components/Modal.d.ts +16 -0
  131. package/dist/types/ui/components/SelfCustodyViaWeb3Auth.d.ts +1 -0
  132. package/dist/types/ui/components/SocialLoginPasswordless.d.ts +16 -0
  133. package/dist/types/ui/components/SocialLogins.d.ts +14 -0
  134. package/dist/types/ui/components/WalletConnect.d.ts +8 -0
  135. package/dist/types/ui/config.d.ts +4 -0
  136. package/dist/types/ui/context/ThemeContext.d.ts +3 -0
  137. package/dist/types/ui/helper/countryData.d.ts +7 -0
  138. package/dist/types/ui/i18n/index.d.ts +11 -0
  139. package/dist/types/ui/index.d.ts +4 -0
  140. package/dist/types/ui/interfaces.d.ts +106 -0
  141. package/dist/types/ui/localeImport.d.ts +3 -0
  142. package/dist/types/ui/loginModal.d.ts +27 -0
  143. package/dist/types/ui/utils.d.ts +12 -0
  144. package/dist/types/vue/Web3AuthProvider.d.ts +13 -0
  145. package/dist/types/vue/composables/index.d.ts +1 -0
  146. package/dist/types/vue/composables/useWeb3Auth.d.ts +2 -0
  147. package/dist/types/vue/index.d.ts +3 -0
  148. package/dist/types/vue/interfaces.d.ts +45 -0
  149. package/package.json +100 -43
  150. package/dist/modal.esm.js +0 -513
@@ -0,0 +1,57 @@
1
+ import { log, ADAPTER_STATUS } from '@web3auth/no-modal';
2
+ import { useEffect } from 'react';
3
+ import { MODAL_STATUS } from '../interfaces.js';
4
+ import Icon from './Icon.js';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+
7
+ const closeIcon = /*#__PURE__*/jsx(Icon, {
8
+ iconName: "close"
9
+ });
10
+ function Loader(props) {
11
+ const {
12
+ message,
13
+ modalStatus,
14
+ label,
15
+ onClose,
16
+ canEmit = true
17
+ } = props;
18
+ useEffect(() => {
19
+ log.debug("loader re-rendering");
20
+ if (modalStatus === MODAL_STATUS.CONNECTED && canEmit) {
21
+ setTimeout(() => {
22
+ onClose();
23
+ }, 3000);
24
+ }
25
+ }, [canEmit, modalStatus, onClose]);
26
+ return modalStatus !== MODAL_STATUS.INITIALIZED ? /*#__PURE__*/jsxs("div", {
27
+ className: "w3ajs-modal-loader w3a-modal__loader",
28
+ children: [/*#__PURE__*/jsx("div", {
29
+ className: "w3a-modal__loader-content",
30
+ children: /*#__PURE__*/jsxs("div", {
31
+ className: "w3a-modal__loader-info",
32
+ children: [modalStatus === MODAL_STATUS.CONNECTING && /*#__PURE__*/jsx("div", {
33
+ className: "w3ajs-modal-loader__spinner w3a-spinner",
34
+ children: /*#__PURE__*/jsx("div", {
35
+ className: "w3a-spinner__spinner"
36
+ })
37
+ }), /*#__PURE__*/jsx("div", {
38
+ className: "w3ajs-modal-loader__label w3a-spinner-label",
39
+ children: label
40
+ }), modalStatus === ADAPTER_STATUS.CONNECTED && /*#__PURE__*/jsx("div", {
41
+ className: "w3ajs-modal-loader__message w3a-spinner-message",
42
+ children: message
43
+ }), modalStatus === ADAPTER_STATUS.ERRORED && /*#__PURE__*/jsx("div", {
44
+ className: "w3ajs-modal-loader__message w3a-spinner-message w3a-spinner-message--error",
45
+ children: message
46
+ })]
47
+ })
48
+ }), (modalStatus === ADAPTER_STATUS.CONNECTED || modalStatus === ADAPTER_STATUS.ERRORED) && /*#__PURE__*/jsx("button", {
49
+ type: "button",
50
+ className: "w3a-header__button w3ajs-loader-close-btn",
51
+ onClick: onClose,
52
+ children: closeIcon
53
+ })]
54
+ }) : null;
55
+ }
56
+
57
+ export { Loader as default };
@@ -0,0 +1,242 @@
1
+ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
+ import { LOGIN_PROVIDER } from '@web3auth/auth';
3
+ import { log, cloneDeep, ADAPTER_NAMES } from '@web3auth/no-modal';
4
+ import deepmerge from 'deepmerge';
5
+ import { useState, useEffect, useCallback, useMemo } from 'react';
6
+ import { useTranslation } from 'react-i18next';
7
+ import { MODAL_STATUS } from '../interfaces.js';
8
+ import i18nInstance from '../localeImport.js';
9
+ import DetailedLoader from './AdapterLoader.js';
10
+ import Button from './Button/Button.js';
11
+ import ExternalWallet from './ExternalWallets.js';
12
+ import Footer from './Footer.js';
13
+ import memoizedHeader from './Header.js';
14
+ import SocialLoginPasswordless from './SocialLoginPasswordless.js';
15
+ import SocialLogins from './SocialLogins.js';
16
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
17
+
18
+ log.enableAll();
19
+ function Modal(props) {
20
+ var _modalState$socialLog, _modalState$socialLog2, _modalState$socialLog5, _modalState$socialLog7, _modalState$socialLog9, _modalState$socialLog10;
21
+ const [modalTransitionClasses, setModalTransitionClasses] = useState(["w3a-modal__inner"]);
22
+ const [modalState, setModalState] = useState({
23
+ externalWalletsVisibility: false,
24
+ status: MODAL_STATUS.INITIALIZED,
25
+ hasExternalWallets: false,
26
+ externalWalletsInitialized: false,
27
+ modalVisibility: false,
28
+ modalVisibilityDelayed: false,
29
+ postLoadingMessage: "",
30
+ walletConnectUri: "",
31
+ socialLoginsConfig: {
32
+ loginMethods: {},
33
+ loginMethodsOrder: [],
34
+ adapter: "",
35
+ uiConfig: {}
36
+ },
37
+ externalWalletsConfig: {},
38
+ detailedLoaderAdapter: "",
39
+ detailedLoaderAdapterName: "",
40
+ showExternalWalletsOnly: false
41
+ });
42
+ const [t] = useTranslation(undefined, {
43
+ i18n: i18nInstance
44
+ });
45
+ const {
46
+ stateListener,
47
+ appLogo,
48
+ appName,
49
+ chainNamespace,
50
+ walletRegistry,
51
+ handleSocialLoginClick,
52
+ handleExternalWalletClick,
53
+ handleShowExternalWallets,
54
+ closeModal
55
+ } = props;
56
+ const [transition, setTransition] = useState("");
57
+ useEffect(() => {
58
+ stateListener.emit("MOUNTED");
59
+ stateListener.on("STATE_UPDATED", newModalState => {
60
+ log.debug("state updated", newModalState);
61
+ setModalState(prevState => {
62
+ const mergedState = cloneDeep(deepmerge(prevState, newModalState));
63
+ return mergedState;
64
+ });
65
+ });
66
+ }, [stateListener]);
67
+ useEffect(() => {
68
+ let timeOutId;
69
+ if (modalState.modalVisibility) {
70
+ setModalState(prevState => {
71
+ return _objectSpread(_objectSpread({}, prevState), {}, {
72
+ modalVisibilityDelayed: modalState.modalVisibility
73
+ });
74
+ });
75
+ timeOutId = window.setTimeout(() => {
76
+ setModalTransitionClasses(["w3a-modal__inner", modalState.modalVisibility ? "w3a-modal__inner--active" : ""]);
77
+ // hide external wallets, if modal is closing, so that it will show social login screen on reopen.
78
+ }, 100);
79
+ } else {
80
+ setModalTransitionClasses(["w3a-modal__inner", modalState.modalVisibility ? "w3a-modal__inner--active" : ""]);
81
+ // hide external wallets, if modal is closing, so that it will show social login screen on reopen.
82
+
83
+ timeOutId = window.setTimeout(() => {
84
+ setModalState(prevState => {
85
+ return _objectSpread(_objectSpread({}, prevState), {}, {
86
+ modalVisibilityDelayed: modalState.modalVisibility
87
+ });
88
+ });
89
+ }, 250);
90
+ }
91
+ return () => {
92
+ clearTimeout(timeOutId);
93
+ };
94
+ }, [modalState.modalVisibility]);
95
+ const onCloseLoader = useCallback(() => {
96
+ if (modalState.status === MODAL_STATUS.CONNECTED) {
97
+ closeModal();
98
+ }
99
+ if (modalState.status === MODAL_STATUS.ERRORED) {
100
+ setModalState(prevState => {
101
+ return _objectSpread(_objectSpread({}, prevState), {}, {
102
+ modalVisibility: true,
103
+ status: MODAL_STATUS.INITIALIZED
104
+ });
105
+ });
106
+ }
107
+ }, [closeModal, modalState.status]);
108
+ const preHandleExternalWalletClick = useCallback(params => {
109
+ const {
110
+ adapter
111
+ } = params;
112
+ setModalState(prevState => {
113
+ return _objectSpread(_objectSpread({}, prevState), {}, {
114
+ detailedLoaderAdapter: adapter,
115
+ detailedLoaderAdapterName: ADAPTER_NAMES[adapter]
116
+ });
117
+ });
118
+ handleExternalWalletClick(params);
119
+ }, [handleExternalWalletClick]);
120
+ const preHandleSocialWalletClick = params => {
121
+ const {
122
+ loginParams
123
+ } = params;
124
+ setModalState(prevState => {
125
+ return _objectSpread(_objectSpread({}, prevState), {}, {
126
+ detailedLoaderAdapter: loginParams.loginProvider,
127
+ detailedLoaderAdapterName: loginParams.name
128
+ });
129
+ });
130
+ handleSocialLoginClick(params);
131
+ };
132
+ const isEmailPrimary = ((_modalState$socialLog = modalState.socialLoginsConfig) === null || _modalState$socialLog === void 0 || (_modalState$socialLog = _modalState$socialLog.uiConfig) === null || _modalState$socialLog === void 0 ? void 0 : _modalState$socialLog.primaryButton) === "emailLogin";
133
+ const isExternalPrimary = ((_modalState$socialLog2 = modalState.socialLoginsConfig) === null || _modalState$socialLog2 === void 0 || (_modalState$socialLog2 = _modalState$socialLog2.uiConfig) === null || _modalState$socialLog2 === void 0 ? void 0 : _modalState$socialLog2.primaryButton) === "externalLogin";
134
+ const externalWalletButton = /*#__PURE__*/jsx("div", {
135
+ className: "w3ajs-external-wallet w3a-group w3a--w-full",
136
+ children: /*#__PURE__*/jsx("div", {
137
+ className: "w3a-external-toggle w3ajs-external-toggle",
138
+ children: /*#__PURE__*/jsx(Button, {
139
+ variant: isExternalPrimary ? "primary" : "tertiary",
140
+ type: "button",
141
+ className: "w3a--w-full w3ajs-external-toggle__button",
142
+ style: {
143
+ width: "100%"
144
+ },
145
+ onClick: () => {
146
+ setModalState(prevState => {
147
+ return _objectSpread(_objectSpread({}, prevState), {}, {
148
+ externalWalletsVisibility: true
149
+ });
150
+ });
151
+ setTransition("slide-enter");
152
+ handleShowExternalWallets(modalState.externalWalletsInitialized);
153
+ setTimeout(() => {
154
+ setTransition("slide-exit");
155
+ }, 300);
156
+ },
157
+ children: t("modal.external.connect")
158
+ })
159
+ })
160
+ });
161
+ const areSocialLoginsVisible = useMemo(() => {
162
+ var _modalState$socialLog3, _modalState$socialLog4;
163
+ if (modalState.showExternalWalletsOnly) return false;
164
+ if (Object.keys(((_modalState$socialLog3 = modalState.socialLoginsConfig) === null || _modalState$socialLog3 === void 0 ? void 0 : _modalState$socialLog3.loginMethods) || {}).length === 0) return false;
165
+ const isAnySocialLoginVisible = Object.entries(((_modalState$socialLog4 = modalState.socialLoginsConfig) === null || _modalState$socialLog4 === void 0 ? void 0 : _modalState$socialLog4.loginMethods) || {}).some(([k, v]) => k !== LOGIN_PROVIDER.EMAIL_PASSWORDLESS && v.showOnModal !== false);
166
+ if (isAnySocialLoginVisible) return true;
167
+ return false;
168
+ }, [modalState.showExternalWalletsOnly, (_modalState$socialLog5 = modalState.socialLoginsConfig) === null || _modalState$socialLog5 === void 0 ? void 0 : _modalState$socialLog5.loginMethods]);
169
+ log.info("modal state", modalState, areSocialLoginsVisible);
170
+ const isEmailPasswordlessLoginVisible = useMemo(() => {
171
+ var _modalState$socialLog6;
172
+ return (_modalState$socialLog6 = modalState.socialLoginsConfig) === null || _modalState$socialLog6 === void 0 || (_modalState$socialLog6 = _modalState$socialLog6.loginMethods[LOGIN_PROVIDER.EMAIL_PASSWORDLESS]) === null || _modalState$socialLog6 === void 0 ? void 0 : _modalState$socialLog6.showOnModal;
173
+ }, [(_modalState$socialLog7 = modalState.socialLoginsConfig) === null || _modalState$socialLog7 === void 0 ? void 0 : _modalState$socialLog7.loginMethods]);
174
+ const isSmsPasswordlessLoginVisible = useMemo(() => {
175
+ var _modalState$socialLog8;
176
+ return (_modalState$socialLog8 = modalState.socialLoginsConfig) === null || _modalState$socialLog8 === void 0 || (_modalState$socialLog8 = _modalState$socialLog8.loginMethods[LOGIN_PROVIDER.SMS_PASSWORDLESS]) === null || _modalState$socialLog8 === void 0 ? void 0 : _modalState$socialLog8.showOnModal;
177
+ }, [(_modalState$socialLog9 = modalState.socialLoginsConfig) === null || _modalState$socialLog9 === void 0 ? void 0 : _modalState$socialLog9.loginMethods]);
178
+ return modalState.modalVisibilityDelayed && /*#__PURE__*/jsx("div", {
179
+ id: "w3a-modal",
180
+ className: "w3a-modal",
181
+ children: /*#__PURE__*/jsxs("div", {
182
+ className: `${modalTransitionClasses.join(" ")} ${modalState.status !== MODAL_STATUS.INITIALIZED ? "w3a--p-6 w3a--pt-7" : ""} ${(areSocialLoginsVisible || isEmailPasswordlessLoginVisible || isSmsPasswordlessLoginVisible) && !modalState.externalWalletsVisibility ? "" : "wallet-adapter-container"}`,
183
+ children: [modalState.status !== MODAL_STATUS.INITIALIZED ? /*#__PURE__*/jsxs(Fragment, {
184
+ children: [/*#__PURE__*/jsx(memoizedHeader, {
185
+ onClose: closeModal,
186
+ appLogo: appLogo,
187
+ appName: appName
188
+ }), /*#__PURE__*/jsx("div", {
189
+ className: "w3a-modal__content w3ajs-content",
190
+ children: /*#__PURE__*/jsx(DetailedLoader, {
191
+ onClose: onCloseLoader,
192
+ appLogo: appLogo,
193
+ modalStatus: modalState.status,
194
+ message: t(modalState.postLoadingMessage),
195
+ adapter: modalState.detailedLoaderAdapter,
196
+ adapterName: modalState.detailedLoaderAdapterName
197
+ })
198
+ })]
199
+ }) : /*#__PURE__*/jsx("div", {
200
+ className: `transition-wrapper ${transition}`,
201
+ children: (areSocialLoginsVisible || isEmailPasswordlessLoginVisible || isSmsPasswordlessLoginVisible) && !modalState.externalWalletsVisibility ? /*#__PURE__*/jsxs(Fragment, {
202
+ children: [/*#__PURE__*/jsx(memoizedHeader, {
203
+ onClose: closeModal,
204
+ appLogo: appLogo,
205
+ appName: appName
206
+ }), /*#__PURE__*/jsxs("div", {
207
+ className: "w3a-modal__content w3ajs-content",
208
+ children: [areSocialLoginsVisible ? /*#__PURE__*/jsx(SocialLogins, {
209
+ handleSocialLoginClick: params => preHandleSocialWalletClick(params),
210
+ socialLoginsConfig: modalState.socialLoginsConfig
211
+ }) : null, (isEmailPasswordlessLoginVisible || isSmsPasswordlessLoginVisible) && /*#__PURE__*/jsx(SocialLoginPasswordless, {
212
+ isEmailVisible: isEmailPasswordlessLoginVisible,
213
+ isSmsVisible: isSmsPasswordlessLoginVisible,
214
+ adapter: (_modalState$socialLog10 = modalState.socialLoginsConfig) === null || _modalState$socialLog10 === void 0 ? void 0 : _modalState$socialLog10.adapter,
215
+ handleSocialLoginClick: params => preHandleSocialWalletClick(params),
216
+ isPrimaryBtn: isEmailPrimary
217
+ }), modalState.hasExternalWallets && externalWalletButton]
218
+ })]
219
+ }) : /*#__PURE__*/jsx("div", {
220
+ className: "w3a-modal__content_external_wallet w3ajs-content",
221
+ children: /*#__PURE__*/jsx(ExternalWallet, {
222
+ modalStatus: modalState.status,
223
+ showBackButton: areSocialLoginsVisible || isEmailPasswordlessLoginVisible || isSmsPasswordlessLoginVisible,
224
+ handleExternalWalletClick: preHandleExternalWalletClick,
225
+ chainNamespace: chainNamespace,
226
+ walletConnectUri: modalState.walletConnectUri,
227
+ config: modalState.externalWalletsConfig,
228
+ hideExternalWallets: () => setModalState(prevState => {
229
+ return _objectSpread(_objectSpread({}, prevState), {}, {
230
+ externalWalletsVisibility: false
231
+ });
232
+ }),
233
+ walletRegistry: walletRegistry,
234
+ closeModal: closeModal
235
+ })
236
+ })
237
+ }), /*#__PURE__*/jsx(Footer, {})]
238
+ })
239
+ });
240
+ }
241
+
242
+ export { Modal as default };
@@ -0,0 +1,28 @@
1
+ import { useTranslation } from 'react-i18next';
2
+ import i18nInstance from '../localeImport.js';
3
+ import { jsxs, jsx } from 'react/jsx-runtime';
4
+
5
+ function SelfCustodyViaWeb3Auth() {
6
+ const [t] = useTranslation(undefined, {
7
+ i18n: i18nInstance
8
+ });
9
+ return /*#__PURE__*/jsxs("div", {
10
+ className: "w3a--flex w3a--items-center w3a--gap-2 w3a--justify-center",
11
+ children: [/*#__PURE__*/jsx("div", {
12
+ className: "w3a--text-xs w3a--text-app-gray-300 dark:w3a--text-app-gray-500",
13
+ children: t("modal.footer.message-new")
14
+ }), /*#__PURE__*/jsx("img", {
15
+ height: "16",
16
+ src: "https://images.web3auth.io/web3auth-footer-logo-light.svg",
17
+ alt: "Web3Auth Logo Light",
18
+ className: "w3a--h-4 w3a--block dark:w3a--hidden"
19
+ }), /*#__PURE__*/jsx("img", {
20
+ height: "16",
21
+ src: "https://images.web3auth.io/web3auth-footer-logo-dark.svg",
22
+ alt: "Web3Auth Logo Dark",
23
+ className: "w3a--h-4 w3a--hidden dark:w3a--block"
24
+ })]
25
+ });
26
+ }
27
+
28
+ export { SelfCustodyViaWeb3Auth as default };
@@ -0,0 +1,139 @@
1
+ import { LOGIN_PROVIDER } from '@web3auth/auth';
2
+ import { useState, useEffect, useMemo } from 'react';
3
+ import { useTranslation } from 'react-i18next';
4
+ import i18nInstance from '../localeImport.js';
5
+ import { validatePhoneNumber, getUserCountry } from '../utils.js';
6
+ import Button from './Button/Button.js';
7
+ import Icon from './Icon.js';
8
+ import { jsxs, jsx } from 'react/jsx-runtime';
9
+
10
+ function SocialLoginPasswordless(props) {
11
+ const {
12
+ handleSocialLoginClick,
13
+ adapter,
14
+ isPrimaryBtn,
15
+ isEmailVisible,
16
+ isSmsVisible
17
+ } = props;
18
+ const [fieldValue, setFieldValue] = useState("");
19
+ const [countryCode, setCountryCode] = useState("");
20
+ const [isValidInput, setIsValidInput] = useState(null);
21
+ const [t] = useTranslation(undefined, {
22
+ i18n: i18nInstance
23
+ });
24
+ const handleFormSubmit = async e => {
25
+ e.preventDefault();
26
+ const value = fieldValue;
27
+ if (isEmailVisible) {
28
+ const isEmailValid = value.match(/^([\w.%+-]+)@([\w-]+\.)+([\w]{2,})$/i);
29
+ if (isEmailValid) {
30
+ return handleSocialLoginClick({
31
+ adapter,
32
+ loginParams: {
33
+ loginProvider: LOGIN_PROVIDER.EMAIL_PASSWORDLESS,
34
+ login_hint: value,
35
+ name: "Email"
36
+ }
37
+ });
38
+ }
39
+ }
40
+ if (isSmsVisible) {
41
+ const number = value.startsWith("+") ? value : `${countryCode}${value}`;
42
+ const result = await validatePhoneNumber(number);
43
+ if (result) {
44
+ return handleSocialLoginClick({
45
+ adapter,
46
+ loginParams: {
47
+ loginProvider: LOGIN_PROVIDER.SMS_PASSWORDLESS,
48
+ login_hint: typeof result === "string" ? result : number,
49
+ name: "Mobile"
50
+ }
51
+ });
52
+ }
53
+ }
54
+ setIsValidInput(false);
55
+ return undefined;
56
+ };
57
+ useEffect(() => {
58
+ const getLocation = async () => {
59
+ const result = await getUserCountry();
60
+ if (result && result.dialCode) {
61
+ setCountryCode(result.dialCode);
62
+ }
63
+ };
64
+ if (isSmsVisible) getLocation();
65
+ }, [isSmsVisible]);
66
+ const handleInputChange = e => {
67
+ setFieldValue(e.target.value);
68
+ if (isValidInput === false) setIsValidInput(null);
69
+ };
70
+ const title = useMemo(() => {
71
+ if (isEmailVisible && isSmsVisible) return "modal.social.passwordless-title";
72
+ if (isEmailVisible) return "modal.social.email";
73
+ return "modal.social.phone";
74
+ }, [isEmailVisible, isSmsVisible]);
75
+ const placeholder = useMemo(() => {
76
+ if (isEmailVisible && isSmsVisible) return "+(00)123456/name@example.com";
77
+ if (isEmailVisible) return "name@example.com";
78
+ return "+(00)123456";
79
+ }, [isEmailVisible, isSmsVisible]);
80
+ const invalidInputErrorMessage = useMemo(() => {
81
+ if (isEmailVisible && isSmsVisible) return "modal.errors-invalid-number-email";
82
+ if (isEmailVisible) return "modal.errors-invalid-email";
83
+ return "modal.errors-invalid-number";
84
+ }, [isEmailVisible, isSmsVisible]);
85
+ return /*#__PURE__*/jsxs("div", {
86
+ className: "w3ajs-passwordless w3a-group w3a-group--passwordless",
87
+ children: [/*#__PURE__*/jsxs("div", {
88
+ className: "w3a-group__title",
89
+ children: [t(title), isSmsVisible && /*#__PURE__*/jsxs("div", {
90
+ className: "w3a--relative w3a--flex w3a--flex-col w3a--items-center w3a--cursor-pointer w3a--group",
91
+ children: [/*#__PURE__*/jsx(Icon, {
92
+ iconName: "information-circle-light",
93
+ darkIconName: "information-circle"
94
+ }), /*#__PURE__*/jsxs("div", {
95
+ className: "w3a--absolute w3a--z-20 w3a--flex-col w3a--items-center w3a--hidden w3a--mb-5 w3a--top-4 group-hover:w3a--flex",
96
+ children: [/*#__PURE__*/jsx("div", {
97
+ className: "w3a--w-3 w3a--h-3 w3a--ml-[3px] -w3a--mb-2 w3a--rotate-45 w3a--bg-app-gray-50 dark:w3a--bg-app-gray-600"
98
+ }), /*#__PURE__*/jsxs("div", {
99
+ className: `w3a--relative w3a--p-4 w3a--w-[300px] w3a--text-xs w3a--leading-none w3a--text-app-white w3a--rounded-md w3a--bg-app-gray-50 dark:w3a--bg-app-gray-600 w3a--shadow-lg ${isSmsVisible && !isEmailVisible ? "w3a--left-20" : "w3a--left-8"}`,
100
+ children: [/*#__PURE__*/jsx("div", {
101
+ className: "w3a--mb-1 w3a--text-xs w3a--font-medium w3a--text-app-gray-900 dark:w3a--text-app-white",
102
+ children: t("modal.popup.phone-header")
103
+ }), /*#__PURE__*/jsx("div", {
104
+ className: "w3a--text-xs w3a--text-app-gray-400",
105
+ children: t("modal.popup.phone-body")
106
+ })]
107
+ })]
108
+ })]
109
+ })]
110
+ }), /*#__PURE__*/jsxs("form", {
111
+ className: "w3ajs-passwordless-form",
112
+ onSubmit: e => handleFormSubmit(e),
113
+ children: [/*#__PURE__*/jsx("input", {
114
+ className: "w3a--w-full w3a--mb-4 w3a-text-field",
115
+ name: "passwordless-input",
116
+ required: true,
117
+ placeholder: `${t("modal.social.sms-placeholder-text")} ${placeholder}`,
118
+ onFocus: e => {
119
+ e.target.placeholder = "";
120
+ },
121
+ onBlur: e => {
122
+ e.target.placeholder = `${t("modal.social.sms-placeholder-text")} ${placeholder}`;
123
+ },
124
+ onChange: e => handleInputChange(e)
125
+ }), isValidInput === false && /*#__PURE__*/jsx("div", {
126
+ className: "w3a-sms-field--error",
127
+ children: t(invalidInputErrorMessage)
128
+ }), /*#__PURE__*/jsx(Button, {
129
+ variant: isPrimaryBtn ? "primary" : "tertiary",
130
+ disabled: fieldValue === "",
131
+ className: "w3a--w-full",
132
+ type: "submit",
133
+ children: t("modal.social.passwordless-cta")
134
+ })]
135
+ })]
136
+ });
137
+ }
138
+
139
+ export { SocialLoginPasswordless as default };
@@ -0,0 +1,146 @@
1
+ import { LOGIN_PROVIDER } from '@web3auth/auth';
2
+ import classNames from 'classnames';
3
+ import { useState, useContext, useEffect } from 'react';
4
+ import { useTranslation } from 'react-i18next';
5
+ import { capitalizeFirstLetter } from '../config.js';
6
+ import { ThemedContext } from '../context/ThemeContext.js';
7
+ import i18nInstance from '../localeImport.js';
8
+ import Button from './Button/Button.js';
9
+ import Image from './Image.js';
10
+ import { jsxs, jsx } from 'react/jsx-runtime';
11
+
12
+ function getProviderIcon(method, isDark, isPrimaryBtn) {
13
+ const imageId = method === LOGIN_PROVIDER.TWITTER ? `login-twitter-x${isDark ? "-light" : "-dark"}` : `login-${method}${isDark ? "-light" : "-dark"}`;
14
+ const hoverId = method === LOGIN_PROVIDER.APPLE || method === LOGIN_PROVIDER.GITHUB || method === LOGIN_PROVIDER.TWITTER ? imageId : `login-${method}-active`;
15
+ if (isPrimaryBtn) {
16
+ return /*#__PURE__*/jsx(Image, {
17
+ width: "20",
18
+ imageId: hoverId,
19
+ hoverImageId: hoverId,
20
+ isButton: true
21
+ });
22
+ }
23
+ return /*#__PURE__*/jsx(Image, {
24
+ width: "20",
25
+ imageId: imageId,
26
+ hoverImageId: hoverId,
27
+ isButton: true
28
+ });
29
+ }
30
+ function SocialLogins(props) {
31
+ const [canShowMore, setCanShowMore] = useState(false);
32
+ const [isExpanded, setIsExpanded] = useState(false);
33
+ const {
34
+ socialLoginsConfig = {
35
+ loginMethods: {},
36
+ loginMethodsOrder: [],
37
+ adapter: "",
38
+ uiConfig: {}
39
+ },
40
+ handleSocialLoginClick
41
+ } = props;
42
+ const {
43
+ isDark
44
+ } = useContext(ThemedContext);
45
+ const [t] = useTranslation(undefined, {
46
+ i18n: i18nInstance
47
+ });
48
+
49
+ // Too small a function to use `useCallback`
50
+ const expandClickHandler = () => {
51
+ setIsExpanded(!isExpanded);
52
+ };
53
+ useEffect(() => {
54
+ const maxOptions = Object.keys(socialLoginsConfig.loginMethods).filter(loginMethodKey => {
55
+ return socialLoginsConfig.loginMethods[loginMethodKey].showOnModal;
56
+ });
57
+ setCanShowMore(maxOptions.length > 4);
58
+ }, [socialLoginsConfig.loginMethods]);
59
+ const adapterListClass = classNames("w3a-adapter-list", "w3ajs-socials-adapters", !isExpanded ? " w3a-adapter-list--shrink" : "");
60
+ const adapterButtonClass = classNames("w3a-button-expand", "w3ajs-button-expand", isExpanded ? "w3a-button--rotate" : "");
61
+ const adapterExpandText = isExpanded ? t("modal.social.view-less") : t("modal.social.view-more");
62
+ const loginMethodsCount = Object.keys(socialLoginsConfig.loginMethods).length + 1;
63
+ const restrictedLoginMethods = [LOGIN_PROVIDER.WEBAUTHN, LOGIN_PROVIDER.JWT, LOGIN_PROVIDER.SMS_PASSWORDLESS, LOGIN_PROVIDER.EMAIL_PASSWORDLESS, LOGIN_PROVIDER.AUTHENTICATOR, LOGIN_PROVIDER.PASSKEYS];
64
+ return /*#__PURE__*/jsxs("div", {
65
+ className: "w3ajs-social-logins w3a-group",
66
+ children: [/*#__PURE__*/jsx("ul", {
67
+ className: adapterListClass,
68
+ children: Object.keys(socialLoginsConfig.loginMethods).map(method => {
69
+ var _socialLoginsConfig$u, _socialLoginsConfig$u2;
70
+ const name = capitalizeFirstLetter(socialLoginsConfig.loginMethods[method].name || method);
71
+ const orderIndex = socialLoginsConfig.loginMethodsOrder.indexOf(method) + 1;
72
+ const order = orderIndex || Object.keys(socialLoginsConfig.loginMethods).length + 1;
73
+ const isMainOption = socialLoginsConfig.loginMethods[method].mainOption;
74
+ const isPrimaryBtn = (socialLoginsConfig === null || socialLoginsConfig === void 0 || (_socialLoginsConfig$u = socialLoginsConfig.uiConfig) === null || _socialLoginsConfig$u === void 0 ? void 0 : _socialLoginsConfig$u.primaryButton) === "socialLogin" && order === 1;
75
+ const providerIcon = getProviderIcon(method, isDark, isPrimaryBtn);
76
+ if (socialLoginsConfig.loginMethods[method].showOnModal === false || restrictedLoginMethods.includes(method)) {
77
+ return null;
78
+ }
79
+ const loginMethodSpan = classNames("w3a-adapter-item", (socialLoginsConfig === null || socialLoginsConfig === void 0 || (_socialLoginsConfig$u2 = socialLoginsConfig.uiConfig) === null || _socialLoginsConfig$u2 === void 0 ? void 0 : _socialLoginsConfig$u2.loginGridCol) === 2 ? "w3a--col-span-3" : "w3a--col-span-2");
80
+ if (isMainOption || order === 1) {
81
+ return /*#__PURE__*/jsx("li", {
82
+ className: "w3a--col-span-6 w3a-adapter-item",
83
+ style: {
84
+ order
85
+ },
86
+ children: /*#__PURE__*/jsxs(Button, {
87
+ variant: "secondary",
88
+ onClick: () => handleSocialLoginClick({
89
+ adapter: socialLoginsConfig.adapter,
90
+ loginParams: {
91
+ loginProvider: method,
92
+ name,
93
+ login_hint: ""
94
+ }
95
+ }),
96
+ className: "w3a--w-full",
97
+ title: name,
98
+ children: [providerIcon, /*#__PURE__*/jsx("p", {
99
+ className: "w3a--ml-2",
100
+ children: t("modal.social.continueCustom", {
101
+ adapter: name
102
+ })
103
+ })]
104
+ })
105
+ }, method);
106
+ }
107
+ return /*#__PURE__*/jsx("li", {
108
+ className: loginMethodSpan,
109
+ style: {
110
+ order: order + loginMethodsCount
111
+ },
112
+ children: /*#__PURE__*/jsx(Button, {
113
+ variant: "secondary",
114
+ onClick: () => handleSocialLoginClick({
115
+ adapter: socialLoginsConfig.adapter,
116
+ loginParams: {
117
+ loginProvider: method,
118
+ name,
119
+ login_hint: ""
120
+ }
121
+ }),
122
+ className: "w3a--w-full",
123
+ title: name,
124
+ children: providerIcon
125
+ })
126
+ }, method);
127
+ })
128
+ }), /*#__PURE__*/jsx("div", {
129
+ className: "w3a-social__policy",
130
+ children: t("modal.social.policy")
131
+ }), canShowMore && /*#__PURE__*/jsx("div", {
132
+ className: "w3a--text-right",
133
+ children: /*#__PURE__*/jsx("button", {
134
+ type: "button",
135
+ className: adapterButtonClass,
136
+ onClick: expandClickHandler,
137
+ children: /*#__PURE__*/jsx("span", {
138
+ className: "w3ajs-button-expand-text",
139
+ children: adapterExpandText
140
+ })
141
+ })
142
+ })]
143
+ });
144
+ }
145
+
146
+ export { SocialLogins as default };