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