@arcblock/did-connect-react 3.4.14 → 3.5.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 (208) hide show
  1. package/dist/standalone/did-connect-react.css +1 -0
  2. package/dist/standalone/index.js +133700 -0
  3. package/lib/Connect/components/login-item/connect-choose-list.js +111 -111
  4. package/lib/Connect/components/login-item/connect-provider-list.js +180 -180
  5. package/lib/Connect/components/login-item/mobile-login-item.js +56 -56
  6. package/lib/Connect/components/login-item/passkey-login-item.js +27 -29
  7. package/lib/Connect/components/login-item/web-login-item.js +31 -29
  8. package/lib/Connect/connect.js +202 -197
  9. package/lib/Connect/contexts/state.js +19 -17
  10. package/lib/Connect/hooks/provider-list.js +33 -33
  11. package/lib/Connect/plugins/email/list-item.js +14 -14
  12. package/lib/Connect/plugins/email/placeholder.js +77 -76
  13. package/lib/package.json.js +1 -1
  14. package/package.json +14 -9
  15. package/.aigne/doc-smith/config.yaml +0 -85
  16. package/.aigne/doc-smith/history.yaml +0 -6
  17. package/.aigne/doc-smith/output/structure-plan.json +0 -204
  18. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  19. package/.aigne/doc-smith/upload-cache.yaml +0 -213
  20. package/docs/_sidebar.md +0 -18
  21. package/docs/advanced-authentication-methods.ja.md +0 -261
  22. package/docs/advanced-authentication-methods.md +0 -261
  23. package/docs/advanced-authentication-methods.zh-TW.md +0 -261
  24. package/docs/advanced-authentication-methods.zh.md +0 -261
  25. package/docs/advanced-utilities.ja.md +0 -132
  26. package/docs/advanced-utilities.md +0 -132
  27. package/docs/advanced-utilities.zh-TW.md +0 -132
  28. package/docs/advanced-utilities.zh.md +0 -132
  29. package/docs/advanced.ja.md +0 -95
  30. package/docs/advanced.md +0 -95
  31. package/docs/advanced.zh-TW.md +0 -95
  32. package/docs/advanced.zh.md +0 -95
  33. package/docs/api-reference.ja.md +0 -178
  34. package/docs/api-reference.md +0 -178
  35. package/docs/api-reference.zh-TW.md +0 -178
  36. package/docs/api-reference.zh.md +0 -178
  37. package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
  38. package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
  39. package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
  40. package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
  41. package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
  42. package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
  43. package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
  44. package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
  45. package/docs/assets/diagram/overview-01.ja.jpg +0 -0
  46. package/docs/assets/diagram/overview-01.jpg +0 -0
  47. package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
  48. package/docs/assets/diagram/overview-01.zh.jpg +0 -0
  49. package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
  50. package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
  51. package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
  52. package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
  53. package/docs/core-components-did-connect.ja.md +0 -166
  54. package/docs/core-components-did-connect.md +0 -166
  55. package/docs/core-components-did-connect.zh-TW.md +0 -166
  56. package/docs/core-components-did-connect.zh.md +0 -166
  57. package/docs/core-components-session-provider.ja.md +0 -197
  58. package/docs/core-components-session-provider.md +0 -197
  59. package/docs/core-components-session-provider.zh-TW.md +0 -197
  60. package/docs/core-components-session-provider.zh.md +0 -197
  61. package/docs/core-components.ja.md +0 -16
  62. package/docs/core-components.md +0 -16
  63. package/docs/core-components.zh-TW.md +0 -16
  64. package/docs/core-components.zh.md +0 -16
  65. package/docs/getting-started.ja.md +0 -138
  66. package/docs/getting-started.md +0 -138
  67. package/docs/getting-started.zh-TW.md +0 -138
  68. package/docs/getting-started.zh.md +0 -138
  69. package/docs/hooks-use-connect.ja.md +0 -178
  70. package/docs/hooks-use-connect.md +0 -178
  71. package/docs/hooks-use-connect.zh-TW.md +0 -178
  72. package/docs/hooks-use-connect.zh.md +0 -178
  73. package/docs/hooks-use-did.ja.md +0 -107
  74. package/docs/hooks-use-did.md +0 -107
  75. package/docs/hooks-use-did.zh-TW.md +0 -107
  76. package/docs/hooks-use-did.zh.md +0 -107
  77. package/docs/hooks-use-oauth-passkey.ja.md +0 -188
  78. package/docs/hooks-use-oauth-passkey.md +0 -188
  79. package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
  80. package/docs/hooks-use-oauth-passkey.zh.md +0 -188
  81. package/docs/hooks.ja.md +0 -23
  82. package/docs/hooks.md +0 -23
  83. package/docs/hooks.zh-TW.md +0 -23
  84. package/docs/hooks.zh.md +0 -23
  85. package/docs/overview.ja.md +0 -119
  86. package/docs/overview.md +0 -119
  87. package/docs/overview.zh-TW.md +0 -119
  88. package/docs/overview.zh.md +0 -119
  89. package/docs/ui-components-address.ja.md +0 -121
  90. package/docs/ui-components-address.md +0 -121
  91. package/docs/ui-components-address.zh-TW.md +0 -121
  92. package/docs/ui-components-address.zh.md +0 -121
  93. package/docs/ui-components-avatar.ja.md +0 -65
  94. package/docs/ui-components-avatar.md +0 -65
  95. package/docs/ui-components-avatar.zh-TW.md +0 -65
  96. package/docs/ui-components-avatar.zh.md +0 -65
  97. package/docs/ui-components-button.ja.md +0 -99
  98. package/docs/ui-components-button.md +0 -99
  99. package/docs/ui-components-button.zh-TW.md +0 -99
  100. package/docs/ui-components-button.zh.md +0 -99
  101. package/docs/ui-components-logo.ja.md +0 -52
  102. package/docs/ui-components-logo.md +0 -52
  103. package/docs/ui-components-logo.zh-TW.md +0 -52
  104. package/docs/ui-components-logo.zh.md +0 -52
  105. package/docs/ui-components.ja.md +0 -57
  106. package/docs/ui-components.md +0 -57
  107. package/docs/ui-components.zh-TW.md +0 -57
  108. package/docs/ui-components.zh.md +0 -57
  109. package/glossary.md +0 -1
  110. package/src/Address/index.jsx +0 -2
  111. package/src/Avatar/index.jsx +0 -2
  112. package/src/Button/Button.stories.jsx +0 -7
  113. package/src/Button/index.jsx +0 -21
  114. package/src/Connect/Connect.stories.jsx +0 -34
  115. package/src/Connect/assets/locale.js +0 -149
  116. package/src/Connect/assets/login-bg.png +0 -0
  117. package/src/Connect/assets/login-slogan.js +0 -7
  118. package/src/Connect/components/action-button.jsx +0 -22
  119. package/src/Connect/components/app-tips.jsx +0 -156
  120. package/src/Connect/components/auto-height.jsx +0 -38
  121. package/src/Connect/components/back-button.jsx +0 -24
  122. package/src/Connect/components/connect-status.jsx +0 -259
  123. package/src/Connect/components/did-connect-title.jsx +0 -107
  124. package/src/Connect/components/download-tips.jsx +0 -55
  125. package/src/Connect/components/loading.jsx +0 -25
  126. package/src/Connect/components/login-item/connect-choose-list.jsx +0 -317
  127. package/src/Connect/components/login-item/connect-provider-list.jsx +0 -462
  128. package/src/Connect/components/login-item/login-method-item.jsx +0 -139
  129. package/src/Connect/components/login-item/mobile-login-item.jsx +0 -181
  130. package/src/Connect/components/login-item/passkey-login-item.jsx +0 -54
  131. package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
  132. package/src/Connect/components/login-item/web-login-item.jsx +0 -157
  133. package/src/Connect/components/mask-overlay.jsx +0 -32
  134. package/src/Connect/components/refresh-overlay.jsx +0 -52
  135. package/src/Connect/components/switch-app.jsx +0 -69
  136. package/src/Connect/connect.jsx +0 -617
  137. package/src/Connect/contexts/state.jsx +0 -234
  138. package/src/Connect/fallback-connect.jsx +0 -47
  139. package/src/Connect/fullpage.jsx +0 -3
  140. package/src/Connect/hooks/auth-url.js +0 -31
  141. package/src/Connect/hooks/method-list.js +0 -121
  142. package/src/Connect/hooks/page-show.js +0 -24
  143. package/src/Connect/hooks/provider-list.js +0 -165
  144. package/src/Connect/hooks/security.js +0 -40
  145. package/src/Connect/hooks/token.js +0 -627
  146. package/src/Connect/hooks/use-apps.js +0 -69
  147. package/src/Connect/hooks/use-quick-connect.js +0 -119
  148. package/src/Connect/index.jsx +0 -21
  149. package/src/Connect/landing-page.jsx +0 -3
  150. package/src/Connect/plugins/email/index.jsx +0 -85
  151. package/src/Connect/plugins/email/list-item.jsx +0 -34
  152. package/src/Connect/plugins/email/placeholder.jsx +0 -365
  153. package/src/Connect/plugins/index.js +0 -2
  154. package/src/Connect/use-connect.jsx +0 -321
  155. package/src/Connect/with-blocklet.jsx +0 -26
  156. package/src/Connect/with-bridge-call.jsx +0 -138
  157. package/src/Federated/context.jsx +0 -93
  158. package/src/Federated/index.jsx +0 -1
  159. package/src/Logo/index.jsx +0 -2
  160. package/src/OAuth/bind-conflict-alert.jsx +0 -37
  161. package/src/OAuth/context.jsx +0 -407
  162. package/src/OAuth/guest.svg +0 -20
  163. package/src/OAuth/index.jsx +0 -1
  164. package/src/OAuth/passport-switcher.jsx +0 -2
  165. package/src/Passkey/actions.jsx +0 -217
  166. package/src/Passkey/constants.js +0 -2
  167. package/src/Passkey/context.jsx +0 -395
  168. package/src/Passkey/dialog.jsx +0 -401
  169. package/src/Passkey/icon.jsx +0 -10
  170. package/src/Passkey/index.jsx +0 -2
  171. package/src/Service/index.jsx +0 -96
  172. package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
  173. package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
  174. package/src/Session/context.jsx +0 -7
  175. package/src/Session/did-spaces-guide.jsx +0 -173
  176. package/src/Session/handler.jsx +0 -98
  177. package/src/Session/hooks/use-federated.js +0 -91
  178. package/src/Session/hooks/use-mobile.jsx +0 -6
  179. package/src/Session/hooks/use-protected-routes.js +0 -16
  180. package/src/Session/hooks/use-session-token.js +0 -400
  181. package/src/Session/hooks/use-verify.jsx +0 -76
  182. package/src/Session/index.jsx +0 -1789
  183. package/src/Session/libs/constants.js +0 -17
  184. package/src/Session/libs/did-spaces.js +0 -38
  185. package/src/Session/libs/federated.js +0 -82
  186. package/src/Session/libs/index.js +0 -5
  187. package/src/Session/libs/locales.js +0 -160
  188. package/src/Session/libs/login-mobile.js +0 -80
  189. package/src/Session/window-focus-aware.jsx +0 -28
  190. package/src/SessionManager/index.jsx +0 -2
  191. package/src/Storage/engine/cookie.js +0 -25
  192. package/src/Storage/engine/local-storage.js +0 -57
  193. package/src/Storage/index.js +0 -25
  194. package/src/User/index.js +0 -4
  195. package/src/User/use-did.js +0 -80
  196. package/src/User/wrap-did.jsx +0 -18
  197. package/src/WebWalletSWKeeper/index.jsx +0 -3
  198. package/src/components/PassportSwitcher.jsx +0 -160
  199. package/src/constant.js +0 -27
  200. package/src/error.js +0 -6
  201. package/src/hooks/use-locale.jsx +0 -6
  202. package/src/index.js +0 -32
  203. package/src/locales/en.jsx +0 -15
  204. package/src/locales/index.jsx +0 -13
  205. package/src/locales/zh.jsx +0 -15
  206. package/src/types.d.ts +0 -355
  207. package/src/utils.js +0 -413
  208. package/vite.config.mjs +0 -29
@@ -1,462 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { Box } from '@mui/material';
3
- import { LOGIN_PROVIDER, LOGIN_PROVIDER_NAME, LOGIN_PROVIDER_ICON_SIZE } from '@arcblock/ux/lib/Util/constant';
4
- import { checkSameProtocol, getWebWalletUrl } from '@arcblock/ux/lib/Util/wallet';
5
- import noop from 'lodash/noop';
6
- import { useMemoizedFn, useCreation } from 'ahooks';
7
- import Cookie from 'js-cookie';
8
- import { detectWalletExtension, getCookieOptions } from '@arcblock/ux/lib/Util';
9
- import { useEffect, useRef } from 'react';
10
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
11
- import ProviderIcon from '@arcblock/ux/lib/DIDConnect/provider-icon';
12
- import { GA_LAST_LOGIN_METHOD } from '@arcblock/ux/lib/withTracker/constant';
13
- import { translate } from '@arcblock/ux/lib/Locale/util';
14
- import Empty from '@arcblock/ux/lib/Empty';
15
- import { useBrowser } from '@arcblock/react-hooks';
16
-
17
- import MobileLoginItem from './mobile-login-item';
18
- import WebLoginItem from './web-login-item';
19
- import LoginMethodItem from './login-method-item';
20
- import WalletLoginOptions from './wallet-login-options';
21
- import { useOAuth } from '../../../OAuth';
22
- import { useStateContext } from '../../contexts/state';
23
- import { getApiErrorMessage, getAppId, logger } from '../../../utils';
24
- import PasskeyLoginItem from './passkey-login-item';
25
- import { usePasskey } from '../../../Passkey';
26
- import { useEmailPlugin } from '../../plugins';
27
- import translations from '../../assets/locale';
28
-
29
- export default function ConnectProviderList({
30
- onSuccess = noop,
31
- onError = noop,
32
- size = 'small',
33
- tokenState,
34
- webWalletUrl = getWebWalletUrl(),
35
- tokenKey,
36
- passkeyBehavior = 'none',
37
- onReset = noop,
38
- providerList = [],
39
- slotProps = {},
40
- disableSwitchApp = false,
41
- forceUpdate = noop,
42
- magicToken = undefined,
43
- baseUrl = '/',
44
- customItems = [],
45
- qrcode = null,
46
- hideQRCode = false,
47
- }) {
48
- const walletLoginRef = useRef(null);
49
- const webLoginRef = useRef(null);
50
- const passkeyLoginRef = useRef(null);
51
- const isSameProtocol = checkSameProtocol(webWalletUrl);
52
- const extension = detectWalletExtension();
53
-
54
- const browser = useBrowser();
55
-
56
- const { loginOAuth, logoutOAuth, t: oauthT, oauthState } = useOAuth();
57
- const { passkeyState } = usePasskey();
58
- const {
59
- extraParams,
60
- locale,
61
- connectState,
62
- plugins,
63
- setPlugins,
64
- setSelectedPlugin,
65
- getPlugin,
66
- showWalletOptions,
67
- setShowWalletOptions,
68
- lastLoginMethod,
69
- } = useStateContext();
70
-
71
- const t = useMemoizedFn((key, data = {}) => {
72
- return translate(translations, key, locale, 'en', data);
73
- });
74
-
75
- const handleLoginOAuth = useMemoizedFn(async (item) => {
76
- localStorage.setItem(GA_LAST_LOGIN_METHOD, item.provider);
77
- tokenState.reset();
78
- oauthState.reset({
79
- status: 'scanned',
80
- });
81
- passkeyState.reset();
82
- connectState.chooseMethod = item.provider;
83
-
84
- const sourceAppPid = extraParams?.sourceAppPid;
85
- try {
86
- oauthState.loading = true;
87
- oauthState.status = 'scanned';
88
- const loginResult = await loginOAuth(item, {
89
- action: tokenState.action,
90
- ...extraParams,
91
- });
92
- const cookieOptions = getCookieOptions({ returnDomain: false });
93
- Cookie.remove('connected_did', cookieOptions);
94
- Cookie.remove('connected_pk', cookieOptions);
95
- Cookie.remove('connected_wallet_os', cookieOptions);
96
-
97
- if (loginResult?.sessionToken) {
98
- await onSuccess(
99
- {
100
- ...loginResult,
101
- encrypted: false,
102
- },
103
- (val) => val,
104
- {
105
- sourceAppPid,
106
- connected_app: getAppId(tokenState.appInfo, tokenState.memberAppInfo),
107
- }
108
- );
109
- oauthState.loading = false;
110
- oauthState.status = 'succeed';
111
- }
112
- } catch (e) {
113
- logger.error(`Failed login OAuth: ${item.provider}`, e);
114
- const errorMessage = getApiErrorMessage(e, oauthT('loginOAuthFailed'));
115
- oauthState.loading = false;
116
- oauthState.error = errorMessage;
117
- oauthState.status = 'error';
118
- await logoutOAuth({ provider: item.provider });
119
- onError(new Error(errorMessage));
120
- }
121
- });
122
-
123
- const defaultRetryConnect = useMemoizedFn(async () => {
124
- tokenState.reset();
125
- await onReset();
126
- tokenState.status = 'created';
127
- connectState.chooseMethod = 'wallet';
128
- });
129
-
130
- const handleMobileLoginClick = useMemoizedFn(async () => {
131
- localStorage.setItem(GA_LAST_LOGIN_METHOD, LOGIN_PROVIDER.WALLET);
132
- tokenState.reset();
133
- await onReset();
134
- tokenState.status = 'created';
135
- connectState.chooseMethod = 'wallet';
136
- const connectFn = walletLoginRef.current?.connect;
137
- connectState.retryConnect = () => {
138
- connectFn(defaultRetryConnect);
139
- };
140
- });
141
-
142
- const handleWebLoginClick = useMemoizedFn(() => {
143
- localStorage.setItem(GA_LAST_LOGIN_METHOD, LOGIN_PROVIDER.WALLET);
144
- // HACK: 在点击插件登录时,直接将状态置为扫码中,避免插件登录时的状态切换
145
- tokenState.status = 'scanned';
146
- connectState.chooseMethod = 'wallet-web';
147
- const connectFn = webLoginRef.current.connect;
148
- connectState.retryConnect = async () => {
149
- await onReset();
150
- tokenState.error = '';
151
- tokenState.status = 'scanned';
152
- connectFn();
153
- };
154
- });
155
-
156
- const handleWalletLoginBack = useMemoizedFn(() => {
157
- setShowWalletOptions(false);
158
- });
159
-
160
- const onlyWalletProvider = useCreation(() => {
161
- return providerList.length === 1 && providerList[0].provider === LOGIN_PROVIDER.WALLET;
162
- }, [providerList]);
163
-
164
- useEffect(() => {
165
- if (hideQRCode && onlyWalletProvider && !browser.mobile.any && !showWalletOptions) {
166
- setShowWalletOptions(true);
167
- }
168
- }, [hideQRCode, onlyWalletProvider, browser.mobile.any, setShowWalletOptions, showWalletOptions]);
169
-
170
- const showEmailLogin = providerList.some((p) => p.provider === LOGIN_PROVIDER.EMAIL);
171
-
172
- const emailPlugin = useEmailPlugin({ baseUrl });
173
-
174
- const setupMagicToken = useMemoizedFn(() => {
175
- if (
176
- magicToken &&
177
- providerList.some((provider) => provider.name === LOGIN_PROVIDER.EMAIL) &&
178
- plugins.some((plugin) => plugin.name === LOGIN_PROVIDER.EMAIL)
179
- ) {
180
- const plugin = getPlugin(LOGIN_PROVIDER.EMAIL);
181
- if (plugin.state.status === 'idle') {
182
- localStorage.setItem(GA_LAST_LOGIN_METHOD, LOGIN_PROVIDER.EMAIL);
183
- plugin.state.reset();
184
- plugin.state.magicToken = magicToken;
185
- connectState.chooseMethod = LOGIN_PROVIDER.EMAIL;
186
- setSelectedPlugin(plugin);
187
- forceUpdate();
188
- }
189
- }
190
- });
191
-
192
- // 考虑到切换账号的情况,此时 showEmailLogin 会根据当前上下文的 blocklet 发生变化,所以需要监听 showEmailLogin 的变化
193
- useEffect(() => {
194
- const finalList = [];
195
- if (showEmailLogin) {
196
- // 尽可能确保在 baseUrl 不变的情况下,不更改 email 插件的数据,以确保页面的展示不会出现闪烁
197
- const prevEmailPlugin = getPlugin(LOGIN_PROVIDER.EMAIL);
198
- if (prevEmailPlugin && prevEmailPlugin.baseUrl === emailPlugin.baseUrl) {
199
- finalList.push(prevEmailPlugin);
200
- } else {
201
- finalList.push(emailPlugin);
202
- }
203
- }
204
- setPlugins(finalList);
205
- connectState.retryConnect = defaultRetryConnect;
206
- // HACK: 必须要设置延迟,不然拿不到最新的 plugins 的值
207
- setTimeout(() => {
208
- setupMagicToken();
209
- }, 100);
210
- // eslint-disable-next-line react-hooks/exhaustive-deps
211
- }, [showEmailLogin]);
212
-
213
- const renderProviderList = providerList
214
- .map((item) => {
215
- if (item.provider === LOGIN_PROVIDER.WALLET) {
216
- if (browser.mobile.any && !showWalletOptions) {
217
- return (
218
- <MobileLoginItem
219
- t={t}
220
- isLatest={lastLoginMethod && lastLoginMethod === LOGIN_PROVIDER.WALLET}
221
- key={LOGIN_PROVIDER.WALLET}
222
- ref={walletLoginRef}
223
- tokenState={tokenState}
224
- sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
225
- locale={locale}
226
- tokenKey={tokenKey}
227
- disableSwitchApp={disableSwitchApp}
228
- onClick={handleMobileLoginClick}
229
- />
230
- );
231
- }
232
- // 是否显示 web 登录项
233
- // 1. 如果隐藏了二维码,会在新页面显示 wallet 登录项
234
- // 2. 如果显示了二维码,不需要在新页面显示 wallet 登录项,根据是否是同一协议、是否安装了钱包扩展、是否是移动端来判断是否显示
235
- const shouldShowWebLoginItem =
236
- hideQRCode || (!hideQRCode && (isSameProtocol || extension) && (!browser.mobile.any || extension));
237
- return shouldShowWebLoginItem ? (
238
- <WebLoginItem
239
- t={t}
240
- isLatest={lastLoginMethod && lastLoginMethod === LOGIN_PROVIDER.WALLET}
241
- key={LOGIN_PROVIDER.WALLET}
242
- ref={webLoginRef}
243
- tokenState={tokenState}
244
- webWalletUrl={webWalletUrl}
245
- sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
246
- disableSwitchApp={disableSwitchApp}
247
- autoConnect={!hideQRCode}
248
- onClick={() => {
249
- if (!hideQRCode) {
250
- handleWebLoginClick();
251
- } else {
252
- setShowWalletOptions(true);
253
- }
254
- }}
255
- />
256
- ) : null;
257
- }
258
-
259
- if (item.provider === LOGIN_PROVIDER.PASSKEY) {
260
- if (passkeyBehavior === 'none') {
261
- return null;
262
- }
263
- return (
264
- <PasskeyLoginItem
265
- key={LOGIN_PROVIDER.PASSKEY}
266
- ref={passkeyLoginRef}
267
- onSuccess={onSuccess}
268
- onError={onError}
269
- tokenState={tokenState}
270
- behavior={passkeyBehavior}
271
- sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
272
- onClick={() => {
273
- localStorage.setItem(GA_LAST_LOGIN_METHOD, LOGIN_PROVIDER.PASSKEY);
274
- const connectFn = passkeyLoginRef.current.connect;
275
- connectState.chooseMethod = 'passkey';
276
- connectState.retryConnect = () => {
277
- passkeyState.verifying = true;
278
- connectState.chooseMethod = 'passkey';
279
- connectFn();
280
- };
281
- }}
282
- slotProps={{
283
- icon: {
284
- sx: {
285
- fontSize: LOGIN_PROVIDER_ICON_SIZE,
286
- '& svg': {
287
- fontSize: LOGIN_PROVIDER_ICON_SIZE,
288
- width: '1em',
289
- height: '1em',
290
- },
291
- },
292
- },
293
- }}
294
- />
295
- );
296
- }
297
-
298
- if (item.provider === LOGIN_PROVIDER.EMAIL) {
299
- const findEmailPlugin = plugins.find((p) => p.name === LOGIN_PROVIDER.EMAIL);
300
- if (!findEmailPlugin) {
301
- return null;
302
- }
303
- return findEmailPlugin?.renderListItem({
304
- key: findEmailPlugin.name,
305
- sx: [size === 'small' ? { p: 1 } : { p: 2 }],
306
- // forceUpdate,
307
- });
308
- }
309
-
310
- if (item.type === 'oauth') {
311
- return (
312
- <LoginMethodItem
313
- t={t}
314
- isLatest={lastLoginMethod && lastLoginMethod === item.provider}
315
- key={item.provider}
316
- title={LOGIN_PROVIDER_NAME[item.provider]}
317
- icon={
318
- <ProviderIcon
319
- provider={item.provider}
320
- sx={{
321
- transform: 'scale(0.95)',
322
- width: LOGIN_PROVIDER_ICON_SIZE,
323
- height: LOGIN_PROVIDER_ICON_SIZE,
324
- color: 'text.primary',
325
- }}
326
- />
327
- }
328
- onClick={() => {
329
- handleLoginOAuth(item);
330
- connectState.retryConnect = () => {
331
- handleLoginOAuth(item);
332
- };
333
- }}
334
- sx={[size === 'small' ? { p: 1.2 } : { p: 2 }]}
335
- />
336
- );
337
- }
338
-
339
- return null;
340
- })
341
- .filter(Boolean);
342
-
343
- return (
344
- <Box className="did-connect__choose" sx={mergeSx({ flex: 1 }, slotProps?.root?.sx)}>
345
- <Box
346
- sx={{
347
- display: 'flex',
348
- flexDirection: 'column',
349
- gap: 2,
350
- }}>
351
- <Box
352
- sx={[
353
- {
354
- display: 'flex',
355
- flexDirection: 'column',
356
- ...(showWalletOptions && !browser.mobile.any ? { alignItems: 'center', gap: 0 } : { gap: 1.5 }),
357
- },
358
- ]}>
359
- {showWalletOptions && !browser.mobile.any ? (
360
- <WalletLoginOptions
361
- qrcode={qrcode}
362
- tokenState={tokenState}
363
- webWalletUrl={webWalletUrl}
364
- size={size}
365
- disableSwitchApp={disableSwitchApp}
366
- tokenKey={tokenKey}
367
- walletLoginRef={walletLoginRef}
368
- webLoginRef={webLoginRef}
369
- onMobileLoginClick={handleMobileLoginClick}
370
- onWebLoginClick={handleWebLoginClick}
371
- onBack={onlyWalletProvider ? undefined : handleWalletLoginBack}
372
- />
373
- ) : (
374
- <Box
375
- sx={{
376
- display: 'grid',
377
- gridTemplateColumns: 'repeat(12, 1fr)' /* 灵活的12列基础网格 */,
378
- gap: 1.5,
379
- '.arc-login-item:nth-child(-n+3)': {
380
- gridColumn: 'span 12',
381
- },
382
- // 当登录项大于等于 5 时,第三个登录项增加一个 marginBottom,用于分割独占一行的和一行多个的登录项
383
- '.arc-login-item:nth-child(3):nth-last-child(n+3)': {
384
- mb: 1,
385
- },
386
- '.arc-login-item:nth-child(4):last-child': {
387
- gridColumn: 'span 12',
388
- },
389
- '.arc-login-item:nth-child(4):nth-last-child(2), .arc-login-item:nth-child(4):nth-last-child(2), .arc-login-item:nth-child(4):nth-last-child(2) ~ .arc-login-item':
390
- {
391
- gridColumn: 'span 6',
392
- justifyContent: 'center',
393
- '.arc-login-item__body, .other-item-icon': {
394
- display: 'none',
395
- },
396
- },
397
- '.arc-login-item:nth-child(4):nth-last-child(3), .arc-login-item:nth-child(4):nth-last-child(3) ~ .arc-login-item':
398
- {
399
- justifyContent: 'center',
400
- gridColumn: 'span 4',
401
- '.arc-login-item__body, .other-item-icon': {
402
- display: 'none',
403
- },
404
- },
405
- '.arc-login-item:nth-child(4):nth-last-child(4), .arc-login-item:nth-child(4):nth-last-child(4) ~ .arc-login-item':
406
- {
407
- gridColumn: 'span 3',
408
- justifyContent: 'center',
409
- '.arc-login-item__body, .other-item-icon': {
410
- display: 'none',
411
- },
412
- },
413
- '&:has(.arc-login-item:nth-child(8)) .arc-login-item:nth-child(n+4)': {
414
- gridColumn: 'span 3',
415
- justifyContent: 'center',
416
- '.arc-login-item__body, .other-item-icon': {
417
- display: 'none',
418
- },
419
- },
420
- }}>
421
- {renderProviderList.length > 0 ? (
422
- renderProviderList
423
- ) : (
424
- <Empty
425
- className="arc-login-item"
426
- sx={{
427
- '.empty-content': {
428
- textAlign: 'center',
429
- },
430
- }}>
431
- {t('noAuthenticationProvider')}
432
- </Empty>
433
- )}
434
- </Box>
435
- )}
436
-
437
- {customItems.map((item) => (!item ? null : item))}
438
- </Box>
439
- </Box>
440
- </Box>
441
- );
442
- }
443
-
444
- ConnectProviderList.propTypes = {
445
- onSuccess: PropTypes.func,
446
- onError: PropTypes.func,
447
- size: PropTypes.oneOf(['small', 'normal', 'large']),
448
- tokenState: PropTypes.object.isRequired,
449
- webWalletUrl: PropTypes.string,
450
- tokenKey: PropTypes.string.isRequired,
451
- passkeyBehavior: PropTypes.oneOf(['none', 'both', 'only-existing', 'only-new']),
452
- onReset: PropTypes.func,
453
- providerList: PropTypes.array,
454
- slotProps: PropTypes.object,
455
- disableSwitchApp: PropTypes.bool,
456
- forceUpdate: PropTypes.func,
457
- magicToken: PropTypes.string,
458
- baseUrl: PropTypes.string,
459
- customItems: PropTypes.arrayOf(PropTypes.node),
460
- qrcode: PropTypes.node,
461
- hideQRCode: PropTypes.bool,
462
- };
@@ -1,139 +0,0 @@
1
- import { Box, Tooltip, Typography, useTheme } from '@mui/material';
2
- import { Icon } from '@iconify/react';
3
- import { isValidElement } from 'react';
4
- import PropTypes from 'prop-types';
5
- import noop from 'lodash/noop';
6
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
7
- import { LOGIN_PROVIDER_ICON_SIZE } from '@arcblock/ux/lib/Util/constant';
8
- import ArrowRightAltRoundedIcon from '@iconify-icons/material-symbols/arrow-right-alt-rounded';
9
-
10
- export default function LoginMethodItem({
11
- isLatest = false,
12
- title,
13
- description = null,
14
- icon,
15
- iconScale = 0.95,
16
- slotProps = {},
17
- mode = 'normal',
18
- t = noop,
19
- ...rest
20
- }) {
21
- const theme = useTheme();
22
-
23
- return (
24
- <Box
25
- {...rest}
26
- className="arc-login-item"
27
- sx={mergeSx(
28
- {
29
- position: 'relative',
30
- display: 'flex',
31
- alignItems: 'center',
32
- gap: 1,
33
- cursor: 'pointer',
34
- p: 1.2,
35
- borderRadius: 1,
36
- backgroundColor: isLatest ? 'grey.100' : 'grey.50',
37
- border: isLatest ? '1px solid' : 'none',
38
- borderColor: isLatest ? 'grey.100' : 'transparent',
39
- textDecoration: 'none',
40
- transition: 'background-color 0.5s',
41
- '&:hover, &:active, &.did-connect__choose-item__active': {
42
- backgroundColor: 'grey.100',
43
- },
44
- '& .other-item-icon': {
45
- opacity: '0',
46
- transform: 'translateX(-100%)',
47
- transition: 'transform 0.2s ease, opacity 0.1s ease',
48
- },
49
- '&:hover': {
50
- '& .other-item-icon': {
51
- display: 'inline-block',
52
- transform: 'translateX(0)',
53
- opacity: '1',
54
- },
55
- },
56
- },
57
- rest?.sx
58
- )}>
59
- <Tooltip title={title}>
60
- <Box
61
- className="arc-login-item__icon"
62
- sx={mergeSx(
63
- {
64
- display: 'flex',
65
- justifyContent: 'center',
66
- alignItems: 'center',
67
- color: 'text.primary',
68
- },
69
- slotProps?.icon?.sx
70
- )}>
71
- {isValidElement(icon) ? (
72
- icon
73
- ) : (
74
- <Box
75
- component={Icon}
76
- icon={icon}
77
- sx={{
78
- transform: `scale(${iconScale})`,
79
- width: LOGIN_PROVIDER_ICON_SIZE,
80
- height: LOGIN_PROVIDER_ICON_SIZE,
81
- }}
82
- />
83
- )}
84
- </Box>
85
- </Tooltip>
86
- {mode === 'normal' ? (
87
- <>
88
- <Box className="arc-login-item__body" sx={{ display: 'flex', flexDirection: 'column', flex: 1 }}>
89
- <Typography
90
- sx={{
91
- fontSize: 14,
92
- fontWeight: '500',
93
- color: 'text.primary',
94
- whiteSpace: 'nowrap',
95
- }}>
96
- {title}
97
- </Typography>
98
- {description ? (
99
- <Typography
100
- sx={{
101
- color: 'text.secondary',
102
- fontSize: 12,
103
- lineHeight: 1,
104
- }}>
105
- {description}
106
- </Typography>
107
- ) : null}
108
- </Box>
109
- {isLatest ? (
110
- <Typography
111
- component="span"
112
- className="latest-badge"
113
- style={{ color: theme.palette.text.secondary, fontSize: 11 }}>
114
- {t('lastUsed')}
115
- </Typography>
116
- ) : (
117
- <Icon
118
- className="other-item-icon"
119
- icon={ArrowRightAltRoundedIcon}
120
- fontSize="1.3rem"
121
- color={theme.palette.primary.main}
122
- />
123
- )}
124
- </>
125
- ) : null}
126
- </Box>
127
- );
128
- }
129
-
130
- LoginMethodItem.propTypes = {
131
- title: PropTypes.string.isRequired,
132
- description: PropTypes.string,
133
- icon: PropTypes.any.isRequired,
134
- iconScale: PropTypes.number,
135
- slotProps: PropTypes.object,
136
- mode: PropTypes.oneOf(['mini', 'simple', 'normal']),
137
- isLatest: PropTypes.bool,
138
- t: PropTypes.func,
139
- };