@arcblock/did-connect-react 3.4.15 → 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 (198) hide show
  1. package/dist/standalone/did-connect-react.css +1 -0
  2. package/dist/standalone/index.js +133700 -0
  3. package/lib/package.json.js +1 -1
  4. package/package.json +11 -6
  5. package/.aigne/doc-smith/config.yaml +0 -85
  6. package/.aigne/doc-smith/history.yaml +0 -6
  7. package/.aigne/doc-smith/output/structure-plan.json +0 -204
  8. package/.aigne/doc-smith/translation-cache.yaml +0 -11
  9. package/.aigne/doc-smith/upload-cache.yaml +0 -213
  10. package/docs/_sidebar.md +0 -18
  11. package/docs/advanced-authentication-methods.ja.md +0 -261
  12. package/docs/advanced-authentication-methods.md +0 -261
  13. package/docs/advanced-authentication-methods.zh-TW.md +0 -261
  14. package/docs/advanced-authentication-methods.zh.md +0 -261
  15. package/docs/advanced-utilities.ja.md +0 -132
  16. package/docs/advanced-utilities.md +0 -132
  17. package/docs/advanced-utilities.zh-TW.md +0 -132
  18. package/docs/advanced-utilities.zh.md +0 -132
  19. package/docs/advanced.ja.md +0 -95
  20. package/docs/advanced.md +0 -95
  21. package/docs/advanced.zh-TW.md +0 -95
  22. package/docs/advanced.zh.md +0 -95
  23. package/docs/api-reference.ja.md +0 -178
  24. package/docs/api-reference.md +0 -178
  25. package/docs/api-reference.zh-TW.md +0 -178
  26. package/docs/api-reference.zh.md +0 -178
  27. package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
  28. package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
  29. package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
  30. package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
  31. package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
  32. package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
  33. package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
  34. package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
  35. package/docs/assets/diagram/overview-01.ja.jpg +0 -0
  36. package/docs/assets/diagram/overview-01.jpg +0 -0
  37. package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
  38. package/docs/assets/diagram/overview-01.zh.jpg +0 -0
  39. package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
  40. package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
  41. package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
  42. package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
  43. package/docs/core-components-did-connect.ja.md +0 -166
  44. package/docs/core-components-did-connect.md +0 -166
  45. package/docs/core-components-did-connect.zh-TW.md +0 -166
  46. package/docs/core-components-did-connect.zh.md +0 -166
  47. package/docs/core-components-session-provider.ja.md +0 -197
  48. package/docs/core-components-session-provider.md +0 -197
  49. package/docs/core-components-session-provider.zh-TW.md +0 -197
  50. package/docs/core-components-session-provider.zh.md +0 -197
  51. package/docs/core-components.ja.md +0 -16
  52. package/docs/core-components.md +0 -16
  53. package/docs/core-components.zh-TW.md +0 -16
  54. package/docs/core-components.zh.md +0 -16
  55. package/docs/getting-started.ja.md +0 -138
  56. package/docs/getting-started.md +0 -138
  57. package/docs/getting-started.zh-TW.md +0 -138
  58. package/docs/getting-started.zh.md +0 -138
  59. package/docs/hooks-use-connect.ja.md +0 -178
  60. package/docs/hooks-use-connect.md +0 -178
  61. package/docs/hooks-use-connect.zh-TW.md +0 -178
  62. package/docs/hooks-use-connect.zh.md +0 -178
  63. package/docs/hooks-use-did.ja.md +0 -107
  64. package/docs/hooks-use-did.md +0 -107
  65. package/docs/hooks-use-did.zh-TW.md +0 -107
  66. package/docs/hooks-use-did.zh.md +0 -107
  67. package/docs/hooks-use-oauth-passkey.ja.md +0 -188
  68. package/docs/hooks-use-oauth-passkey.md +0 -188
  69. package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
  70. package/docs/hooks-use-oauth-passkey.zh.md +0 -188
  71. package/docs/hooks.ja.md +0 -23
  72. package/docs/hooks.md +0 -23
  73. package/docs/hooks.zh-TW.md +0 -23
  74. package/docs/hooks.zh.md +0 -23
  75. package/docs/overview.ja.md +0 -119
  76. package/docs/overview.md +0 -119
  77. package/docs/overview.zh-TW.md +0 -119
  78. package/docs/overview.zh.md +0 -119
  79. package/docs/ui-components-address.ja.md +0 -121
  80. package/docs/ui-components-address.md +0 -121
  81. package/docs/ui-components-address.zh-TW.md +0 -121
  82. package/docs/ui-components-address.zh.md +0 -121
  83. package/docs/ui-components-avatar.ja.md +0 -65
  84. package/docs/ui-components-avatar.md +0 -65
  85. package/docs/ui-components-avatar.zh-TW.md +0 -65
  86. package/docs/ui-components-avatar.zh.md +0 -65
  87. package/docs/ui-components-button.ja.md +0 -99
  88. package/docs/ui-components-button.md +0 -99
  89. package/docs/ui-components-button.zh-TW.md +0 -99
  90. package/docs/ui-components-button.zh.md +0 -99
  91. package/docs/ui-components-logo.ja.md +0 -52
  92. package/docs/ui-components-logo.md +0 -52
  93. package/docs/ui-components-logo.zh-TW.md +0 -52
  94. package/docs/ui-components-logo.zh.md +0 -52
  95. package/docs/ui-components.ja.md +0 -57
  96. package/docs/ui-components.md +0 -57
  97. package/docs/ui-components.zh-TW.md +0 -57
  98. package/docs/ui-components.zh.md +0 -57
  99. package/glossary.md +0 -1
  100. package/src/Address/index.jsx +0 -2
  101. package/src/Avatar/index.jsx +0 -2
  102. package/src/Button/Button.stories.jsx +0 -7
  103. package/src/Button/index.jsx +0 -21
  104. package/src/Connect/Connect.stories.jsx +0 -34
  105. package/src/Connect/assets/locale.js +0 -149
  106. package/src/Connect/assets/login-bg.png +0 -0
  107. package/src/Connect/assets/login-slogan.js +0 -7
  108. package/src/Connect/components/action-button.jsx +0 -22
  109. package/src/Connect/components/app-tips.jsx +0 -156
  110. package/src/Connect/components/auto-height.jsx +0 -38
  111. package/src/Connect/components/back-button.jsx +0 -24
  112. package/src/Connect/components/connect-status.jsx +0 -259
  113. package/src/Connect/components/did-connect-title.jsx +0 -107
  114. package/src/Connect/components/download-tips.jsx +0 -55
  115. package/src/Connect/components/loading.jsx +0 -25
  116. package/src/Connect/components/login-item/connect-choose-list.jsx +0 -328
  117. package/src/Connect/components/login-item/connect-provider-list.jsx +0 -473
  118. package/src/Connect/components/login-item/login-method-item.jsx +0 -139
  119. package/src/Connect/components/login-item/mobile-login-item.jsx +0 -184
  120. package/src/Connect/components/login-item/passkey-login-item.jsx +0 -56
  121. package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
  122. package/src/Connect/components/login-item/web-login-item.jsx +0 -159
  123. package/src/Connect/components/mask-overlay.jsx +0 -32
  124. package/src/Connect/components/refresh-overlay.jsx +0 -52
  125. package/src/Connect/components/switch-app.jsx +0 -69
  126. package/src/Connect/connect.jsx +0 -635
  127. package/src/Connect/contexts/state.jsx +0 -235
  128. package/src/Connect/fallback-connect.jsx +0 -47
  129. package/src/Connect/fullpage.jsx +0 -3
  130. package/src/Connect/hooks/auth-url.js +0 -31
  131. package/src/Connect/hooks/method-list.js +0 -121
  132. package/src/Connect/hooks/page-show.js +0 -24
  133. package/src/Connect/hooks/provider-list.js +0 -168
  134. package/src/Connect/hooks/security.js +0 -40
  135. package/src/Connect/hooks/token.js +0 -627
  136. package/src/Connect/hooks/use-apps.js +0 -69
  137. package/src/Connect/hooks/use-quick-connect.js +0 -119
  138. package/src/Connect/index.jsx +0 -21
  139. package/src/Connect/landing-page.jsx +0 -3
  140. package/src/Connect/plugins/email/index.jsx +0 -85
  141. package/src/Connect/plugins/email/list-item.jsx +0 -35
  142. package/src/Connect/plugins/email/placeholder.jsx +0 -372
  143. package/src/Connect/plugins/index.js +0 -2
  144. package/src/Connect/use-connect.jsx +0 -321
  145. package/src/Connect/with-blocklet.jsx +0 -26
  146. package/src/Connect/with-bridge-call.jsx +0 -138
  147. package/src/Federated/context.jsx +0 -93
  148. package/src/Federated/index.jsx +0 -1
  149. package/src/Logo/index.jsx +0 -2
  150. package/src/OAuth/bind-conflict-alert.jsx +0 -37
  151. package/src/OAuth/context.jsx +0 -407
  152. package/src/OAuth/guest.svg +0 -20
  153. package/src/OAuth/index.jsx +0 -1
  154. package/src/OAuth/passport-switcher.jsx +0 -2
  155. package/src/Passkey/actions.jsx +0 -217
  156. package/src/Passkey/constants.js +0 -2
  157. package/src/Passkey/context.jsx +0 -395
  158. package/src/Passkey/dialog.jsx +0 -401
  159. package/src/Passkey/icon.jsx +0 -10
  160. package/src/Passkey/index.jsx +0 -2
  161. package/src/Service/index.jsx +0 -96
  162. package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
  163. package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
  164. package/src/Session/context.jsx +0 -7
  165. package/src/Session/did-spaces-guide.jsx +0 -173
  166. package/src/Session/handler.jsx +0 -98
  167. package/src/Session/hooks/use-federated.js +0 -91
  168. package/src/Session/hooks/use-mobile.jsx +0 -6
  169. package/src/Session/hooks/use-protected-routes.js +0 -16
  170. package/src/Session/hooks/use-session-token.js +0 -400
  171. package/src/Session/hooks/use-verify.jsx +0 -76
  172. package/src/Session/index.jsx +0 -1789
  173. package/src/Session/libs/constants.js +0 -17
  174. package/src/Session/libs/did-spaces.js +0 -38
  175. package/src/Session/libs/federated.js +0 -82
  176. package/src/Session/libs/index.js +0 -5
  177. package/src/Session/libs/locales.js +0 -160
  178. package/src/Session/libs/login-mobile.js +0 -80
  179. package/src/Session/window-focus-aware.jsx +0 -28
  180. package/src/SessionManager/index.jsx +0 -2
  181. package/src/Storage/engine/cookie.js +0 -25
  182. package/src/Storage/engine/local-storage.js +0 -57
  183. package/src/Storage/index.js +0 -25
  184. package/src/User/index.js +0 -4
  185. package/src/User/use-did.js +0 -80
  186. package/src/User/wrap-did.jsx +0 -18
  187. package/src/WebWalletSWKeeper/index.jsx +0 -3
  188. package/src/components/PassportSwitcher.jsx +0 -160
  189. package/src/constant.js +0 -27
  190. package/src/error.js +0 -6
  191. package/src/hooks/use-locale.jsx +0 -6
  192. package/src/index.js +0 -32
  193. package/src/locales/en.jsx +0 -15
  194. package/src/locales/index.jsx +0 -13
  195. package/src/locales/zh.jsx +0 -15
  196. package/src/types.d.ts +0 -355
  197. package/src/utils.js +0 -413
  198. package/vite.config.mjs +0 -29
@@ -1,635 +0,0 @@
1
- import { use, useEffect, useRef, useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import { Box, Divider, Skeleton } from '@mui/material';
4
- import {
5
- useCreation,
6
- useDebounceFn,
7
- useMemoizedFn,
8
- useMount,
9
- usePrevious,
10
- useSize,
11
- useUpdate,
12
- useUpdateEffect,
13
- } from 'ahooks';
14
- import noop from 'lodash/noop';
15
- import isUndefined from 'lodash/isUndefined';
16
-
17
- import CloseButton from '@arcblock/ux/lib/CloseButton';
18
- import {
19
- LOGIN_PROVIDER,
20
- LOGIN_PROVIDER_NAME,
21
- OAUTH_PROVIDER,
22
- DID_CONNECT_MEDIUM_WIDTH,
23
- DID_CONNECT_SMALL_WIDTH,
24
- LAST_USED_LOGIN_METHOD,
25
- WALLET_LOGIN_METHOD,
26
- } from '@arcblock/ux/lib/Util/constant';
27
- import QRCode from '@arcblock/ux/lib/QRCode';
28
- import { DIDConnectFooter } from '@arcblock/ux/lib/DIDConnect';
29
- import { useTheme } from '@arcblock/ux/lib/Theme';
30
- import ProviderIcon from '@arcblock/ux/lib/DIDConnect/provider-icon';
31
-
32
- import '@fontsource/lexend/400.css';
33
- import '@fontsource/lexend/600.css';
34
-
35
- import { SessionContext } from '../Session/context';
36
- import { StateProvider, useStateContext } from './contexts/state';
37
- import ConnectProviderList from './components/login-item/connect-provider-list';
38
- import AutoHeight from './components/auto-height';
39
- import useToken from './hooks/token';
40
- import { useOAuth } from '../OAuth';
41
- import ConnectStatus from './components/connect-status';
42
- import { usePasskey } from '../Passkey/context';
43
- import { API_DID_PREFIX, DEFAULT_TIMEOUT, BUSY_STATUS, CHECK_STATUS_INTERVAL } from '../constant';
44
- import { getWebWalletUrl } from '../utils';
45
- import DIDConnectTitle from './components/did-connect-title';
46
- import DownloadTips from './components/download-tips';
47
- import useProviderList from './hooks/provider-list';
48
- import useAuthUrl from './hooks/auth-url';
49
- import { getWalletDid } from '../User/use-did';
50
- import FallbackConnect from './fallback-connect';
51
-
52
- function Connect({
53
- hideCloseButton = false,
54
- mode = 'dialog',
55
- action,
56
- baseUrl = '',
57
- checkFn,
58
- checkInterval = CHECK_STATUS_INTERVAL,
59
- checkTimeout = DEFAULT_TIMEOUT * 1000,
60
- prefix = API_DID_PREFIX,
61
- tokenKey = '_t_',
62
- locale = 'en',
63
- encKey = '_ek_',
64
- autoConnect = true,
65
- forceConnected = true,
66
- saveConnect = true,
67
- useSocket = true,
68
- allowWallet = true,
69
- provider = '',
70
- messages = {},
71
- passkeyBehavior = 'none',
72
- webWalletUrl = getWebWalletUrl(),
73
- enabledConnectTypes = ['web', 'mobile', ...Object.keys(OAUTH_PROVIDER)],
74
- extraContent = null,
75
- disableSwitchApp = false,
76
- magicToken = undefined,
77
- customItems = [],
78
- onClose = noop,
79
- onError = noop,
80
- onSuccess = noop,
81
- onRecreateSession = noop,
82
- setColor = noop,
83
- }) {
84
- const theme = useTheme();
85
- const forceUpdate = useUpdate();
86
- const sessionCtx = use(SessionContext);
87
- const currentUserDid = getWalletDid(sessionCtx?.session?.user);
88
-
89
- const {
90
- t,
91
- staticState,
92
- connectState,
93
- extraParams,
94
- currentAppInfo,
95
- currentAppColor,
96
- // 插件相关
97
- selectedPlugin,
98
- blocklet,
99
- masterBlocklet,
100
- showWalletOptions,
101
- setShowWalletOptions,
102
- lastLoginMethod,
103
- } = useStateContext();
104
-
105
- // 包装 onSuccess,在 wallet 登录成功时记录细分的登录方式
106
- const wrappedOnSuccess = useMemoizedFn((...args) => {
107
- // walletMethod 存在说明是点击按钮的 wallet 登录,为空说明是直接扫码登录
108
- // 直接扫码登录不对应任何按钮,设置为 SCAN 避免旧的 last-used 继续显示
109
- const method = connectState.walletMethod || WALLET_LOGIN_METHOD.SCAN;
110
- localStorage.setItem(LAST_USED_LOGIN_METHOD, method);
111
- return onSuccess(...args);
112
- });
113
-
114
- const { state, generate, cancelWhenScanned } = useToken({
115
- action,
116
- baseUrl,
117
- checkFn,
118
- checkInterval,
119
- checkTimeout,
120
- extraParams,
121
- prefix,
122
- onError,
123
- onSuccess: wrappedOnSuccess,
124
- locale,
125
- tokenKey,
126
- encKey,
127
- autoConnect,
128
- forceConnected: forceConnected === true ? currentUserDid || true : forceConnected,
129
- saveConnect,
130
- useSocket,
131
- allowWallet,
132
- provider,
133
- });
134
- const refreshingToken = useRef(false);
135
- const rootRef = useRef(null);
136
- const size = useSize(rootRef);
137
- const isSmallView = useCreation(() => {
138
- if (size) {
139
- return size.width < DID_CONNECT_MEDIUM_WIDTH - 50;
140
- }
141
- return true;
142
- }, [size, size?.width]);
143
-
144
- const [isInitSmallView, setIsInitSmallView] = useState(false);
145
-
146
- useMount(() => {
147
- setIsInitSmallView(size?.width < DID_CONNECT_MEDIUM_WIDTH - 50);
148
- });
149
-
150
- const { oauthState, setBaseUrl } = useOAuth();
151
- const { passkeyState, setTargetAppPid } = usePasskey();
152
-
153
- useMount(() => {
154
- setBaseUrl(baseUrl);
155
- setTargetAppPid(blocklet?.appPid);
156
- // 每次打开 did-connect,都重置状态
157
- state.reset();
158
- oauthState.reset();
159
- passkeyState.reset();
160
- });
161
-
162
- useEffect(() => {
163
- setColor(currentAppColor);
164
- // eslint-disable-next-line react-hooks/exhaustive-deps
165
- }, [currentAppColor]);
166
-
167
- const statusMessages = useCreation(() => {
168
- return {
169
- confirm: messages.confirm,
170
- success: messages.success,
171
- error: selectedPlugin?.state?.error || state.error || passkeyState.error || oauthState.error || '',
172
- };
173
- }, [
174
- messages.confirm,
175
- messages.success,
176
- state.error,
177
- oauthState.error,
178
- passkeyState.error,
179
- selectedPlugin?.state?.error,
180
- ]);
181
-
182
- const showStatus = useCreation(() => {
183
- return (
184
- BUSY_STATUS.includes(passkeyState.status) ||
185
- BUSY_STATUS.includes(oauthState.status) ||
186
- BUSY_STATUS.includes(state.status) ||
187
- BUSY_STATUS.includes(selectedPlugin?.state?.computedStatus)
188
- );
189
- }, [state.status, oauthState.status, passkeyState.status, selectedPlugin?.state?.computedStatus]);
190
-
191
- const _onRecreateSession = useMemoizedFn(() => {
192
- connectState.chooseMethod = 'wallet';
193
- connectState.walletMethod = '';
194
- onRecreateSession();
195
- });
196
-
197
- const handleReset = useMemoizedFn(async () => {
198
- _onRecreateSession();
199
- oauthState.reset();
200
- passkeyState.reset();
201
- await generate(false);
202
- });
203
- const handleRetry = useMemoizedFn(() => {
204
- connectState?.retryConnect();
205
- });
206
- const handleCancel = useMemoizedFn(() => {
207
- _onRecreateSession();
208
- oauthState.reset();
209
- passkeyState.reset();
210
- selectedPlugin?.state?.reset();
211
- staticState.current.cancelCount++;
212
- cancelWhenScanned();
213
- });
214
-
215
- const { run: debounceHandleTimeout } = useDebounceFn(
216
- () => {
217
- if (refreshingToken.current) return;
218
- if (state.status === 'timeout') {
219
- refreshingToken.current = true;
220
- state.reset();
221
- handleReset();
222
- refreshingToken.current = false;
223
- }
224
- },
225
- { leading: true, trailing: false }
226
- );
227
- // eslint-disable-next-line react-hooks/exhaustive-deps
228
- useEffect(debounceHandleTimeout, [state.status]);
229
-
230
- const chooseMethod = useCreation(() => {
231
- return LOGIN_PROVIDER_NAME[connectState.chooseMethod] || 'DID Wallet';
232
- }, [connectState.chooseMethod]);
233
-
234
- const { providerList, hideQRCode, hideChooseList, loadingProviderList } = useProviderList({
235
- action: state.action,
236
- sourceAppPid: connectState?.sourceAppPid,
237
- allowWallet,
238
- passkeyBehavior,
239
- webWalletUrl,
240
- mode,
241
- blocklet: connectState?.sourceAppPid ? masterBlocklet : blocklet,
242
- isSmallView,
243
- lastLoginMethod,
244
- });
245
-
246
- const prevSourceAppPid = usePrevious(connectState?.sourceAppPid);
247
-
248
- // 切换了当前展示的应用后,需要重新生成二维码
249
- useUpdateEffect(() => {
250
- // HACK: connectState.sourceAppPid 是用户在页面中执行操作修改的值,最开始的时候就是 undefined,并在 did-connect 页面加载后,会由 app-info 触发一次更新(无论如何都会触发,这一次更新不应该触发 generate)
251
- if (isUndefined(prevSourceAppPid)) {
252
- return;
253
- }
254
- generate();
255
- }, [connectState?.sourceAppPid]);
256
-
257
- const getSpacingNumber = (value) => {
258
- const spacingValue = theme.spacing(value);
259
- return parseInt(spacingValue, 10);
260
- };
261
- const closeButton = useCreation(() => {
262
- return hideCloseButton ? null : (
263
- <CloseButton
264
- onClose={onClose}
265
- sx={{
266
- position: 'absolute',
267
- right: 14,
268
- top: 14,
269
- }}
270
- />
271
- );
272
- }, [hideCloseButton, onClose]);
273
-
274
- // 预渲染 ConnectStatus,通过 CSS 控制显示/隐藏,避免 DOM 的创建/销毁导致卡顿
275
- const statusContent = (
276
- <Box
277
- sx={{
278
- flex: 1,
279
- display: showStatus ? 'flex' : 'none',
280
- alignItems: 'center',
281
- justifyContent: 'center',
282
- }}>
283
- <Box>
284
- <ConnectStatus
285
- status={selectedPlugin?.state?.computedStatus || oauthState.status || passkeyState.status || state.status}
286
- nextWorkflow={state.nextWorkflow}
287
- mfaCode={state.mfaCode}
288
- onCancel={handleCancel}
289
- onRetry={handleRetry}
290
- onClose={onClose}
291
- messages={statusMessages}
292
- locale={locale}
293
- className="did-connect__auth-status auth-status"
294
- loadingIcon={
295
- connectState.chooseMethod ? (
296
- <ProviderIcon provider={connectState.chooseMethod} sx={{ color: 'text.primary' }} />
297
- ) : null
298
- }
299
- chooseMethod={chooseMethod}
300
- hideRetry={connectState.chooseMethod === 'email'}
301
- hideBack={!!magicToken}
302
- />
303
- </Box>
304
- </Box>
305
- );
306
-
307
- const urlWithParams = useAuthUrl({ disableSwitchApp, tokenState: state });
308
-
309
- // 防止二维码抖动,使用 useCreation 进行缓存
310
- const qrcode = useCreation(() => {
311
- const backgroundColor = theme.mode === 'dark' ? theme.palette.grey[600] : 'white';
312
-
313
- let qrcodeSize = hideChooseList ? 240 - getSpacingNumber(3) * 2 : 196 - getSpacingNumber(2) * 2;
314
- let padding = hideChooseList ? 3 : 2;
315
- // 如果显示钱包登录,将 download tips 移动到顶部,调整间距,增加二维码的尺寸和内边距
316
- if (showWalletOptions) {
317
- padding = 1;
318
- qrcodeSize += getSpacingNumber(padding) * 2;
319
- }
320
- return (
321
- <Box
322
- className="did-connect__qrcode"
323
- sx={{
324
- p: padding,
325
- width: (hideChooseList ? 240 : 196) + getSpacingNumber(1) * 2,
326
- height: (hideChooseList ? 240 : 196) + getSpacingNumber(1) * 2,
327
- }}>
328
- {state.url ? (
329
- <QRCode
330
- data={urlWithParams}
331
- size={qrcodeSize}
332
- sx={{
333
- width: qrcodeSize + getSpacingNumber(1) * 2,
334
- height: qrcodeSize + getSpacingNumber(1) * 2,
335
- flex: 1,
336
- backgroundColor,
337
- p: 1,
338
- fontSize: 0,
339
- textAlign: 'center',
340
- boxSizing: 'border-box',
341
- borderRadius: 1,
342
- border: '1px solid',
343
- borderColor: 'divider',
344
- }}
345
- config={{
346
- backgroundOptions: {
347
- color: backgroundColor,
348
- },
349
- }}
350
- />
351
- ) : (
352
- <Skeleton
353
- animation="wave"
354
- variant="rectangular"
355
- sx={{
356
- position: 'absolute',
357
- left: getSpacingNumber(2) + 1,
358
- right: getSpacingNumber(2) + 1,
359
- top: getSpacingNumber(2) + 1,
360
- bottom: getSpacingNumber(2) + 1,
361
- borderRadius: 1,
362
- zIndex: 1,
363
- width: 'auto',
364
- height: 'auto',
365
- }}
366
- />
367
- )}
368
- </Box>
369
- );
370
- }, [urlWithParams, hideChooseList, showWalletOptions]);
371
-
372
- const didConnectFlexDirection = useCreation(() => {
373
- if (hideChooseList) {
374
- return 'column-reverse';
375
- }
376
- if (!hideQRCode && isInitSmallView) {
377
- return 'column';
378
- }
379
- return 'row';
380
- }, [hideChooseList, isInitSmallView, hideQRCode]);
381
-
382
- const qrcodeContent = useCreation(() => {
383
- if (!qrcode) return null;
384
- return (
385
- <Box
386
- sx={{
387
- display: 'flex',
388
- alignItems: 'center',
389
- overflowX: 'auto',
390
- overflowY: 'visible',
391
- maxWidth: '100%',
392
- margin: 'auto',
393
- }}>
394
- <Box
395
- sx={{
396
- fontSize: 0,
397
- position: 'relative',
398
- ...(showWalletOptions
399
- ? {
400
- mt: hideChooseList ? 4 : 2.5,
401
- mb: hideChooseList ? 0 : 0,
402
- }
403
- : {
404
- mb: hideChooseList ? 4 : 2.5,
405
- mt: 0,
406
- }),
407
- }}>
408
- {qrcode}
409
- <Box
410
- sx={{
411
- position: 'absolute',
412
- color: 'text.secondary',
413
- fontSize: 12,
414
- zIndex: 1,
415
- whiteSpace: 'nowrap',
416
- ...(showWalletOptions
417
- ? {
418
- top: hideChooseList ? -8 : -4,
419
- transform: 'translateY(-100%)',
420
- }
421
- : {
422
- bottom: hideChooseList ? -8 : -4,
423
- transform: 'translateY(100%)',
424
- }),
425
- left: 0,
426
- right: 0,
427
- textAlign: 'center',
428
- }}>
429
- {t('scanWithWallet1')} <DownloadTips /> {t('scanWithWallet2')}
430
- </Box>
431
- </Box>
432
- </Box>
433
- );
434
- }, [qrcode, hideChooseList, showWalletOptions]);
435
-
436
- const fallbackContent = (
437
- <Box
438
- className="did-connect__body"
439
- sx={{
440
- display: 'flex',
441
- flexDirection: didConnectFlexDirection,
442
- justifyContent: 'center',
443
- alignItems: 'stretch',
444
- flex: 1,
445
- gap: !hideQRCode && isSmallView ? 0 : 1.5,
446
- overflow: 'visible',
447
- px: hideChooseList ? 2 : 0,
448
- }}>
449
- {!showStatus && !hideQRCode ? (
450
- <>
451
- {qrcodeContent}
452
- {hideChooseList ? null : (
453
- <Box>
454
- <Divider
455
- orientation="vertical"
456
- sx={{
457
- fontSize: 12,
458
- color: 'text.hint',
459
- '&::before, &::after': {
460
- borderColor: 'divider',
461
- },
462
- }}>
463
- or
464
- </Divider>
465
- </Box>
466
- )}
467
- </>
468
- ) : null}
469
- <Box
470
- sx={{
471
- display: 'flex',
472
- flex: 1,
473
- }}>
474
- {/* ConnectStatus:始终渲染,通过 CSS 控制显示/隐藏 */}
475
- {statusContent}
476
- {/* ConnectProviderList:始终渲染,通过 CSS 控制显示/隐藏 */}
477
- <ConnectProviderList
478
- slotProps={{
479
- root: {
480
- sx: [showStatus ? { display: 'none' } : {}],
481
- },
482
- }}
483
- allowWallet={allowWallet}
484
- size={hideQRCode && mode !== 'dialog' ? 'normal' : 'small'}
485
- tokenState={state}
486
- hideQRCode={hideQRCode}
487
- messages={messages}
488
- tokenKey={tokenKey}
489
- onSuccess={onSuccess}
490
- passkeyBehavior={passkeyBehavior}
491
- webWalletUrl={webWalletUrl}
492
- extraContent={extraContent}
493
- enabledConnectTypes={enabledConnectTypes}
494
- onReset={handleReset}
495
- disableSwitchApp={disableSwitchApp}
496
- forceUpdate={forceUpdate}
497
- magicToken={magicToken}
498
- baseUrl={baseUrl}
499
- customItems={customItems}
500
- providerList={providerList}
501
- qrcode={qrcodeContent}
502
- />
503
- </Box>
504
- </Box>
505
- );
506
- let contentResult = fallbackContent;
507
- if (selectedPlugin) {
508
- contentResult = selectedPlugin.renderPlaceholder({
509
- fallback: fallbackContent,
510
- forceUpdate,
511
- onSuccess,
512
- onError,
513
- });
514
- } else {
515
- contentResult = fallbackContent;
516
- }
517
-
518
- const containerWidth = hideQRCode || showStatus ? DID_CONNECT_SMALL_WIDTH : DID_CONNECT_MEDIUM_WIDTH;
519
-
520
- if (loadingProviderList) {
521
- return <FallbackConnect />;
522
- }
523
- return (
524
- <Box
525
- ref={rootRef}
526
- className="did-connect__root"
527
- sx={{
528
- backgroundColor: 'background.default',
529
- display: 'flex',
530
- flexDirection: 'column',
531
- height: '100%',
532
- position: 'relative',
533
- maxWidth: '100%',
534
- width:
535
- // eslint-disable-next-line no-nested-ternary
536
- mode === 'drawer' ? '100%' : showWalletOptions ? containerWidth - 20 : containerWidth,
537
- transition: 'width 0.2s ease-in-out',
538
- margin: 'auto',
539
- p: 3,
540
- pb: 0,
541
- gap: 2.5,
542
- }}>
543
- <Box data-did-auth-url={state.url} sx={{ display: 'none' }} />
544
- <DIDConnectTitle
545
- title={messages.title}
546
- description={messages.scan}
547
- extraContent={extraContent}
548
- disableSwitchApp={disableSwitchApp}
549
- showWalletOptions={showWalletOptions}
550
- onBack={() => setShowWalletOptions(false)}
551
- />
552
- <AutoHeight initHeight={24 + 16 + 32}>{contentResult}</AutoHeight>
553
- <DIDConnectFooter currentAppInfo={currentAppInfo} currentAppColor={currentAppColor} />
554
- {closeButton}
555
- </Box>
556
- );
557
- }
558
-
559
- Connect.propTypes = {
560
- mode: PropTypes.oneOf(['dialog', 'drawer', 'page']),
561
-
562
- action: PropTypes.string.isRequired,
563
- baseUrl: PropTypes.string,
564
- checkFn: PropTypes.func.isRequired,
565
- checkInterval: PropTypes.number,
566
- checkTimeout: PropTypes.number,
567
- // extraParams: PropTypes.object, // 需要使用 useStateContext 中导出的
568
- prefix: PropTypes.string,
569
- messages: PropTypes.object,
570
- tokenKey: PropTypes.string,
571
- locale: PropTypes.oneOf(['en', 'zh', '']),
572
- encKey: PropTypes.string,
573
- autoConnect: PropTypes.bool,
574
- forceConnected: PropTypes.oneOfType([PropTypes.bool, PropTypes.string]),
575
- saveConnect: PropTypes.bool,
576
- useSocket: PropTypes.bool,
577
- extraContent: PropTypes.any,
578
- passkeyBehavior: PropTypes.oneOf(['none', 'both', 'only-existing', 'only-new']),
579
- enabledConnectTypes: PropTypes.arrayOf(PropTypes.oneOf(['web', 'mobile', ...Object.keys(OAUTH_PROVIDER)])),
580
- webWalletUrl: PropTypes.string,
581
-
582
- allowWallet: PropTypes.bool,
583
- provider: PropTypes.oneOf([LOGIN_PROVIDER.WALLET, ...Object.keys(OAUTH_PROVIDER), '']),
584
- hideCloseButton: PropTypes.bool,
585
- disableSwitchApp: PropTypes.bool,
586
- onClose: PropTypes.func,
587
- onError: PropTypes.func,
588
- onSuccess: PropTypes.func,
589
- onRecreateSession: PropTypes.func,
590
- setColor: PropTypes.func,
591
- magicToken: PropTypes.string,
592
- customItems: PropTypes.arrayOf(PropTypes.node),
593
- };
594
-
595
- function WrapConnect({ testOnlyBorderColor = undefined, ...props }) {
596
- const { checkFn, extraParams = {}, blocklet, masterBlocklet, action, locale = 'en' } = props;
597
- if (typeof checkFn !== 'function') {
598
- throw new Error('Cannot initialize did connect component without a fetchFn');
599
- }
600
-
601
- return (
602
- <StateProvider
603
- blocklet={blocklet}
604
- masterBlocklet={masterBlocklet}
605
- action={action}
606
- locale={locale}
607
- extraParams={extraParams}
608
- testOnlyBorderColor={testOnlyBorderColor}
609
- sx={{
610
- position: 'relative',
611
- width: '100%',
612
- height: '100%',
613
- lineHeight: 1.2,
614
- color: 'grey.700',
615
- '&, & *, & *:before, & *:after': {
616
- fontFamily: 'Lexend', // 保持跟 DID Wallet 一致
617
- boxSizing: 'border-box',
618
- },
619
- }}>
620
- <Connect {...props} />
621
- </StateProvider>
622
- );
623
- }
624
-
625
- WrapConnect.propTypes = {
626
- checkFn: PropTypes.func.isRequired,
627
- extraParams: PropTypes.object,
628
- blocklet: PropTypes.object.isRequired,
629
- masterBlocklet: PropTypes.object,
630
- action: PropTypes.string.isRequired,
631
- locale: PropTypes.string,
632
- testOnlyBorderColor: PropTypes.string,
633
- };
634
-
635
- export default WrapConnect;