@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,181 +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 } 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 } = 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
- handleWalletConnect();
124
- } else if (browser.mobile.any || isTablet) {
125
- handleOpenDeeplink();
126
- } else {
127
- fallback();
128
- }
129
- });
130
-
131
- const handleConnect = useMemoizedFn(() => {
132
- handleConnectFn(onClick);
133
- });
134
-
135
- useImperativeHandle(ref, () => ({
136
- connect: handleConnectFn,
137
- }));
138
-
139
- return (
140
- <LoginMethodItem
141
- {...rest}
142
- {...modifyProps}
143
- sx={mergeSx(rest?.sx, modifyProps?.sx)}
144
- title={title}
145
- icon={
146
- currentState.loading || !tokenState.url ? (
147
- <CircularProgress
148
- color="primary"
149
- size={LOGIN_PROVIDER_ICON_SIZE}
150
- sx={{
151
- '& svg': {
152
- transform: 'scale(0.75)',
153
- },
154
- }}
155
- />
156
- ) : (
157
- <ProviderIcon
158
- provider={LOGIN_PROVIDER.DID_WALLET}
159
- sx={{
160
- width: LOGIN_PROVIDER_ICON_SIZE,
161
- height: LOGIN_PROVIDER_ICON_SIZE,
162
- transform: 'scale(0.9)',
163
- }}
164
- />
165
- )
166
- }
167
- iconScale={1}
168
- onClick={handleConnect}
169
- />
170
- );
171
- }
172
-
173
- MobileLoginItem.propTypes = {
174
- tokenState: PropTypes.object.isRequired,
175
- tokenKey: PropTypes.string.isRequired,
176
- locale: PropTypes.string.isRequired,
177
- onClick: PropTypes.func,
178
- disableSwitchApp: PropTypes.bool,
179
- ref: PropTypes.any,
180
- isTablet: PropTypes.bool,
181
- };
@@ -1,54 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { useImperativeHandle, useRef } from 'react';
3
- import { useMemoizedFn } from 'ahooks';
4
- import { LOGIN_PROVIDER } 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
- onSuccess(
16
- {
17
- ...result,
18
- encrypted: false,
19
- },
20
- (val) => val,
21
- {
22
- sourceAppPid: extraParams?.sourceAppPid,
23
- connected_app: getAppId(tokenState.appInfo, tokenState.memberAppInfo),
24
- }
25
- )
26
- );
27
-
28
- useImperativeHandle(ref, () => ({
29
- connect: passkeyActionRef.current.click,
30
- }));
31
-
32
- if (behavior === 'none') {
33
- return null;
34
- }
35
-
36
- return (
37
- <PasskeyActions
38
- {...rest}
39
- ref={passkeyActionRef}
40
- isLatest={lastLoginMethod && lastLoginMethod === LOGIN_PROVIDER.PASSKEY}
41
- action={tokenState.action}
42
- behavior={behavior}
43
- onSuccess={handleSuccess}
44
- extraParams={extraParams}
45
- />
46
- );
47
- }
48
-
49
- PasskeyLoginItem.propTypes = {
50
- onSuccess: PropTypes.func.isRequired,
51
- tokenState: PropTypes.object.isRequired,
52
- behavior: PropTypes.oneOf(['none', 'both', 'only-existing', 'only-new']),
53
- ref: PropTypes.any,
54
- };
@@ -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,157 +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 } 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 } = 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
- if (openResult?.type === 'web') {
48
- currentState.loading = false;
49
- } else {
50
- // 后续需要通过插件回传消息,才能准确的关闭 loading 状态
51
- setTimeout(() => {
52
- currentState.loading = false;
53
- }, 3000);
54
- }
55
- });
56
- const handleConnect = useMemoizedFn((e) => {
57
- if (!tokenState.url) {
58
- return;
59
- }
60
-
61
- onClick(e);
62
- e?.preventDefault();
63
- handleConnectFn();
64
- });
65
-
66
- useImperativeHandle(ref, () => ({
67
- connect: handleConnectFn,
68
- }));
69
-
70
- const extDownloadUrl = useCreation(() => {
71
- if (browserBrand === 'edge') {
72
- return EXT_DOWNLOAD_URL.edge;
73
- }
74
- if (browserBrand === 'chrome') {
75
- return EXT_DOWNLOAD_URL.chrome;
76
- }
77
- return null;
78
- }, [browserBrand]);
79
-
80
- const buttonProps = useCreation(() => {
81
- const result = {};
82
- if (extension || !autoConnect) {
83
- result.onClick = handleConnect;
84
- } else if (extDownloadUrl && autoConnect) {
85
- result.component = 'a';
86
- result.href = extDownloadUrl;
87
- result.target = '_blank';
88
- result.rel = 'noopener';
89
- } else {
90
- result.onClick = handleConnect;
91
- }
92
-
93
- if (!tokenState.url) {
94
- result.sx = {
95
- cursor: 'not-allowed',
96
- };
97
- }
98
- return result;
99
- }, [handleConnect, tokenState.url]);
100
-
101
- const title = useCreation(() => {
102
- if (!autoConnect) {
103
- return 'DID Wallet';
104
- }
105
- if (extension || extDownloadUrl) {
106
- return 'DID Wallet (Extension)';
107
- }
108
- return 'DID Wallet (Web)';
109
- }, [extension, extDownloadUrl]);
110
-
111
- return (
112
- <LoginMethodItem
113
- {...rest}
114
- sx={mergeSx(
115
- {
116
- textDecoration: 'none',
117
- },
118
- rest?.sx,
119
- buttonProps.sx
120
- )}
121
- title={title}
122
- icon={
123
- currentState.loading || !tokenState.url ? (
124
- <CircularProgress
125
- color="primary"
126
- size={LOGIN_PROVIDER_ICON_SIZE}
127
- sx={{
128
- '& svg': {
129
- transform: 'scale(0.75)',
130
- },
131
- }}
132
- />
133
- ) : (
134
- <ProviderIcon
135
- sx={{
136
- width: LOGIN_PROVIDER_ICON_SIZE,
137
- height: LOGIN_PROVIDER_ICON_SIZE,
138
- transform: 'scale(0.9)',
139
- }}
140
- provider={LOGIN_PROVIDER.DID_WALLET}
141
- />
142
- )
143
- }
144
- {...omit(buttonProps, 'sx')}
145
- />
146
- );
147
- }
148
-
149
- WebLoginItem.propTypes = {
150
- tokenState: PropTypes.object.isRequired,
151
- locale: PropTypes.string,
152
- webWalletUrl: PropTypes.string.isRequired,
153
- onClick: PropTypes.func,
154
- disableSwitchApp: PropTypes.bool,
155
- autoConnect: PropTypes.bool, // 点击后是否自动连接,默认true
156
- ref: PropTypes.any,
157
- };
@@ -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
- };