@arcblock/did-connect-react 3.4.15 → 3.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/standalone/did-connect-react.css +1 -0
- package/dist/standalone/index.js +133700 -0
- package/lib/package.json.js +1 -1
- package/package.json +11 -6
- package/.aigne/doc-smith/config.yaml +0 -85
- package/.aigne/doc-smith/history.yaml +0 -6
- package/.aigne/doc-smith/output/structure-plan.json +0 -204
- package/.aigne/doc-smith/translation-cache.yaml +0 -11
- package/.aigne/doc-smith/upload-cache.yaml +0 -213
- package/docs/_sidebar.md +0 -18
- package/docs/advanced-authentication-methods.ja.md +0 -261
- package/docs/advanced-authentication-methods.md +0 -261
- package/docs/advanced-authentication-methods.zh-TW.md +0 -261
- package/docs/advanced-authentication-methods.zh.md +0 -261
- package/docs/advanced-utilities.ja.md +0 -132
- package/docs/advanced-utilities.md +0 -132
- package/docs/advanced-utilities.zh-TW.md +0 -132
- package/docs/advanced-utilities.zh.md +0 -132
- package/docs/advanced.ja.md +0 -95
- package/docs/advanced.md +0 -95
- package/docs/advanced.zh-TW.md +0 -95
- package/docs/advanced.zh.md +0 -95
- package/docs/api-reference.ja.md +0 -178
- package/docs/api-reference.md +0 -178
- package/docs/api-reference.zh-TW.md +0 -178
- package/docs/api-reference.zh.md +0 -178
- package/docs/assets/diagram/core-components-session-provider-01.ja.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/core-components-session-provider-01.zh.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/did-connect-diagram-0.zh.jpg +0 -0
- package/docs/assets/diagram/overview-01.ja.jpg +0 -0
- package/docs/assets/diagram/overview-01.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh-TW.jpg +0 -0
- package/docs/assets/diagram/overview-01.zh.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.ja.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.zh-TW.jpg +0 -0
- package/docs/assets/diagram/use-connect-diagram-0.zh.jpg +0 -0
- package/docs/core-components-did-connect.ja.md +0 -166
- package/docs/core-components-did-connect.md +0 -166
- package/docs/core-components-did-connect.zh-TW.md +0 -166
- package/docs/core-components-did-connect.zh.md +0 -166
- package/docs/core-components-session-provider.ja.md +0 -197
- package/docs/core-components-session-provider.md +0 -197
- package/docs/core-components-session-provider.zh-TW.md +0 -197
- package/docs/core-components-session-provider.zh.md +0 -197
- package/docs/core-components.ja.md +0 -16
- package/docs/core-components.md +0 -16
- package/docs/core-components.zh-TW.md +0 -16
- package/docs/core-components.zh.md +0 -16
- package/docs/getting-started.ja.md +0 -138
- package/docs/getting-started.md +0 -138
- package/docs/getting-started.zh-TW.md +0 -138
- package/docs/getting-started.zh.md +0 -138
- package/docs/hooks-use-connect.ja.md +0 -178
- package/docs/hooks-use-connect.md +0 -178
- package/docs/hooks-use-connect.zh-TW.md +0 -178
- package/docs/hooks-use-connect.zh.md +0 -178
- package/docs/hooks-use-did.ja.md +0 -107
- package/docs/hooks-use-did.md +0 -107
- package/docs/hooks-use-did.zh-TW.md +0 -107
- package/docs/hooks-use-did.zh.md +0 -107
- package/docs/hooks-use-oauth-passkey.ja.md +0 -188
- package/docs/hooks-use-oauth-passkey.md +0 -188
- package/docs/hooks-use-oauth-passkey.zh-TW.md +0 -188
- package/docs/hooks-use-oauth-passkey.zh.md +0 -188
- package/docs/hooks.ja.md +0 -23
- package/docs/hooks.md +0 -23
- package/docs/hooks.zh-TW.md +0 -23
- package/docs/hooks.zh.md +0 -23
- package/docs/overview.ja.md +0 -119
- package/docs/overview.md +0 -119
- package/docs/overview.zh-TW.md +0 -119
- package/docs/overview.zh.md +0 -119
- package/docs/ui-components-address.ja.md +0 -121
- package/docs/ui-components-address.md +0 -121
- package/docs/ui-components-address.zh-TW.md +0 -121
- package/docs/ui-components-address.zh.md +0 -121
- package/docs/ui-components-avatar.ja.md +0 -65
- package/docs/ui-components-avatar.md +0 -65
- package/docs/ui-components-avatar.zh-TW.md +0 -65
- package/docs/ui-components-avatar.zh.md +0 -65
- package/docs/ui-components-button.ja.md +0 -99
- package/docs/ui-components-button.md +0 -99
- package/docs/ui-components-button.zh-TW.md +0 -99
- package/docs/ui-components-button.zh.md +0 -99
- package/docs/ui-components-logo.ja.md +0 -52
- package/docs/ui-components-logo.md +0 -52
- package/docs/ui-components-logo.zh-TW.md +0 -52
- package/docs/ui-components-logo.zh.md +0 -52
- package/docs/ui-components.ja.md +0 -57
- package/docs/ui-components.md +0 -57
- package/docs/ui-components.zh-TW.md +0 -57
- package/docs/ui-components.zh.md +0 -57
- package/glossary.md +0 -1
- package/src/Address/index.jsx +0 -2
- package/src/Avatar/index.jsx +0 -2
- package/src/Button/Button.stories.jsx +0 -7
- package/src/Button/index.jsx +0 -21
- package/src/Connect/Connect.stories.jsx +0 -34
- package/src/Connect/assets/locale.js +0 -149
- package/src/Connect/assets/login-bg.png +0 -0
- package/src/Connect/assets/login-slogan.js +0 -7
- package/src/Connect/components/action-button.jsx +0 -22
- package/src/Connect/components/app-tips.jsx +0 -156
- package/src/Connect/components/auto-height.jsx +0 -38
- package/src/Connect/components/back-button.jsx +0 -24
- package/src/Connect/components/connect-status.jsx +0 -259
- package/src/Connect/components/did-connect-title.jsx +0 -107
- package/src/Connect/components/download-tips.jsx +0 -55
- package/src/Connect/components/loading.jsx +0 -25
- package/src/Connect/components/login-item/connect-choose-list.jsx +0 -328
- package/src/Connect/components/login-item/connect-provider-list.jsx +0 -473
- package/src/Connect/components/login-item/login-method-item.jsx +0 -139
- package/src/Connect/components/login-item/mobile-login-item.jsx +0 -184
- package/src/Connect/components/login-item/passkey-login-item.jsx +0 -56
- package/src/Connect/components/login-item/wallet-login-options.jsx +0 -129
- package/src/Connect/components/login-item/web-login-item.jsx +0 -159
- package/src/Connect/components/mask-overlay.jsx +0 -32
- package/src/Connect/components/refresh-overlay.jsx +0 -52
- package/src/Connect/components/switch-app.jsx +0 -69
- package/src/Connect/connect.jsx +0 -635
- package/src/Connect/contexts/state.jsx +0 -235
- package/src/Connect/fallback-connect.jsx +0 -47
- package/src/Connect/fullpage.jsx +0 -3
- package/src/Connect/hooks/auth-url.js +0 -31
- package/src/Connect/hooks/method-list.js +0 -121
- package/src/Connect/hooks/page-show.js +0 -24
- package/src/Connect/hooks/provider-list.js +0 -168
- package/src/Connect/hooks/security.js +0 -40
- package/src/Connect/hooks/token.js +0 -627
- package/src/Connect/hooks/use-apps.js +0 -69
- package/src/Connect/hooks/use-quick-connect.js +0 -119
- package/src/Connect/index.jsx +0 -21
- package/src/Connect/landing-page.jsx +0 -3
- package/src/Connect/plugins/email/index.jsx +0 -85
- package/src/Connect/plugins/email/list-item.jsx +0 -35
- package/src/Connect/plugins/email/placeholder.jsx +0 -372
- package/src/Connect/plugins/index.js +0 -2
- package/src/Connect/use-connect.jsx +0 -321
- package/src/Connect/with-blocklet.jsx +0 -26
- package/src/Connect/with-bridge-call.jsx +0 -138
- package/src/Federated/context.jsx +0 -93
- package/src/Federated/index.jsx +0 -1
- package/src/Logo/index.jsx +0 -2
- package/src/OAuth/bind-conflict-alert.jsx +0 -37
- package/src/OAuth/context.jsx +0 -407
- package/src/OAuth/guest.svg +0 -20
- package/src/OAuth/index.jsx +0 -1
- package/src/OAuth/passport-switcher.jsx +0 -2
- package/src/Passkey/actions.jsx +0 -217
- package/src/Passkey/constants.js +0 -2
- package/src/Passkey/context.jsx +0 -395
- package/src/Passkey/dialog.jsx +0 -401
- package/src/Passkey/icon.jsx +0 -10
- package/src/Passkey/index.jsx +0 -2
- package/src/Service/index.jsx +0 -96
- package/src/Session/assets/did-spaces-guide-cover.svg +0 -1
- package/src/Session/assets/did-spaces-guide-icon.svg +0 -7
- package/src/Session/context.jsx +0 -7
- package/src/Session/did-spaces-guide.jsx +0 -173
- package/src/Session/handler.jsx +0 -98
- package/src/Session/hooks/use-federated.js +0 -91
- package/src/Session/hooks/use-mobile.jsx +0 -6
- package/src/Session/hooks/use-protected-routes.js +0 -16
- package/src/Session/hooks/use-session-token.js +0 -400
- package/src/Session/hooks/use-verify.jsx +0 -76
- package/src/Session/index.jsx +0 -1789
- package/src/Session/libs/constants.js +0 -17
- package/src/Session/libs/did-spaces.js +0 -38
- package/src/Session/libs/federated.js +0 -82
- package/src/Session/libs/index.js +0 -5
- package/src/Session/libs/locales.js +0 -160
- package/src/Session/libs/login-mobile.js +0 -80
- package/src/Session/window-focus-aware.jsx +0 -28
- package/src/SessionManager/index.jsx +0 -2
- package/src/Storage/engine/cookie.js +0 -25
- package/src/Storage/engine/local-storage.js +0 -57
- package/src/Storage/index.js +0 -25
- package/src/User/index.js +0 -4
- package/src/User/use-did.js +0 -80
- package/src/User/wrap-did.jsx +0 -18
- package/src/WebWalletSWKeeper/index.jsx +0 -3
- package/src/components/PassportSwitcher.jsx +0 -160
- package/src/constant.js +0 -27
- package/src/error.js +0 -6
- package/src/hooks/use-locale.jsx +0 -6
- package/src/index.js +0 -32
- package/src/locales/en.jsx +0 -15
- package/src/locales/index.jsx +0 -13
- package/src/locales/zh.jsx +0 -15
- package/src/types.d.ts +0 -355
- package/src/utils.js +0 -413
- package/vite.config.mjs +0 -29
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/* eslint-disable import/no-unresolved */
|
|
2
|
-
/* eslint-disable jsx-a11y/anchor-is-valid */
|
|
3
|
-
import React, { useState } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
Dialog,
|
|
6
|
-
DialogTitle,
|
|
7
|
-
DialogContent,
|
|
8
|
-
DialogActions,
|
|
9
|
-
Button,
|
|
10
|
-
ImageListItem,
|
|
11
|
-
Typography,
|
|
12
|
-
Stack,
|
|
13
|
-
Box,
|
|
14
|
-
CircularProgress,
|
|
15
|
-
} from '@mui/material';
|
|
16
|
-
import { useCreation, useReactive } from 'ahooks';
|
|
17
|
-
import PropTypes from 'prop-types';
|
|
18
|
-
import isUndefined from 'lodash/isUndefined';
|
|
19
|
-
import noop from 'lodash/noop';
|
|
20
|
-
|
|
21
|
-
import DIDSpacesGuideCoverSVG from './assets/did-spaces-guide-cover.svg?react';
|
|
22
|
-
import DidSpacesGuideIcon from './assets/did-spaces-guide-icon.svg?react';
|
|
23
|
-
import { useLocale } from '../hooks/use-locale';
|
|
24
|
-
import { t } from '../locales';
|
|
25
|
-
import useMobile from './hooks/use-mobile';
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @typedef {{
|
|
29
|
-
* autoClose?: true | false;
|
|
30
|
-
* open?: boolean;
|
|
31
|
-
* }} DIDSpacesGuideProps
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @type {React.ForwardRefExoticComponent<React.PropsWithoutRef<DIDSpacesGuideProps> & React.RefAttributes<HTMLDivElement>>}
|
|
36
|
-
*/
|
|
37
|
-
function DIDSpacesGuideView({ ...rawProps }) {
|
|
38
|
-
const props = Object.assign({}, rawProps);
|
|
39
|
-
if (isUndefined(props.open)) {
|
|
40
|
-
props.open = false;
|
|
41
|
-
}
|
|
42
|
-
if (isUndefined(props.onConnect)) {
|
|
43
|
-
props.onConnect = noop;
|
|
44
|
-
}
|
|
45
|
-
const locale = useLocale();
|
|
46
|
-
const isMobile = useMobile();
|
|
47
|
-
const currentState = useReactive({
|
|
48
|
-
loading: false,
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
const features = useCreation(() => {
|
|
52
|
-
return [
|
|
53
|
-
t('didSpacesGuide.feature.dataSecurity', locale),
|
|
54
|
-
t('didSpacesGuide.feature.dataSharing', locale),
|
|
55
|
-
t('didSpacesGuide.feature.dataSync', locale),
|
|
56
|
-
t('didSpacesGuide.feature.dataIntegration', locale),
|
|
57
|
-
];
|
|
58
|
-
}, []);
|
|
59
|
-
|
|
60
|
-
return (
|
|
61
|
-
<Dialog
|
|
62
|
-
disableEscapeKeyDown
|
|
63
|
-
aria-labelledby="alert-dialog-title"
|
|
64
|
-
aria-describedby="alert-dialog-description"
|
|
65
|
-
open={props.open}>
|
|
66
|
-
<DialogTitle id="alert-dialog-title">
|
|
67
|
-
<Typography
|
|
68
|
-
sx={{
|
|
69
|
-
fontSize: '20px',
|
|
70
|
-
fontWeight: '500',
|
|
71
|
-
}}>
|
|
72
|
-
{t('didSpacesGuide.title', locale)}
|
|
73
|
-
</Typography>
|
|
74
|
-
<Typography
|
|
75
|
-
sx={{
|
|
76
|
-
fontSize: '14px',
|
|
77
|
-
fontWeight: '300',
|
|
78
|
-
color: '#9397A1',
|
|
79
|
-
}}>
|
|
80
|
-
{t('didSpacesGuide.description', locale)}
|
|
81
|
-
</Typography>
|
|
82
|
-
</DialogTitle>
|
|
83
|
-
<DialogContent sx={{ padding: '12px 20px !important' }}>
|
|
84
|
-
<ImageListItem sx={{ width: '100%' }}>
|
|
85
|
-
<DIDSpacesGuideCoverSVG style={{ width: '100%', height: isMobile ? '100%' : '167px' }} />
|
|
86
|
-
</ImageListItem>
|
|
87
|
-
<Stack
|
|
88
|
-
direction="row"
|
|
89
|
-
sx={{
|
|
90
|
-
justifyContent: 'space-between',
|
|
91
|
-
width: '100%',
|
|
92
|
-
padding: '16px',
|
|
93
|
-
mt: 1,
|
|
94
|
-
backgroundColor: '#F6F6F6',
|
|
95
|
-
borderRadius: '8px',
|
|
96
|
-
}}>
|
|
97
|
-
{features.map((x) => {
|
|
98
|
-
return (
|
|
99
|
-
<Box key={x} sx={{ display: 'flex', flex: 1, padding: 'auto 16px' }}>
|
|
100
|
-
<DidSpacesGuideIcon size="16px" />
|
|
101
|
-
<Typography
|
|
102
|
-
variant="body1"
|
|
103
|
-
sx={{
|
|
104
|
-
marginLeft: '1.5px',
|
|
105
|
-
color: '#030712',
|
|
106
|
-
fontFamily: 'Helvetica Neue',
|
|
107
|
-
fontSize: '12px',
|
|
108
|
-
fontStyle: 'normal',
|
|
109
|
-
fontWeight: '400',
|
|
110
|
-
lineHeight: 'normal',
|
|
111
|
-
letterSpacing: '-0.12px',
|
|
112
|
-
}}>
|
|
113
|
-
{x}
|
|
114
|
-
</Typography>
|
|
115
|
-
</Box>
|
|
116
|
-
);
|
|
117
|
-
})}
|
|
118
|
-
</Stack>
|
|
119
|
-
</DialogContent>
|
|
120
|
-
<DialogActions>
|
|
121
|
-
<Button
|
|
122
|
-
variant="contained"
|
|
123
|
-
size="small"
|
|
124
|
-
onClick={() => {
|
|
125
|
-
currentState.loading = true;
|
|
126
|
-
props.onConnect(() => {
|
|
127
|
-
currentState.loading = false;
|
|
128
|
-
});
|
|
129
|
-
}}
|
|
130
|
-
sx={{
|
|
131
|
-
boxShadow: 'none',
|
|
132
|
-
}}
|
|
133
|
-
disabled={currentState.loading}>
|
|
134
|
-
{currentState.loading ? <CircularProgress color="inherit" size={12} sx={{ mr: 1 }} /> : null}
|
|
135
|
-
{t('didSpacesGuide.connectNow', locale)}
|
|
136
|
-
</Button>
|
|
137
|
-
</DialogActions>
|
|
138
|
-
</Dialog>
|
|
139
|
-
);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
DIDSpacesGuideView.propTypes = {
|
|
143
|
-
open: PropTypes.bool,
|
|
144
|
-
onConnect: PropTypes.func,
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* @export
|
|
151
|
-
* @param {DIDSpacesGuideProps} [props={}]
|
|
152
|
-
* @return {*}
|
|
153
|
-
*/
|
|
154
|
-
export default function useDIDSpacesGuide(props = {}) {
|
|
155
|
-
const [open, setOpen] = useState(false);
|
|
156
|
-
const [onConnect, setOnConnect] = useState(() => {});
|
|
157
|
-
|
|
158
|
-
const invokeOpen = () => {
|
|
159
|
-
setOpen(true);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const invokeClose = () => {
|
|
163
|
-
setOpen(false);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
const invokeOnConnect = (callback) => {
|
|
167
|
-
setOnConnect(() => callback);
|
|
168
|
-
};
|
|
169
|
-
return {
|
|
170
|
-
DidSpacesGuideView: <DIDSpacesGuideView {...props} open={open} onConnect={onConnect} />,
|
|
171
|
-
didSpacesGuideApi: { open: invokeOpen, close: invokeClose, onConnect: invokeOnConnect },
|
|
172
|
-
};
|
|
173
|
-
}
|
package/src/Session/handler.jsx
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { ReactGA } from '@arcblock/ux/lib/withTracker';
|
|
2
|
-
import { GA_LAST_LOGIN_METHOD, GA_LAST_ROLE, GA_LAST_SOURCE_PROVIDER } from '@arcblock/ux/lib/withTracker/constant';
|
|
3
|
-
|
|
4
|
-
// 监听用户登录事件
|
|
5
|
-
export const gaLoginSuccessHandler = () => {
|
|
6
|
-
/**
|
|
7
|
-
* @type {import('@arcblock/ux/lib/withTracker/action/login').LoginSuccessEvent}
|
|
8
|
-
*/
|
|
9
|
-
const loginSuccessEvent = {
|
|
10
|
-
action: 'loginSuccess',
|
|
11
|
-
provider: localStorage.getItem(GA_LAST_LOGIN_METHOD),
|
|
12
|
-
success: true,
|
|
13
|
-
};
|
|
14
|
-
ReactGA.event(loginSuccessEvent.action, loginSuccessEvent);
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
*
|
|
19
|
-
* @param {Error} error
|
|
20
|
-
*/
|
|
21
|
-
export const gaLoginFailedHandler = (error) => {
|
|
22
|
-
/**
|
|
23
|
-
* @type {import('@arcblock/ux/lib/withTracker/action/login').LoginFailedEvent}
|
|
24
|
-
*/
|
|
25
|
-
const loginFailedEvent = {
|
|
26
|
-
action: 'loginFailed',
|
|
27
|
-
provider: localStorage.getItem(GA_LAST_LOGIN_METHOD),
|
|
28
|
-
success: false,
|
|
29
|
-
errorMessage: error.message,
|
|
30
|
-
};
|
|
31
|
-
ReactGA.event(loginFailedEvent.action, loginFailedEvent);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const gaSwitchPassportSuccessHandler = (_result, _decrypt, session) => {
|
|
35
|
-
const fromRole = localStorage.getItem(GA_LAST_ROLE);
|
|
36
|
-
const toRole = session?.user?.role;
|
|
37
|
-
const change = `${fromRole} -> ${toRole}`;
|
|
38
|
-
/** @type {import('@arcblock/ux/lib/withTracker/action/switch-passport').SwitchPassportSuccessEvent} */
|
|
39
|
-
const switchPassportSuccessEvent = {
|
|
40
|
-
action: 'switchPassportSuccess',
|
|
41
|
-
change,
|
|
42
|
-
success: true,
|
|
43
|
-
};
|
|
44
|
-
ReactGA.event(switchPassportSuccessEvent.action, switchPassportSuccessEvent);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
*
|
|
49
|
-
* @param {Error} error
|
|
50
|
-
*/
|
|
51
|
-
export const gaSwitchPassportFailedHandler = (error) => {
|
|
52
|
-
/** @type {import('@arcblock/ux/lib/withTracker/action/switch-passport').SwitchPassportFailedEvent} */
|
|
53
|
-
const switchPassportFailedEvent = {
|
|
54
|
-
action: 'switchPassportFailed',
|
|
55
|
-
success: false,
|
|
56
|
-
errorMessage: error.message,
|
|
57
|
-
};
|
|
58
|
-
ReactGA.event(switchPassportFailedEvent.action, switchPassportFailedEvent);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
*
|
|
63
|
-
* @param {any} _result
|
|
64
|
-
* @param {Function} _decrypt
|
|
65
|
-
* @param {import('../types').SessionProps} session
|
|
66
|
-
*/
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
|
-
* @param {any} _result
|
|
70
|
-
* @param {Function} _decrypt
|
|
71
|
-
* @param {import('../types').SessionProps} session
|
|
72
|
-
*/
|
|
73
|
-
export const gaBindWalletSuccessHandler = (_result, _decrypt, session) => {
|
|
74
|
-
/**
|
|
75
|
-
* @type {import('@arcblock/ux/lib/withTracker/action/bind-wallet').BindWalletSuccessEvent} */
|
|
76
|
-
const bindWalletEvent = {
|
|
77
|
-
action: 'bindWalletSuccess',
|
|
78
|
-
provider: session?.user?.sourceProvider,
|
|
79
|
-
success: true,
|
|
80
|
-
};
|
|
81
|
-
ReactGA.event(bindWalletEvent.action, bindWalletEvent);
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @param {Error} error
|
|
86
|
-
* @param {import('../types').User} user
|
|
87
|
-
*/
|
|
88
|
-
export const gaBindWalletFailedHandler = (error) => {
|
|
89
|
-
/** @type {import('@arcblock/ux/lib/withTracker/action/bind-wallet').BindWalletFailedEvent} */
|
|
90
|
-
const bindWalletFailedEvent = {
|
|
91
|
-
action: 'bindWalletFailed',
|
|
92
|
-
provider: localStorage.getItem(GA_LAST_SOURCE_PROVIDER),
|
|
93
|
-
success: false,
|
|
94
|
-
errorMessage: error.message,
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
ReactGA.event(bindWalletFailedEvent.action, bindWalletFailedEvent);
|
|
98
|
-
};
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { useMemoizedFn, useReactive } from 'ahooks';
|
|
2
|
-
import { getConfig, getFederatedEnabled, getMaster } from '@arcblock/ux/lib/Util/federated';
|
|
3
|
-
import noop from 'lodash/noop';
|
|
4
|
-
|
|
5
|
-
import { loginFederatedMaster } from '../libs/federated';
|
|
6
|
-
|
|
7
|
-
const translations = {
|
|
8
|
-
zh: {
|
|
9
|
-
notFoundFederatedInfo: '未发现统一登录的信息',
|
|
10
|
-
autoLoginFederatedFailed: '自动登录统一登录账号失败',
|
|
11
|
-
manualLoginFederatedFailed: '手动登录统一登录账号失败',
|
|
12
|
-
},
|
|
13
|
-
en: {
|
|
14
|
-
notFoundFederatedInfo: 'No federated login info detected',
|
|
15
|
-
autoLoginFederatedFailed: 'Auto login federated account failed',
|
|
16
|
-
manualLoginFederatedFailed: 'Manual login federated account failed',
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default function useFederated({ locale, handleLoginResult, login, handleRefreshUser }) {
|
|
21
|
-
const state = useReactive({
|
|
22
|
-
federatedMaster: null,
|
|
23
|
-
});
|
|
24
|
-
const federatedEnabled = getFederatedEnabled();
|
|
25
|
-
const master = getMaster();
|
|
26
|
-
const config = getConfig();
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated no longer used
|
|
30
|
-
*/
|
|
31
|
-
const loginFederated = useMemoizedFn(
|
|
32
|
-
async (callback = noop, extraParams = {}, options = {}) => {
|
|
33
|
-
// @compatible: 兼容旧的传递 origin 的方式
|
|
34
|
-
if (typeof options === 'string') {
|
|
35
|
-
// eslint-disable-next-line no-param-reassign
|
|
36
|
-
options = { origin: options };
|
|
37
|
-
}
|
|
38
|
-
// eslint-disable-next-line prefer-const
|
|
39
|
-
let { mode = 'auto', ...params } = extraParams;
|
|
40
|
-
if (options.mode) {
|
|
41
|
-
mode = options.mode;
|
|
42
|
-
}
|
|
43
|
-
// @compatible end
|
|
44
|
-
|
|
45
|
-
if (mode === 'auto') {
|
|
46
|
-
if (!federatedEnabled) {
|
|
47
|
-
// NOTE: 这里的错误仅展示在控制台,不需要展示给用户看
|
|
48
|
-
throw new Error(translations[locale].notFoundFederatedInfo);
|
|
49
|
-
}
|
|
50
|
-
try {
|
|
51
|
-
// 自动登录的前提是:master 已经登录成功,这里需要通过 master 拿到 member 的登录 token
|
|
52
|
-
// FIXME: @zhanghan 当 connect 组件使用不同的 baseUrl 时,不应该直接从 window.blocklet 去取值
|
|
53
|
-
const data = await loginFederatedMaster({ appId: globalThis.blocklet.appId }, { fetchToken: false });
|
|
54
|
-
handleLoginResult({ ...data, encrypted: false });
|
|
55
|
-
await handleRefreshUser({ showProgress: true });
|
|
56
|
-
callback();
|
|
57
|
-
} catch (err) {
|
|
58
|
-
const errMessage = err?.response ? err.response?.data : err?.message;
|
|
59
|
-
callback(errMessage || translations[locale].autoLoginFederatedFailed);
|
|
60
|
-
}
|
|
61
|
-
} else if (mode === 'manual') {
|
|
62
|
-
try {
|
|
63
|
-
login(
|
|
64
|
-
async () => {
|
|
65
|
-
await loginFederatedMaster(
|
|
66
|
-
// FIXME: @zhanghan 当 connect 组件使用不同的 baseUrl 时,不应该直接从 window.blocklet 去取值
|
|
67
|
-
{ appId: globalThis.blocklet.appId, onlyWriteCookie: true }
|
|
68
|
-
);
|
|
69
|
-
callback();
|
|
70
|
-
},
|
|
71
|
-
{ ...params },
|
|
72
|
-
options
|
|
73
|
-
);
|
|
74
|
-
} catch (err) {
|
|
75
|
-
const errMessage = err?.response ? err.response?.data : err?.message;
|
|
76
|
-
callback(errMessage || translations[locale].autoLoginFederatedFailed);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
[handleRefreshUser, login, locale, handleLoginResult]
|
|
81
|
-
);
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
master,
|
|
85
|
-
config,
|
|
86
|
-
federatedMaster: state.federatedMaster,
|
|
87
|
-
federatedEnabled,
|
|
88
|
-
loginFederated,
|
|
89
|
-
loginFederatedMaster,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useCreation, useMemoizedFn } from 'ahooks';
|
|
2
|
-
import pathToRegexp from 'path-to-regexp';
|
|
3
|
-
|
|
4
|
-
export default function useProtectedRoutes({ protectedRoutes = [] }) {
|
|
5
|
-
const matchList = useCreation(() => {
|
|
6
|
-
return protectedRoutes.map((item) => pathToRegexp(item, []));
|
|
7
|
-
}, [protectedRoutes]);
|
|
8
|
-
|
|
9
|
-
const checkMatch = useMemoizedFn((currentRoute = window.location.pathname) => {
|
|
10
|
-
return matchList.some((item) => item.exec(currentRoute));
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
return {
|
|
14
|
-
checkMatch,
|
|
15
|
-
};
|
|
16
|
-
}
|