@arcblock/ux 2.13.13 → 2.13.14
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/lib/Address/responsive-did-address.js +3 -1
- package/lib/DIDConnect/app-icon.d.ts +8 -0
- package/lib/DIDConnect/app-icon.js +31 -0
- package/lib/DIDConnect/app-info-item.d.ts +7 -0
- package/lib/DIDConnect/app-info-item.js +73 -0
- package/lib/DIDConnect/did-connect-footer.d.ts +4 -0
- package/lib/DIDConnect/did-connect-footer.js +54 -0
- package/lib/DIDConnect/did-connect-logo.d.ts +1 -0
- package/lib/DIDConnect/did-connect-logo.js +11 -0
- package/lib/DIDConnect/index.d.ts +7 -0
- package/lib/DIDConnect/index.js +7 -0
- package/lib/DIDConnect/powered-by.d.ts +3 -0
- package/lib/DIDConnect/powered-by.js +46 -0
- package/lib/DIDConnect/with-container.d.ts +11 -0
- package/lib/DIDConnect/with-container.js +273 -0
- package/lib/DIDConnect/with-ux-theme.d.ts +1 -0
- package/lib/DIDConnect/with-ux-theme.js +23 -0
- package/lib/Dialog/confirm.d.ts +6 -1
- package/lib/Dialog/confirm.js +7 -3
- package/lib/Dialog/use-confirm.js +6 -0
- package/lib/Locale/util.d.ts +3 -3
- package/lib/Locale/util.js +6 -1
- package/lib/LoginButton/index.d.ts +12 -0
- package/lib/LoginButton/index.js +74 -0
- package/lib/SessionUser/components/un-login.js +42 -31
- package/lib/SharedBridge/index.d.ts +16 -0
- package/lib/SharedBridge/index.js +109 -0
- package/lib/SharedBridge/need-storage-access-api-dialog.d.ts +7 -0
- package/lib/SharedBridge/need-storage-access-api-dialog.js +212 -0
- package/lib/Theme/index.d.ts +2 -2
- package/lib/Theme/index.js +1 -1
- package/lib/Util/iframe.d.ts +5 -0
- package/lib/Util/iframe.js +24 -0
- package/lib/Util/index.d.ts +10 -1
- package/lib/Util/index.js +67 -4
- package/package.json +7 -6
- package/src/Address/responsive-did-address.tsx +11 -1
- package/src/DIDConnect/app-icon.tsx +36 -0
- package/src/DIDConnect/app-info-item.tsx +82 -0
- package/src/DIDConnect/did-connect-footer.tsx +51 -0
- package/src/DIDConnect/did-connect-logo.tsx +8 -0
- package/src/DIDConnect/index.ts +7 -0
- package/src/DIDConnect/powered-by.tsx +48 -0
- package/src/DIDConnect/with-container.tsx +307 -0
- package/src/DIDConnect/with-ux-theme.tsx +22 -0
- package/src/Dialog/confirm.jsx +31 -23
- package/src/Dialog/use-confirm.jsx +6 -0
- package/src/Locale/util.ts +7 -2
- package/src/LoginButton/index.tsx +73 -0
- package/src/SessionUser/components/un-login.tsx +34 -27
- package/src/SharedBridge/index.tsx +123 -0
- package/src/SharedBridge/need-storage-access-api-dialog.tsx +171 -0
- package/src/Theme/index.ts +2 -2
- package/src/Util/iframe.ts +19 -0
- package/src/Util/index.ts +77 -4
package/lib/Dialog/confirm.js
CHANGED
@@ -15,6 +15,7 @@ import Dialog from './dialog';
|
|
15
15
|
* children?: React.ReactNode,
|
16
16
|
* showCancelButton?: true | false,
|
17
17
|
* showCloseButton?: true | false,
|
18
|
+
* showConfirmButton?: true | false,
|
18
19
|
* fullScreen?: false | true,
|
19
20
|
* confirmButton?: {text: React.ReactNode, props?: ButtonProps}
|
20
21
|
* cancelButton?: {text: React.ReactNode, props?: ButtonProps}
|
@@ -35,6 +36,7 @@ export default function Confirm({
|
|
35
36
|
onCancel,
|
36
37
|
showCloseButton,
|
37
38
|
showCancelButton,
|
39
|
+
showConfirmButton,
|
38
40
|
fullScreen,
|
39
41
|
confirmButton,
|
40
42
|
cancelButton,
|
@@ -74,7 +76,7 @@ export default function Confirm({
|
|
74
76
|
}
|
75
77
|
}
|
76
78
|
},
|
77
|
-
actions: /*#__PURE__*/_jsxs(_Fragment, {
|
79
|
+
actions: showCancelButton || showConfirmButton ? /*#__PURE__*/_jsxs(_Fragment, {
|
78
80
|
children: [showCancelButton && /*#__PURE__*/_jsx(Button, {
|
79
81
|
onClick: e => {
|
80
82
|
e.stopPropagation();
|
@@ -83,7 +85,7 @@ export default function Confirm({
|
|
83
85
|
color: "primary",
|
84
86
|
...cancelButton.props,
|
85
87
|
children: cancelButton.text
|
86
|
-
}), /*#__PURE__*/_jsx(Button, {
|
88
|
+
}), showConfirmButton && /*#__PURE__*/_jsx(Button, {
|
87
89
|
onClick: e => {
|
88
90
|
e.stopPropagation();
|
89
91
|
onConfirm(e);
|
@@ -93,7 +95,7 @@ export default function Confirm({
|
|
93
95
|
...confirmButton.props,
|
94
96
|
children: confirmButton.text
|
95
97
|
})]
|
96
|
-
}),
|
98
|
+
}) : null,
|
97
99
|
children: children
|
98
100
|
});
|
99
101
|
}
|
@@ -104,6 +106,7 @@ Confirm.propTypes = {
|
|
104
106
|
onCancel: PropTypes.func.isRequired,
|
105
107
|
children: PropTypes.node,
|
106
108
|
showCancelButton: PropTypes.bool,
|
109
|
+
showConfirmButton: PropTypes.bool,
|
107
110
|
showCloseButton: PropTypes.bool,
|
108
111
|
fullScreen: PropTypes.bool,
|
109
112
|
// 可以传入 {text: ..., props: ...}
|
@@ -119,6 +122,7 @@ Confirm.propTypes = {
|
|
119
122
|
};
|
120
123
|
Confirm.defaultProps = {
|
121
124
|
showCancelButton: true,
|
125
|
+
showConfirmButton: true,
|
122
126
|
showCloseButton: true,
|
123
127
|
fullScreen: false,
|
124
128
|
confirmButton: {
|
@@ -18,6 +18,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
|
|
18
18
|
loading: false,
|
19
19
|
showCancelButton: true,
|
20
20
|
showCloseButton: true,
|
21
|
+
showConfirmButton: true,
|
21
22
|
confirmButtonText: 'Confirm',
|
22
23
|
confirmButtonProps: {},
|
23
24
|
cancelButtonText: 'Cancel',
|
@@ -42,6 +43,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
|
|
42
43
|
state.onCancel = params.onCancel || noop;
|
43
44
|
state.showCloseButton = params.showCloseButton ?? true;
|
44
45
|
state.showCancelButton = params.showCancelButton ?? true;
|
46
|
+
state.showConfirmButton = params.showConfirmButton ?? true;
|
45
47
|
if (params.confirmButtonText) state.confirmButtonText = params.confirmButtonText;
|
46
48
|
if (params.confirmButtonProps) state.confirmButtonProps = params.confirmButtonProps;
|
47
49
|
if (params.cancelButtonText) state.cancelButtonText = params.cancelButtonText;
|
@@ -60,6 +62,9 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
|
|
60
62
|
state.confirmButtonProps = {};
|
61
63
|
state.cancelButtonText = 'Cancel';
|
62
64
|
state.cancelButtonProps = {};
|
65
|
+
state.showConfirmButton = true;
|
66
|
+
state.showCancelButton = true;
|
67
|
+
state.showCloseButton = true;
|
63
68
|
});
|
64
69
|
const close = useMemoizedFn(() => {
|
65
70
|
state.show = false;
|
@@ -125,6 +130,7 @@ const ConfirmHolder = /*#__PURE__*/forwardRef((props, ref) => {
|
|
125
130
|
},
|
126
131
|
showCloseButton: state.showCloseButton,
|
127
132
|
showCancelButton: state.showCancelButton,
|
133
|
+
showConfirmButton: state.showConfirmButton,
|
128
134
|
cancelButton: {
|
129
135
|
text: state.cancelButtonText,
|
130
136
|
props: {
|
package/lib/Locale/util.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import type { Locale, Translations } from '../type';
|
2
|
-
export declare const replace: (template: string, data: Record<string, any>) =>
|
3
|
-
export declare const translate: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) =>
|
4
|
-
export declare const t: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) =>
|
2
|
+
export declare const replace: (template: string | Function, data: Record<string, any>) => any;
|
3
|
+
export declare const translate: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => any;
|
4
|
+
export declare const t: (translations: Translations, key: string, locale: Locale, fallbackLocale?: string, data?: {}) => any;
|
package/lib/Locale/util.js
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
import get from 'lodash/get';
|
2
2
|
/* eslint-disable no-prototype-builtins */
|
3
|
-
export const replace = (template, data) =>
|
3
|
+
export const replace = (template, data) => {
|
4
|
+
if (typeof template === 'function') {
|
5
|
+
return template(data);
|
6
|
+
}
|
7
|
+
return template.replace(/{(\w*)}/g, (m, key) => data.hasOwnProperty(key) ? data[key] : '');
|
8
|
+
};
|
4
9
|
export const translate = (translations, key, locale, fallbackLocale = 'en', data = {}) => {
|
5
10
|
const translation = translations[locale];
|
6
11
|
const translationValue = get(translation, key);
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { Locale } from '../type';
|
2
|
+
type LoginButtonProps = {
|
3
|
+
onClick: (options?: {
|
4
|
+
openMode?: 'popup' | 'window';
|
5
|
+
}) => void;
|
6
|
+
render: (options: {
|
7
|
+
onClick: () => void;
|
8
|
+
}) => React.ReactNode;
|
9
|
+
locale?: Locale;
|
10
|
+
};
|
11
|
+
export default function LoginButton({ onClick, render, locale }: LoginButtonProps): string | number | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
12
|
+
export {};
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { Box } from '@mui/material';
|
3
|
+
import { joinURL } from 'ufo';
|
4
|
+
import { useRef, useState } from 'react';
|
5
|
+
import { useMemoizedFn } from 'ahooks';
|
6
|
+
import { useBrowser } from '@arcblock/react-hooks';
|
7
|
+
import SharedBridge from '../SharedBridge';
|
8
|
+
import { setVisitorId } from '../Util';
|
9
|
+
import { getFederatedEnabled, getMaster } from '../Util/federated';
|
10
|
+
import { callIframe } from '../Util/iframe';
|
11
|
+
export default function LoginButton({
|
12
|
+
onClick,
|
13
|
+
render,
|
14
|
+
locale
|
15
|
+
}) {
|
16
|
+
const blocklet = window?.blocklet;
|
17
|
+
const federatedEnabled = getFederatedEnabled(blocklet);
|
18
|
+
const masterSite = getMaster(blocklet);
|
19
|
+
const sharedBridgeRef = useRef(null);
|
20
|
+
const [hasStorageAccess, setHasStorageAccess] = useState(false);
|
21
|
+
const browser = useBrowser();
|
22
|
+
const handleClick = useMemoizedFn(() => {
|
23
|
+
if (hasStorageAccess) {
|
24
|
+
onClick({
|
25
|
+
openMode: 'popup'
|
26
|
+
});
|
27
|
+
} else {
|
28
|
+
onClick();
|
29
|
+
}
|
30
|
+
});
|
31
|
+
const handleLoad = useMemoizedFn(async () => {
|
32
|
+
const {
|
33
|
+
value: visitorId
|
34
|
+
} = await callIframe(sharedBridgeRef.current, 'getVisitorId');
|
35
|
+
if (visitorId) {
|
36
|
+
setHasStorageAccess(true);
|
37
|
+
setVisitorId(visitorId);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
const handleClickBridge = useMemoizedFn(({
|
41
|
+
value,
|
42
|
+
visitorId
|
43
|
+
}) => {
|
44
|
+
if (visitorId) {
|
45
|
+
setVisitorId(visitorId);
|
46
|
+
}
|
47
|
+
if (value) {
|
48
|
+
onClick({
|
49
|
+
openMode: 'popup'
|
50
|
+
});
|
51
|
+
} else {
|
52
|
+
onClick();
|
53
|
+
}
|
54
|
+
});
|
55
|
+
if (browser.arcSphere || browser.wallet) {
|
56
|
+
return render({
|
57
|
+
onClick
|
58
|
+
});
|
59
|
+
}
|
60
|
+
return /*#__PURE__*/_jsxs(Box, {
|
61
|
+
sx: {
|
62
|
+
position: 'relative'
|
63
|
+
},
|
64
|
+
children: [render({
|
65
|
+
onClick: handleClick
|
66
|
+
}), masterSite?.appUrl && federatedEnabled ? /*#__PURE__*/_jsx(SharedBridge, {
|
67
|
+
locale: locale,
|
68
|
+
iframeRef: sharedBridgeRef,
|
69
|
+
onLoad: handleLoad,
|
70
|
+
onClick: handleClickBridge,
|
71
|
+
src: joinURL(masterSite.appUrl, '/.well-known/service/share/shared-bridge.html')
|
72
|
+
}) : null]
|
73
|
+
});
|
74
|
+
}
|
@@ -14,6 +14,7 @@ import { translations } from '../libs/translation';
|
|
14
14
|
import Typography from '../../Typography';
|
15
15
|
import QuickLoginItem from './quick-login-item';
|
16
16
|
import { getFederatedEnabled, getMaster } from '../../Util/federated';
|
17
|
+
import LoginButton from '../../LoginButton';
|
17
18
|
export default function UnLogin({
|
18
19
|
session,
|
19
20
|
onLogin = noop,
|
@@ -40,16 +41,20 @@ export default function UnLogin({
|
|
40
41
|
const onTogglePopper = useMemoizedFn((value = !currentState.open) => {
|
41
42
|
currentState.open = value;
|
42
43
|
});
|
43
|
-
const _onLogin = useMemoizedFn((
|
44
|
+
const _onLogin = useMemoizedFn(({
|
45
|
+
openMode
|
46
|
+
} = {}) => {
|
44
47
|
if (isFirstLoading) {
|
45
48
|
return;
|
46
49
|
}
|
47
|
-
session.login(onLogin
|
50
|
+
session.login(onLogin, {
|
51
|
+
openMode
|
52
|
+
});
|
48
53
|
});
|
49
54
|
const blocklet = window?.blocklet;
|
50
55
|
const federatedEnabled = getFederatedEnabled(blocklet);
|
51
|
-
const
|
52
|
-
const loginApp = federatedEnabled &&
|
56
|
+
const masterSite = getMaster(blocklet);
|
57
|
+
const loginApp = federatedEnabled && masterSite ? masterSite : blocklet;
|
53
58
|
const loginAppName = loginApp?.appName || 'DID Connect';
|
54
59
|
const loginAppLogo = joinURL(loginApp?.appUrl || '/', loginApp?.appLogo || '/.well-known/service/blocklet/logo?imageFilter=convert&f=png&h=80');
|
55
60
|
useEffect(() => {
|
@@ -83,36 +88,42 @@ export default function UnLogin({
|
|
83
88
|
}
|
84
89
|
});
|
85
90
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
86
|
-
children: [/*#__PURE__*/_jsx(
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
91
|
+
children: [/*#__PURE__*/_jsx(LoginButton, {
|
92
|
+
locale: locale,
|
93
|
+
onClick: _onLogin,
|
94
|
+
render: ({
|
95
|
+
onClick
|
96
|
+
}) => {
|
97
|
+
return /*#__PURE__*/_jsx(IconButton, {
|
98
|
+
ref: userAnchorRef,
|
99
|
+
"data-cy": "sessionManager-login",
|
100
|
+
className: "arc-session-user-unlogin",
|
101
|
+
size: "medium",
|
102
|
+
onClick: onClick,
|
103
|
+
"aria-label": "Login button",
|
104
|
+
children: isFirstLoading ? /*#__PURE__*/_jsx(Box, {
|
105
|
+
width: size,
|
106
|
+
height: size,
|
107
|
+
display: "flex",
|
108
|
+
justifyContent: "center",
|
109
|
+
alignItems: "center",
|
110
|
+
children: /*#__PURE__*/_jsx(CircularProgress, {
|
111
|
+
style: {
|
112
|
+
width: size - 4,
|
113
|
+
height: size - 4,
|
114
|
+
color: dark ? '#fff' : ''
|
115
|
+
}
|
116
|
+
})
|
117
|
+
}) : /*#__PURE__*/_jsx(Icon, {
|
118
|
+
icon: UserIcon,
|
119
|
+
fontSize: size,
|
120
|
+
color: dark ? '#fff' : 'inherit',
|
101
121
|
style: {
|
102
|
-
|
103
|
-
height: size - 4,
|
104
|
-
color: dark ? '#fff' : ''
|
122
|
+
transform: 'scale(1.25)'
|
105
123
|
}
|
106
124
|
})
|
107
|
-
})
|
108
|
-
|
109
|
-
fontSize: size,
|
110
|
-
color: dark ? '#fff' : 'inherit',
|
111
|
-
style: {
|
112
|
-
transform: 'scale(1.25)'
|
113
|
-
}
|
114
|
-
})
|
115
|
-
})
|
125
|
+
});
|
126
|
+
}
|
116
127
|
}), /*#__PURE__*/_jsx(Popper, {
|
117
128
|
open: currentState.open,
|
118
129
|
anchorEl: userAnchorRef.current,
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { SxProps } from '@mui/material';
|
2
|
+
import React from 'react';
|
3
|
+
import { Locale } from '../type';
|
4
|
+
declare const SharedBridge: React.NamedExoticComponent<{
|
5
|
+
src: string;
|
6
|
+
onClick: (data: {
|
7
|
+
action: string;
|
8
|
+
value: boolean;
|
9
|
+
visitorId?: string;
|
10
|
+
}) => void;
|
11
|
+
onLoad: () => void;
|
12
|
+
sx?: SxProps;
|
13
|
+
iframeRef?: React.RefObject<HTMLIFrameElement>;
|
14
|
+
locale?: Locale;
|
15
|
+
}>;
|
16
|
+
export default SharedBridge;
|
@@ -0,0 +1,109 @@
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
2
|
+
import { Box } from '@mui/material';
|
3
|
+
import React, { memo, useEffect, useId, useRef } from 'react';
|
4
|
+
import { withQuery } from 'ufo';
|
5
|
+
import { useMemoizedFn, useReactive } from 'ahooks';
|
6
|
+
import { mergeSx } from '../Util/style';
|
7
|
+
import { callIframe, getCallbackAction } from '../Util/iframe';
|
8
|
+
import NeedStorageAccessApiDialog from './need-storage-access-api-dialog';
|
9
|
+
import { withContainer, withUxTheme } from '../DIDConnect';
|
10
|
+
const SharedBridge = /*#__PURE__*/memo(function SharedBridge({
|
11
|
+
src,
|
12
|
+
onClick,
|
13
|
+
onLoad,
|
14
|
+
sx,
|
15
|
+
iframeRef,
|
16
|
+
locale = 'en',
|
17
|
+
...rest
|
18
|
+
}) {
|
19
|
+
const _iframeRef = useRef(null);
|
20
|
+
const refId = useId();
|
21
|
+
const dataId = `shared-bridge_${refId}`;
|
22
|
+
const currentState = useReactive({
|
23
|
+
open: false,
|
24
|
+
hasStorageAccess: false,
|
25
|
+
get origin() {
|
26
|
+
try {
|
27
|
+
return new URL(src).origin;
|
28
|
+
} catch (error) {
|
29
|
+
return src;
|
30
|
+
}
|
31
|
+
},
|
32
|
+
get host() {
|
33
|
+
try {
|
34
|
+
return new URL(src).host;
|
35
|
+
} catch (error) {
|
36
|
+
return src;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
});
|
40
|
+
const targetIframeRef = iframeRef ?? _iframeRef;
|
41
|
+
useEffect(() => {
|
42
|
+
async function handleMessage(event) {
|
43
|
+
const {
|
44
|
+
data
|
45
|
+
} = event;
|
46
|
+
if (data.action === getCallbackAction(dataId, 'requestStorageAccess')) {
|
47
|
+
currentState.open = false;
|
48
|
+
if (!data.value) {
|
49
|
+
onClick(data);
|
50
|
+
return;
|
51
|
+
}
|
52
|
+
const {
|
53
|
+
value: visitorId
|
54
|
+
} = await callIframe(targetIframeRef.current, 'getVisitorId');
|
55
|
+
onClick({
|
56
|
+
...data,
|
57
|
+
visitorId
|
58
|
+
});
|
59
|
+
} else if (data.action === getCallbackAction(dataId, 'preRequestStorageAccess')) {
|
60
|
+
currentState.open = true;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
window.addEventListener('message', handleMessage);
|
64
|
+
return () => {
|
65
|
+
window.removeEventListener('message', handleMessage);
|
66
|
+
};
|
67
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
68
|
+
}, [onClick, dataId, targetIframeRef?.current]);
|
69
|
+
const DialogComponent = withUxTheme(withContainer(NeedStorageAccessApiDialog));
|
70
|
+
const handleLoad = useMemoizedFn(() => {
|
71
|
+
callIframe(targetIframeRef.current, 'hasStorageAccess').then(({
|
72
|
+
value
|
73
|
+
}) => {
|
74
|
+
currentState.hasStorageAccess = value;
|
75
|
+
});
|
76
|
+
onLoad();
|
77
|
+
});
|
78
|
+
return currentState.hasStorageAccess ? null : /*#__PURE__*/_jsxs(_Fragment, {
|
79
|
+
children: [/*#__PURE__*/_jsx(DialogComponent, {
|
80
|
+
popup: true,
|
81
|
+
locale: locale,
|
82
|
+
blocklet: window.blocklet,
|
83
|
+
open: currentState.open,
|
84
|
+
origin: currentState.origin,
|
85
|
+
host: currentState.host,
|
86
|
+
onClose: () => {}
|
87
|
+
}), /*#__PURE__*/_jsx(Box, {
|
88
|
+
...rest,
|
89
|
+
component: "iframe",
|
90
|
+
ref: targetIframeRef,
|
91
|
+
onLoad: handleLoad,
|
92
|
+
title: "shared-bridge",
|
93
|
+
"data-id": dataId,
|
94
|
+
src: withQuery(src, {
|
95
|
+
id: dataId
|
96
|
+
}),
|
97
|
+
sx: mergeSx({
|
98
|
+
border: 0,
|
99
|
+
position: 'absolute',
|
100
|
+
top: 0,
|
101
|
+
left: 0,
|
102
|
+
width: '100%',
|
103
|
+
height: '100%',
|
104
|
+
cursor: 'pointer'
|
105
|
+
}, sx)
|
106
|
+
})]
|
107
|
+
});
|
108
|
+
});
|
109
|
+
export default SharedBridge;
|
@@ -0,0 +1,212 @@
|
|
1
|
+
import { Fragment as _Fragment, jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
2
|
+
import { Box, Typography, Chip, List, ListItem } from '@mui/material';
|
3
|
+
import { Icon } from '@iconify/react';
|
4
|
+
import externalLinkIcon from '@iconify-icons/tabler/external-link';
|
5
|
+
import lockOutlineIcon from '@iconify-icons/material-symbols/lock-outline';
|
6
|
+
import checkCircleIcon from '@iconify-icons/material-symbols/check-circle';
|
7
|
+
import rocketLaunchRoundedIcon from '@iconify-icons/material-symbols/rocket-launch-rounded';
|
8
|
+
import { useCreation, useMemoizedFn } from 'ahooks';
|
9
|
+
import { useEffect } from 'react';
|
10
|
+
import { getDIDMotifInfo } from '@arcblock/did-motif';
|
11
|
+
import { translate } from '../Locale/util';
|
12
|
+
import { getDIDColor, isEthereumDid } from '../Util';
|
13
|
+
import { DIDConnectFooter } from '../DIDConnect';
|
14
|
+
const translations = {
|
15
|
+
en: {
|
16
|
+
allow: 'Allow',
|
17
|
+
dataUsage: 'Your data is only used for identity authentication, and will not be collected or used for any other purpose.',
|
18
|
+
title: 'Cross-site authorization request',
|
19
|
+
clickAllow: ({
|
20
|
+
allowButton
|
21
|
+
}) => {
|
22
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
23
|
+
children: ["You only need to click the ", allowButton, " button above, and you will not see this request again."]
|
24
|
+
});
|
25
|
+
},
|
26
|
+
reason: ({
|
27
|
+
site
|
28
|
+
}) => {
|
29
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
30
|
+
children: ["For a better login experience, we need to apply for the storage permission of the ", site, " site."]
|
31
|
+
});
|
32
|
+
},
|
33
|
+
afterAllow: {
|
34
|
+
title: 'After authorization, you will enjoy:',
|
35
|
+
list1: 'More convenient login experience',
|
36
|
+
list2: 'Faster access speed'
|
37
|
+
}
|
38
|
+
},
|
39
|
+
zh: {
|
40
|
+
allow: '允许',
|
41
|
+
dataUsage: '您的数据仅用于身份认证,不会被收集或用于其他用途。',
|
42
|
+
title: '跨站授权请求',
|
43
|
+
clickAllow: ({
|
44
|
+
allowButton
|
45
|
+
}) => {
|
46
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
47
|
+
children: ["\u60A8\u53EA\u9700\u8981\u70B9\u51FB\u5C4F\u5E55\u4E0A\u65B9\u7684 ", allowButton, " \u6309\u94AE\uFF0C\u540E\u7EED\u5C06\u4E0D\u4F1A\u518D\u770B\u5230\u8FD9\u4E2A\u8BF7\u6C42\u3002"]
|
48
|
+
});
|
49
|
+
},
|
50
|
+
reason: ({
|
51
|
+
site
|
52
|
+
}) => {
|
53
|
+
return /*#__PURE__*/_jsxs(_Fragment, {
|
54
|
+
children: ["\u4E3A\u4E86\u8BA9\u60A8\u83B7\u5F97\u66F4\u597D\u7684\u767B\u5F55\u4F53\u9A8C\uFF0C\u6211\u4EEC\u9700\u8981\u7533\u8BF7 ", site, " \u7AD9\u70B9\u5B58\u50A8\u6743\u9650\u3002"]
|
55
|
+
});
|
56
|
+
},
|
57
|
+
afterAllow: {
|
58
|
+
title: '授权后,您将享受:',
|
59
|
+
list1: '更便捷的登录体验',
|
60
|
+
list2: '更快的访问速度'
|
61
|
+
}
|
62
|
+
}
|
63
|
+
};
|
64
|
+
export default function NeedStorageAccessApiDialog({
|
65
|
+
locale = 'en',
|
66
|
+
origin,
|
67
|
+
host,
|
68
|
+
setColor
|
69
|
+
}) {
|
70
|
+
const t = useMemoizedFn((key, data = {}) => {
|
71
|
+
return translate(translations, key, locale, 'en', data);
|
72
|
+
});
|
73
|
+
const currentAppColor = useCreation(() => {
|
74
|
+
const did = window.blocklet.appPid;
|
75
|
+
const isEthDid = isEthereumDid(did);
|
76
|
+
const didMotifInfo = isEthDid ? undefined : getDIDMotifInfo(did);
|
77
|
+
if (isEthDid) {
|
78
|
+
return getDIDColor(did);
|
79
|
+
}
|
80
|
+
return didMotifInfo.color;
|
81
|
+
}, []);
|
82
|
+
useEffect(() => {
|
83
|
+
setColor(currentAppColor);
|
84
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
85
|
+
}, [currentAppColor]);
|
86
|
+
return /*#__PURE__*/_jsxs(Box, {
|
87
|
+
sx: {
|
88
|
+
backgroundColor: 'background.default',
|
89
|
+
display: 'flex',
|
90
|
+
flexDirection: 'column',
|
91
|
+
height: '100%',
|
92
|
+
position: 'relative',
|
93
|
+
maxWidth: '100%',
|
94
|
+
transition: 'width 0.2s ease-in-out',
|
95
|
+
margin: 'auto',
|
96
|
+
p: 3,
|
97
|
+
pb: 0,
|
98
|
+
gap: 2
|
99
|
+
},
|
100
|
+
children: [/*#__PURE__*/_jsxs(Typography, {
|
101
|
+
component: "h1",
|
102
|
+
variant: "h4",
|
103
|
+
sx: {
|
104
|
+
fontWeight: 700,
|
105
|
+
fontFamily: 'Lexend',
|
106
|
+
display: 'flex',
|
107
|
+
alignItems: 'center',
|
108
|
+
gap: 1
|
109
|
+
},
|
110
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
111
|
+
component: Icon,
|
112
|
+
icon: lockOutlineIcon,
|
113
|
+
fontSize: 28,
|
114
|
+
sx: {
|
115
|
+
color: 'warning.main'
|
116
|
+
}
|
117
|
+
}), t('title')]
|
118
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
119
|
+
sx: {
|
120
|
+
display: 'flex',
|
121
|
+
flexDirection: 'column',
|
122
|
+
gap: 1
|
123
|
+
},
|
124
|
+
children: [/*#__PURE__*/_jsx(Typography, {
|
125
|
+
children: t('reason', {
|
126
|
+
site: /*#__PURE__*/_jsx(Chip, {
|
127
|
+
clickable: true,
|
128
|
+
component: "a",
|
129
|
+
href: origin,
|
130
|
+
label: host,
|
131
|
+
size: "small",
|
132
|
+
deleteIcon: /*#__PURE__*/_jsx(Icon, {
|
133
|
+
icon: externalLinkIcon
|
134
|
+
}),
|
135
|
+
onDelete: () => {},
|
136
|
+
target: "_blank"
|
137
|
+
})
|
138
|
+
})
|
139
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
140
|
+
children: t('clickAllow', {
|
141
|
+
allowButton: /*#__PURE__*/_jsx(Chip, {
|
142
|
+
label: t('allow'),
|
143
|
+
size: "small",
|
144
|
+
color: "success"
|
145
|
+
})
|
146
|
+
})
|
147
|
+
}), /*#__PURE__*/_jsxs(Box, {
|
148
|
+
sx: {
|
149
|
+
mt: 2
|
150
|
+
},
|
151
|
+
children: [/*#__PURE__*/_jsxs(Typography, {
|
152
|
+
sx: {
|
153
|
+
display: 'flex',
|
154
|
+
alignItems: 'center',
|
155
|
+
gap: 1,
|
156
|
+
mb: 0.5
|
157
|
+
},
|
158
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
159
|
+
component: Icon,
|
160
|
+
icon: checkCircleIcon,
|
161
|
+
fontSize: 24,
|
162
|
+
sx: {
|
163
|
+
color: 'success.main'
|
164
|
+
}
|
165
|
+
}), t('afterAllow.title')]
|
166
|
+
}), /*#__PURE__*/_jsxs(List, {
|
167
|
+
dense: true,
|
168
|
+
sx: {
|
169
|
+
py: 0,
|
170
|
+
pl: 2
|
171
|
+
},
|
172
|
+
children: [/*#__PURE__*/_jsxs(ListItem, {
|
173
|
+
sx: {
|
174
|
+
display: 'flex',
|
175
|
+
alignItems: 'center',
|
176
|
+
gap: 0.8
|
177
|
+
},
|
178
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
179
|
+
component: Icon,
|
180
|
+
icon: rocketLaunchRoundedIcon,
|
181
|
+
fontSize: 20,
|
182
|
+
sx: {
|
183
|
+
color: 'success.main'
|
184
|
+
}
|
185
|
+
}), t('afterAllow.list1')]
|
186
|
+
}), /*#__PURE__*/_jsxs(ListItem, {
|
187
|
+
sx: {
|
188
|
+
display: 'flex',
|
189
|
+
alignItems: 'center',
|
190
|
+
gap: 0.8
|
191
|
+
},
|
192
|
+
children: [/*#__PURE__*/_jsx(Box, {
|
193
|
+
component: Icon,
|
194
|
+
icon: rocketLaunchRoundedIcon,
|
195
|
+
fontSize: 20,
|
196
|
+
sx: {
|
197
|
+
color: 'success.main'
|
198
|
+
}
|
199
|
+
}), t('afterAllow.list2')]
|
200
|
+
})]
|
201
|
+
})]
|
202
|
+
}), /*#__PURE__*/_jsx(Typography, {
|
203
|
+
component: "div",
|
204
|
+
variant: "body2",
|
205
|
+
color: "grey.700",
|
206
|
+
children: t('dataUsage')
|
207
|
+
})]
|
208
|
+
}), /*#__PURE__*/_jsx(DIDConnectFooter, {
|
209
|
+
currentAppColor: currentAppColor
|
210
|
+
})]
|
211
|
+
});
|
212
|
+
}
|
package/lib/Theme/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { CreateMUIStyled, Theme } from '@mui/material';
|
2
|
-
import { useTheme } from '@mui/material
|
1
|
+
import type { CreateMUIStyled, Theme } from '@mui/material';
|
2
|
+
import { useTheme } from '@mui/material';
|
3
3
|
export * from './theme';
|
4
4
|
export { default as ThemeProvider } from './theme-provider';
|
5
5
|
export { useTheme };
|
package/lib/Theme/index.js
CHANGED