@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,235 +0,0 @@
1
- import PropTypes from 'prop-types';
2
- import { createContext, use, useEffect, useRef, useState } from 'react';
3
- import useBrowser from '@arcblock/react-hooks/lib/useBrowser';
4
- import { useCreation, useLatest, useMemoizedFn, useReactive, useSize, useUpdate } from 'ahooks';
5
- import isUndefined from 'lodash/isUndefined';
6
- import noop from 'lodash/noop';
7
- import { Box } from '@mui/material';
8
- import { translate } from '@arcblock/ux/lib/Locale/util';
9
- import { getCurrentApp, getMaster } from '@arcblock/ux/lib/Util/federated';
10
- import { getDIDMotifInfo } from '@arcblock/did-motif';
11
- import { getDIDColor, isEthereumDid } from '@arcblock/ux/lib/Util';
12
- import { LAST_USED_LOGIN_METHOD } from '@arcblock/ux/lib/Util/constant';
13
-
14
- import useApps from '../hooks/use-apps';
15
- import { SessionContext } from '../../Session/context';
16
- import translations from '../assets/locale';
17
-
18
- const StateContext = createContext({
19
- isWalletWebview: false,
20
- isMobile: false,
21
- matchSmallScreen: false,
22
- blocklet: null,
23
- });
24
-
25
- const { Provider, Consumer } = StateContext;
26
-
27
- function StateProvider({
28
- children,
29
- blocklet,
30
- masterBlocklet = undefined,
31
- action,
32
- extraParams = {},
33
- locale = 'en',
34
- testOnlyBorderColor = undefined,
35
- ...rest
36
- }) {
37
- const forceUpdate = useUpdate();
38
- const [plugins, setPlugins] = useState([]);
39
- const [showWalletOptions, setShowWalletOptions] = useState(false);
40
- const [selectedPlugin, setSelectedPlugin] = useState('');
41
- const pluginsMap = useCreation(() => {
42
- return new Map(plugins.map((plugin) => [plugin.name, plugin]));
43
- }, [plugins]);
44
- const getPlugin = useMemoizedFn((name) => {
45
- return pluginsMap.get(name);
46
- });
47
- const latestActivePlugin = useLatest(selectedPlugin);
48
- const t = useMemoizedFn((key, data = {}) => {
49
- return translate(translations, key, locale, 'en', data);
50
- });
51
- const sessionContext = use(SessionContext);
52
- const reactiveState = useReactive({
53
- sourceAppPid: undefined,
54
- status: 'created',
55
- autoActiveWebview: true,
56
- deeplink: undefined,
57
- chooseMethod: '',
58
- walletMethod: '', // 细分的 wallet 登录方式,如 wallet-ext, wallet-web, wallet-scan 等
59
- retryConnect: noop,
60
- });
61
- const staticState = useRef({
62
- cancelCount: 0,
63
- });
64
-
65
- const browser = useBrowser();
66
- const { appInfoList, autoGenerateSourceAppPid, canSwitchApp } = useApps({
67
- blocklet,
68
- connectState: reactiveState,
69
- action,
70
- sourceAppPid: extraParams?.sourceAppPid,
71
- enableSwitchApp: extraParams?.forceSwitch || extraParams?.enableSwitchApp,
72
- });
73
- const lastLoginMethod = useCreation(() => {
74
- try {
75
- return localStorage.getItem(LAST_USED_LOGIN_METHOD);
76
- } catch (error) {
77
- return '';
78
- }
79
- }, []);
80
-
81
- const rootRef = useRef(null);
82
- const size = useSize(rootRef);
83
-
84
- const matchSmallScreen = useCreation(() => {
85
- const width = size?.width || 0;
86
- return width < 500;
87
- }, [size?.width]);
88
-
89
- const mergeExtraParams = useCreation(() => {
90
- if (canSwitchApp) {
91
- return {
92
- ...extraParams,
93
- sourceAppPid: isUndefined(reactiveState.sourceAppPid) ? autoGenerateSourceAppPid : reactiveState.sourceAppPid,
94
- };
95
- }
96
-
97
- const masterAppPid = getMaster(blocklet)?.appPid;
98
- const currentPageMasterAppPid = getMaster(globalThis.blocklet)?.appPid;
99
- if (sessionContext?.session?.user && (masterAppPid === currentPageMasterAppPid || !masterAppPid)) {
100
- if (!isUndefined(extraParams?.sourceAppPid)) {
101
- return extraParams;
102
- }
103
- return {
104
- ...extraParams,
105
- sourceAppPid: sessionContext.session.user?.sourceAppPid,
106
- };
107
- }
108
-
109
- return {
110
- ...extraParams,
111
- sourceAppPid: autoGenerateSourceAppPid,
112
- };
113
- }, [
114
- canSwitchApp,
115
- extraParams,
116
- reactiveState.sourceAppPid,
117
- action,
118
- autoGenerateSourceAppPid,
119
- sessionContext?.session?.user,
120
- ]);
121
-
122
- const browserBrand = useCreation(() => {
123
- const userAgent = window?.navigator?.userAgent;
124
- if (userAgent.indexOf('Edge') > -1 || userAgent.indexOf('Edg') > -1) {
125
- return 'edge';
126
- }
127
- if (userAgent.indexOf('Chrome') > -1) {
128
- return 'chrome';
129
- }
130
- return 'unknown';
131
- }, []);
132
-
133
- useEffect(() => {
134
- reactiveState.sourceAppPid = mergeExtraParams.sourceAppPid;
135
- // eslint-disable-next-line react-hooks/exhaustive-deps
136
- }, [mergeExtraParams.sourceAppPid]);
137
-
138
- const changeStatus = useMemoizedFn((value) => {
139
- reactiveState.status = value || 'created';
140
- });
141
-
142
- // currentAppInfo 固定不变,就是当前网站的应用信息
143
- const currentAppInfo = globalThis.blocklet ? getCurrentApp(blocklet) : globalThis.env;
144
-
145
- const currentAppColor = useCreation(() => {
146
- if (testOnlyBorderColor) {
147
- return testOnlyBorderColor;
148
- }
149
-
150
- const did = currentAppInfo.appPid;
151
- const isEthDid = isEthereumDid(did);
152
- const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
153
- if (isEthDid) {
154
- return getDIDColor(did);
155
- }
156
-
157
- return didMotifInfo.color;
158
- }, [currentAppInfo.appId, testOnlyBorderColor]);
159
-
160
- // NOTICE: size 的变化频率很高,会触发子组件多次渲染,需要在传递 context 时,排除 size 对它的影响
161
- const value = useCreation(() => {
162
- return {
163
- isWalletWebview: browser.wallet || browser.arcSphere,
164
- isMobile: browser.mobile.any,
165
- matchSmallScreen,
166
- connectState: reactiveState,
167
- staticState,
168
- reactiveState,
169
- appInfoList,
170
- extraParams: mergeExtraParams,
171
- blocklet,
172
- masterBlocklet,
173
- browserBrand,
174
- currentAppInfo,
175
- currentAppColor,
176
-
177
- t,
178
- locale,
179
- action,
180
- changeStatus,
181
- getPlugin,
182
- latestActivePlugin,
183
- plugins,
184
- setPlugins,
185
- selectedPlugin,
186
- setSelectedPlugin,
187
- forceUpdate,
188
-
189
- // 控制钱包登录的显示
190
- showWalletOptions,
191
- setShowWalletOptions,
192
- // 用于记录上一次登录方式
193
- lastLoginMethod,
194
- };
195
- }, [
196
- browser.wallet,
197
- browser.arcSphere,
198
- browser.mobile.any,
199
- matchSmallScreen,
200
- JSON.stringify(reactiveState),
201
- JSON.stringify(appInfoList),
202
- JSON.stringify(mergeExtraParams),
203
- blocklet,
204
- masterBlocklet,
205
- locale,
206
- selectedPlugin,
207
- forceUpdate,
208
- currentAppInfo,
209
- currentAppColor,
210
- ]);
211
-
212
- return (
213
- <Provider value={value}>
214
- <Box {...rest} ref={rootRef}>
215
- {children}
216
- </Box>
217
- </Provider>
218
- );
219
- }
220
-
221
- StateProvider.propTypes = {
222
- children: PropTypes.any.isRequired,
223
- blocklet: PropTypes.object.isRequired,
224
- masterBlocklet: PropTypes.object,
225
- action: PropTypes.string.isRequired,
226
- extraParams: PropTypes.object,
227
- locale: PropTypes.string,
228
- testOnlyBorderColor: PropTypes.string,
229
- };
230
-
231
- function useStateContext() {
232
- return use(StateContext);
233
- }
234
-
235
- export { StateContext, StateProvider, Consumer as StateConsumer, useStateContext };
@@ -1,47 +0,0 @@
1
- import { DIDConnectFooter } from '@arcblock/ux/lib/DIDConnect';
2
- import { DID_CONNECT_SMALL_WIDTH } from '@arcblock/ux/lib/Util/constant';
3
- import { getCurrentApp } from '@arcblock/ux/lib/Util/federated';
4
- import { Box, Skeleton } from '@mui/material';
5
-
6
- export default function FallbackConnect(props) {
7
- const currentAppInfo = globalThis.blocklet ? getCurrentApp(globalThis.blocklet) : globalThis.env;
8
- return (
9
- <Box
10
- className="did-connect__root"
11
- sx={{
12
- backgroundColor: 'background.default',
13
- display: 'flex',
14
- flexDirection: 'column',
15
- height: '100%',
16
- position: 'relative',
17
- maxWidth: '100%',
18
- // eslint-disable-next-line react/prop-types
19
- width: props.mode === 'drawer' ? '100%' : DID_CONNECT_SMALL_WIDTH - 20,
20
- transition: 'width 0.2s ease-in-out',
21
- margin: 'auto',
22
- p: 3,
23
- pb: 0,
24
- gap: 2.5,
25
- }}>
26
- <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>
27
- <Skeleton variant="rounded" height={28} sx={{ width: '6rem' }} />
28
- <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
29
- <Skeleton variant="rounded" sx={{ fontSize: '13px', height: '15px' }} />
30
- <Skeleton variant="rounded" sx={{ fontSize: '13px', height: '15px', width: '3rem' }} />
31
- </Box>
32
- </Box>
33
- <Box sx={{ display: 'flex', flexDirection: 'column', gap: 1.5 }}>
34
- <Skeleton variant="rounded" sx={{ height: '35px' }} />
35
- <Skeleton variant="rounded" sx={{ height: '35px' }} />
36
- <Skeleton variant="rounded" sx={{ height: '35px' }} />
37
- <Box sx={{ display: 'flex', gap: 1.5, mt: 1 }}>
38
- <Skeleton variant="rounded" sx={{ flex: 1, height: '32px' }} />
39
- <Skeleton variant="rounded" sx={{ flex: 1, height: '32px' }} />
40
- <Skeleton variant="rounded" sx={{ flex: 1, height: '32px' }} />
41
- <Skeleton variant="rounded" sx={{ flex: 1, height: '32px' }} />
42
- </Box>
43
- </Box>
44
- <DIDConnectFooter currentAppInfo={currentAppInfo} />
45
- </Box>
46
- );
47
- }
@@ -1,3 +0,0 @@
1
- import LandingPage from '@arcblock/ux/lib/DIDConnect/landing-page';
2
-
3
- export default LandingPage;
@@ -1,31 +0,0 @@
1
- import { useCreation } from 'ahooks';
2
- import { useStateContext } from '../contexts/state';
3
- import useSecurity from './security';
4
- import { getVisitorId } from '../../utils';
5
-
6
- export default function useAuthUrl({ disableSwitchApp, tokenState }) {
7
- const { appInfoList, connectState } = useStateContext();
8
- const { encryptKey } = useSecurity();
9
- const urlWithParams = useCreation(() => {
10
- if (!tokenState.url) {
11
- return '';
12
- }
13
- const canSwitch = !disableSwitchApp && appInfoList.length > 1;
14
- const resultUrl = new URL(tokenState.url || 'https://www.didwallet.io');
15
- const actionRawUrl = resultUrl.searchParams.get('url');
16
- if (actionRawUrl && canSwitch) {
17
- const actionUrl = new URL(decodeURIComponent(actionRawUrl));
18
- actionUrl.searchParams.set('_ek_', encryptKey);
19
- const visitorId = getVisitorId();
20
- if (visitorId) {
21
- actionUrl.searchParams.set('vid', visitorId);
22
- }
23
- if (connectState?.sourceAppPid) {
24
- actionUrl.searchParams.set('spid', connectState?.sourceAppPid);
25
- }
26
- resultUrl.searchParams.set('url', actionUrl.toString());
27
- }
28
- return resultUrl.toString();
29
- }, [tokenState.url, appInfoList.length, connectState?.sourceAppPid, encryptKey]);
30
- return urlWithParams;
31
- }
@@ -1,121 +0,0 @@
1
- import { useBrowser } from '@arcblock/react-hooks';
2
- import { detectWalletExtension } from '@arcblock/ux/lib/Util';
3
- import { useCreation, useRequest } from 'ahooks';
4
- import intersection from 'lodash/intersection';
5
- import { OAUTH_PROVIDER } from '@arcblock/ux/lib/Util/constant';
6
-
7
- import { useOAuth } from '../../OAuth';
8
- import { checkSameProtocol, getWebWalletUrl } from '../../utils';
9
-
10
- export default function useMethodList({
11
- enabledConnectTypes = [],
12
- allowWallet = true,
13
- passkeyBehavior = 'none',
14
- webWalletUrl = getWebWalletUrl(),
15
- action,
16
- sourceAppPid,
17
- mode = 'dialog',
18
- blocklet = globalThis.blocklet,
19
- isSmallView = false,
20
- }) {
21
- const actionList = ['login', 'invite', 'connect-to-did-space', 'connect-to-did-domain', 'destroy-self'];
22
- const { getOAuthConfigList } = useOAuth();
23
- const browser = useBrowser();
24
- const extension = detectWalletExtension();
25
- const { data: oauthConfigList = [] } = useRequest(
26
- async () => {
27
- const data = await getOAuthConfigList({ sourceAppPid });
28
- return data;
29
- },
30
- { refreshDeps: [sourceAppPid] }
31
- );
32
-
33
- const oauthProviderList = useCreation(() => {
34
- // return [];
35
- const showProviders = intersection(Object.keys(OAUTH_PROVIDER), enabledConnectTypes);
36
- const result = oauthConfigList.filter((item) => showProviders.includes(item.provider));
37
- return result;
38
- }, [oauthConfigList, enabledConnectTypes]);
39
-
40
- const showOAuthLogin = useCreation(() => {
41
- if (!actionList.includes(action)) {
42
- return false;
43
- }
44
- return oauthProviderList.length > 0;
45
- }, [oauthProviderList, action]);
46
-
47
- const showMobileLogin = useCreation(() => {
48
- let _allowWallet = allowWallet;
49
- if (!actionList.includes(action)) {
50
- _allowWallet = true;
51
- }
52
- return _allowWallet && enabledConnectTypes.includes('mobile');
53
- }, [allowWallet, enabledConnectTypes, action]);
54
-
55
- const isSameProtocol = checkSameProtocol(webWalletUrl);
56
- const showWebLogin = useCreation(() => {
57
- let _allowWallet = allowWallet;
58
- if (!actionList.includes(action)) {
59
- _allowWallet = true;
60
- }
61
- return (
62
- _allowWallet &&
63
- enabledConnectTypes.includes('web') &&
64
- (isSameProtocol || extension) &&
65
- (!browser.mobile.any || extension)
66
- );
67
- }, [allowWallet, enabledConnectTypes, browser?.mobile?.any, action]);
68
-
69
- const showPasskeyLogin = useCreation(() => {
70
- // NOTICE: 允许所有 action 都展示 passkey
71
- // if (!actionList.includes(action)) {
72
- // return false;
73
- // }
74
- return passkeyBehavior !== 'none' && !browser.wallet && !browser.arcSphere;
75
- }, [action]);
76
-
77
- const showEmailLogin = useCreation(() => {
78
- if (!actionList.includes(action)) {
79
- return false;
80
- }
81
- // FIXME: @zhanghan 这里是临时用于控制是否展示邮箱登录,待确认没问题后,需要移除
82
- if (!['true', undefined, null].includes(blocklet?.DID_CONNECT_ALLOW_EMAIL)) {
83
- return false;
84
- }
85
- return blocklet?.settings?.notification?.email?.enabled ?? false;
86
- }, [action, blocklet]);
87
-
88
- const hideChooseList = useCreation(() => {
89
- return false;
90
- // NOTICE: 先保留这部分逻辑,后续根据需求调整
91
- // if (showOAuthLogin || showPasskeyLogin) {
92
- // return false;
93
- // }
94
- // return true;
95
- });
96
-
97
- const hideQRCode = useCreation(() => {
98
- if (mode === 'drawer' || (isSmallView && browser.mobile.any)) {
99
- return true;
100
- }
101
- if (actionList.includes(action) && !showMobileLogin) {
102
- return true;
103
- }
104
- return false;
105
- }, [mode, isSmallView]);
106
-
107
- const result = {
108
- hideQRCode,
109
- hideChooseList,
110
-
111
- showOAuthLogin,
112
- showMobileLogin,
113
- showWebLogin,
114
- showPasskeyLogin,
115
- showEmailLogin,
116
-
117
- oauthProviderList,
118
- };
119
-
120
- return result;
121
- }
@@ -1,24 +0,0 @@
1
- import { useEffect, useRef } from 'react';
2
-
3
- function usePageShow(handler) {
4
- const handlerRef = useRef(handler);
5
-
6
- useEffect(() => {
7
- handlerRef.current = handler;
8
- }, [handler]);
9
-
10
- useEffect(() => {
11
- const onChange = (event) => {
12
- if (!document.hidden && handlerRef.current) {
13
- handlerRef.current(event);
14
- }
15
- };
16
-
17
- document.addEventListener('visibilitychange', onChange);
18
- return () => {
19
- document.removeEventListener('visibilitychange', onChange);
20
- };
21
- }, []);
22
- }
23
-
24
- export default usePageShow;
@@ -1,168 +0,0 @@
1
- import { useBrowser } from '@arcblock/react-hooks';
2
- import { useCreation, useRequest } from 'ahooks';
3
- import isNil from 'lodash/isNil';
4
- import { LOGIN_PROVIDER, WALLET_LOGIN_METHOD } from '@arcblock/ux/lib/Util/constant';
5
- import { getBlockletData, getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
6
- import { useState } from 'react';
7
-
8
- const getAuthenticationConfig = async ({ sourceAppPid }) => {
9
- const blocklet = globalThis?.blocklet;
10
- if (!blocklet) {
11
- return {
12
- [LOGIN_PROVIDER.WALLET]: {
13
- order: 0,
14
- enabled: true,
15
- showQrcode: true,
16
- },
17
- [LOGIN_PROVIDER.PASSKEY]: {
18
- order: 1,
19
- enabled: true,
20
- },
21
- };
22
- }
23
- const federatedEnabled = getFederatedEnabled(blocklet);
24
- const master = getMaster(blocklet);
25
- if (federatedEnabled && master?.appPid && sourceAppPid === master?.appPid) {
26
- const masterBlocklet = await getBlockletData(master.appUrl);
27
- return masterBlocklet?.settings?.authentication || {};
28
- }
29
- return blocklet?.settings?.authentication || {};
30
- };
31
-
32
- const getLoginProviderList = async ({ sourceAppPid } = {}) => {
33
- const authenticationConfig = await getAuthenticationConfig({ sourceAppPid });
34
- const loginProviderList = Object.entries(authenticationConfig)
35
- .map(([key, value]) => {
36
- return { ...value, provider: key };
37
- })
38
- .filter((item) => item.enabled)
39
- .sort((a, b) => {
40
- if (!isNil(a?.order) && !isNil(b?.order)) {
41
- return a.order - b.order;
42
- }
43
- if (!isNil(a?.order)) {
44
- return -1;
45
- }
46
- return 1;
47
- });
48
- return loginProviderList;
49
- };
50
-
51
- export default function useProviderList({
52
- allowWallet = true,
53
- passkeyBehavior = 'none',
54
- action,
55
- sourceAppPid,
56
- mode = 'dialog',
57
- blocklet = globalThis.blocklet,
58
- isSmallView = false,
59
- lastLoginMethod = '',
60
- }) {
61
- const [loadingProviderList, setLoadingProviderList] = useState(false);
62
- const oauthActionList = ['login', 'invite', 'connect-to-did-space', 'connect-to-did-domain', 'destroy-self'];
63
- const emailActionList = ['login', 'invite', 'connect-to-did-space', 'connect-to-did-domain', 'destroy-self'];
64
- const browser = useBrowser();
65
-
66
- const { data: loginProviderList = [] } = useRequest(
67
- async () => {
68
- setLoadingProviderList(true);
69
- const data = await getLoginProviderList({ sourceAppPid });
70
- setLoadingProviderList(false);
71
- return data;
72
- },
73
- { refreshDeps: [sourceAppPid] }
74
- );
75
-
76
- const showedLoginProviderList = useCreation(() => {
77
- const allowedProviders = globalThis?.blocklet?.DID_CONNECT_ENABLED_PROVIDERS?.split(',') || [];
78
- const result = loginProviderList
79
- .filter((item) => {
80
- if (allowedProviders.length > 0) {
81
- if (!allowedProviders.includes(item.provider)) {
82
- return false;
83
- }
84
- }
85
- if (item.provider === LOGIN_PROVIDER.WALLET) {
86
- return allowWallet;
87
- }
88
- if (item.provider === LOGIN_PROVIDER.PASSKEY) {
89
- return passkeyBehavior !== 'none' && !browser.wallet && !browser.arcSphere;
90
- }
91
- if (item.provider === LOGIN_PROVIDER.EMAIL) {
92
- return emailActionList.includes(action) && (blocklet?.settings?.notification?.email?.enabled ?? false);
93
- }
94
-
95
- if (item.type === 'oauth') {
96
- if (!oauthActionList.includes(action)) {
97
- return false;
98
- }
99
- }
100
- return true;
101
- })
102
- .sort((a, b) => {
103
- // 优先处理 lastLoginMethod:匹配的项目排在最前面
104
- if (lastLoginMethod) {
105
- // 检查是否匹配,wallet 的细分类型需要特殊处理
106
- const walletMethods = Object.values(WALLET_LOGIN_METHOD);
107
- const isWalletMethod = walletMethods.includes(lastLoginMethod);
108
- const aIsLastMethod = isWalletMethod ? a.provider === LOGIN_PROVIDER.WALLET : a.provider === lastLoginMethod;
109
- const bIsLastMethod = isWalletMethod ? b.provider === LOGIN_PROVIDER.WALLET : b.provider === lastLoginMethod;
110
- if (aIsLastMethod && !bIsLastMethod) {
111
- return -1;
112
- }
113
- if (!aIsLastMethod && bIsLastMethod) {
114
- return 1;
115
- }
116
- }
117
- // 然后按照 order 属性排序
118
- if (!isNil(a?.order) && !isNil(b?.order)) {
119
- return a.order - b.order;
120
- }
121
- if (!isNil(a?.order)) {
122
- return -1;
123
- }
124
- if (!isNil(b?.order)) {
125
- return 1;
126
- }
127
- return 0;
128
- });
129
- return result;
130
- }, [loginProviderList, lastLoginMethod]);
131
-
132
- const hideQRCode = useCreation(() => {
133
- const isMobileView = mode === 'drawer' || (isSmallView && browser.mobile.any);
134
- if (!globalThis?.blocklet) {
135
- if (!isMobileView) {
136
- return false;
137
- }
138
- return true;
139
- }
140
-
141
- const walletProvider = showedLoginProviderList.find((item) => item.provider === LOGIN_PROVIDER.WALLET);
142
- if (walletProvider?.showQrcode !== true) {
143
- return true;
144
- }
145
- if (isMobileView) {
146
- return true;
147
- }
148
- return false;
149
- }, [mode, isSmallView, showedLoginProviderList]);
150
-
151
- const hideChooseList = useCreation(() => {
152
- return false;
153
- // NOTICE: 先保留这部分逻辑,后续根据需求调整
154
- // if (showOAuthLogin || showPasskeyLogin) {
155
- // return false;
156
- // }
157
- // return true;
158
- });
159
-
160
- const result = {
161
- hideChooseList,
162
- hideQRCode,
163
- providerList: showedLoginProviderList,
164
- loadingProviderList,
165
- };
166
-
167
- return result;
168
- }
@@ -1,40 +0,0 @@
1
- import tweetnacl from 'tweetnacl';
2
- import { useLocalStorageState } from 'ahooks';
3
- import { useEffect } from 'react';
4
-
5
- import { encodeKey, decrypt as _decrypt, encrypt as _encrypt } from '../../utils';
6
-
7
- const keyPair = tweetnacl.box.keyPair();
8
-
9
- export default function useSecurity() {
10
- const [encryptKey, setEncryptKey] = useLocalStorageState('__encKey', {
11
- defaultValue: encodeKey(keyPair.publicKey),
12
- deserializer: (str) => str,
13
- serializer: (str) => str,
14
- });
15
- const [decryptKey, setDecryptKey] = useLocalStorageState('__decKey', {
16
- defaultValue: encodeKey(keyPair.secretKey),
17
- deserializer: (str) => str,
18
- serializer: (str) => str,
19
- });
20
-
21
- useEffect(() => {
22
- if (!localStorage.getItem('__encKey')) {
23
- setEncryptKey(encodeKey(keyPair.publicKey));
24
- }
25
- if (!localStorage.getItem('__decKey')) {
26
- setDecryptKey(encodeKey(keyPair.secretKey));
27
- }
28
- // eslint-disable-next-line react-hooks/exhaustive-deps
29
- }, []);
30
-
31
- const decrypt = (v, _encryptKey = encryptKey, _decryptKey = decryptKey) => _decrypt(v, _encryptKey, _decryptKey);
32
- const encrypt = (v, _encryptKey = encryptKey) => _encrypt(v, _encryptKey);
33
-
34
- return {
35
- encryptKey,
36
- decryptKey,
37
- decrypt,
38
- encrypt,
39
- };
40
- }