@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,234 +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 { GA_LAST_LOGIN_METHOD } from '@arcblock/ux/lib/withTracker/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
- retryConnect: noop,
59
- });
60
- const staticState = useRef({
61
- cancelCount: 0,
62
- });
63
-
64
- const browser = useBrowser();
65
- const { appInfoList, autoGenerateSourceAppPid, canSwitchApp } = useApps({
66
- blocklet,
67
- connectState: reactiveState,
68
- action,
69
- sourceAppPid: extraParams?.sourceAppPid,
70
- enableSwitchApp: extraParams?.forceSwitch || extraParams?.enableSwitchApp,
71
- });
72
- const lastLoginMethod = useCreation(() => {
73
- try {
74
- return localStorage.getItem(GA_LAST_LOGIN_METHOD);
75
- } catch (error) {
76
- return '';
77
- }
78
- }, []);
79
-
80
- const rootRef = useRef(null);
81
- const size = useSize(rootRef);
82
-
83
- const matchSmallScreen = useCreation(() => {
84
- const width = size?.width || 0;
85
- return width < 500;
86
- }, [size?.width]);
87
-
88
- const mergeExtraParams = useCreation(() => {
89
- if (canSwitchApp) {
90
- return {
91
- ...extraParams,
92
- sourceAppPid: isUndefined(reactiveState.sourceAppPid) ? autoGenerateSourceAppPid : reactiveState.sourceAppPid,
93
- };
94
- }
95
-
96
- const masterAppPid = getMaster(blocklet)?.appPid;
97
- const currentPageMasterAppPid = getMaster(globalThis.blocklet)?.appPid;
98
- if (sessionContext?.session?.user && (masterAppPid === currentPageMasterAppPid || !masterAppPid)) {
99
- if (!isUndefined(extraParams?.sourceAppPid)) {
100
- return extraParams;
101
- }
102
- return {
103
- ...extraParams,
104
- sourceAppPid: sessionContext.session.user?.sourceAppPid,
105
- };
106
- }
107
-
108
- return {
109
- ...extraParams,
110
- sourceAppPid: autoGenerateSourceAppPid,
111
- };
112
- }, [
113
- canSwitchApp,
114
- extraParams,
115
- reactiveState.sourceAppPid,
116
- action,
117
- autoGenerateSourceAppPid,
118
- sessionContext?.session?.user,
119
- ]);
120
-
121
- const browserBrand = useCreation(() => {
122
- const userAgent = window?.navigator?.userAgent;
123
- if (userAgent.indexOf('Edge') > -1 || userAgent.indexOf('Edg') > -1) {
124
- return 'edge';
125
- }
126
- if (userAgent.indexOf('Chrome') > -1) {
127
- return 'chrome';
128
- }
129
- return 'unknown';
130
- }, []);
131
-
132
- useEffect(() => {
133
- reactiveState.sourceAppPid = mergeExtraParams.sourceAppPid;
134
- // eslint-disable-next-line react-hooks/exhaustive-deps
135
- }, [mergeExtraParams.sourceAppPid]);
136
-
137
- const changeStatus = useMemoizedFn((value) => {
138
- reactiveState.status = value || 'created';
139
- });
140
-
141
- // currentAppInfo 固定不变,就是当前网站的应用信息
142
- const currentAppInfo = globalThis.blocklet ? getCurrentApp(blocklet) : globalThis.env;
143
-
144
- const currentAppColor = useCreation(() => {
145
- if (testOnlyBorderColor) {
146
- return testOnlyBorderColor;
147
- }
148
-
149
- const did = currentAppInfo.appPid;
150
- const isEthDid = isEthereumDid(did);
151
- const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
152
- if (isEthDid) {
153
- return getDIDColor(did);
154
- }
155
-
156
- return didMotifInfo.color;
157
- }, [currentAppInfo.appId, testOnlyBorderColor]);
158
-
159
- // NOTICE: size 的变化频率很高,会触发子组件多次渲染,需要在传递 context 时,排除 size 对它的影响
160
- const value = useCreation(() => {
161
- return {
162
- isWalletWebview: browser.wallet || browser.arcSphere,
163
- isMobile: browser.mobile.any,
164
- matchSmallScreen,
165
- connectState: reactiveState,
166
- staticState,
167
- reactiveState,
168
- appInfoList,
169
- extraParams: mergeExtraParams,
170
- blocklet,
171
- masterBlocklet,
172
- browserBrand,
173
- currentAppInfo,
174
- currentAppColor,
175
-
176
- t,
177
- locale,
178
- action,
179
- changeStatus,
180
- getPlugin,
181
- latestActivePlugin,
182
- plugins,
183
- setPlugins,
184
- selectedPlugin,
185
- setSelectedPlugin,
186
- forceUpdate,
187
-
188
- // 控制钱包登录的显示
189
- showWalletOptions,
190
- setShowWalletOptions,
191
- // 用于记录上一次登录方式
192
- lastLoginMethod,
193
- };
194
- }, [
195
- browser.wallet,
196
- browser.arcSphere,
197
- browser.mobile.any,
198
- matchSmallScreen,
199
- JSON.stringify(reactiveState),
200
- JSON.stringify(appInfoList),
201
- JSON.stringify(mergeExtraParams),
202
- blocklet,
203
- masterBlocklet,
204
- locale,
205
- selectedPlugin,
206
- forceUpdate,
207
- currentAppInfo,
208
- currentAppColor,
209
- ]);
210
-
211
- return (
212
- <Provider value={value}>
213
- <Box {...rest} ref={rootRef}>
214
- {children}
215
- </Box>
216
- </Provider>
217
- );
218
- }
219
-
220
- StateProvider.propTypes = {
221
- children: PropTypes.any.isRequired,
222
- blocklet: PropTypes.object.isRequired,
223
- masterBlocklet: PropTypes.object,
224
- action: PropTypes.string.isRequired,
225
- extraParams: PropTypes.object,
226
- locale: PropTypes.string,
227
- testOnlyBorderColor: PropTypes.string,
228
- };
229
-
230
- function useStateContext() {
231
- return use(StateContext);
232
- }
233
-
234
- 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,165 +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 } 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
- const aIsLastMethod = a.provider === lastLoginMethod;
106
- const bIsLastMethod = b.provider === lastLoginMethod;
107
- if (aIsLastMethod && !bIsLastMethod) {
108
- return -1;
109
- }
110
- if (!aIsLastMethod && bIsLastMethod) {
111
- return 1;
112
- }
113
- }
114
- // 然后按照 order 属性排序
115
- if (!isNil(a?.order) && !isNil(b?.order)) {
116
- return a.order - b.order;
117
- }
118
- if (!isNil(a?.order)) {
119
- return -1;
120
- }
121
- if (!isNil(b?.order)) {
122
- return 1;
123
- }
124
- return 0;
125
- });
126
- return result;
127
- }, [loginProviderList, lastLoginMethod]);
128
-
129
- const hideQRCode = useCreation(() => {
130
- const isMobileView = mode === 'drawer' || (isSmallView && browser.mobile.any);
131
- if (!globalThis?.blocklet) {
132
- if (!isMobileView) {
133
- return false;
134
- }
135
- return true;
136
- }
137
-
138
- const walletProvider = showedLoginProviderList.find((item) => item.provider === LOGIN_PROVIDER.WALLET);
139
- if (walletProvider?.showQrcode !== true) {
140
- return true;
141
- }
142
- if (isMobileView) {
143
- return true;
144
- }
145
- return false;
146
- }, [mode, isSmallView, showedLoginProviderList]);
147
-
148
- const hideChooseList = useCreation(() => {
149
- return false;
150
- // NOTICE: 先保留这部分逻辑,后续根据需求调整
151
- // if (showOAuthLogin || showPasskeyLogin) {
152
- // return false;
153
- // }
154
- // return true;
155
- });
156
-
157
- const result = {
158
- hideChooseList,
159
- hideQRCode,
160
- providerList: showedLoginProviderList,
161
- loadingProviderList,
162
- };
163
-
164
- return result;
165
- }
@@ -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
- }