@arcblock/did-connect-react 3.4.15 → 3.5.1

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,184 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { CircularProgress } from '@mui/material';
3
- import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
4
- import bridge from '@arcblock/bridge';
5
- import { useBrowser } from '@arcblock/react-hooks';
6
- import noop from 'lodash/noop';
7
- import { useImperativeHandle } from 'react';
8
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
9
- import ProviderIcon from '@arcblock/ux/lib/DIDConnect/provider-icon';
10
- import { LOGIN_PROVIDER, LOGIN_PROVIDER_ICON_SIZE, WALLET_LOGIN_METHOD } from '@arcblock/ux/lib/Util/constant';
11
-
12
- import { useStateContext } from '../../contexts/state';
13
- import LoginMethodItem from './login-method-item';
14
- import { logger } from '../../../utils';
15
- import useAuthUrl from '../../hooks/auth-url';
16
-
17
- export default function MobileLoginItem({
18
- isTablet = false,
19
- ref = null,
20
- tokenState,
21
- locale,
22
- tokenKey,
23
- onClick = noop,
24
- disableSwitchApp = false,
25
- ...rest
26
- }) {
27
- const currentState = useReactive({
28
- loading: false,
29
- });
30
- const { isWalletWebview, connectState } = useStateContext();
31
- const title = 'DID Wallet';
32
- const browser = useBrowser();
33
-
34
- const callbackUrl = new URL(window.location.href);
35
- const urlWithParams = useAuthUrl({ disableSwitchApp, tokenState });
36
-
37
- const deepLink = useCreation(() => {
38
- if (!tokenState.url) {
39
- return '';
40
- }
41
-
42
- callbackUrl.searchParams.set('tokenKey', tokenState.token);
43
-
44
- const link = new URL(urlWithParams);
45
- if (!browser.wallet) {
46
- link.searchParams.set('callback', encodeURIComponent(callbackUrl));
47
- link.searchParams.set('callback_delay', 1500);
48
- }
49
- link.searchParams.set('locale', locale);
50
- const encoder = new TextEncoder();
51
- const currentUrlLength = link.href.length;
52
-
53
- let appInfo = '';
54
- let memberAppInfo = '';
55
- try {
56
- if (tokenState.appInfo) {
57
- const encoded = encoder.encode(JSON.stringify(tokenState.appInfo));
58
- appInfo = btoa(String.fromCharCode(...encoded));
59
- }
60
- if (tokenState.memberAppInfo) {
61
- const encoded = encoder.encode(JSON.stringify(tokenState.memberAppInfo));
62
- memberAppInfo = btoa(String.fromCharCode(...encoded));
63
- }
64
- // NOTICE: 当长度过长时,不再添加 appInfo & memberAppInfo
65
- if (
66
- currentUrlLength + 'appInfo='.length + appInfo.length + 'memberAppInfo='.length + memberAppInfo.length >
67
- 2000
68
- ) {
69
- logger.warn('URL too long, drop appInfo & memberAppInfo', { appInfo, memberAppInfo });
70
- throw new Error('URL too long');
71
- }
72
-
73
- if (memberAppInfo) {
74
- if (appInfo) {
75
- // 在有 memberAppInfo 的情况下,两个值必须一起写入
76
- link.searchParams.set('appInfo', appInfo);
77
- link.searchParams.set('memberAppInfo', memberAppInfo);
78
- }
79
- } else if (appInfo) {
80
- link.searchParams.set('appInfo', appInfo);
81
- }
82
- } catch (error) {
83
- logger.warn('Failed to convert appInfo & memberAppInfo', error);
84
- }
85
- return link.href.replace(/^https?:\/\//, 'abt://');
86
- }, [tokenKey, tokenState.token, tokenState.appInfo, tokenState.memberAppInfo, tokenState.url]);
87
-
88
- const handleWalletConnect = useMemoizedFn(() => {
89
- currentState.loading = true;
90
- setTimeout(() => {
91
- bridge.call('authAction', { action: 'auth', deepLink });
92
- }, 600);
93
- setTimeout(() => {
94
- currentState.loading = false;
95
- }, 2000);
96
- });
97
-
98
- // 此处用于在 mobile 浏览器中,用户在点击打开按钮时,直接渲染 scanned 的样式(解决 safari 在页面隐藏后,无法正常发起请求带来的体验较差)
99
- // 需要在页面再次可见时,将状态设置为正确的值
100
- const handleOpenDeeplink = useMemoizedFn(() => {
101
- tokenState.checking = true;
102
- tokenState.status = 'scanned';
103
- });
104
-
105
- const modifyProps = {};
106
- if (!isWalletWebview && browser.mobile.any) {
107
- modifyProps.component = 'a';
108
- modifyProps.href = deepLink;
109
- }
110
-
111
- if (!tokenState.url) {
112
- modifyProps.sx = {
113
- cursor: 'not-allowed',
114
- };
115
- }
116
-
117
- const handleConnectFn = useMemoizedFn((fallback) => {
118
- if (!tokenState.url) {
119
- return;
120
- }
121
-
122
- if (isWalletWebview) {
123
- connectState.walletMethod = WALLET_LOGIN_METHOD.MOBILE;
124
- handleWalletConnect();
125
- } else if (browser.mobile.any || isTablet) {
126
- connectState.walletMethod = WALLET_LOGIN_METHOD.MOBILE;
127
- handleOpenDeeplink();
128
- } else {
129
- connectState.walletMethod = WALLET_LOGIN_METHOD.SCAN;
130
- fallback();
131
- }
132
- });
133
-
134
- const handleConnect = useMemoizedFn(() => {
135
- handleConnectFn(onClick);
136
- });
137
-
138
- useImperativeHandle(ref, () => ({
139
- connect: handleConnectFn,
140
- }));
141
-
142
- return (
143
- <LoginMethodItem
144
- {...rest}
145
- {...modifyProps}
146
- sx={mergeSx(rest?.sx, modifyProps?.sx)}
147
- title={title}
148
- icon={
149
- currentState.loading || !tokenState.url ? (
150
- <CircularProgress
151
- color="primary"
152
- size={LOGIN_PROVIDER_ICON_SIZE}
153
- sx={{
154
- '& svg': {
155
- transform: 'scale(0.75)',
156
- },
157
- }}
158
- />
159
- ) : (
160
- <ProviderIcon
161
- provider={LOGIN_PROVIDER.DID_WALLET}
162
- sx={{
163
- width: LOGIN_PROVIDER_ICON_SIZE,
164
- height: LOGIN_PROVIDER_ICON_SIZE,
165
- transform: 'scale(0.9)',
166
- }}
167
- />
168
- )
169
- }
170
- iconScale={1}
171
- onClick={handleConnect}
172
- />
173
- );
174
- }
175
-
176
- MobileLoginItem.propTypes = {
177
- tokenState: PropTypes.object.isRequired,
178
- tokenKey: PropTypes.string.isRequired,
179
- locale: PropTypes.string.isRequired,
180
- onClick: PropTypes.func,
181
- disableSwitchApp: PropTypes.bool,
182
- ref: PropTypes.any,
183
- isTablet: PropTypes.bool,
184
- };
@@ -1,56 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { useImperativeHandle, useRef } from 'react';
3
- import { useMemoizedFn } from 'ahooks';
4
- import { LOGIN_PROVIDER, LAST_USED_LOGIN_METHOD } from '@arcblock/ux/lib/Util/constant';
5
-
6
- import PasskeyActions from '../../../Passkey/actions';
7
- import { getAppId } from '../../../utils';
8
- import { useStateContext } from '../../contexts/state';
9
-
10
- export default function PasskeyLoginItem({ ref = null, onSuccess, tokenState, behavior = 'none', ...rest }) {
11
- const { extraParams, lastLoginMethod } = useStateContext();
12
- const passkeyActionRef = useRef(null);
13
-
14
- const handleSuccess = useMemoizedFn((result) => {
15
- // 登录成功后记录最后使用的登录方式(用于显示 Last Used 标签)
16
- localStorage.setItem(LAST_USED_LOGIN_METHOD, LOGIN_PROVIDER.PASSKEY);
17
- return onSuccess(
18
- {
19
- ...result,
20
- encrypted: false,
21
- },
22
- (val) => val,
23
- {
24
- sourceAppPid: extraParams?.sourceAppPid,
25
- connected_app: getAppId(tokenState.appInfo, tokenState.memberAppInfo),
26
- }
27
- );
28
- });
29
-
30
- useImperativeHandle(ref, () => ({
31
- connect: passkeyActionRef.current.click,
32
- }));
33
-
34
- if (behavior === 'none') {
35
- return null;
36
- }
37
-
38
- return (
39
- <PasskeyActions
40
- {...rest}
41
- ref={passkeyActionRef}
42
- isLatest={lastLoginMethod && lastLoginMethod === LOGIN_PROVIDER.PASSKEY}
43
- action={tokenState.action}
44
- behavior={behavior}
45
- onSuccess={handleSuccess}
46
- extraParams={extraParams}
47
- />
48
- );
49
- }
50
-
51
- PasskeyLoginItem.propTypes = {
52
- onSuccess: PropTypes.func.isRequired,
53
- tokenState: PropTypes.object.isRequired,
54
- behavior: PropTypes.oneOf(['none', 'both', 'only-existing', 'only-new']),
55
- ref: PropTypes.any,
56
- };
@@ -1,129 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { Box, Divider } from '@mui/material';
3
- import { LOGIN_PROVIDER } from '@arcblock/ux/lib/Util/constant';
4
- import { checkSameProtocol, getWebWalletUrl } from '@arcblock/ux/lib/Util/wallet';
5
- import { detectWalletExtension } from '@arcblock/ux/lib/Util';
6
- import { useCreation } from 'ahooks';
7
- import { useBrowser } from '@arcblock/react-hooks';
8
-
9
- import MobileLoginItem from './mobile-login-item';
10
- import WebLoginItem from './web-login-item';
11
- import BackButton from '../back-button';
12
- import { useStateContext } from '../../contexts/state';
13
-
14
- export default function WalletLoginOptions({
15
- qrcode,
16
- tokenState,
17
- webWalletUrl = getWebWalletUrl(),
18
- size = 'small',
19
- disableSwitchApp = false,
20
- tokenKey,
21
- walletLoginRef = null,
22
- webLoginRef = null,
23
- onMobileLoginClick,
24
- onWebLoginClick,
25
- onBack,
26
- }) {
27
- const { t, locale } = useStateContext();
28
- const browser = useBrowser();
29
- const isSameProtocol = checkSameProtocol(webWalletUrl);
30
- const extension = detectWalletExtension();
31
-
32
- const isTablet = useCreation(() => {
33
- const ua = navigator.userAgent.toLowerCase();
34
-
35
- // 1. 判断是否是 iPad (iOS 13+ 可能会显示为 Macintosh,需要结合触控点判断)
36
- const isIpad = /ipad/.test(ua) || (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1);
37
-
38
- // 2. 判断是否是 Android 平板 (即 User Agent 包含 Android 但不包含 Mobile)
39
- const isAndroidTablet = /android/.test(ua) && !/mobile/.test(ua);
40
-
41
- // 3. 综合判断平板
42
- if (isIpad || isAndroidTablet) {
43
- return true;
44
- }
45
- return false;
46
- }, []);
47
- return (
48
- <>
49
- {qrcode}
50
-
51
- <Box sx={{ width: '100%', display: 'flex', flexDirection: 'column', gap: 1.5 }}>
52
- <Box sx={{ width: '100%' }}>
53
- <Divider
54
- orientation="horizontal"
55
- sx={{
56
- fontSize: 12,
57
- color: 'text.hint',
58
- '&::before, &::after': {
59
- borderColor: 'divider',
60
- },
61
- }}>
62
- or
63
- </Divider>
64
- </Box>
65
- <Box
66
- sx={{
67
- width: '100%',
68
- '.arc-login-item': {
69
- width: '100%',
70
- justifyContent: 'center',
71
- '& > .arc-login-item__body': {
72
- flex: 'unset',
73
- },
74
- '& > .other-item-icon': {
75
- display: 'none !important',
76
- },
77
- },
78
- }}>
79
- {isTablet ? (
80
- <MobileLoginItem
81
- t={t}
82
- key={LOGIN_PROVIDER.WALLET}
83
- ref={walletLoginRef}
84
- tokenState={tokenState}
85
- isTablet={isTablet}
86
- sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
87
- locale={locale}
88
- tokenKey={tokenKey}
89
- disableSwitchApp={disableSwitchApp}
90
- onClick={onMobileLoginClick}
91
- />
92
- ) : (
93
- // eslint-disable-next-line react/jsx-no-useless-fragment
94
- <>
95
- {(isSameProtocol || extension) && (!browser.mobile.any || extension) ? (
96
- <WebLoginItem
97
- t={t}
98
- key={LOGIN_PROVIDER.WALLET}
99
- ref={webLoginRef}
100
- tokenState={tokenState}
101
- webWalletUrl={webWalletUrl}
102
- sx={[size === 'small' ? { p: 1 } : { p: 2 }]}
103
- disableSwitchApp={disableSwitchApp}
104
- onClick={onWebLoginClick}
105
- />
106
- ) : null}
107
- </>
108
- )}
109
- </Box>
110
-
111
- {onBack && <BackButton variant="text" onClick={onBack} />}
112
- </Box>
113
- </>
114
- );
115
- }
116
-
117
- WalletLoginOptions.propTypes = {
118
- qrcode: PropTypes.node.isRequired,
119
- tokenState: PropTypes.object.isRequired,
120
- webWalletUrl: PropTypes.string,
121
- size: PropTypes.oneOf(['small', 'normal', 'large']),
122
- disableSwitchApp: PropTypes.bool,
123
- tokenKey: PropTypes.string.isRequired,
124
- walletLoginRef: PropTypes.object,
125
- webLoginRef: PropTypes.object,
126
- onMobileLoginClick: PropTypes.func.isRequired,
127
- onWebLoginClick: PropTypes.func.isRequired,
128
- onBack: PropTypes.func.isRequired,
129
- };
@@ -1,159 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { CircularProgress } from '@mui/material';
3
- import { useCreation, useMemoizedFn, useReactive } from 'ahooks';
4
- import { openWebWallet, detectWalletExtension } from '@arcblock/ux/lib/Util';
5
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
6
- import noop from 'lodash/noop';
7
- import omit from 'lodash/omit';
8
- import { useImperativeHandle } from 'react';
9
- import ProviderIcon from '@arcblock/ux/lib/DIDConnect/provider-icon';
10
- import { LOGIN_PROVIDER, LOGIN_PROVIDER_ICON_SIZE, WALLET_LOGIN_METHOD } from '@arcblock/ux/lib/Util/constant';
11
-
12
- import LoginMethodItem from './login-method-item';
13
- import { useStateContext } from '../../contexts/state';
14
- import { EXT_DOWNLOAD_URL } from '../../../constant';
15
- import useAuthUrl from '../../hooks/auth-url';
16
-
17
- export default function WebLoginItem({
18
- ref = null,
19
- tokenState,
20
- locale = 'en',
21
- webWalletUrl,
22
- onClick = noop,
23
- disableSwitchApp = false,
24
- autoConnect = true,
25
- ...rest
26
- }) {
27
- const { browserBrand, connectState } = useStateContext();
28
- const extension = detectWalletExtension();
29
- const currentState = useReactive({
30
- loading: false,
31
- });
32
-
33
- const urlWithParams = useAuthUrl({ disableSwitchApp, tokenState });
34
-
35
- const handleConnectFn = useMemoizedFn(() => {
36
- if (!autoConnect) {
37
- return;
38
- }
39
- currentState.loading = true;
40
- const openResult = openWebWallet({
41
- webWalletUrl,
42
- url: urlWithParams,
43
- locale,
44
- appInfo: tokenState.appInfo,
45
- memberAppInfo: tokenState.memberAppInfo,
46
- });
47
- // Web Wallet 和扩展都使用 WEB 类型
48
- connectState.walletMethod = WALLET_LOGIN_METHOD.WEB;
49
- if (openResult?.type === 'web') {
50
- currentState.loading = false;
51
- } else {
52
- // 后续需要通过插件回传消息,才能准确的关闭 loading 状态
53
- setTimeout(() => {
54
- currentState.loading = false;
55
- }, 3000);
56
- }
57
- });
58
- const handleConnect = useMemoizedFn((e) => {
59
- if (!tokenState.url) {
60
- return;
61
- }
62
-
63
- onClick(e);
64
- e?.preventDefault();
65
- handleConnectFn();
66
- });
67
-
68
- useImperativeHandle(ref, () => ({
69
- connect: handleConnectFn,
70
- }));
71
-
72
- const extDownloadUrl = useCreation(() => {
73
- if (browserBrand === 'edge') {
74
- return EXT_DOWNLOAD_URL.edge;
75
- }
76
- if (browserBrand === 'chrome') {
77
- return EXT_DOWNLOAD_URL.chrome;
78
- }
79
- return null;
80
- }, [browserBrand]);
81
-
82
- const buttonProps = useCreation(() => {
83
- const result = {};
84
- if (extension || !autoConnect) {
85
- result.onClick = handleConnect;
86
- } else if (extDownloadUrl && autoConnect) {
87
- result.component = 'a';
88
- result.href = extDownloadUrl;
89
- result.target = '_blank';
90
- result.rel = 'noopener';
91
- } else {
92
- result.onClick = handleConnect;
93
- }
94
-
95
- if (!tokenState.url) {
96
- result.sx = {
97
- cursor: 'not-allowed',
98
- };
99
- }
100
- return result;
101
- }, [handleConnect, tokenState.url]);
102
-
103
- const title = useCreation(() => {
104
- if (!autoConnect) {
105
- return 'DID Wallet';
106
- }
107
- if (extension || extDownloadUrl) {
108
- return 'DID Wallet (Extension)';
109
- }
110
- return 'DID Wallet (Web)';
111
- }, [extension, extDownloadUrl]);
112
-
113
- return (
114
- <LoginMethodItem
115
- {...rest}
116
- sx={mergeSx(
117
- {
118
- textDecoration: 'none',
119
- },
120
- rest?.sx,
121
- buttonProps.sx
122
- )}
123
- title={title}
124
- icon={
125
- currentState.loading || !tokenState.url ? (
126
- <CircularProgress
127
- color="primary"
128
- size={LOGIN_PROVIDER_ICON_SIZE}
129
- sx={{
130
- '& svg': {
131
- transform: 'scale(0.75)',
132
- },
133
- }}
134
- />
135
- ) : (
136
- <ProviderIcon
137
- sx={{
138
- width: LOGIN_PROVIDER_ICON_SIZE,
139
- height: LOGIN_PROVIDER_ICON_SIZE,
140
- transform: 'scale(0.9)',
141
- }}
142
- provider={LOGIN_PROVIDER.DID_WALLET}
143
- />
144
- )
145
- }
146
- {...omit(buttonProps, 'sx')}
147
- />
148
- );
149
- }
150
-
151
- WebLoginItem.propTypes = {
152
- tokenState: PropTypes.object.isRequired,
153
- locale: PropTypes.string,
154
- webWalletUrl: PropTypes.string.isRequired,
155
- onClick: PropTypes.func,
156
- disableSwitchApp: PropTypes.bool,
157
- autoConnect: PropTypes.bool, // 点击后是否自动连接,默认true
158
- ref: PropTypes.any,
159
- };
@@ -1,32 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { alpha, Box } from '@mui/material';
3
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
4
-
5
- // 需要父元素设置 relative position
6
- export default function MaskOverlay({ children, ...rest }) {
7
- return (
8
- <Box
9
- {...rest}
10
- sx={mergeSx(
11
- {
12
- position: 'absolute',
13
- top: 0,
14
- bottom: 0,
15
- left: 0,
16
- right: 0,
17
- display: 'flex',
18
- justifyContent: 'center',
19
- alignItems: 'center',
20
- backgroundColor: ({ palette }) => alpha(palette.background.default, 0.75),
21
- backdropFilter: 'blur(3px)',
22
- },
23
- rest?.sx
24
- )}>
25
- {children}
26
- </Box>
27
- );
28
- }
29
-
30
- MaskOverlay.propTypes = {
31
- children: PropTypes.any.isRequired,
32
- };
@@ -1,52 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { Box, useTheme } from '@mui/material';
3
- import { Icon } from '@iconify/react';
4
- import RefreshRoundedIcon from '@iconify-icons/material-symbols/refresh-rounded';
5
-
6
- // 需要父元素设置 relative position
7
- export default function RefreshOverlay({ onRefresh, ...rest }) {
8
- const { palette } = useTheme();
9
- const handleOnRefresh = (e) => {
10
- e.stopPropagation();
11
- onRefresh();
12
- };
13
-
14
- return (
15
- <Box
16
- {...rest}
17
- onClick={handleOnRefresh}
18
- sx={{
19
- position: 'absolute',
20
- top: 0,
21
- bottom: 0,
22
- left: 0,
23
- right: 0,
24
- display: 'flex',
25
- justifyContent: 'center',
26
- alignItems: 'center',
27
- backgroundColor: 'rgba(255, 255, 255, 0.75)',
28
- cursor: 'pointer',
29
- ...rest.sx,
30
- }}>
31
- <Box
32
- sx={{
33
- backgroundColor: 'secondary.main',
34
- borderRadius: '100%',
35
- fontSize: 0,
36
- }}>
37
- <Icon
38
- icon={RefreshRoundedIcon}
39
- fontSize={52}
40
- style={{
41
- transform: 'scale(0.7)',
42
- color: palette.secondary.contrastText,
43
- }}
44
- />
45
- </Box>
46
- </Box>
47
- );
48
- }
49
-
50
- RefreshOverlay.propTypes = {
51
- onRefresh: PropTypes.func.isRequired,
52
- };
@@ -1,69 +0,0 @@
1
- import { useRef } from 'react';
2
- import { Box, Menu, MenuItem } from '@mui/material';
3
- import { useReactive } from 'ahooks';
4
- import { mergeSx } from '@arcblock/ux/lib/Util/style';
5
- import PropTypes from 'prop-types';
6
- import { AppInfoItem } from '@arcblock/ux/lib/DIDConnect';
7
-
8
- import { useStateContext } from '../contexts/state';
9
-
10
- export default function SwitchApp({ sx = {}, children }) {
11
- const { appInfoList, extraParams, connectState } = useStateContext();
12
- const switchAppRef = useRef(null);
13
- const currentState = useReactive({
14
- open: false,
15
- });
16
- if (appInfoList.length <= 1) return null;
17
-
18
- return (
19
- <>
20
- <Box
21
- component="span"
22
- ref={switchAppRef}
23
- sx={mergeSx(
24
- {
25
- color: 'text.secondary',
26
- cursor: 'pointer',
27
- },
28
- sx
29
- )}
30
- onClick={() => {
31
- currentState.open = true;
32
- }}>
33
- {children}
34
- </Box>
35
- <Menu
36
- anchorEl={switchAppRef.current}
37
- open={currentState.open}
38
- onClose={() => {
39
- currentState.open = false;
40
- }}
41
- slotProps={{
42
- paper: {
43
- variant: 'outlined',
44
- sx: {
45
- border: 0,
46
- boxShadow: ({ palette }) => `0px 4px 8px 0px ${palette.grey[100]}, 0px 0px 0px 1px ${palette.grey[100]}`,
47
- borderRadius: 1,
48
- },
49
- },
50
- }}>
51
- {appInfoList.map((item) => (
52
- <MenuItem
53
- key={item.appPid}
54
- onClick={() => {
55
- currentState.open = false;
56
- connectState.sourceAppPid = item.sourceAppPid;
57
- }}>
58
- <AppInfoItem appInfo={item} active={item.sourceAppPid === extraParams?.sourceAppPid} />
59
- </MenuItem>
60
- ))}
61
- </Menu>
62
- </>
63
- );
64
- }
65
-
66
- SwitchApp.propTypes = {
67
- sx: PropTypes.object,
68
- children: PropTypes.any.isRequired,
69
- };