@onekeyfe/inpage-providers-hub 2.2.37 → 2.2.38
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/builtInPerpInjected/HyperliquidBuilderStore.d.ts +1 -1
- package/dist/builtInPerpInjected/HyperliquidBuilderStore.js +1 -1
- package/dist/builtInPerpInjected/hijackMethods.js +1 -1
- package/dist/builtInPerpInjected/hyperLiquidOneKeyWalletApi.d.ts +4 -1
- package/dist/builtInPerpInjected/hyperLiquidOneKeyWalletApi.js +155 -14
- package/dist/builtInPerpInjected/index.js +70 -9
- package/dist/cjs/builtInPerpInjected/HyperliquidBuilderStore.js +1 -1
- package/dist/cjs/builtInPerpInjected/hijackMethods.js +1 -1
- package/dist/cjs/builtInPerpInjected/hyperLiquidOneKeyWalletApi.js +154 -13
- package/dist/cjs/builtInPerpInjected/index.js +70 -9
- package/dist/cjs/connectButtonHack/hackConnectButton.js +9 -3
- package/dist/cjs/injectWeb3Provider.js +1 -1
- package/dist/cjs/utils/providersHubUtils.js +4 -2
- package/dist/connectButtonHack/hackConnectButton.d.ts +3 -2
- package/dist/connectButtonHack/hackConnectButton.js +10 -4
- package/dist/injectWeb3Provider.js +1 -1
- package/dist/utils/providersHubUtils.js +3 -1
- package/package.json +23 -23
|
@@ -8,5 +8,5 @@ export declare class HyperliquidBuilderStore {
|
|
|
8
8
|
static set expectMaxBuilderFee(value: number | undefined);
|
|
9
9
|
static updateBuilderInfo(address: string, fee: number): void;
|
|
10
10
|
static flush(): void;
|
|
11
|
-
static
|
|
11
|
+
static storeUpdateByOneKeyWallet: boolean;
|
|
12
12
|
}
|
|
@@ -51,7 +51,7 @@ function hijackReactUseContext() {
|
|
|
51
51
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.order_type']) &&
|
|
52
52
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.limit_order_tif']) &&
|
|
53
53
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.locale-setting']) &&
|
|
54
|
-
(HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.
|
|
54
|
+
(HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.storeUpdateByOneKeyWallet) &&
|
|
55
55
|
(HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.expectBuilderAddress) &&
|
|
56
56
|
isNumber(HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.expectMaxBuilderFee) &&
|
|
57
57
|
(HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.expectMaxBuilderFee) >= 0) {
|
|
@@ -3,12 +3,15 @@ declare function initHyperliquidBuilderFeeConfig(ethereum: ProviderEthereum | un
|
|
|
3
3
|
declare function checkHyperliquidUserApproveStatus({ shouldApproveBuilderFee, }: {
|
|
4
4
|
shouldApproveBuilderFee: boolean;
|
|
5
5
|
}): Promise<void>;
|
|
6
|
-
declare function logHyperLiquidServerApiAction({ payload }: {
|
|
6
|
+
declare function logHyperLiquidServerApiAction({ payload, error }: {
|
|
7
7
|
payload: any;
|
|
8
|
+
error?: any;
|
|
8
9
|
}): Promise<undefined>;
|
|
10
|
+
declare function clearUserMaxBuilderFeeCache(): Promise<undefined>;
|
|
9
11
|
declare const _default: {
|
|
10
12
|
initHyperliquidBuilderFeeConfig: typeof initHyperliquidBuilderFeeConfig;
|
|
11
13
|
checkHyperliquidUserApproveStatus: typeof checkHyperliquidUserApproveStatus;
|
|
12
14
|
logHyperLiquidServerApiAction: typeof logHyperLiquidServerApiAction;
|
|
15
|
+
clearUserMaxBuilderFeeCache: typeof clearUserMaxBuilderFeeCache;
|
|
13
16
|
};
|
|
14
17
|
export default _default;
|
|
@@ -7,8 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
11
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
12
|
+
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
|
|
13
|
+
import { isNumber, isString } from 'lodash-es';
|
|
14
|
+
import { hackConnectButton } from '../connectButtonHack/hackConnectButton';
|
|
11
15
|
import providersHubUtils from '../utils/providersHubUtils';
|
|
16
|
+
import { HYPERLIQUID_HOSTNAME } from './consts';
|
|
12
17
|
import { HyperliquidBuilderStore } from './HyperliquidBuilderStore';
|
|
13
18
|
import hyperLiquidDappDetecter from './hyperLiquidDappDetecter';
|
|
14
19
|
function getEthereum() {
|
|
@@ -25,13 +30,39 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
|
|
|
25
30
|
return;
|
|
26
31
|
}
|
|
27
32
|
providersHubUtils.consoleLog('BuiltInPerpInjected___saveBuilderFeeConfigToStorage>>>>result', result, fromSource);
|
|
33
|
+
if (result === null || result === void 0 ? void 0 : result.customLocalStorage) {
|
|
34
|
+
try {
|
|
35
|
+
Object.entries(result.customLocalStorage).forEach(([key, value]) => {
|
|
36
|
+
try {
|
|
37
|
+
if (isString(value) && value && key) {
|
|
38
|
+
if (key === 'hyperliquid.locale-setting') {
|
|
39
|
+
localStorage.setItem(key, value);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
const currentValue = localStorage.getItem(key);
|
|
43
|
+
if (currentValue === null || currentValue === undefined) {
|
|
44
|
+
localStorage.setItem(key, value);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error(error);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
28
58
|
if ((result === null || result === void 0 ? void 0 : result.expectBuilderAddress) &&
|
|
29
59
|
isNumber(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) &&
|
|
30
60
|
(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) >= 0) {
|
|
31
61
|
// HyperliquidBuilderStore --> hijackReactUseContextMethod
|
|
32
62
|
HyperliquidBuilderStore.updateBuilderInfo(result.expectBuilderAddress.toLowerCase(), result.expectMaxBuilderFee);
|
|
33
|
-
HyperliquidBuilderStore.
|
|
63
|
+
HyperliquidBuilderStore.storeUpdateByOneKeyWallet = true;
|
|
34
64
|
// do not modify localStorage, otherwise the hyperliquid page will not work properly when the onekey plugin is disabled
|
|
65
|
+
localStorage.removeItem('hyperliquid.order_builder_info');
|
|
35
66
|
// localStorage.setItem(
|
|
36
67
|
// 'hyperliquid.order_builder_info',
|
|
37
68
|
// JSON.stringify({
|
|
@@ -40,23 +71,100 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
|
|
|
40
71
|
// }),
|
|
41
72
|
// );
|
|
42
73
|
}
|
|
74
|
+
else if (!(result === null || result === void 0 ? void 0 : result.expectBuilderAddress) || (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) < 0) {
|
|
75
|
+
localStorage.removeItem('hyperliquid.order_builder_info');
|
|
76
|
+
HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
|
|
77
|
+
}
|
|
43
78
|
}
|
|
44
79
|
function registerBuilderFeeUpdateEvents(ethereum) {
|
|
45
80
|
if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
|
|
46
81
|
return;
|
|
47
82
|
}
|
|
48
83
|
ethereum === null || ethereum === void 0 ? void 0 : ethereum.on('message', (payload, p1, p2) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
84
|
+
try {
|
|
85
|
+
const { type: method, data: params } = payload || {};
|
|
86
|
+
if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
|
|
87
|
+
const paramsInfo = params;
|
|
88
|
+
saveBuilderFeeConfigToStorage({
|
|
89
|
+
result: {
|
|
90
|
+
expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
|
|
91
|
+
expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
|
|
92
|
+
},
|
|
93
|
+
fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
59
96
|
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
console.error(error);
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
function hackConnectionButton() {
|
|
103
|
+
hackConnectButton({
|
|
104
|
+
urls: [HYPERLIQUID_HOSTNAME],
|
|
105
|
+
providers: [IInjectedProviderNames.ethereum],
|
|
106
|
+
replaceMethod() {
|
|
107
|
+
const hideNavigationBar = () => {
|
|
108
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
109
|
+
const siteIcon = (_d = (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.querySelectorAll) === null || _b === void 0 ? void 0 : _b.call(_a, 'a[href="/trade"]>svg')) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.parentElement;
|
|
110
|
+
const navBarItems = (_e = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _e === void 0 ? void 0 : _e.childNodes;
|
|
111
|
+
const navBarRightContainer = (_f = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _f === void 0 ? void 0 : _f.nextElementSibling;
|
|
112
|
+
navBarItems === null || navBarItems === void 0 ? void 0 : navBarItems.forEach((item, index) => {
|
|
113
|
+
var _a;
|
|
114
|
+
try {
|
|
115
|
+
const ele = item;
|
|
116
|
+
if (index >= 1) {
|
|
117
|
+
const href = (_a = ele === null || ele === void 0 ? void 0 : ele.querySelector('a')) === null || _a === void 0 ? void 0 : _a.getAttribute('href');
|
|
118
|
+
if (ele && !(href === null || href === void 0 ? void 0 : href.includes('/trade'))) {
|
|
119
|
+
ele.style.display = 'none';
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
console.error(error);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if (navBarRightContainer) {
|
|
128
|
+
const button = navBarRightContainer.querySelector('button');
|
|
129
|
+
if (button && ((_h = (_g = button === null || button === void 0 ? void 0 : button.textContent) === null || _g === void 0 ? void 0 : _g.toLowerCase()) === null || _h === void 0 ? void 0 : _h.trim()) === 'connect') {
|
|
130
|
+
button.style.display = 'none';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const hideConnectButton = () => {
|
|
135
|
+
var _a;
|
|
136
|
+
const buttons = Array.from((_a = document === null || document === void 0 ? void 0 : document.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(document, 'div.modal button'));
|
|
137
|
+
const oneKeyButton = buttons.find((button) => { var _a, _b, _c; return (_c = (_b = (_a = button === null || button === void 0 ? void 0 : button.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, 'onekey'); });
|
|
138
|
+
const oneKeyButtonParent = oneKeyButton === null || oneKeyButton === void 0 ? void 0 : oneKeyButton.parentElement;
|
|
139
|
+
const connectButtons = oneKeyButtonParent === null || oneKeyButtonParent === void 0 ? void 0 : oneKeyButtonParent.childNodes;
|
|
140
|
+
connectButtons === null || connectButtons === void 0 ? void 0 : connectButtons.forEach((button) => {
|
|
141
|
+
var _a, _b, _c;
|
|
142
|
+
try {
|
|
143
|
+
const ele = button;
|
|
144
|
+
if (ele &&
|
|
145
|
+
ele !== oneKeyButton &&
|
|
146
|
+
!((_c = (_b = (_a = ele.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, 'onekey'))) {
|
|
147
|
+
ele.style.display = 'none';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
console.error(error);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
try {
|
|
156
|
+
hideNavigationBar();
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
console.error(error);
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
hideConnectButton();
|
|
163
|
+
}
|
|
164
|
+
catch (error) {
|
|
165
|
+
console.error(error);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
60
168
|
});
|
|
61
169
|
}
|
|
62
170
|
function initHyperliquidBuilderFeeConfig(ethereum) {
|
|
@@ -65,6 +173,7 @@ function initHyperliquidBuilderFeeConfig(ethereum) {
|
|
|
65
173
|
if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
|
|
66
174
|
return;
|
|
67
175
|
}
|
|
176
|
+
hackConnectionButton();
|
|
68
177
|
ethereum = ethereum || getEthereum();
|
|
69
178
|
const isEthereumValid = !!ethereum && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey);
|
|
70
179
|
if (ethereum && isEthereumValid) {
|
|
@@ -113,15 +222,46 @@ function checkHyperliquidUserApproveStatus(_a) {
|
|
|
113
222
|
});
|
|
114
223
|
}
|
|
115
224
|
function logHyperLiquidServerApiAction(_a) {
|
|
116
|
-
return __awaiter(this, arguments, void 0, function* ({ payload }) {
|
|
225
|
+
return __awaiter(this, arguments, void 0, function* ({ payload, error }) {
|
|
117
226
|
if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
|
|
118
227
|
return Promise.resolve(undefined);
|
|
119
228
|
}
|
|
120
229
|
const ethereum = getEthereum();
|
|
121
230
|
if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
|
|
231
|
+
let errorMessage = '';
|
|
232
|
+
if (error) {
|
|
233
|
+
try {
|
|
234
|
+
errorMessage = JSON.stringify(error);
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
console.error(error);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
122
240
|
void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
|
|
123
241
|
method: 'hl_logApiEvent',
|
|
124
|
-
params: [
|
|
242
|
+
params: [
|
|
243
|
+
{
|
|
244
|
+
apiPayload: payload,
|
|
245
|
+
userAddress: ethereum === null || ethereum === void 0 ? void 0 : ethereum.selectedAddress,
|
|
246
|
+
chainId: ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId,
|
|
247
|
+
errorMessage,
|
|
248
|
+
},
|
|
249
|
+
],
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
252
|
+
return Promise.resolve(undefined);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
function clearUserMaxBuilderFeeCache() {
|
|
256
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
257
|
+
if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
|
|
258
|
+
return Promise.resolve(undefined);
|
|
259
|
+
}
|
|
260
|
+
const ethereum = getEthereum();
|
|
261
|
+
if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
|
|
262
|
+
void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
|
|
263
|
+
method: 'hl_clearUserBuilderFeeCache',
|
|
264
|
+
params: [],
|
|
125
265
|
}));
|
|
126
266
|
}
|
|
127
267
|
return Promise.resolve(undefined);
|
|
@@ -131,4 +271,5 @@ export default {
|
|
|
131
271
|
initHyperliquidBuilderFeeConfig,
|
|
132
272
|
checkHyperliquidUserApproveStatus,
|
|
133
273
|
logHyperLiquidServerApiAction,
|
|
274
|
+
clearUserMaxBuilderFeeCache,
|
|
134
275
|
};
|
|
@@ -7,12 +7,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { merge } from 'lodash';
|
|
10
11
|
import providersHubUtils from '../utils/providersHubUtils';
|
|
11
12
|
import { FIXED_ADDITIONAL_POST_BODY } from './consts';
|
|
12
13
|
import hijackMethods from './hijackMethods';
|
|
14
|
+
import hyperLiquidDappDetecter from './hyperLiquidDappDetecter';
|
|
13
15
|
import hyperLiquidOneKeyWalletApi from './hyperLiquidOneKeyWalletApi';
|
|
14
16
|
import hyperLiquidApiUtils from './hyperLiquidServerApi';
|
|
15
|
-
import hyperLiquidDappDetecter from './hyperLiquidDappDetecter';
|
|
16
17
|
const originalConsoleLog = providersHubUtils.consoleLog;
|
|
17
18
|
export class BuiltInPerpInjected {
|
|
18
19
|
constructor() {
|
|
@@ -31,7 +32,7 @@ export class BuiltInPerpInjected {
|
|
|
31
32
|
}
|
|
32
33
|
modifyApiPostBody({ originalBody, jsonBody, jsonBodyToUpdate, }) {
|
|
33
34
|
if (Object.keys(jsonBodyToUpdate).length) {
|
|
34
|
-
|
|
35
|
+
merge(jsonBody, jsonBodyToUpdate);
|
|
35
36
|
return JSON.stringify(jsonBody);
|
|
36
37
|
}
|
|
37
38
|
return originalBody;
|
|
@@ -48,6 +49,14 @@ export class BuiltInPerpInjected {
|
|
|
48
49
|
yield hyperLiquidOneKeyWalletApi.checkHyperliquidUserApproveStatus({
|
|
49
50
|
shouldApproveBuilderFee: true,
|
|
50
51
|
});
|
|
52
|
+
// TODO remove
|
|
53
|
+
// merge(jsonBodyToUpdate, {
|
|
54
|
+
// action: {
|
|
55
|
+
// builder: {
|
|
56
|
+
// f: 9999,
|
|
57
|
+
// },
|
|
58
|
+
// },
|
|
59
|
+
// });
|
|
51
60
|
}
|
|
52
61
|
originalConsoleLog('BuiltInPerpInjected>>>>isPlaceOrderRequest', isPlaceOrderRequest, url, jsonBody);
|
|
53
62
|
});
|
|
@@ -82,9 +91,6 @@ export class BuiltInPerpInjected {
|
|
|
82
91
|
const jsonBodyToUpdate = Object.assign({}, FIXED_ADDITIONAL_POST_BODY);
|
|
83
92
|
const isPlaceOrderRequest = hyperLiquidApiUtils.isPlaceOrderRequest({ jsonBody, url });
|
|
84
93
|
if (isPlaceOrderRequest) {
|
|
85
|
-
void hyperLiquidOneKeyWalletApi.logHyperLiquidServerApiAction({
|
|
86
|
-
payload: jsonBody,
|
|
87
|
-
});
|
|
88
94
|
yield this.waitBuilderFeeApproved({
|
|
89
95
|
jsonBody,
|
|
90
96
|
url,
|
|
@@ -96,7 +102,56 @@ export class BuiltInPerpInjected {
|
|
|
96
102
|
jsonBody,
|
|
97
103
|
jsonBodyToUpdate,
|
|
98
104
|
});
|
|
99
|
-
|
|
105
|
+
try {
|
|
106
|
+
const result = yield originalFetch(input, modifiedInit);
|
|
107
|
+
try {
|
|
108
|
+
if (isPlaceOrderRequest) {
|
|
109
|
+
const resData = (yield result.clone().json());
|
|
110
|
+
if ((resData === null || resData === void 0 ? void 0 : resData.status) === 'err') {
|
|
111
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error1', resData);
|
|
112
|
+
void hyperLiquidOneKeyWalletApi.clearUserMaxBuilderFeeCache();
|
|
113
|
+
void hyperLiquidOneKeyWalletApi.logHyperLiquidServerApiAction({
|
|
114
|
+
payload: jsonBody,
|
|
115
|
+
error: resData,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/*
|
|
119
|
+
{
|
|
120
|
+
"status": "ok",
|
|
121
|
+
"response": {
|
|
122
|
+
"type": "order",
|
|
123
|
+
"data": {
|
|
124
|
+
"statuses": [
|
|
125
|
+
{
|
|
126
|
+
"resting": {
|
|
127
|
+
"oid": 133956942251
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
*/
|
|
135
|
+
if ((resData === null || resData === void 0 ? void 0 : resData.status) === 'ok') {
|
|
136
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Success', resData);
|
|
137
|
+
void hyperLiquidOneKeyWalletApi.logHyperLiquidServerApiAction({
|
|
138
|
+
payload: jsonBody,
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (eeee) {
|
|
144
|
+
// ignore
|
|
145
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error2', eeee);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
if (isPlaceOrderRequest) {
|
|
151
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error3', error);
|
|
152
|
+
}
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
100
155
|
}
|
|
101
156
|
}
|
|
102
157
|
}
|
|
@@ -106,9 +161,15 @@ export class BuiltInPerpInjected {
|
|
|
106
161
|
}
|
|
107
162
|
export default {
|
|
108
163
|
createInstance: () => {
|
|
109
|
-
|
|
110
|
-
|
|
164
|
+
try {
|
|
165
|
+
if (hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
|
|
166
|
+
return new BuiltInPerpInjected();
|
|
167
|
+
}
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
originalConsoleLog('BuiltInPerpInjected__createInstance__Error', error);
|
|
172
|
+
return undefined;
|
|
111
173
|
}
|
|
112
|
-
return undefined;
|
|
113
174
|
},
|
|
114
175
|
};
|
|
@@ -46,4 +46,4 @@ class HyperliquidBuilderStore {
|
|
|
46
46
|
}
|
|
47
47
|
exports.HyperliquidBuilderStore = HyperliquidBuilderStore;
|
|
48
48
|
HyperliquidBuilderStore.store = new LocalStorageStore_1.LocalStorageStore(prefix);
|
|
49
|
-
HyperliquidBuilderStore.
|
|
49
|
+
HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
|
|
@@ -56,7 +56,7 @@ function hijackReactUseContext() {
|
|
|
56
56
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.order_type']) &&
|
|
57
57
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.limit_order_tif']) &&
|
|
58
58
|
(result === null || result === void 0 ? void 0 : result['hyperliquid.locale-setting']) &&
|
|
59
|
-
(HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.
|
|
59
|
+
(HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKeyWallet) &&
|
|
60
60
|
(HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.expectBuilderAddress) &&
|
|
61
61
|
(0, lodash_es_1.isNumber)(HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.expectMaxBuilderFee) &&
|
|
62
62
|
(HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.expectMaxBuilderFee) >= 0) {
|
|
@@ -12,8 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
16
|
+
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
17
|
+
const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
|
|
15
18
|
const lodash_es_1 = require("lodash-es");
|
|
19
|
+
const hackConnectButton_1 = require("../connectButtonHack/hackConnectButton");
|
|
16
20
|
const providersHubUtils_1 = __importDefault(require("../utils/providersHubUtils"));
|
|
21
|
+
const consts_1 = require("./consts");
|
|
17
22
|
const HyperliquidBuilderStore_1 = require("./HyperliquidBuilderStore");
|
|
18
23
|
const hyperLiquidDappDetecter_1 = __importDefault(require("./hyperLiquidDappDetecter"));
|
|
19
24
|
function getEthereum() {
|
|
@@ -30,13 +35,39 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
|
|
|
30
35
|
return;
|
|
31
36
|
}
|
|
32
37
|
providersHubUtils_1.default.consoleLog('BuiltInPerpInjected___saveBuilderFeeConfigToStorage>>>>result', result, fromSource);
|
|
38
|
+
if (result === null || result === void 0 ? void 0 : result.customLocalStorage) {
|
|
39
|
+
try {
|
|
40
|
+
Object.entries(result.customLocalStorage).forEach(([key, value]) => {
|
|
41
|
+
try {
|
|
42
|
+
if ((0, lodash_es_1.isString)(value) && value && key) {
|
|
43
|
+
if (key === 'hyperliquid.locale-setting') {
|
|
44
|
+
localStorage.setItem(key, value);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const currentValue = localStorage.getItem(key);
|
|
48
|
+
if (currentValue === null || currentValue === undefined) {
|
|
49
|
+
localStorage.setItem(key, value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
console.error(error);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
console.error(error);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
33
63
|
if ((result === null || result === void 0 ? void 0 : result.expectBuilderAddress) &&
|
|
34
64
|
(0, lodash_es_1.isNumber)(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) &&
|
|
35
65
|
(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) >= 0) {
|
|
36
66
|
// HyperliquidBuilderStore --> hijackReactUseContextMethod
|
|
37
67
|
HyperliquidBuilderStore_1.HyperliquidBuilderStore.updateBuilderInfo(result.expectBuilderAddress.toLowerCase(), result.expectMaxBuilderFee);
|
|
38
|
-
HyperliquidBuilderStore_1.HyperliquidBuilderStore.
|
|
68
|
+
HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKeyWallet = true;
|
|
39
69
|
// do not modify localStorage, otherwise the hyperliquid page will not work properly when the onekey plugin is disabled
|
|
70
|
+
localStorage.removeItem('hyperliquid.order_builder_info');
|
|
40
71
|
// localStorage.setItem(
|
|
41
72
|
// 'hyperliquid.order_builder_info',
|
|
42
73
|
// JSON.stringify({
|
|
@@ -45,23 +76,100 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
|
|
|
45
76
|
// }),
|
|
46
77
|
// );
|
|
47
78
|
}
|
|
79
|
+
else if (!(result === null || result === void 0 ? void 0 : result.expectBuilderAddress) || (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) < 0) {
|
|
80
|
+
localStorage.removeItem('hyperliquid.order_builder_info');
|
|
81
|
+
HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
|
|
82
|
+
}
|
|
48
83
|
}
|
|
49
84
|
function registerBuilderFeeUpdateEvents(ethereum) {
|
|
50
85
|
if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
|
|
51
86
|
return;
|
|
52
87
|
}
|
|
53
88
|
ethereum === null || ethereum === void 0 ? void 0 : ethereum.on('message', (payload, p1, p2) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
89
|
+
try {
|
|
90
|
+
const { type: method, data: params } = payload || {};
|
|
91
|
+
if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
|
|
92
|
+
const paramsInfo = params;
|
|
93
|
+
saveBuilderFeeConfigToStorage({
|
|
94
|
+
result: {
|
|
95
|
+
expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
|
|
96
|
+
expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
|
|
97
|
+
},
|
|
98
|
+
fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
|
|
99
|
+
});
|
|
100
|
+
}
|
|
64
101
|
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
function hackConnectionButton() {
|
|
108
|
+
(0, hackConnectButton_1.hackConnectButton)({
|
|
109
|
+
urls: [consts_1.HYPERLIQUID_HOSTNAME],
|
|
110
|
+
providers: [cross_inpage_provider_types_1.IInjectedProviderNames.ethereum],
|
|
111
|
+
replaceMethod() {
|
|
112
|
+
const hideNavigationBar = () => {
|
|
113
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
114
|
+
const siteIcon = (_d = (_c = (_b = (_a = window === null || window === void 0 ? void 0 : window.document) === null || _a === void 0 ? void 0 : _a.querySelectorAll) === null || _b === void 0 ? void 0 : _b.call(_a, 'a[href="/trade"]>svg')) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.parentElement;
|
|
115
|
+
const navBarItems = (_e = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _e === void 0 ? void 0 : _e.childNodes;
|
|
116
|
+
const navBarRightContainer = (_f = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _f === void 0 ? void 0 : _f.nextElementSibling;
|
|
117
|
+
navBarItems === null || navBarItems === void 0 ? void 0 : navBarItems.forEach((item, index) => {
|
|
118
|
+
var _a;
|
|
119
|
+
try {
|
|
120
|
+
const ele = item;
|
|
121
|
+
if (index >= 1) {
|
|
122
|
+
const href = (_a = ele === null || ele === void 0 ? void 0 : ele.querySelector('a')) === null || _a === void 0 ? void 0 : _a.getAttribute('href');
|
|
123
|
+
if (ele && !(href === null || href === void 0 ? void 0 : href.includes('/trade'))) {
|
|
124
|
+
ele.style.display = 'none';
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
catch (error) {
|
|
129
|
+
console.error(error);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
if (navBarRightContainer) {
|
|
133
|
+
const button = navBarRightContainer.querySelector('button');
|
|
134
|
+
if (button && ((_h = (_g = button === null || button === void 0 ? void 0 : button.textContent) === null || _g === void 0 ? void 0 : _g.toLowerCase()) === null || _h === void 0 ? void 0 : _h.trim()) === 'connect') {
|
|
135
|
+
button.style.display = 'none';
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
const hideConnectButton = () => {
|
|
140
|
+
var _a;
|
|
141
|
+
const buttons = Array.from((_a = document === null || document === void 0 ? void 0 : document.querySelectorAll) === null || _a === void 0 ? void 0 : _a.call(document, 'div.modal button'));
|
|
142
|
+
const oneKeyButton = buttons.find((button) => { var _a, _b, _c; return (_c = (_b = (_a = button === null || button === void 0 ? void 0 : button.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, 'onekey'); });
|
|
143
|
+
const oneKeyButtonParent = oneKeyButton === null || oneKeyButton === void 0 ? void 0 : oneKeyButton.parentElement;
|
|
144
|
+
const connectButtons = oneKeyButtonParent === null || oneKeyButtonParent === void 0 ? void 0 : oneKeyButtonParent.childNodes;
|
|
145
|
+
connectButtons === null || connectButtons === void 0 ? void 0 : connectButtons.forEach((button) => {
|
|
146
|
+
var _a, _b, _c;
|
|
147
|
+
try {
|
|
148
|
+
const ele = button;
|
|
149
|
+
if (ele &&
|
|
150
|
+
ele !== oneKeyButton &&
|
|
151
|
+
!((_c = (_b = (_a = ele.textContent) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes) === null || _c === void 0 ? void 0 : _c.call(_b, 'onekey'))) {
|
|
152
|
+
ele.style.display = 'none';
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error(error);
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
try {
|
|
161
|
+
hideNavigationBar();
|
|
162
|
+
}
|
|
163
|
+
catch (error) {
|
|
164
|
+
console.error(error);
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
hideConnectButton();
|
|
168
|
+
}
|
|
169
|
+
catch (error) {
|
|
170
|
+
console.error(error);
|
|
171
|
+
}
|
|
172
|
+
},
|
|
65
173
|
});
|
|
66
174
|
}
|
|
67
175
|
function initHyperliquidBuilderFeeConfig(ethereum) {
|
|
@@ -70,6 +178,7 @@ function initHyperliquidBuilderFeeConfig(ethereum) {
|
|
|
70
178
|
if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
|
|
71
179
|
return;
|
|
72
180
|
}
|
|
181
|
+
hackConnectionButton();
|
|
73
182
|
ethereum = ethereum || getEthereum();
|
|
74
183
|
const isEthereumValid = !!ethereum && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey);
|
|
75
184
|
if (ethereum && isEthereumValid) {
|
|
@@ -118,15 +227,46 @@ function checkHyperliquidUserApproveStatus(_a) {
|
|
|
118
227
|
});
|
|
119
228
|
}
|
|
120
229
|
function logHyperLiquidServerApiAction(_a) {
|
|
121
|
-
return __awaiter(this, arguments, void 0, function* ({ payload }) {
|
|
230
|
+
return __awaiter(this, arguments, void 0, function* ({ payload, error }) {
|
|
122
231
|
if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
|
|
123
232
|
return Promise.resolve(undefined);
|
|
124
233
|
}
|
|
125
234
|
const ethereum = getEthereum();
|
|
126
235
|
if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
|
|
236
|
+
let errorMessage = '';
|
|
237
|
+
if (error) {
|
|
238
|
+
try {
|
|
239
|
+
errorMessage = JSON.stringify(error);
|
|
240
|
+
}
|
|
241
|
+
catch (error) {
|
|
242
|
+
console.error(error);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
127
245
|
void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
|
|
128
246
|
method: 'hl_logApiEvent',
|
|
129
|
-
params: [
|
|
247
|
+
params: [
|
|
248
|
+
{
|
|
249
|
+
apiPayload: payload,
|
|
250
|
+
userAddress: ethereum === null || ethereum === void 0 ? void 0 : ethereum.selectedAddress,
|
|
251
|
+
chainId: ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId,
|
|
252
|
+
errorMessage,
|
|
253
|
+
},
|
|
254
|
+
],
|
|
255
|
+
}));
|
|
256
|
+
}
|
|
257
|
+
return Promise.resolve(undefined);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function clearUserMaxBuilderFeeCache() {
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
|
|
263
|
+
return Promise.resolve(undefined);
|
|
264
|
+
}
|
|
265
|
+
const ethereum = getEthereum();
|
|
266
|
+
if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
|
|
267
|
+
void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
|
|
268
|
+
method: 'hl_clearUserBuilderFeeCache',
|
|
269
|
+
params: [],
|
|
130
270
|
}));
|
|
131
271
|
}
|
|
132
272
|
return Promise.resolve(undefined);
|
|
@@ -136,4 +276,5 @@ exports.default = {
|
|
|
136
276
|
initHyperliquidBuilderFeeConfig,
|
|
137
277
|
checkHyperliquidUserApproveStatus,
|
|
138
278
|
logHyperLiquidServerApiAction,
|
|
279
|
+
clearUserMaxBuilderFeeCache,
|
|
139
280
|
};
|
|
@@ -13,12 +13,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.BuiltInPerpInjected = void 0;
|
|
16
|
+
const lodash_1 = require("lodash");
|
|
16
17
|
const providersHubUtils_1 = __importDefault(require("../utils/providersHubUtils"));
|
|
17
18
|
const consts_1 = require("./consts");
|
|
18
19
|
const hijackMethods_1 = __importDefault(require("./hijackMethods"));
|
|
20
|
+
const hyperLiquidDappDetecter_1 = __importDefault(require("./hyperLiquidDappDetecter"));
|
|
19
21
|
const hyperLiquidOneKeyWalletApi_1 = __importDefault(require("./hyperLiquidOneKeyWalletApi"));
|
|
20
22
|
const hyperLiquidServerApi_1 = __importDefault(require("./hyperLiquidServerApi"));
|
|
21
|
-
const hyperLiquidDappDetecter_1 = __importDefault(require("./hyperLiquidDappDetecter"));
|
|
22
23
|
const originalConsoleLog = providersHubUtils_1.default.consoleLog;
|
|
23
24
|
class BuiltInPerpInjected {
|
|
24
25
|
constructor() {
|
|
@@ -37,7 +38,7 @@ class BuiltInPerpInjected {
|
|
|
37
38
|
}
|
|
38
39
|
modifyApiPostBody({ originalBody, jsonBody, jsonBodyToUpdate, }) {
|
|
39
40
|
if (Object.keys(jsonBodyToUpdate).length) {
|
|
40
|
-
|
|
41
|
+
(0, lodash_1.merge)(jsonBody, jsonBodyToUpdate);
|
|
41
42
|
return JSON.stringify(jsonBody);
|
|
42
43
|
}
|
|
43
44
|
return originalBody;
|
|
@@ -54,6 +55,14 @@ class BuiltInPerpInjected {
|
|
|
54
55
|
yield hyperLiquidOneKeyWalletApi_1.default.checkHyperliquidUserApproveStatus({
|
|
55
56
|
shouldApproveBuilderFee: true,
|
|
56
57
|
});
|
|
58
|
+
// TODO remove
|
|
59
|
+
// merge(jsonBodyToUpdate, {
|
|
60
|
+
// action: {
|
|
61
|
+
// builder: {
|
|
62
|
+
// f: 9999,
|
|
63
|
+
// },
|
|
64
|
+
// },
|
|
65
|
+
// });
|
|
57
66
|
}
|
|
58
67
|
originalConsoleLog('BuiltInPerpInjected>>>>isPlaceOrderRequest', isPlaceOrderRequest, url, jsonBody);
|
|
59
68
|
});
|
|
@@ -88,9 +97,6 @@ class BuiltInPerpInjected {
|
|
|
88
97
|
const jsonBodyToUpdate = Object.assign({}, consts_1.FIXED_ADDITIONAL_POST_BODY);
|
|
89
98
|
const isPlaceOrderRequest = hyperLiquidServerApi_1.default.isPlaceOrderRequest({ jsonBody, url });
|
|
90
99
|
if (isPlaceOrderRequest) {
|
|
91
|
-
void hyperLiquidOneKeyWalletApi_1.default.logHyperLiquidServerApiAction({
|
|
92
|
-
payload: jsonBody,
|
|
93
|
-
});
|
|
94
100
|
yield this.waitBuilderFeeApproved({
|
|
95
101
|
jsonBody,
|
|
96
102
|
url,
|
|
@@ -102,7 +108,56 @@ class BuiltInPerpInjected {
|
|
|
102
108
|
jsonBody,
|
|
103
109
|
jsonBodyToUpdate,
|
|
104
110
|
});
|
|
105
|
-
|
|
111
|
+
try {
|
|
112
|
+
const result = yield originalFetch(input, modifiedInit);
|
|
113
|
+
try {
|
|
114
|
+
if (isPlaceOrderRequest) {
|
|
115
|
+
const resData = (yield result.clone().json());
|
|
116
|
+
if ((resData === null || resData === void 0 ? void 0 : resData.status) === 'err') {
|
|
117
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error1', resData);
|
|
118
|
+
void hyperLiquidOneKeyWalletApi_1.default.clearUserMaxBuilderFeeCache();
|
|
119
|
+
void hyperLiquidOneKeyWalletApi_1.default.logHyperLiquidServerApiAction({
|
|
120
|
+
payload: jsonBody,
|
|
121
|
+
error: resData,
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/*
|
|
125
|
+
{
|
|
126
|
+
"status": "ok",
|
|
127
|
+
"response": {
|
|
128
|
+
"type": "order",
|
|
129
|
+
"data": {
|
|
130
|
+
"statuses": [
|
|
131
|
+
{
|
|
132
|
+
"resting": {
|
|
133
|
+
"oid": 133956942251
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
*/
|
|
141
|
+
if ((resData === null || resData === void 0 ? void 0 : resData.status) === 'ok') {
|
|
142
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Success', resData);
|
|
143
|
+
void hyperLiquidOneKeyWalletApi_1.default.logHyperLiquidServerApiAction({
|
|
144
|
+
payload: jsonBody,
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
catch (eeee) {
|
|
150
|
+
// ignore
|
|
151
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error2', eeee);
|
|
152
|
+
}
|
|
153
|
+
return result;
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
if (isPlaceOrderRequest) {
|
|
157
|
+
originalConsoleLog('BuiltInPerpInjected__PlaceOrderRequest__Error3', error);
|
|
158
|
+
}
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
106
161
|
}
|
|
107
162
|
}
|
|
108
163
|
}
|
|
@@ -113,9 +168,15 @@ class BuiltInPerpInjected {
|
|
|
113
168
|
exports.BuiltInPerpInjected = BuiltInPerpInjected;
|
|
114
169
|
exports.default = {
|
|
115
170
|
createInstance: () => {
|
|
116
|
-
|
|
117
|
-
|
|
171
|
+
try {
|
|
172
|
+
if (hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
|
|
173
|
+
return new BuiltInPerpInjected();
|
|
174
|
+
}
|
|
175
|
+
return undefined;
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
originalConsoleLog('BuiltInPerpInjected__createInstance__Error', error);
|
|
179
|
+
return undefined;
|
|
118
180
|
}
|
|
119
|
-
return undefined;
|
|
120
181
|
},
|
|
121
182
|
};
|
|
@@ -14,8 +14,8 @@ exports.createWalletConnectToButton = createWalletConnectToButton;
|
|
|
14
14
|
exports.createNewImageToContainer = createNewImageToContainer;
|
|
15
15
|
exports.hackConnectButton = hackConnectButton;
|
|
16
16
|
const cross_inpage_provider_core_1 = require("@onekeyfe/cross-inpage-provider-core");
|
|
17
|
-
const lodash_es_1 = require("lodash-es");
|
|
18
17
|
const cross_inpage_provider_types_1 = require("@onekeyfe/cross-inpage-provider-types");
|
|
18
|
+
const lodash_es_1 = require("lodash-es");
|
|
19
19
|
const hackButtonLogger = new cross_inpage_provider_core_1.Logger('hackButton');
|
|
20
20
|
function checkIfInjectedProviderConnected({ providerName, }) {
|
|
21
21
|
var _a;
|
|
@@ -230,7 +230,7 @@ function createNewImageToContainer({ container, icon, removeSvg = true, onCreate
|
|
|
230
230
|
container.prepend(newImg);
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
|
-
function hackConnectButton({ urls, replaceMethod, providers, mutationObserverOptions = {
|
|
233
|
+
function hackConnectButton({ urls, isSiteCustomMatchedFn, replaceMethod, providers, mutationObserverOptions = {
|
|
234
234
|
attributes: false,
|
|
235
235
|
characterData: false,
|
|
236
236
|
childList: true,
|
|
@@ -239,7 +239,13 @@ function hackConnectButton({ urls, replaceMethod, providers, mutationObserverOpt
|
|
|
239
239
|
leading: true,
|
|
240
240
|
trailing: true,
|
|
241
241
|
}, callbackDelay = 10, }) {
|
|
242
|
-
const isUrlMatched = () =>
|
|
242
|
+
const isUrlMatched = () => {
|
|
243
|
+
const r = Boolean(urls.includes(window.location.hostname) || urls.includes('*'));
|
|
244
|
+
if (isSiteCustomMatchedFn) {
|
|
245
|
+
return (isSiteCustomMatchedFn === null || isSiteCustomMatchedFn === void 0 ? void 0 : isSiteCustomMatchedFn()) === true && r;
|
|
246
|
+
}
|
|
247
|
+
return r;
|
|
248
|
+
};
|
|
243
249
|
const getEnabledInjectedProviders = () => {
|
|
244
250
|
if (!isUrlMatched()) {
|
|
245
251
|
return;
|
|
@@ -39,7 +39,7 @@ function injectWeb3Provider({ showFloatingButton = false, } = {}) {
|
|
|
39
39
|
}
|
|
40
40
|
const bridge = (_b = window === null || window === void 0 ? void 0 : window.$onekey) === null || _b === void 0 ? void 0 : _b.jsBridge;
|
|
41
41
|
const builtInPerpInjectedInstance = builtInPerpInjected_1.default.createInstance();
|
|
42
|
-
if (builtInPerpInjectedInstance) {
|
|
42
|
+
if (builtInPerpInjectedInstance && (window === null || window === void 0 ? void 0 : window.$onekey)) {
|
|
43
43
|
// @ts-ignore
|
|
44
44
|
window.$onekey.$builtInPerpInjected = builtInPerpInjectedInstance;
|
|
45
45
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
2
|
// Save original console.log before it might be overridden
|
|
4
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const originalConsoleLog = process.env.NODE_ENV !== 'production' ? console.log : () => {
|
|
5
|
+
//
|
|
6
|
+
};
|
|
5
7
|
exports.default = {
|
|
6
8
|
consoleLog: originalConsoleLog,
|
|
7
9
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ThrottleSettings } from 'lodash-es';
|
|
2
1
|
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
|
|
2
|
+
import { ThrottleSettings } from 'lodash-es';
|
|
3
3
|
export declare function detectQrcodeFromSvg({ img, }: {
|
|
4
4
|
img: HTMLImageElement | Element;
|
|
5
5
|
}): Promise<string>;
|
|
@@ -16,8 +16,9 @@ export declare function createNewImageToContainer({ container, icon, removeSvg,
|
|
|
16
16
|
width?: string;
|
|
17
17
|
height?: string;
|
|
18
18
|
}): void;
|
|
19
|
-
declare function hackConnectButton({ urls, replaceMethod, providers, mutationObserverOptions, throttleDelay, throttleSettings, callbackDelay, }: {
|
|
19
|
+
declare function hackConnectButton({ urls, isSiteCustomMatchedFn, replaceMethod, providers, mutationObserverOptions, throttleDelay, throttleSettings, callbackDelay, }: {
|
|
20
20
|
urls: string[];
|
|
21
|
+
isSiteCustomMatchedFn?: () => boolean;
|
|
21
22
|
replaceMethod: (options?: {
|
|
22
23
|
providers: IInjectedProviderNames[];
|
|
23
24
|
}) => void;
|
|
@@ -7,9 +7,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { ISpecialPropertyProviderNamesReflection, Logger,
|
|
11
|
-
import { throttle } from 'lodash-es';
|
|
10
|
+
import { checkWalletSwitchEnable, ISpecialPropertyProviderNamesReflection, Logger, } from '@onekeyfe/cross-inpage-provider-core';
|
|
12
11
|
import { IInjectedProviderNames } from '@onekeyfe/cross-inpage-provider-types';
|
|
12
|
+
import { throttle } from 'lodash-es';
|
|
13
13
|
const hackButtonLogger = new Logger('hackButton');
|
|
14
14
|
function checkIfInjectedProviderConnected({ providerName, }) {
|
|
15
15
|
var _a;
|
|
@@ -224,7 +224,7 @@ export function createNewImageToContainer({ container, icon, removeSvg = true, o
|
|
|
224
224
|
container.prepend(newImg);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
|
-
function hackConnectButton({ urls, replaceMethod, providers, mutationObserverOptions = {
|
|
227
|
+
function hackConnectButton({ urls, isSiteCustomMatchedFn, replaceMethod, providers, mutationObserverOptions = {
|
|
228
228
|
attributes: false,
|
|
229
229
|
characterData: false,
|
|
230
230
|
childList: true,
|
|
@@ -233,7 +233,13 @@ function hackConnectButton({ urls, replaceMethod, providers, mutationObserverOpt
|
|
|
233
233
|
leading: true,
|
|
234
234
|
trailing: true,
|
|
235
235
|
}, callbackDelay = 10, }) {
|
|
236
|
-
const isUrlMatched = () =>
|
|
236
|
+
const isUrlMatched = () => {
|
|
237
|
+
const r = Boolean(urls.includes(window.location.hostname) || urls.includes('*'));
|
|
238
|
+
if (isSiteCustomMatchedFn) {
|
|
239
|
+
return (isSiteCustomMatchedFn === null || isSiteCustomMatchedFn === void 0 ? void 0 : isSiteCustomMatchedFn()) === true && r;
|
|
240
|
+
}
|
|
241
|
+
return r;
|
|
242
|
+
};
|
|
237
243
|
const getEnabledInjectedProviders = () => {
|
|
238
244
|
if (!isUrlMatched()) {
|
|
239
245
|
return;
|
|
@@ -33,7 +33,7 @@ function injectWeb3Provider({ showFloatingButton = false, } = {}) {
|
|
|
33
33
|
}
|
|
34
34
|
const bridge = (_b = window === null || window === void 0 ? void 0 : window.$onekey) === null || _b === void 0 ? void 0 : _b.jsBridge;
|
|
35
35
|
const builtInPerpInjectedInstance = builtInPerpInjected.createInstance();
|
|
36
|
-
if (builtInPerpInjectedInstance) {
|
|
36
|
+
if (builtInPerpInjectedInstance && (window === null || window === void 0 ? void 0 : window.$onekey)) {
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
window.$onekey.$builtInPerpInjected = builtInPerpInjectedInstance;
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/inpage-providers-hub",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.38",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"cross-inpage-provider"
|
|
6
6
|
],
|
|
@@ -27,27 +27,27 @@
|
|
|
27
27
|
"start": "tsc --watch"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@onekeyfe/cross-inpage-provider-core": "2.2.
|
|
31
|
-
"@onekeyfe/cross-inpage-provider-types": "2.2.
|
|
32
|
-
"@onekeyfe/onekey-algo-provider": "2.2.
|
|
33
|
-
"@onekeyfe/onekey-alph-provider": "2.2.
|
|
34
|
-
"@onekeyfe/onekey-aptos-provider": "2.2.
|
|
35
|
-
"@onekeyfe/onekey-bfc-provider": "2.2.
|
|
36
|
-
"@onekeyfe/onekey-btc-provider": "2.2.
|
|
37
|
-
"@onekeyfe/onekey-cardano-provider": "2.2.
|
|
38
|
-
"@onekeyfe/onekey-conflux-provider": "2.2.
|
|
39
|
-
"@onekeyfe/onekey-cosmos-provider": "2.2.
|
|
40
|
-
"@onekeyfe/onekey-eth-provider": "2.2.
|
|
41
|
-
"@onekeyfe/onekey-neo-provider": "2.2.
|
|
42
|
-
"@onekeyfe/onekey-nostr-provider": "2.2.
|
|
43
|
-
"@onekeyfe/onekey-polkadot-provider": "2.2.
|
|
44
|
-
"@onekeyfe/onekey-private-provider": "2.2.
|
|
45
|
-
"@onekeyfe/onekey-scdo-provider": "2.2.
|
|
46
|
-
"@onekeyfe/onekey-solana-provider": "2.2.
|
|
47
|
-
"@onekeyfe/onekey-sui-provider": "2.2.
|
|
48
|
-
"@onekeyfe/onekey-ton-provider": "2.2.
|
|
49
|
-
"@onekeyfe/onekey-tron-provider": "2.2.
|
|
50
|
-
"@onekeyfe/onekey-webln-provider": "2.2.
|
|
30
|
+
"@onekeyfe/cross-inpage-provider-core": "2.2.38",
|
|
31
|
+
"@onekeyfe/cross-inpage-provider-types": "2.2.38",
|
|
32
|
+
"@onekeyfe/onekey-algo-provider": "2.2.38",
|
|
33
|
+
"@onekeyfe/onekey-alph-provider": "2.2.38",
|
|
34
|
+
"@onekeyfe/onekey-aptos-provider": "2.2.38",
|
|
35
|
+
"@onekeyfe/onekey-bfc-provider": "2.2.38",
|
|
36
|
+
"@onekeyfe/onekey-btc-provider": "2.2.38",
|
|
37
|
+
"@onekeyfe/onekey-cardano-provider": "2.2.38",
|
|
38
|
+
"@onekeyfe/onekey-conflux-provider": "2.2.38",
|
|
39
|
+
"@onekeyfe/onekey-cosmos-provider": "2.2.38",
|
|
40
|
+
"@onekeyfe/onekey-eth-provider": "2.2.38",
|
|
41
|
+
"@onekeyfe/onekey-neo-provider": "2.2.38",
|
|
42
|
+
"@onekeyfe/onekey-nostr-provider": "2.2.38",
|
|
43
|
+
"@onekeyfe/onekey-polkadot-provider": "2.2.38",
|
|
44
|
+
"@onekeyfe/onekey-private-provider": "2.2.38",
|
|
45
|
+
"@onekeyfe/onekey-scdo-provider": "2.2.38",
|
|
46
|
+
"@onekeyfe/onekey-solana-provider": "2.2.38",
|
|
47
|
+
"@onekeyfe/onekey-sui-provider": "2.2.38",
|
|
48
|
+
"@onekeyfe/onekey-ton-provider": "2.2.38",
|
|
49
|
+
"@onekeyfe/onekey-tron-provider": "2.2.38",
|
|
50
|
+
"@onekeyfe/onekey-webln-provider": "2.2.38",
|
|
51
51
|
"lodash-es": "^4.17.21",
|
|
52
52
|
"preact": "^10.25.1"
|
|
53
53
|
},
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"@types/lodash-es": "^4.17.12",
|
|
56
56
|
"@types/node": "^20.12.7"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "42c209ede6357a1910ba184de8f33cefc5ee3bdb"
|
|
59
59
|
}
|