@onekeyfe/inpage-providers-hub 2.2.7-alpha.1 → 2.2.7-alpha.2
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/cjs/floatingButton/images.js +21 -5
- package/dist/cjs/floatingButton/index.js +152 -32
- package/dist/floatingButton/images.d.ts +2 -1
- package/dist/floatingButton/images.js +18 -3
- package/dist/floatingButton/index.d.ts +6 -0
- package/dist/floatingButton/index.js +153 -33
- package/package.json +22 -22
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
14
|
+
exports.MediumRisk = exports.HighRisk = exports.Logo = void 0;
|
|
15
|
+
exports.Image = Image;
|
|
4
16
|
const jsx_runtime_1 = require("preact/jsx-runtime");
|
|
5
17
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
6
|
-
|
|
18
|
+
function Image(_a) {
|
|
19
|
+
var { style } = _a, props = __rest(_a, ["style"]);
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)("img", Object.assign({ style: Object.assign({ userSelect: 'none', WebkitUserDrag: 'none' }, style) }, props)));
|
|
21
|
+
}
|
|
22
|
+
const Logo = ({ style }) => ((0, jsx_runtime_1.jsx)(Image, { alt: "OneKey Logo", style: style, src: "data:image/webp;base64,UklGRswEAABXRUJQVlA4WAoAAAAQAAAALwAALwAAQUxQSCgDAAABoGTbtuq6OdLTNzPbxXCJoehehJlKbkKYmZMGMDPUmZmZOWaM3tN9axXuvVKaEBETEPXhvIhYdOw5Nz35xld//wf//f3Vm0/edO6xiyJi3jBmHsxFLD7poZ/9H39+6KRFEXODGZphLL/iN9WubbvUo/Spa8ed6m9XrohhM9Uo4oKtmtqut47FvmuTbj0/YjTFXMx7StuEIrnUVVKrT82LucooVnxqmwQBpCpI0dT6yYoYFZqY94kHEAEpioW6HPCTedFExGAYT3nAgiAguRRFBA/4VAwHEXNxgS1SFdQMC1O2XhBzMYwV20wCgswuCAImt66I4by4ylYyQRAsZ4CCgK1XxbxY8rsJEBAQLFMUkGLy9yURp5goSXkaC5ILyVMiHrGVXFGclrKiKLY+Ekt+tSuoACI1MxVAtPPXJSdor1QFhApSFdReT7jQTgRBM5lB0Ayw84LbbAXQkhkVQEsKtt72bEFUBMGaIiqCYPbsu04EECqIZQChAk589zuTIAioIDURBFQQk99ttS8IIgKiKIAIIgLau3UsqqCAgoIqqqCABXAMKAKCIGKdXBDEDGRKEcBZQAQkHwvmILnToyC5II632otK2VmkqoC9W783SVnyAgg1KarJH953UhIUVMGMgqAg4MQPXrQTpCiWcovkAoidL91rK3WhJAJTCWDrPVvsNBNrkltERDDr3LJZ+kI9M6NUFexx89q/nAiCYE2sgiC5E/9aE8/ZSq4gUKgDChZan4u4yAmAgBSnAgEpJy+K2LTVVJJcmElySW7dFKO421YARXEqBFAUsfXuGA3jkL32ggogoohQUMnt3XtIDKOJS+ykLCgIYKko2HpJNBGDmPeKYwXNchFLgiKOfWVeDCKiiYN+cawlZUYtOPaXg6KJvIljfrXrRRAEFEVEBfvOX4+JJspNHPGmdj0ouQgKoNB3+uYR0US9ieXX79fUJTAHsdinLun+65dHE9M2ESfev0tl0k1S6rM+TSbdBHXXfSdGNDH9YBhx1MUv77CK9R0vX3x0xHAQMw8HEYuOPOO6x1778redLbQ7f/vytceuPeOoRRGDYdQBVlA4IH4BAACQCACdASowADAAPpE2lkiloqIhMdZqALASCWkABRXm1xMlLv4/sMpVEDsQhAZmdBuj/t2DLLfSj9jeN2h/33kRqlO8uEYD82VJykmZgAD++u9Yi1iq75P1V2sgP+qtpKI6W2w+S89zFwU6NocVAgS4Ahpa8cwJdBVEzwmXPHuS+Bkf1jepfuaBisZjtz5k66v9TsX4ZHJ5vxopXrXVhzZQUpWcle5eRr0hlxA/4qZCdCu7tBQ5hgNercW+3c8xj+8Y/zuF1X58pDYUF3k54O/II2gG8Dqeo/A55jNiCpze2OAuo27ogApJXra1b+faewFXX38yPcZcdAUmJbAX3uojPiByizCXOCi4wxWsVeiO7lp3pZm8f0ZyYUdSt4Zp0OC1vqmHm6T91y+5ksk6nQ1HLhk4+cITpVoLHyAFiOAJR65xrUvCXEZkm4vPDlcD+/++gTsKJ77gEkOU8XBObUsURriu7kcnYOLmxbgVkhgyFKQgHakg1e2tS8mJzSAA" }));
|
|
7
23
|
exports.Logo = Logo;
|
|
8
|
-
const HighRisk = ({ style }) => ((0, jsx_runtime_1.jsx)(
|
|
24
|
+
const HighRisk = ({ style }) => ((0, jsx_runtime_1.jsx)(Image, { style: style, src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAgCAYAAACYTcH3AAACrElEQVRYCe1XvW5TMRT+fFMCBNGBNQ8AL8CAxERLB6ZIzJGY6QO0UmekdkViBqkrAxNDaF+AvkBfAEYGQgsq3GvOZ/cqvonta1uRWPAS/xyf893j7/wE+D/8HlD+7bTdEwwnDaqJgn54feNc5sfbuPqQpqErVQzmE4b7gJp21bUrffwUV4ftKvW3ShV05eiRMBBKqqmVcW/1z7M98xH3Noe4eK+BcUy9hpr/wWjnGb59j8m5Z9me2cDFtA8IDQh37lLWNdY3z/LMKW6PGzSzPqXtOb0zgHq+hZ9f2r3Yb5ZnNPTLmLLlM3qnhn61vB9aJ4MhIQWMEDdvMOxPMGpDP3o5GYywIMsrrtUGdZJ3ksDMcCuJtC4Ady7EHM9wc9fd8817wZC0FXQwKhqor79x51GFakcMnPuM2D01ZVoInwO9YEjaWCgP0LxhLmHEsBSEjJHMN/Aj+tRRMPRKCWlDgGxmDpM5CkajeRtWXHYieSrInSAYG8rxlF8Cx4Y6a9vq8IKxRCsP5VUz3R1pO/Z9ZPaCSa0/XRPpK5LZV7dWwJC0kheirHfNSqQ9WKyrpExr5dWUthZ3gQ13wXlu/WGESFI0gORuMhh6pwaYmV/QLkfHM6X1R5QwxyT3Lda0aTM6dWvJM/mkVRgcbOPS9LwsiBr1u9ZYyu913WL2XnimpP6wX2mBUJnMz+R7szzk1i3zTH31h4Z8g+/uktDOdbT++PSQdwx180zSAD0hQr9gfLeWLC1ePaKUZOy9uLT/lB9V4XJiwCgoiQIJ0oJhP0K/5tUyDdaoALlvnkmQzQtwrPWKtCKbBkwT7UPWajOorII6NWBG+CWhmRcFQa0FB2zQ5HXODJjHwFwmB/8CENOD5KpD25w5X8LQZDmQZ9siw52jtU8tCP1Z2tWj9n/VX19Qwam7VmWvAAAAAElFTkSuQmCC" }));
|
|
9
25
|
exports.HighRisk = HighRisk;
|
|
10
|
-
const
|
|
11
|
-
exports.
|
|
26
|
+
const MediumRisk = ({ style }) => ((0, jsx_runtime_1.jsx)(Image, { style: style, src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAABk0lEQVRIDe2XPU7DQBCF3zqRaEgukAuEAyS0AaWhA1qkhJ5cAA6DZEu0IaKhAQ4QDoAvkAvEDRTx8mbJILceJyshsZK1uyPNfLMz+zN2qLSrM3TbnzhHgn5FvLOh93insWX2hpUYdWr5eoR+mSDlvKuyPfUCvqMDywCfnKJHwZzfvsFhPd6hcB4Xicw4uYkFFh7BHXazAOdkKMLIbRDghErYY7eewmODA88M5z7JNwc4ppWxjC3em+HcJ9nDM9ZyZmUcFc4L4/ci4soHFrie8w+LMqFL0bOelrYFqjpWqOpbcz5lro/ko6F4G845vMq9rN5H3XAlMJTXT+FN+tphZ547rS/MJyOMm4BFtzZ8C+xRUx6HRs0KbwRV5X+4RiJq/zfD7iq7XY6fJWTmu730mE1PfpB8YKQGrN3McFktobe1iRUFzfm6Ios2VHgRjbgFeSBX+CI2PEnwGODtQ6TMn6kINDq9Sl+QBfj9U/h9mdFQjAgsWPVeitOhhqt6L281n0wtDnfyM+FaWPsNCkJzqXiV9w3zlWKqZDoCQAAAAABJRU5ErkJggg==" }));
|
|
27
|
+
exports.MediumRisk = MediumRisk;
|
|
@@ -15,8 +15,15 @@ const preact_1 = require("preact");
|
|
|
15
15
|
const hooks_1 = require("preact/hooks");
|
|
16
16
|
const type_1 = require("./type");
|
|
17
17
|
const images_1 = require("./images");
|
|
18
|
+
const lodash_1 = require("lodash");
|
|
18
19
|
let isInjected = false;
|
|
19
20
|
let i18n = {};
|
|
21
|
+
let defaultSettings = {
|
|
22
|
+
position: {
|
|
23
|
+
side: 'right',
|
|
24
|
+
bottom: '30%',
|
|
25
|
+
}
|
|
26
|
+
};
|
|
20
27
|
const logoStyle = {
|
|
21
28
|
width: '24px',
|
|
22
29
|
height: '24px',
|
|
@@ -45,17 +52,17 @@ const useOutsideClick = (ref, callback) => {
|
|
|
45
52
|
};
|
|
46
53
|
}, [callback, ref]);
|
|
47
54
|
};
|
|
48
|
-
function CloseDialog({ onClose }) {
|
|
55
|
+
function CloseDialog({ onClose, side }) {
|
|
49
56
|
const dialogRef = (0, hooks_1.useRef)(null);
|
|
50
57
|
useOutsideClick(dialogRef, onClose);
|
|
51
58
|
const handleDisable = (0, hooks_1.useCallback)(() => {
|
|
52
|
-
void
|
|
59
|
+
void window.$onekey.$private.request({
|
|
53
60
|
method: 'wallet_disableFloatingButton',
|
|
54
61
|
});
|
|
55
62
|
removeIcon();
|
|
56
63
|
}, []);
|
|
57
64
|
const handleHideOnSite = (0, hooks_1.useCallback)(() => {
|
|
58
|
-
void
|
|
65
|
+
void window.$onekey.$private.request({
|
|
59
66
|
method: 'wallet_hideFloatingButtonOnSite',
|
|
60
67
|
params: { url: window.location.origin },
|
|
61
68
|
});
|
|
@@ -67,7 +74,7 @@ function CloseDialog({ onClose }) {
|
|
|
67
74
|
gap: '8px',
|
|
68
75
|
padding: '12px',
|
|
69
76
|
position: 'absolute',
|
|
70
|
-
|
|
77
|
+
[side]: '100%',
|
|
71
78
|
background: '#fff',
|
|
72
79
|
top: '40px',
|
|
73
80
|
width: '196px',
|
|
@@ -92,29 +99,30 @@ function CloseDialog({ onClose }) {
|
|
|
92
99
|
lineHeight: '16px',
|
|
93
100
|
}, children: i18n.canBeReEnabledInSettings })] })] })] }));
|
|
94
101
|
}
|
|
95
|
-
function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, showCloseDialog, }) {
|
|
102
|
+
function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, isDragging, showCloseDialog, side, }) {
|
|
96
103
|
const [showCloseButton, setIsShowCloseButton] = (0, hooks_1.useState)(false);
|
|
97
104
|
return ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
98
105
|
display: 'flex',
|
|
99
106
|
alignItems: 'center',
|
|
100
107
|
position: 'relative',
|
|
101
108
|
cursor: 'pointer',
|
|
109
|
+
flexDirection: side === 'left' ? 'row-reverse' : 'row',
|
|
102
110
|
}, onMouseEnter: () => {
|
|
103
|
-
if (isExpanded || isShowCloseDialog) {
|
|
111
|
+
if (isDragging || isExpanded || isShowCloseDialog) {
|
|
104
112
|
return;
|
|
105
113
|
}
|
|
106
114
|
setIsShowCloseButton(true);
|
|
107
115
|
}, onMouseLeave: () => setIsShowCloseButton(false), onClick: () => {
|
|
108
|
-
if (isShowCloseDialog) {
|
|
116
|
+
if (isDragging || isShowCloseDialog) {
|
|
109
117
|
return;
|
|
110
118
|
}
|
|
111
119
|
setIsShowCloseButton(false);
|
|
112
120
|
onClick();
|
|
113
|
-
}, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', alignItems: 'center', padding: '8px' }, children: [(0, jsx_runtime_1.jsx)(images_1.Logo, { style: logoStyle }), !dataLoaded && (0, jsx_runtime_1.jsx)("span", { style: textStyle, children: isExpanded ? i18n.fetchingDAppInfo : '' })] }), (0, jsx_runtime_1.jsx)("div", { style: {
|
|
121
|
+
}, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', alignItems: 'center', padding: '8px', flexDirection: side === 'left' ? 'row-reverse' : 'row' }, children: [(0, jsx_runtime_1.jsx)(images_1.Logo, { style: logoStyle }), !dataLoaded && (0, jsx_runtime_1.jsx)("span", { style: textStyle, children: isExpanded ? i18n.fetchingDAppInfo : '' })] }), isDragging ? null : ((0, jsx_runtime_1.jsx)("div", { style: {
|
|
114
122
|
display: 'flex',
|
|
115
123
|
padding: '$4',
|
|
116
124
|
position: 'absolute',
|
|
117
|
-
left: '-6px',
|
|
125
|
+
[side === 'left' ? 'right' : 'left']: '-6px',
|
|
118
126
|
bottom: '-10px',
|
|
119
127
|
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
120
128
|
opacity: showCloseButton ? 1 : 0,
|
|
@@ -125,7 +133,7 @@ function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, showCl
|
|
|
125
133
|
event.stopPropagation();
|
|
126
134
|
setIsShowCloseButton(false);
|
|
127
135
|
showCloseDialog();
|
|
128
|
-
}, children: (0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M7.29289 7.29289C7.68342 6.90237 8.31658 6.90237 8.70711 7.29289L12 10.5858L15.2929 7.29289C15.6834 6.90237 16.3166 6.90237 16.7071 7.29289C17.0976 7.68342 17.0976 8.31658 16.7071 8.70711L13.4142 12L16.7071 15.2929C17.0976 15.6834 17.0976 16.3166 16.7071 16.7071C16.3166 17.0976 15.6834 17.0976 15.2929 16.7071L12 13.4142L8.70711 16.7071C8.31658 17.0976 7.68342 17.0976 7.29289 16.7071C6.90237 16.3166 6.90237 15.6834 7.29289 15.2929L10.5858 12L7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289Z", fill: "rgba(0, 0, 0, 0.61)" }) }) })] }));
|
|
136
|
+
}, children: (0, jsx_runtime_1.jsx)("svg", { width: "16", height: "16", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: (0, jsx_runtime_1.jsx)("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M7.29289 7.29289C7.68342 6.90237 8.31658 6.90237 8.70711 7.29289L12 10.5858L15.2929 7.29289C15.6834 6.90237 16.3166 6.90237 16.7071 7.29289C17.0976 7.68342 17.0976 8.31658 16.7071 8.70711L13.4142 12L16.7071 15.2929C17.0976 15.6834 17.0976 16.3166 16.7071 16.7071C16.3166 17.0976 15.6834 17.0976 15.2929 16.7071L12 13.4142L8.70711 16.7071C8.31658 17.0976 7.68342 17.0976 7.29289 16.7071C6.90237 16.3166 6.90237 15.6834 7.29289 15.2929L10.5858 12L7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289Z", fill: "rgba(0, 0, 0, 0.61)" }) }) }))] }));
|
|
129
137
|
}
|
|
130
138
|
function SecurityInfoRow({ title, children }) {
|
|
131
139
|
return ((0, jsx_runtime_1.jsxs)("div", { style: {
|
|
@@ -150,7 +158,7 @@ const SECURITY_INFO = {
|
|
|
150
158
|
},
|
|
151
159
|
[type_1.EHostSecurityLevel.Medium]: {
|
|
152
160
|
titleId: 'suspectedMaliciousBehavior',
|
|
153
|
-
icon: ((0, jsx_runtime_1.jsx)(images_1.
|
|
161
|
+
icon: ((0, jsx_runtime_1.jsx)(images_1.MediumRisk, { style: { width: 16, height: 16 } })),
|
|
154
162
|
},
|
|
155
163
|
};
|
|
156
164
|
function SecurityRiskDetectionRow({ securityInfo }) {
|
|
@@ -209,7 +217,7 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
209
217
|
fontSize: '14px',
|
|
210
218
|
fontWeight: '500',
|
|
211
219
|
overflow: 'hidden',
|
|
212
|
-
}, children: [((_a = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _a === void 0 ? void 0 : _a.logo) ? ((0, jsx_runtime_1.jsx)(
|
|
220
|
+
}, children: [((_a = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _a === void 0 ? void 0 : _a.logo) ? ((0, jsx_runtime_1.jsx)(images_1.Image, { src: (_b = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _b === void 0 ? void 0 : _b.logo, style: {
|
|
213
221
|
height: '24px',
|
|
214
222
|
width: '24px',
|
|
215
223
|
borderRadius: '8px',
|
|
@@ -233,7 +241,7 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
233
241
|
display: 'flex',
|
|
234
242
|
alignItems: 'center',
|
|
235
243
|
gap: '2px',
|
|
236
|
-
}, children: (_e = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _e === void 0 ? void 0 : _e.origins.map((item) => ((0, jsx_runtime_1.jsx)(
|
|
244
|
+
}, children: (_e = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _e === void 0 ? void 0 : _e.origins.map((item) => ((0, jsx_runtime_1.jsx)(images_1.Image, { src: item.logo, style: {
|
|
237
245
|
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
238
246
|
borderRadius: '9999px',
|
|
239
247
|
width: '16px',
|
|
@@ -269,49 +277,158 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
269
277
|
lineHeight: '16px',
|
|
270
278
|
}, children: "OneKey" })] })] }));
|
|
271
279
|
}
|
|
280
|
+
const savePosition = (params) => {
|
|
281
|
+
void window.$onekey.$private.request({
|
|
282
|
+
method: 'wallet_saveFloatingIconSettings',
|
|
283
|
+
params: {
|
|
284
|
+
position: params
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
};
|
|
272
288
|
function App() {
|
|
273
289
|
const [isExpanded, setIsExpanded] = (0, hooks_1.useState)(false);
|
|
274
290
|
const [showSecurityInfo, setIsShowSecurityInfo] = (0, hooks_1.useState)(false);
|
|
275
291
|
const [securityInfo, setSecurityInfo] = (0, hooks_1.useState)(null);
|
|
276
292
|
const [showCloseDialog, setIsShowCloseDialog] = (0, hooks_1.useState)(false);
|
|
293
|
+
const [settings, setSettings] = (0, hooks_1.useState)(defaultSettings);
|
|
294
|
+
const containerRef = (0, hooks_1.useRef)(null);
|
|
295
|
+
const containerPositionRef = (0, hooks_1.useRef)({ x: 0, y: 0 });
|
|
296
|
+
const [isDragging, setIsDragging] = (0, hooks_1.useState)(false);
|
|
297
|
+
const isDraggingRef = (0, hooks_1.useRef)(isDragging);
|
|
298
|
+
isDraggingRef.current = isDragging;
|
|
299
|
+
const isDraggingTimerIdRef = (0, hooks_1.useRef)(null);
|
|
277
300
|
const handleShowCloseDialog = (0, hooks_1.useCallback)(() => {
|
|
278
301
|
setIsShowCloseDialog(true);
|
|
279
302
|
}, []);
|
|
280
303
|
const handleClick = (0, hooks_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
304
|
+
if (!isDraggingRef.current) {
|
|
305
|
+
setIsExpanded(!isExpanded);
|
|
306
|
+
setIsShowSecurityInfo(true);
|
|
307
|
+
if (!securityInfo) {
|
|
308
|
+
const result = yield window.$onekey.$private.request({
|
|
309
|
+
method: 'wallet_detectRiskLevel',
|
|
310
|
+
params: { url: window.location.origin },
|
|
311
|
+
});
|
|
312
|
+
setSecurityInfo(result.securityInfo);
|
|
313
|
+
}
|
|
289
314
|
}
|
|
290
315
|
}), [isExpanded, securityInfo]);
|
|
291
|
-
|
|
316
|
+
const handleMouseDown = (0, hooks_1.useCallback)((e) => {
|
|
317
|
+
if (isExpanded) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
isDraggingTimerIdRef.current = setTimeout(() => {
|
|
321
|
+
setIsDragging(true);
|
|
322
|
+
isDraggingRef.current = true;
|
|
323
|
+
const newX = e.clientX - 20;
|
|
324
|
+
const newY = e.clientY - 20;
|
|
325
|
+
if (containerRef.current) {
|
|
326
|
+
containerRef.current.style.left = `${newX}px`;
|
|
327
|
+
containerRef.current.style.top = `${newY}px`;
|
|
328
|
+
containerRef.current.style.right = 'auto';
|
|
329
|
+
containerRef.current.style.bottom = 'auto';
|
|
330
|
+
containerPositionRef.current = {
|
|
331
|
+
x: newX,
|
|
332
|
+
y: newY,
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
}, 200);
|
|
336
|
+
}, [isExpanded]);
|
|
337
|
+
const handleMouseMove = (0, hooks_1.useCallback)((0, lodash_1.throttle)((e) => {
|
|
338
|
+
if (isDraggingRef.current) {
|
|
339
|
+
const newX = Math.min(Math.max(e.clientX - 20, 0), window.innerWidth - 40);
|
|
340
|
+
const newY = Math.min(Math.max(e.clientY - 20, 60), window.innerHeight - 60);
|
|
341
|
+
containerPositionRef.current = {
|
|
342
|
+
x: newX,
|
|
343
|
+
y: newY,
|
|
344
|
+
};
|
|
345
|
+
if (containerRef.current) {
|
|
346
|
+
containerRef.current.style.left = `${newX}px`;
|
|
347
|
+
containerRef.current.style.top = `${newY}px`;
|
|
348
|
+
containerRef.current.style.right = 'auto';
|
|
349
|
+
containerRef.current.style.bottom = 'auto';
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}, 16), []);
|
|
353
|
+
const handleMouseUp = (0, hooks_1.useCallback)(() => {
|
|
354
|
+
if (isDraggingTimerIdRef.current) {
|
|
355
|
+
clearTimeout(isDraggingTimerIdRef.current);
|
|
356
|
+
}
|
|
357
|
+
if (isDraggingRef.current) {
|
|
358
|
+
isDraggingRef.current = false;
|
|
359
|
+
setTimeout(() => {
|
|
360
|
+
setIsDragging(false);
|
|
361
|
+
}, 50);
|
|
362
|
+
const { x, y } = containerPositionRef.current;
|
|
363
|
+
const halfWidth = window.innerWidth / 2;
|
|
364
|
+
const side = x < halfWidth ? 'left' : 'right';
|
|
365
|
+
const bottomNumber = 100 - y / window.innerHeight * 100;
|
|
366
|
+
const bottom = `${(bottomNumber).toFixed(4)}%`;
|
|
367
|
+
const resetPosition = () => {
|
|
368
|
+
if (containerRef.current) {
|
|
369
|
+
containerRef.current.style.left = side === 'left' ? '0px' : 'auto';
|
|
370
|
+
containerRef.current.style.right = side === 'right' ? '0px' : 'auto';
|
|
371
|
+
containerRef.current.style.top = bottomNumber > 50 ? `${100 - bottomNumber}%` : 'auto';
|
|
372
|
+
containerRef.current.style.bottom = bottomNumber > 50 ? 'auto' : bottom;
|
|
373
|
+
}
|
|
374
|
+
};
|
|
375
|
+
setTimeout(() => {
|
|
376
|
+
resetPosition();
|
|
377
|
+
}, 20);
|
|
378
|
+
setSettings(prev => (Object.assign(Object.assign({}, prev), { position: {
|
|
379
|
+
bottom,
|
|
380
|
+
side,
|
|
381
|
+
} })));
|
|
382
|
+
savePosition({
|
|
383
|
+
side,
|
|
384
|
+
bottom,
|
|
385
|
+
});
|
|
386
|
+
// Provide a fallback correction for the misalignment of the floating icon.
|
|
387
|
+
setTimeout(() => {
|
|
388
|
+
resetPosition();
|
|
389
|
+
}, 800);
|
|
390
|
+
}
|
|
391
|
+
}, []);
|
|
392
|
+
(0, hooks_1.useEffect)(() => {
|
|
393
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
394
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
395
|
+
return () => {
|
|
396
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
397
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
398
|
+
};
|
|
399
|
+
}, [handleMouseMove, handleMouseUp]);
|
|
400
|
+
const { side, bottom } = settings.position;
|
|
401
|
+
const bottomNumber = Number.parseFloat(bottom);
|
|
402
|
+
return ((0, jsx_runtime_1.jsxs)("div", { id: containerId, ref: containerRef, style: {
|
|
292
403
|
position: 'fixed',
|
|
293
404
|
zIndex: 999999,
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
405
|
+
top: bottomNumber > 50 ? `${100 - bottomNumber}%` : 'auto',
|
|
406
|
+
bottom: bottomNumber > 50 ? 'auto' : bottom,
|
|
407
|
+
userSelect: 'none',
|
|
408
|
+
left: isDragging ? "auto" : side === 'left' ? '0px' : 'auto',
|
|
409
|
+
right: isDragging ? "auto" : side === 'right' ? '0px' : 'auto',
|
|
410
|
+
width: isDragging ? '40px' : '256px',
|
|
297
411
|
background: '#fff',
|
|
298
|
-
borderRadius: '12px',
|
|
299
|
-
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
412
|
+
borderRadius: isDragging ? '100%' : '12px',
|
|
413
|
+
transition: isDragging ? 'none' : 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
300
414
|
boxShadow: '0px 0px 0px 1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
|
|
301
|
-
transform:
|
|
415
|
+
transform: isDragging ? "unset" : (isExpanded ?
|
|
416
|
+
`translateX(${side === 'right' ? '-20px' : '20px'})` :
|
|
417
|
+
`translateX(${side === 'right' ? '216px' : '-216px'})`),
|
|
302
418
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
|
|
303
419
|
WebkitTextSizeAdjust: '100%',
|
|
304
420
|
fontSmooth: 'antialiased',
|
|
305
|
-
|
|
421
|
+
cursor: isDragging ? 'grabbing' : (isExpanded ? 'default' : 'grab'),
|
|
422
|
+
}, onMouseDown: handleMouseDown, children: [showSecurityInfo && securityInfo ? ((0, jsx_runtime_1.jsx)(SecurityInfo, { securityInfo: securityInfo, onClose: () => {
|
|
306
423
|
setIsExpanded(false);
|
|
307
424
|
setIsShowSecurityInfo(false);
|
|
308
|
-
} })) : ((0, jsx_runtime_1.jsx)(IconButton, { onClick: handleClick, isExpanded: isExpanded, isShowCloseDialog: showCloseDialog, showCloseDialog: handleShowCloseDialog, dataLoaded: !!securityInfo })), !isExpanded && showCloseDialog && ((0, jsx_runtime_1.jsx)(CloseDialog, { onClose: () => {
|
|
425
|
+
} })) : ((0, jsx_runtime_1.jsx)(IconButton, { onClick: handleClick, side: side, isExpanded: isExpanded, isShowCloseDialog: showCloseDialog, isDragging: isDragging, showCloseDialog: handleShowCloseDialog, dataLoaded: !!securityInfo })), !isExpanded && showCloseDialog && ((0, jsx_runtime_1.jsx)(CloseDialog, { side: side, onClose: () => {
|
|
309
426
|
setIsShowCloseDialog(false);
|
|
310
427
|
} }))] }));
|
|
311
428
|
}
|
|
312
429
|
function injectIcon() {
|
|
313
430
|
return __awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
const { isShow, i18n: i18nResponse } = yield
|
|
431
|
+
const { isShow, i18n: i18nResponse, settings } = yield window.$onekey.$private.request({
|
|
315
432
|
method: 'wallet_isShowFloatingButton',
|
|
316
433
|
params: { url: window.location.origin },
|
|
317
434
|
});
|
|
@@ -325,6 +442,9 @@ function injectIcon() {
|
|
|
325
442
|
if (!document.body) {
|
|
326
443
|
return;
|
|
327
444
|
}
|
|
445
|
+
if (settings) {
|
|
446
|
+
defaultSettings = Object.assign(Object.assign({}, defaultSettings), settings);
|
|
447
|
+
}
|
|
328
448
|
isInjected = true;
|
|
329
449
|
const div = document.createElement('div');
|
|
330
450
|
document.body.appendChild(div);
|
|
@@ -336,7 +456,7 @@ function injectFloatingButton() {
|
|
|
336
456
|
if (window.top !== window.self) {
|
|
337
457
|
return;
|
|
338
458
|
}
|
|
339
|
-
|
|
459
|
+
window.$onekey.$private.onNotifyFloatingIconChanged(({ showFloatingIcon }) => {
|
|
340
460
|
if (showFloatingIcon) {
|
|
341
461
|
void injectIcon();
|
|
342
462
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
export declare function Image({ style, ...props }: any): import("preact").JSX.Element;
|
|
1
2
|
export declare const Logo: ({ style }: {
|
|
2
3
|
style: any;
|
|
3
4
|
}) => import("preact").JSX.Element;
|
|
4
5
|
export declare const HighRisk: ({ style }: {
|
|
5
6
|
style: any;
|
|
6
7
|
}) => import("preact").JSX.Element;
|
|
7
|
-
export declare const
|
|
8
|
+
export declare const MediumRisk: ({ style }: {
|
|
8
9
|
style: any;
|
|
9
10
|
}) => import("preact").JSX.Element;
|
|
@@ -1,5 +1,20 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx } from "preact/jsx-runtime";
|
|
2
13
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
14
|
+
export function Image(_a) {
|
|
15
|
+
var { style } = _a, props = __rest(_a, ["style"]);
|
|
16
|
+
return (_jsx("img", Object.assign({ style: Object.assign({ userSelect: 'none', WebkitUserDrag: 'none' }, style) }, props)));
|
|
17
|
+
}
|
|
18
|
+
export const Logo = ({ style }) => (_jsx(Image, { alt: "OneKey Logo", style: style, src: "data:image/webp;base64,UklGRswEAABXRUJQVlA4WAoAAAAQAAAALwAALwAAQUxQSCgDAAABoGTbtuq6OdLTNzPbxXCJoehehJlKbkKYmZMGMDPUmZmZOWaM3tN9axXuvVKaEBETEPXhvIhYdOw5Nz35xld//wf//f3Vm0/edO6xiyJi3jBmHsxFLD7poZ/9H39+6KRFEXODGZphLL/iN9WubbvUo/Spa8ed6m9XrohhM9Uo4oKtmtqut47FvmuTbj0/YjTFXMx7StuEIrnUVVKrT82LucooVnxqmwQBpCpI0dT6yYoYFZqY94kHEAEpioW6HPCTedFExGAYT3nAgiAguRRFBA/4VAwHEXNxgS1SFdQMC1O2XhBzMYwV20wCgswuCAImt66I4by4ylYyQRAsZ4CCgK1XxbxY8rsJEBAQLFMUkGLy9yURp5goSXkaC5ILyVMiHrGVXFGclrKiKLY+Ekt+tSuoACI1MxVAtPPXJSdor1QFhApSFdReT7jQTgRBM5lB0Ayw84LbbAXQkhkVQEsKtt72bEFUBMGaIiqCYPbsu04EECqIZQChAk589zuTIAioIDURBFQQk99ttS8IIgKiKIAIIgLau3UsqqCAgoIqqqCABXAMKAKCIGKdXBDEDGRKEcBZQAQkHwvmILnToyC5II632otK2VmkqoC9W783SVnyAgg1KarJH953UhIUVMGMgqAg4MQPXrQTpCiWcovkAoidL91rK3WhJAJTCWDrPVvsNBNrkltERDDr3LJZ+kI9M6NUFexx89q/nAiCYE2sgiC5E/9aE8/ZSq4gUKgDChZan4u4yAmAgBSnAgEpJy+K2LTVVJJcmElySW7dFKO421YARXEqBFAUsfXuGA3jkL32ggogoohQUMnt3XtIDKOJS+ykLCgIYKko2HpJNBGDmPeKYwXNchFLgiKOfWVeDCKiiYN+cawlZUYtOPaXg6KJvIljfrXrRRAEFEVEBfvOX4+JJspNHPGmdj0ouQgKoNB3+uYR0US9ieXX79fUJTAHsdinLun+65dHE9M2ESfev0tl0k1S6rM+TSbdBHXXfSdGNDH9YBhx1MUv77CK9R0vX3x0xHAQMw8HEYuOPOO6x1778redLbQ7f/vytceuPeOoRRGDYdQBVlA4IH4BAACQCACdASowADAAPpE2lkiloqIhMdZqALASCWkABRXm1xMlLv4/sMpVEDsQhAZmdBuj/t2DLLfSj9jeN2h/33kRqlO8uEYD82VJykmZgAD++u9Yi1iq75P1V2sgP+qtpKI6W2w+S89zFwU6NocVAgS4Ahpa8cwJdBVEzwmXPHuS+Bkf1jepfuaBisZjtz5k66v9TsX4ZHJ5vxopXrXVhzZQUpWcle5eRr0hlxA/4qZCdCu7tBQ5hgNercW+3c8xj+8Y/zuF1X58pDYUF3k54O/II2gG8Dqeo/A55jNiCpze2OAuo27ogApJXra1b+faewFXX38yPcZcdAUmJbAX3uojPiByizCXOCi4wxWsVeiO7lp3pZm8f0ZyYUdSt4Zp0OC1vqmHm6T91y+5ksk6nQ1HLhk4+cITpVoLHyAFiOAJR65xrUvCXEZkm4vPDlcD+/++gTsKJ77gEkOU8XBObUsURriu7kcnYOLmxbgVkhgyFKQgHakg1e2tS8mJzSAA" }));
|
|
19
|
+
export const HighRisk = ({ style }) => (_jsx(Image, { style: style, src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACMAAAAgCAYAAACYTcH3AAACrElEQVRYCe1XvW5TMRT+fFMCBNGBNQ8AL8CAxERLB6ZIzJGY6QO0UmekdkViBqkrAxNDaF+AvkBfAEYGQgsq3GvOZ/cqvonta1uRWPAS/xyf893j7/wE+D/8HlD+7bTdEwwnDaqJgn54feNc5sfbuPqQpqErVQzmE4b7gJp21bUrffwUV4ftKvW3ShV05eiRMBBKqqmVcW/1z7M98xH3Noe4eK+BcUy9hpr/wWjnGb59j8m5Z9me2cDFtA8IDQh37lLWNdY3z/LMKW6PGzSzPqXtOb0zgHq+hZ9f2r3Yb5ZnNPTLmLLlM3qnhn61vB9aJ4MhIQWMEDdvMOxPMGpDP3o5GYywIMsrrtUGdZJ3ksDMcCuJtC4Ady7EHM9wc9fd8817wZC0FXQwKhqor79x51GFakcMnPuM2D01ZVoInwO9YEjaWCgP0LxhLmHEsBSEjJHMN/Aj+tRRMPRKCWlDgGxmDpM5CkajeRtWXHYieSrInSAYG8rxlF8Cx4Y6a9vq8IKxRCsP5VUz3R1pO/Z9ZPaCSa0/XRPpK5LZV7dWwJC0kheirHfNSqQ9WKyrpExr5dWUthZ3gQ13wXlu/WGESFI0gORuMhh6pwaYmV/QLkfHM6X1R5QwxyT3Lda0aTM6dWvJM/mkVRgcbOPS9LwsiBr1u9ZYyu913WL2XnimpP6wX2mBUJnMz+R7szzk1i3zTH31h4Z8g+/uktDOdbT++PSQdwx180zSAD0hQr9gfLeWLC1ePaKUZOy9uLT/lB9V4XJiwCgoiQIJ0oJhP0K/5tUyDdaoALlvnkmQzQtwrPWKtCKbBkwT7UPWajOorII6NWBG+CWhmRcFQa0FB2zQ5HXODJjHwFwmB/8CENOD5KpD25w5X8LQZDmQZ9siw52jtU8tCP1Z2tWj9n/VX19Qwam7VmWvAAAAAElFTkSuQmCC" }));
|
|
20
|
+
export const MediumRisk = ({ style }) => (_jsx(Image, { style: style, src: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB8AAAAfCAYAAAAfrhY5AAABk0lEQVRIDe2XPU7DQBCF3zqRaEgukAuEAyS0AaWhA1qkhJ5cAA6DZEu0IaKhAQ4QDoAvkAvEDRTx8mbJILceJyshsZK1uyPNfLMz+zN2qLSrM3TbnzhHgn5FvLOh93insWX2hpUYdWr5eoR+mSDlvKuyPfUCvqMDywCfnKJHwZzfvsFhPd6hcB4Xicw4uYkFFh7BHXazAOdkKMLIbRDghErYY7eewmODA88M5z7JNwc4ppWxjC3em+HcJ9nDM9ZyZmUcFc4L4/ci4soHFrie8w+LMqFL0bOelrYFqjpWqOpbcz5lro/ko6F4G845vMq9rN5H3XAlMJTXT+FN+tphZ547rS/MJyOMm4BFtzZ8C+xRUx6HRs0KbwRV5X+4RiJq/zfD7iq7XY6fJWTmu730mE1PfpB8YKQGrN3McFktobe1iRUFzfm6Ios2VHgRjbgFeSBX+CI2PEnwGODtQ6TMn6kINDq9Sl+QBfj9U/h9mdFQjAgsWPVeitOhhqt6L281n0wtDnfyM+FaWPsNCkJzqXiV9w3zlWKqZDoCQAAAAABJRU5ErkJggg==" }));
|
|
@@ -11,9 +11,16 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "preact/jsx-ru
|
|
|
11
11
|
import { render } from 'preact';
|
|
12
12
|
import { useEffect, useMemo, useCallback, useRef, useState } from 'preact/hooks';
|
|
13
13
|
import { EHostSecurityLevel } from './type';
|
|
14
|
-
import { HighRisk, Logo,
|
|
14
|
+
import { HighRisk, Logo, MediumRisk, Image } from './images';
|
|
15
|
+
import { throttle } from 'lodash';
|
|
15
16
|
let isInjected = false;
|
|
16
17
|
let i18n = {};
|
|
18
|
+
let defaultSettings = {
|
|
19
|
+
position: {
|
|
20
|
+
side: 'right',
|
|
21
|
+
bottom: '30%',
|
|
22
|
+
}
|
|
23
|
+
};
|
|
17
24
|
const logoStyle = {
|
|
18
25
|
width: '24px',
|
|
19
26
|
height: '24px',
|
|
@@ -42,17 +49,17 @@ const useOutsideClick = (ref, callback) => {
|
|
|
42
49
|
};
|
|
43
50
|
}, [callback, ref]);
|
|
44
51
|
};
|
|
45
|
-
function CloseDialog({ onClose }) {
|
|
52
|
+
function CloseDialog({ onClose, side }) {
|
|
46
53
|
const dialogRef = useRef(null);
|
|
47
54
|
useOutsideClick(dialogRef, onClose);
|
|
48
55
|
const handleDisable = useCallback(() => {
|
|
49
|
-
void
|
|
56
|
+
void window.$onekey.$private.request({
|
|
50
57
|
method: 'wallet_disableFloatingButton',
|
|
51
58
|
});
|
|
52
59
|
removeIcon();
|
|
53
60
|
}, []);
|
|
54
61
|
const handleHideOnSite = useCallback(() => {
|
|
55
|
-
void
|
|
62
|
+
void window.$onekey.$private.request({
|
|
56
63
|
method: 'wallet_hideFloatingButtonOnSite',
|
|
57
64
|
params: { url: window.location.origin },
|
|
58
65
|
});
|
|
@@ -64,7 +71,7 @@ function CloseDialog({ onClose }) {
|
|
|
64
71
|
gap: '8px',
|
|
65
72
|
padding: '12px',
|
|
66
73
|
position: 'absolute',
|
|
67
|
-
|
|
74
|
+
[side]: '100%',
|
|
68
75
|
background: '#fff',
|
|
69
76
|
top: '40px',
|
|
70
77
|
width: '196px',
|
|
@@ -89,29 +96,30 @@ function CloseDialog({ onClose }) {
|
|
|
89
96
|
lineHeight: '16px',
|
|
90
97
|
}, children: i18n.canBeReEnabledInSettings })] })] })] }));
|
|
91
98
|
}
|
|
92
|
-
function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, showCloseDialog, }) {
|
|
99
|
+
function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, isDragging, showCloseDialog, side, }) {
|
|
93
100
|
const [showCloseButton, setIsShowCloseButton] = useState(false);
|
|
94
101
|
return (_jsxs("div", { style: {
|
|
95
102
|
display: 'flex',
|
|
96
103
|
alignItems: 'center',
|
|
97
104
|
position: 'relative',
|
|
98
105
|
cursor: 'pointer',
|
|
106
|
+
flexDirection: side === 'left' ? 'row-reverse' : 'row',
|
|
99
107
|
}, onMouseEnter: () => {
|
|
100
|
-
if (isExpanded || isShowCloseDialog) {
|
|
108
|
+
if (isDragging || isExpanded || isShowCloseDialog) {
|
|
101
109
|
return;
|
|
102
110
|
}
|
|
103
111
|
setIsShowCloseButton(true);
|
|
104
112
|
}, onMouseLeave: () => setIsShowCloseButton(false), onClick: () => {
|
|
105
|
-
if (isShowCloseDialog) {
|
|
113
|
+
if (isDragging || isShowCloseDialog) {
|
|
106
114
|
return;
|
|
107
115
|
}
|
|
108
116
|
setIsShowCloseButton(false);
|
|
109
117
|
onClick();
|
|
110
|
-
}, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', padding: '8px' }, children: [_jsx(Logo, { style: logoStyle }), !dataLoaded && _jsx("span", { style: textStyle, children: isExpanded ? i18n.fetchingDAppInfo : '' })] }), _jsx("div", { style: {
|
|
118
|
+
}, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', padding: '8px', flexDirection: side === 'left' ? 'row-reverse' : 'row' }, children: [_jsx(Logo, { style: logoStyle }), !dataLoaded && _jsx("span", { style: textStyle, children: isExpanded ? i18n.fetchingDAppInfo : '' })] }), isDragging ? null : (_jsx("div", { style: {
|
|
111
119
|
display: 'flex',
|
|
112
120
|
padding: '$4',
|
|
113
121
|
position: 'absolute',
|
|
114
|
-
left: '-6px',
|
|
122
|
+
[side === 'left' ? 'right' : 'left']: '-6px',
|
|
115
123
|
bottom: '-10px',
|
|
116
124
|
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
117
125
|
opacity: showCloseButton ? 1 : 0,
|
|
@@ -122,7 +130,7 @@ function IconButton({ isExpanded, onClick, dataLoaded, isShowCloseDialog, showCl
|
|
|
122
130
|
event.stopPropagation();
|
|
123
131
|
setIsShowCloseButton(false);
|
|
124
132
|
showCloseDialog();
|
|
125
|
-
}, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M7.29289 7.29289C7.68342 6.90237 8.31658 6.90237 8.70711 7.29289L12 10.5858L15.2929 7.29289C15.6834 6.90237 16.3166 6.90237 16.7071 7.29289C17.0976 7.68342 17.0976 8.31658 16.7071 8.70711L13.4142 12L16.7071 15.2929C17.0976 15.6834 17.0976 16.3166 16.7071 16.7071C16.3166 17.0976 15.6834 17.0976 15.2929 16.7071L12 13.4142L8.70711 16.7071C8.31658 17.0976 7.68342 17.0976 7.29289 16.7071C6.90237 16.3166 6.90237 15.6834 7.29289 15.2929L10.5858 12L7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289Z", fill: "rgba(0, 0, 0, 0.61)" }) }) })] }));
|
|
133
|
+
}, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { "fill-rule": "evenodd", "clip-rule": "evenodd", d: "M7.29289 7.29289C7.68342 6.90237 8.31658 6.90237 8.70711 7.29289L12 10.5858L15.2929 7.29289C15.6834 6.90237 16.3166 6.90237 16.7071 7.29289C17.0976 7.68342 17.0976 8.31658 16.7071 8.70711L13.4142 12L16.7071 15.2929C17.0976 15.6834 17.0976 16.3166 16.7071 16.7071C16.3166 17.0976 15.6834 17.0976 15.2929 16.7071L12 13.4142L8.70711 16.7071C8.31658 17.0976 7.68342 17.0976 7.29289 16.7071C6.90237 16.3166 6.90237 15.6834 7.29289 15.2929L10.5858 12L7.29289 8.70711C6.90237 8.31658 6.90237 7.68342 7.29289 7.29289Z", fill: "rgba(0, 0, 0, 0.61)" }) }) }))] }));
|
|
126
134
|
}
|
|
127
135
|
function SecurityInfoRow({ title, children }) {
|
|
128
136
|
return (_jsxs("div", { style: {
|
|
@@ -147,7 +155,7 @@ const SECURITY_INFO = {
|
|
|
147
155
|
},
|
|
148
156
|
[EHostSecurityLevel.Medium]: {
|
|
149
157
|
titleId: 'suspectedMaliciousBehavior',
|
|
150
|
-
icon: (_jsx(
|
|
158
|
+
icon: (_jsx(MediumRisk, { style: { width: 16, height: 16 } })),
|
|
151
159
|
},
|
|
152
160
|
};
|
|
153
161
|
function SecurityRiskDetectionRow({ securityInfo }) {
|
|
@@ -206,7 +214,7 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
206
214
|
fontSize: '14px',
|
|
207
215
|
fontWeight: '500',
|
|
208
216
|
overflow: 'hidden',
|
|
209
|
-
}, children: [((_a = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _a === void 0 ? void 0 : _a.logo) ? (_jsx(
|
|
217
|
+
}, children: [((_a = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _a === void 0 ? void 0 : _a.logo) ? (_jsx(Image, { src: (_b = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _b === void 0 ? void 0 : _b.logo, style: {
|
|
210
218
|
height: '24px',
|
|
211
219
|
width: '24px',
|
|
212
220
|
borderRadius: '8px',
|
|
@@ -230,7 +238,7 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
230
238
|
display: 'flex',
|
|
231
239
|
alignItems: 'center',
|
|
232
240
|
gap: '2px',
|
|
233
|
-
}, children: (_e = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _e === void 0 ? void 0 : _e.origins.map((item) => (_jsx(
|
|
241
|
+
}, children: (_e = securityInfo === null || securityInfo === void 0 ? void 0 : securityInfo.dapp) === null || _e === void 0 ? void 0 : _e.origins.map((item) => (_jsx(Image, { src: item.logo, style: {
|
|
234
242
|
border: '1px solid rgba(0, 0, 0, 0.1)',
|
|
235
243
|
borderRadius: '9999px',
|
|
236
244
|
width: '16px',
|
|
@@ -266,49 +274,158 @@ function SecurityInfo({ securityInfo, onClose, }) {
|
|
|
266
274
|
lineHeight: '16px',
|
|
267
275
|
}, children: "OneKey" })] })] }));
|
|
268
276
|
}
|
|
277
|
+
const savePosition = (params) => {
|
|
278
|
+
void window.$onekey.$private.request({
|
|
279
|
+
method: 'wallet_saveFloatingIconSettings',
|
|
280
|
+
params: {
|
|
281
|
+
position: params
|
|
282
|
+
},
|
|
283
|
+
});
|
|
284
|
+
};
|
|
269
285
|
function App() {
|
|
270
286
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
271
287
|
const [showSecurityInfo, setIsShowSecurityInfo] = useState(false);
|
|
272
288
|
const [securityInfo, setSecurityInfo] = useState(null);
|
|
273
289
|
const [showCloseDialog, setIsShowCloseDialog] = useState(false);
|
|
290
|
+
const [settings, setSettings] = useState(defaultSettings);
|
|
291
|
+
const containerRef = useRef(null);
|
|
292
|
+
const containerPositionRef = useRef({ x: 0, y: 0 });
|
|
293
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
294
|
+
const isDraggingRef = useRef(isDragging);
|
|
295
|
+
isDraggingRef.current = isDragging;
|
|
296
|
+
const isDraggingTimerIdRef = useRef(null);
|
|
274
297
|
const handleShowCloseDialog = useCallback(() => {
|
|
275
298
|
setIsShowCloseDialog(true);
|
|
276
299
|
}, []);
|
|
277
300
|
const handleClick = useCallback(() => __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
301
|
+
if (!isDraggingRef.current) {
|
|
302
|
+
setIsExpanded(!isExpanded);
|
|
303
|
+
setIsShowSecurityInfo(true);
|
|
304
|
+
if (!securityInfo) {
|
|
305
|
+
const result = yield window.$onekey.$private.request({
|
|
306
|
+
method: 'wallet_detectRiskLevel',
|
|
307
|
+
params: { url: window.location.origin },
|
|
308
|
+
});
|
|
309
|
+
setSecurityInfo(result.securityInfo);
|
|
310
|
+
}
|
|
286
311
|
}
|
|
287
312
|
}), [isExpanded, securityInfo]);
|
|
288
|
-
|
|
313
|
+
const handleMouseDown = useCallback((e) => {
|
|
314
|
+
if (isExpanded) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
isDraggingTimerIdRef.current = setTimeout(() => {
|
|
318
|
+
setIsDragging(true);
|
|
319
|
+
isDraggingRef.current = true;
|
|
320
|
+
const newX = e.clientX - 20;
|
|
321
|
+
const newY = e.clientY - 20;
|
|
322
|
+
if (containerRef.current) {
|
|
323
|
+
containerRef.current.style.left = `${newX}px`;
|
|
324
|
+
containerRef.current.style.top = `${newY}px`;
|
|
325
|
+
containerRef.current.style.right = 'auto';
|
|
326
|
+
containerRef.current.style.bottom = 'auto';
|
|
327
|
+
containerPositionRef.current = {
|
|
328
|
+
x: newX,
|
|
329
|
+
y: newY,
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
}, 200);
|
|
333
|
+
}, [isExpanded]);
|
|
334
|
+
const handleMouseMove = useCallback(throttle((e) => {
|
|
335
|
+
if (isDraggingRef.current) {
|
|
336
|
+
const newX = Math.min(Math.max(e.clientX - 20, 0), window.innerWidth - 40);
|
|
337
|
+
const newY = Math.min(Math.max(e.clientY - 20, 60), window.innerHeight - 60);
|
|
338
|
+
containerPositionRef.current = {
|
|
339
|
+
x: newX,
|
|
340
|
+
y: newY,
|
|
341
|
+
};
|
|
342
|
+
if (containerRef.current) {
|
|
343
|
+
containerRef.current.style.left = `${newX}px`;
|
|
344
|
+
containerRef.current.style.top = `${newY}px`;
|
|
345
|
+
containerRef.current.style.right = 'auto';
|
|
346
|
+
containerRef.current.style.bottom = 'auto';
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}, 16), []);
|
|
350
|
+
const handleMouseUp = useCallback(() => {
|
|
351
|
+
if (isDraggingTimerIdRef.current) {
|
|
352
|
+
clearTimeout(isDraggingTimerIdRef.current);
|
|
353
|
+
}
|
|
354
|
+
if (isDraggingRef.current) {
|
|
355
|
+
isDraggingRef.current = false;
|
|
356
|
+
setTimeout(() => {
|
|
357
|
+
setIsDragging(false);
|
|
358
|
+
}, 50);
|
|
359
|
+
const { x, y } = containerPositionRef.current;
|
|
360
|
+
const halfWidth = window.innerWidth / 2;
|
|
361
|
+
const side = x < halfWidth ? 'left' : 'right';
|
|
362
|
+
const bottomNumber = 100 - y / window.innerHeight * 100;
|
|
363
|
+
const bottom = `${(bottomNumber).toFixed(4)}%`;
|
|
364
|
+
const resetPosition = () => {
|
|
365
|
+
if (containerRef.current) {
|
|
366
|
+
containerRef.current.style.left = side === 'left' ? '0px' : 'auto';
|
|
367
|
+
containerRef.current.style.right = side === 'right' ? '0px' : 'auto';
|
|
368
|
+
containerRef.current.style.top = bottomNumber > 50 ? `${100 - bottomNumber}%` : 'auto';
|
|
369
|
+
containerRef.current.style.bottom = bottomNumber > 50 ? 'auto' : bottom;
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
setTimeout(() => {
|
|
373
|
+
resetPosition();
|
|
374
|
+
}, 20);
|
|
375
|
+
setSettings(prev => (Object.assign(Object.assign({}, prev), { position: {
|
|
376
|
+
bottom,
|
|
377
|
+
side,
|
|
378
|
+
} })));
|
|
379
|
+
savePosition({
|
|
380
|
+
side,
|
|
381
|
+
bottom,
|
|
382
|
+
});
|
|
383
|
+
// Provide a fallback correction for the misalignment of the floating icon.
|
|
384
|
+
setTimeout(() => {
|
|
385
|
+
resetPosition();
|
|
386
|
+
}, 800);
|
|
387
|
+
}
|
|
388
|
+
}, []);
|
|
389
|
+
useEffect(() => {
|
|
390
|
+
document.addEventListener('mousemove', handleMouseMove);
|
|
391
|
+
document.addEventListener('mouseup', handleMouseUp);
|
|
392
|
+
return () => {
|
|
393
|
+
document.removeEventListener('mousemove', handleMouseMove);
|
|
394
|
+
document.removeEventListener('mouseup', handleMouseUp);
|
|
395
|
+
};
|
|
396
|
+
}, [handleMouseMove, handleMouseUp]);
|
|
397
|
+
const { side, bottom } = settings.position;
|
|
398
|
+
const bottomNumber = Number.parseFloat(bottom);
|
|
399
|
+
return (_jsxs("div", { id: containerId, ref: containerRef, style: {
|
|
289
400
|
position: 'fixed',
|
|
290
401
|
zIndex: 999999,
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
402
|
+
top: bottomNumber > 50 ? `${100 - bottomNumber}%` : 'auto',
|
|
403
|
+
bottom: bottomNumber > 50 ? 'auto' : bottom,
|
|
404
|
+
userSelect: 'none',
|
|
405
|
+
left: isDragging ? "auto" : side === 'left' ? '0px' : 'auto',
|
|
406
|
+
right: isDragging ? "auto" : side === 'right' ? '0px' : 'auto',
|
|
407
|
+
width: isDragging ? '40px' : '256px',
|
|
294
408
|
background: '#fff',
|
|
295
|
-
borderRadius: '12px',
|
|
296
|
-
transition: 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
409
|
+
borderRadius: isDragging ? '100%' : '12px',
|
|
410
|
+
transition: isDragging ? 'none' : 'all 150ms cubic-bezier(0.4, 0, 0.2, 1)',
|
|
297
411
|
boxShadow: '0px 0px 0px 1px rgba(0, 0, 0, 0.05), 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1)',
|
|
298
|
-
transform:
|
|
412
|
+
transform: isDragging ? "unset" : (isExpanded ?
|
|
413
|
+
`translateX(${side === 'right' ? '-20px' : '20px'})` :
|
|
414
|
+
`translateX(${side === 'right' ? '216px' : '-216px'})`),
|
|
299
415
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
|
|
300
416
|
WebkitTextSizeAdjust: '100%',
|
|
301
417
|
fontSmooth: 'antialiased',
|
|
302
|
-
|
|
418
|
+
cursor: isDragging ? 'grabbing' : (isExpanded ? 'default' : 'grab'),
|
|
419
|
+
}, onMouseDown: handleMouseDown, children: [showSecurityInfo && securityInfo ? (_jsx(SecurityInfo, { securityInfo: securityInfo, onClose: () => {
|
|
303
420
|
setIsExpanded(false);
|
|
304
421
|
setIsShowSecurityInfo(false);
|
|
305
|
-
} })) : (_jsx(IconButton, { onClick: handleClick, isExpanded: isExpanded, isShowCloseDialog: showCloseDialog, showCloseDialog: handleShowCloseDialog, dataLoaded: !!securityInfo })), !isExpanded && showCloseDialog && (_jsx(CloseDialog, { onClose: () => {
|
|
422
|
+
} })) : (_jsx(IconButton, { onClick: handleClick, side: side, isExpanded: isExpanded, isShowCloseDialog: showCloseDialog, isDragging: isDragging, showCloseDialog: handleShowCloseDialog, dataLoaded: !!securityInfo })), !isExpanded && showCloseDialog && (_jsx(CloseDialog, { side: side, onClose: () => {
|
|
306
423
|
setIsShowCloseDialog(false);
|
|
307
424
|
} }))] }));
|
|
308
425
|
}
|
|
309
426
|
function injectIcon() {
|
|
310
427
|
return __awaiter(this, void 0, void 0, function* () {
|
|
311
|
-
const { isShow, i18n: i18nResponse } = yield
|
|
428
|
+
const { isShow, i18n: i18nResponse, settings } = yield window.$onekey.$private.request({
|
|
312
429
|
method: 'wallet_isShowFloatingButton',
|
|
313
430
|
params: { url: window.location.origin },
|
|
314
431
|
});
|
|
@@ -322,6 +439,9 @@ function injectIcon() {
|
|
|
322
439
|
if (!document.body) {
|
|
323
440
|
return;
|
|
324
441
|
}
|
|
442
|
+
if (settings) {
|
|
443
|
+
defaultSettings = Object.assign(Object.assign({}, defaultSettings), settings);
|
|
444
|
+
}
|
|
325
445
|
isInjected = true;
|
|
326
446
|
const div = document.createElement('div');
|
|
327
447
|
document.body.appendChild(div);
|
|
@@ -333,7 +453,7 @@ export function injectFloatingButton() {
|
|
|
333
453
|
if (window.top !== window.self) {
|
|
334
454
|
return;
|
|
335
455
|
}
|
|
336
|
-
|
|
456
|
+
window.$onekey.$private.onNotifyFloatingIconChanged(({ showFloatingIcon }) => {
|
|
337
457
|
if (showFloatingIcon) {
|
|
338
458
|
void injectIcon();
|
|
339
459
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/inpage-providers-hub",
|
|
3
|
-
"version": "2.2.7-alpha.
|
|
3
|
+
"version": "2.2.7-alpha.2",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -28,26 +28,26 @@
|
|
|
28
28
|
"start": "tsc --watch"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-core": "2.2.7-alpha.
|
|
32
|
-
"@onekeyfe/cross-inpage-provider-types": "2.2.7-alpha.
|
|
33
|
-
"@onekeyfe/onekey-algo-provider": "2.2.7-alpha.
|
|
34
|
-
"@onekeyfe/onekey-alph-provider": "2.2.7-alpha.
|
|
35
|
-
"@onekeyfe/onekey-aptos-provider": "2.2.7-alpha.
|
|
36
|
-
"@onekeyfe/onekey-bfc-provider": "2.2.7-alpha.
|
|
37
|
-
"@onekeyfe/onekey-btc-provider": "2.2.7-alpha.
|
|
38
|
-
"@onekeyfe/onekey-cardano-provider": "2.2.7-alpha.
|
|
39
|
-
"@onekeyfe/onekey-conflux-provider": "2.2.7-alpha.
|
|
40
|
-
"@onekeyfe/onekey-cosmos-provider": "2.2.7-alpha.
|
|
41
|
-
"@onekeyfe/onekey-eth-provider": "2.2.7-alpha.
|
|
42
|
-
"@onekeyfe/onekey-nostr-provider": "2.2.7-alpha.
|
|
43
|
-
"@onekeyfe/onekey-polkadot-provider": "2.2.7-alpha.
|
|
44
|
-
"@onekeyfe/onekey-private-provider": "2.2.7-alpha.
|
|
45
|
-
"@onekeyfe/onekey-scdo-provider": "2.2.7-alpha.
|
|
46
|
-
"@onekeyfe/onekey-solana-provider": "2.2.7-alpha.
|
|
47
|
-
"@onekeyfe/onekey-sui-provider": "2.2.7-alpha.
|
|
48
|
-
"@onekeyfe/onekey-ton-provider": "2.2.7-alpha.
|
|
49
|
-
"@onekeyfe/onekey-tron-provider": "2.2.7-alpha.
|
|
50
|
-
"@onekeyfe/onekey-webln-provider": "2.2.7-alpha.
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.7-alpha.2",
|
|
32
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.7-alpha.2",
|
|
33
|
+
"@onekeyfe/onekey-algo-provider": "2.2.7-alpha.2",
|
|
34
|
+
"@onekeyfe/onekey-alph-provider": "2.2.7-alpha.2",
|
|
35
|
+
"@onekeyfe/onekey-aptos-provider": "2.2.7-alpha.2",
|
|
36
|
+
"@onekeyfe/onekey-bfc-provider": "2.2.7-alpha.2",
|
|
37
|
+
"@onekeyfe/onekey-btc-provider": "2.2.7-alpha.2",
|
|
38
|
+
"@onekeyfe/onekey-cardano-provider": "2.2.7-alpha.2",
|
|
39
|
+
"@onekeyfe/onekey-conflux-provider": "2.2.7-alpha.2",
|
|
40
|
+
"@onekeyfe/onekey-cosmos-provider": "2.2.7-alpha.2",
|
|
41
|
+
"@onekeyfe/onekey-eth-provider": "2.2.7-alpha.2",
|
|
42
|
+
"@onekeyfe/onekey-nostr-provider": "2.2.7-alpha.2",
|
|
43
|
+
"@onekeyfe/onekey-polkadot-provider": "2.2.7-alpha.2",
|
|
44
|
+
"@onekeyfe/onekey-private-provider": "2.2.7-alpha.2",
|
|
45
|
+
"@onekeyfe/onekey-scdo-provider": "2.2.7-alpha.2",
|
|
46
|
+
"@onekeyfe/onekey-solana-provider": "2.2.7-alpha.2",
|
|
47
|
+
"@onekeyfe/onekey-sui-provider": "2.2.7-alpha.2",
|
|
48
|
+
"@onekeyfe/onekey-ton-provider": "2.2.7-alpha.2",
|
|
49
|
+
"@onekeyfe/onekey-tron-provider": "2.2.7-alpha.2",
|
|
50
|
+
"@onekeyfe/onekey-webln-provider": "2.2.7-alpha.2",
|
|
51
51
|
"lodash-es": "^4.17.21",
|
|
52
52
|
"preact": "^10.25.1",
|
|
53
53
|
"web3": "^1.7.3"
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"@types/lodash-es": "^4.17.12",
|
|
57
57
|
"@types/node": "^20.12.7"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ac22d6fa7cafe210d0afabf65c92ea7cea52e787"
|
|
60
60
|
}
|