@onekeyfe/inpage-providers-hub 2.2.37 → 2.2.39

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.
@@ -1,12 +1,24 @@
1
+ export type IHyperliquidBuilderCustomSettings = {
2
+ hideNavBar?: boolean;
3
+ hideNavBarConnectButton?: boolean;
4
+ hideNotOneKeyWalletConnectButton?: boolean;
5
+ };
1
6
  export declare class HyperliquidBuilderStore {
2
7
  private static store;
3
8
  private static _expectBuilderAddress;
4
9
  private static _expectMaxBuilderFee;
10
+ private static _customSettings;
5
11
  static get expectBuilderAddress(): string | undefined;
6
12
  static set expectBuilderAddress(value: string | undefined);
7
13
  static get expectMaxBuilderFee(): number | undefined;
8
14
  static set expectMaxBuilderFee(value: number | undefined);
15
+ static get customSettings(): {
16
+ hideNavBar?: boolean;
17
+ hideNavBarConnectButton?: boolean;
18
+ hideNotOneKeyWalletConnectButton?: boolean;
19
+ } | undefined;
20
+ static set customSettings(value: IHyperliquidBuilderCustomSettings | undefined);
9
21
  static updateBuilderInfo(address: string, fee: number): void;
10
22
  static flush(): void;
11
- static storeUpdateByOneKey: boolean;
23
+ static storeUpdateByOneKeyWallet: boolean;
12
24
  }
@@ -1,36 +1,54 @@
1
1
  import { LocalStorageStore } from '../utils/LocalStorageStore';
2
2
  const prefix = 'hyperliquid.k_config_v3.'; //builder
3
- const expectBuilderAddressKey = 'a';
4
- const expectMaxBuilderFeeKey = 'v';
3
+ const storageKeys = {
4
+ expectBuilderAddress: 'a',
5
+ expectMaxBuilderFee: 'f',
6
+ customSettings: 's',
7
+ };
5
8
  export class HyperliquidBuilderStore {
6
9
  static get expectBuilderAddress() {
7
10
  if (this._expectBuilderAddress === undefined) {
8
- this._expectBuilderAddress = this.store.get(expectBuilderAddressKey);
11
+ this._expectBuilderAddress = this.store.get(storageKeys.expectBuilderAddress);
9
12
  }
10
13
  return this._expectBuilderAddress;
11
14
  }
12
15
  static set expectBuilderAddress(value) {
13
16
  this._expectBuilderAddress = value;
14
17
  if (value === undefined) {
15
- this.store.remove(expectBuilderAddressKey);
18
+ this.store.remove(storageKeys.expectBuilderAddress);
16
19
  }
17
20
  else {
18
- this.store.set(expectBuilderAddressKey, value);
21
+ this.store.set(storageKeys.expectBuilderAddress, value);
19
22
  }
20
23
  }
21
24
  static get expectMaxBuilderFee() {
22
25
  if (this._expectMaxBuilderFee === undefined) {
23
- this._expectMaxBuilderFee = this.store.get(expectMaxBuilderFeeKey);
26
+ this._expectMaxBuilderFee = this.store.get(storageKeys.expectMaxBuilderFee);
24
27
  }
25
28
  return this._expectMaxBuilderFee;
26
29
  }
27
30
  static set expectMaxBuilderFee(value) {
28
31
  this._expectMaxBuilderFee = value;
29
32
  if (value === undefined) {
30
- this.store.remove(expectMaxBuilderFeeKey);
33
+ this.store.remove(storageKeys.expectMaxBuilderFee);
31
34
  }
32
35
  else {
33
- this.store.set(expectMaxBuilderFeeKey, value);
36
+ this.store.set(storageKeys.expectMaxBuilderFee, value);
37
+ }
38
+ }
39
+ static get customSettings() {
40
+ if (this._customSettings === undefined) {
41
+ this._customSettings = this.store.get(storageKeys.customSettings);
42
+ }
43
+ return this._customSettings;
44
+ }
45
+ static set customSettings(value) {
46
+ this._customSettings = value;
47
+ if (value === undefined) {
48
+ this.store.remove(storageKeys.customSettings);
49
+ }
50
+ else {
51
+ this.store.set(storageKeys.customSettings, value);
34
52
  }
35
53
  }
36
54
  static updateBuilderInfo(address, fee) {
@@ -42,4 +60,4 @@ export class HyperliquidBuilderStore {
42
60
  }
43
61
  }
44
62
  HyperliquidBuilderStore.store = new LocalStorageStore(prefix);
45
- HyperliquidBuilderStore.storeUpdateByOneKey = false;
63
+ HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
@@ -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.storeUpdateByOneKey) &&
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,9 +7,14 @@ 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 { isNumber } from 'lodash-es';
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';
12
- import { HyperliquidBuilderStore } from './HyperliquidBuilderStore';
16
+ import { HYPERLIQUID_HOSTNAME } from './consts';
17
+ import { HyperliquidBuilderStore, } from './HyperliquidBuilderStore';
13
18
  import hyperLiquidDappDetecter from './hyperLiquidDappDetecter';
14
19
  function getEthereum() {
15
20
  var _a;
@@ -25,13 +30,48 @@ 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
+ }
58
+ if (result === null || result === void 0 ? void 0 : result.customSettings) {
59
+ providersHubUtils.consoleLog('BuiltInPerpInjected___saveBuilderFeeConfigToStorage>>>>result.customSettings22211', result.customSettings);
60
+ try {
61
+ HyperliquidBuilderStore.customSettings = result.customSettings;
62
+ }
63
+ catch (error) {
64
+ console.error(error);
65
+ }
66
+ }
28
67
  if ((result === null || result === void 0 ? void 0 : result.expectBuilderAddress) &&
29
68
  isNumber(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) &&
30
69
  (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) >= 0) {
31
70
  // HyperliquidBuilderStore --> hijackReactUseContextMethod
32
71
  HyperliquidBuilderStore.updateBuilderInfo(result.expectBuilderAddress.toLowerCase(), result.expectMaxBuilderFee);
33
- HyperliquidBuilderStore.storeUpdateByOneKey = true;
72
+ HyperliquidBuilderStore.storeUpdateByOneKeyWallet = true;
34
73
  // do not modify localStorage, otherwise the hyperliquid page will not work properly when the onekey plugin is disabled
74
+ localStorage.removeItem('hyperliquid.order_builder_info');
35
75
  // localStorage.setItem(
36
76
  // 'hyperliquid.order_builder_info',
37
77
  // JSON.stringify({
@@ -40,23 +80,109 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
40
80
  // }),
41
81
  // );
42
82
  }
83
+ else if (!(result === null || result === void 0 ? void 0 : result.expectBuilderAddress) || (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) < 0) {
84
+ localStorage.removeItem('hyperliquid.order_builder_info');
85
+ HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
86
+ }
43
87
  }
44
88
  function registerBuilderFeeUpdateEvents(ethereum) {
45
89
  if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
46
90
  return;
47
91
  }
48
92
  ethereum === null || ethereum === void 0 ? void 0 : ethereum.on('message', (payload, p1, p2) => {
49
- const { type: method, data: params } = payload || {};
50
- if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
51
- const paramsInfo = params;
52
- saveBuilderFeeConfigToStorage({
53
- result: {
54
- expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
55
- expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
56
- },
57
- fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
58
- });
93
+ try {
94
+ const { type: method, data: params } = payload || {};
95
+ if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
96
+ const paramsInfo = params;
97
+ saveBuilderFeeConfigToStorage({
98
+ result: {
99
+ expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
100
+ expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
101
+ },
102
+ fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
103
+ });
104
+ }
59
105
  }
106
+ catch (error) {
107
+ console.error(error);
108
+ }
109
+ });
110
+ }
111
+ function hackConnectionButton() {
112
+ hackConnectButton({
113
+ urls: [HYPERLIQUID_HOSTNAME],
114
+ providers: [IInjectedProviderNames.ethereum],
115
+ replaceMethod() {
116
+ var _a;
117
+ const customSettings = HyperliquidBuilderStore === null || HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore.customSettings;
118
+ const hideNavigationBar = () => {
119
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
120
+ let navBarRightContainer;
121
+ if ((_a = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNavBar) !== null && _a !== void 0 ? _a : true) {
122
+ const siteIcon = (_e = (_d = (_c = (_b = window === null || window === void 0 ? void 0 : window.document) === null || _b === void 0 ? void 0 : _b.querySelectorAll) === null || _c === void 0 ? void 0 : _c.call(_b, 'a[href="/trade"]>svg')) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.parentElement;
123
+ const navBarItems = (_f = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _f === void 0 ? void 0 : _f.childNodes;
124
+ navBarRightContainer = (_g = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _g === void 0 ? void 0 : _g.nextElementSibling;
125
+ navBarItems === null || navBarItems === void 0 ? void 0 : navBarItems.forEach((item, index) => {
126
+ var _a;
127
+ try {
128
+ const ele = item;
129
+ if (index >= 1) {
130
+ const href = (_a = ele === null || ele === void 0 ? void 0 : ele.querySelector('a')) === null || _a === void 0 ? void 0 : _a.getAttribute('href');
131
+ if (ele && !(href === null || href === void 0 ? void 0 : href.includes('/trade'))) {
132
+ ele.style.display = 'none';
133
+ }
134
+ }
135
+ }
136
+ catch (error) {
137
+ console.error(error);
138
+ }
139
+ });
140
+ }
141
+ if ((_h = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNavBarConnectButton) !== null && _h !== void 0 ? _h : false) {
142
+ if (navBarRightContainer) {
143
+ const button = navBarRightContainer.querySelector('button');
144
+ if (button && ((_k = (_j = button === null || button === void 0 ? void 0 : button.textContent) === null || _j === void 0 ? void 0 : _j.toLowerCase()) === null || _k === void 0 ? void 0 : _k.trim()) === 'connect') {
145
+ button.style.display = 'none';
146
+ }
147
+ }
148
+ }
149
+ };
150
+ const hideNotOneKeyWalletConnectButton = () => {
151
+ var _a;
152
+ 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'));
153
+ 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'); });
154
+ const oneKeyButtonParent = oneKeyButton === null || oneKeyButton === void 0 ? void 0 : oneKeyButton.parentElement;
155
+ const connectButtons = oneKeyButtonParent === null || oneKeyButtonParent === void 0 ? void 0 : oneKeyButtonParent.childNodes;
156
+ connectButtons === null || connectButtons === void 0 ? void 0 : connectButtons.forEach((button) => {
157
+ var _a, _b, _c;
158
+ try {
159
+ const ele = button;
160
+ if (ele &&
161
+ ele !== oneKeyButton &&
162
+ !((_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'))) {
163
+ ele.style.display = 'none';
164
+ }
165
+ }
166
+ catch (error) {
167
+ console.error(error);
168
+ }
169
+ });
170
+ };
171
+ try {
172
+ hideNavigationBar();
173
+ }
174
+ catch (error) {
175
+ console.error(error);
176
+ }
177
+ try {
178
+ if ((_a = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNotOneKeyWalletConnectButton) !== null && _a !== void 0 ? _a : true) {
179
+ hideNotOneKeyWalletConnectButton();
180
+ }
181
+ }
182
+ catch (error) {
183
+ console.error(error);
184
+ }
185
+ },
60
186
  });
61
187
  }
62
188
  function initHyperliquidBuilderFeeConfig(ethereum) {
@@ -65,6 +191,7 @@ function initHyperliquidBuilderFeeConfig(ethereum) {
65
191
  if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
66
192
  return;
67
193
  }
194
+ hackConnectionButton();
68
195
  ethereum = ethereum || getEthereum();
69
196
  const isEthereumValid = !!ethereum && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey);
70
197
  if (ethereum && isEthereumValid) {
@@ -113,15 +240,46 @@ function checkHyperliquidUserApproveStatus(_a) {
113
240
  });
114
241
  }
115
242
  function logHyperLiquidServerApiAction(_a) {
116
- return __awaiter(this, arguments, void 0, function* ({ payload }) {
243
+ return __awaiter(this, arguments, void 0, function* ({ payload, error }) {
117
244
  if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
118
245
  return Promise.resolve(undefined);
119
246
  }
120
247
  const ethereum = getEthereum();
121
248
  if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
249
+ let errorMessage = '';
250
+ if (error) {
251
+ try {
252
+ errorMessage = JSON.stringify(error);
253
+ }
254
+ catch (error) {
255
+ console.error(error);
256
+ }
257
+ }
122
258
  void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
123
259
  method: 'hl_logApiEvent',
124
- params: [{ apiPayload: payload }],
260
+ params: [
261
+ {
262
+ apiPayload: payload,
263
+ userAddress: ethereum === null || ethereum === void 0 ? void 0 : ethereum.selectedAddress,
264
+ chainId: ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId,
265
+ errorMessage,
266
+ },
267
+ ],
268
+ }));
269
+ }
270
+ return Promise.resolve(undefined);
271
+ });
272
+ }
273
+ function clearUserMaxBuilderFeeCache() {
274
+ return __awaiter(this, void 0, void 0, function* () {
275
+ if (!hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
276
+ return Promise.resolve(undefined);
277
+ }
278
+ const ethereum = getEthereum();
279
+ if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
280
+ void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
281
+ method: 'hl_clearUserBuilderFeeCache',
282
+ params: [],
125
283
  }));
126
284
  }
127
285
  return Promise.resolve(undefined);
@@ -131,4 +289,5 @@ export default {
131
289
  initHyperliquidBuilderFeeConfig,
132
290
  checkHyperliquidUserApproveStatus,
133
291
  logHyperLiquidServerApiAction,
292
+ clearUserMaxBuilderFeeCache,
134
293
  };
@@ -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
- Object.assign(jsonBody, jsonBodyToUpdate);
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
- return originalFetch(input, modifiedInit);
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
- if (hyperLiquidDappDetecter.isBuiltInHyperLiquidSite()) {
110
- return new BuiltInPerpInjected();
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
  };
@@ -3,37 +3,55 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HyperliquidBuilderStore = void 0;
4
4
  const LocalStorageStore_1 = require("../utils/LocalStorageStore");
5
5
  const prefix = 'hyperliquid.k_config_v3.'; //builder
6
- const expectBuilderAddressKey = 'a';
7
- const expectMaxBuilderFeeKey = 'v';
6
+ const storageKeys = {
7
+ expectBuilderAddress: 'a',
8
+ expectMaxBuilderFee: 'f',
9
+ customSettings: 's',
10
+ };
8
11
  class HyperliquidBuilderStore {
9
12
  static get expectBuilderAddress() {
10
13
  if (this._expectBuilderAddress === undefined) {
11
- this._expectBuilderAddress = this.store.get(expectBuilderAddressKey);
14
+ this._expectBuilderAddress = this.store.get(storageKeys.expectBuilderAddress);
12
15
  }
13
16
  return this._expectBuilderAddress;
14
17
  }
15
18
  static set expectBuilderAddress(value) {
16
19
  this._expectBuilderAddress = value;
17
20
  if (value === undefined) {
18
- this.store.remove(expectBuilderAddressKey);
21
+ this.store.remove(storageKeys.expectBuilderAddress);
19
22
  }
20
23
  else {
21
- this.store.set(expectBuilderAddressKey, value);
24
+ this.store.set(storageKeys.expectBuilderAddress, value);
22
25
  }
23
26
  }
24
27
  static get expectMaxBuilderFee() {
25
28
  if (this._expectMaxBuilderFee === undefined) {
26
- this._expectMaxBuilderFee = this.store.get(expectMaxBuilderFeeKey);
29
+ this._expectMaxBuilderFee = this.store.get(storageKeys.expectMaxBuilderFee);
27
30
  }
28
31
  return this._expectMaxBuilderFee;
29
32
  }
30
33
  static set expectMaxBuilderFee(value) {
31
34
  this._expectMaxBuilderFee = value;
32
35
  if (value === undefined) {
33
- this.store.remove(expectMaxBuilderFeeKey);
36
+ this.store.remove(storageKeys.expectMaxBuilderFee);
34
37
  }
35
38
  else {
36
- this.store.set(expectMaxBuilderFeeKey, value);
39
+ this.store.set(storageKeys.expectMaxBuilderFee, value);
40
+ }
41
+ }
42
+ static get customSettings() {
43
+ if (this._customSettings === undefined) {
44
+ this._customSettings = this.store.get(storageKeys.customSettings);
45
+ }
46
+ return this._customSettings;
47
+ }
48
+ static set customSettings(value) {
49
+ this._customSettings = value;
50
+ if (value === undefined) {
51
+ this.store.remove(storageKeys.customSettings);
52
+ }
53
+ else {
54
+ this.store.set(storageKeys.customSettings, value);
37
55
  }
38
56
  }
39
57
  static updateBuilderInfo(address, fee) {
@@ -46,4 +64,4 @@ class HyperliquidBuilderStore {
46
64
  }
47
65
  exports.HyperliquidBuilderStore = HyperliquidBuilderStore;
48
66
  HyperliquidBuilderStore.store = new LocalStorageStore_1.LocalStorageStore(prefix);
49
- HyperliquidBuilderStore.storeUpdateByOneKey = false;
67
+ 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.storeUpdateByOneKey) &&
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,48 @@ 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
+ }
63
+ if (result === null || result === void 0 ? void 0 : result.customSettings) {
64
+ providersHubUtils_1.default.consoleLog('BuiltInPerpInjected___saveBuilderFeeConfigToStorage>>>>result.customSettings22211', result.customSettings);
65
+ try {
66
+ HyperliquidBuilderStore_1.HyperliquidBuilderStore.customSettings = result.customSettings;
67
+ }
68
+ catch (error) {
69
+ console.error(error);
70
+ }
71
+ }
33
72
  if ((result === null || result === void 0 ? void 0 : result.expectBuilderAddress) &&
34
73
  (0, lodash_es_1.isNumber)(result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) &&
35
74
  (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) >= 0) {
36
75
  // HyperliquidBuilderStore --> hijackReactUseContextMethod
37
76
  HyperliquidBuilderStore_1.HyperliquidBuilderStore.updateBuilderInfo(result.expectBuilderAddress.toLowerCase(), result.expectMaxBuilderFee);
38
- HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKey = true;
77
+ HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKeyWallet = true;
39
78
  // do not modify localStorage, otherwise the hyperliquid page will not work properly when the onekey plugin is disabled
79
+ localStorage.removeItem('hyperliquid.order_builder_info');
40
80
  // localStorage.setItem(
41
81
  // 'hyperliquid.order_builder_info',
42
82
  // JSON.stringify({
@@ -45,23 +85,109 @@ function saveBuilderFeeConfigToStorage({ result, fromSource, }) {
45
85
  // }),
46
86
  // );
47
87
  }
88
+ else if (!(result === null || result === void 0 ? void 0 : result.expectBuilderAddress) || (result === null || result === void 0 ? void 0 : result.expectMaxBuilderFee) < 0) {
89
+ localStorage.removeItem('hyperliquid.order_builder_info');
90
+ HyperliquidBuilderStore_1.HyperliquidBuilderStore.storeUpdateByOneKeyWallet = false;
91
+ }
48
92
  }
49
93
  function registerBuilderFeeUpdateEvents(ethereum) {
50
94
  if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
51
95
  return;
52
96
  }
53
97
  ethereum === null || ethereum === void 0 ? void 0 : ethereum.on('message', (payload, p1, p2) => {
54
- const { type: method, data: params } = payload || {};
55
- if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
56
- const paramsInfo = params;
57
- saveBuilderFeeConfigToStorage({
58
- result: {
59
- expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
60
- expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
61
- },
62
- fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
63
- });
98
+ try {
99
+ const { type: method, data: params } = payload || {};
100
+ if (method === 'onekeyWalletEvents_builtInPerpConfigChanged') {
101
+ const paramsInfo = params;
102
+ saveBuilderFeeConfigToStorage({
103
+ result: {
104
+ expectBuilderAddress: paramsInfo.hyperliquidBuilderAddress,
105
+ expectMaxBuilderFee: paramsInfo.hyperliquidMaxBuilderFee,
106
+ },
107
+ fromSource: 'onekeyWalletEvents_builtInPerpConfigChanged',
108
+ });
109
+ }
64
110
  }
111
+ catch (error) {
112
+ console.error(error);
113
+ }
114
+ });
115
+ }
116
+ function hackConnectionButton() {
117
+ (0, hackConnectButton_1.hackConnectButton)({
118
+ urls: [consts_1.HYPERLIQUID_HOSTNAME],
119
+ providers: [cross_inpage_provider_types_1.IInjectedProviderNames.ethereum],
120
+ replaceMethod() {
121
+ var _a;
122
+ const customSettings = HyperliquidBuilderStore_1.HyperliquidBuilderStore === null || HyperliquidBuilderStore_1.HyperliquidBuilderStore === void 0 ? void 0 : HyperliquidBuilderStore_1.HyperliquidBuilderStore.customSettings;
123
+ const hideNavigationBar = () => {
124
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
125
+ let navBarRightContainer;
126
+ if ((_a = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNavBar) !== null && _a !== void 0 ? _a : true) {
127
+ const siteIcon = (_e = (_d = (_c = (_b = window === null || window === void 0 ? void 0 : window.document) === null || _b === void 0 ? void 0 : _b.querySelectorAll) === null || _c === void 0 ? void 0 : _c.call(_b, 'a[href="/trade"]>svg')) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.parentElement;
128
+ const navBarItems = (_f = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _f === void 0 ? void 0 : _f.childNodes;
129
+ navBarRightContainer = (_g = siteIcon === null || siteIcon === void 0 ? void 0 : siteIcon.nextElementSibling) === null || _g === void 0 ? void 0 : _g.nextElementSibling;
130
+ navBarItems === null || navBarItems === void 0 ? void 0 : navBarItems.forEach((item, index) => {
131
+ var _a;
132
+ try {
133
+ const ele = item;
134
+ if (index >= 1) {
135
+ const href = (_a = ele === null || ele === void 0 ? void 0 : ele.querySelector('a')) === null || _a === void 0 ? void 0 : _a.getAttribute('href');
136
+ if (ele && !(href === null || href === void 0 ? void 0 : href.includes('/trade'))) {
137
+ ele.style.display = 'none';
138
+ }
139
+ }
140
+ }
141
+ catch (error) {
142
+ console.error(error);
143
+ }
144
+ });
145
+ }
146
+ if ((_h = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNavBarConnectButton) !== null && _h !== void 0 ? _h : false) {
147
+ if (navBarRightContainer) {
148
+ const button = navBarRightContainer.querySelector('button');
149
+ if (button && ((_k = (_j = button === null || button === void 0 ? void 0 : button.textContent) === null || _j === void 0 ? void 0 : _j.toLowerCase()) === null || _k === void 0 ? void 0 : _k.trim()) === 'connect') {
150
+ button.style.display = 'none';
151
+ }
152
+ }
153
+ }
154
+ };
155
+ const hideNotOneKeyWalletConnectButton = () => {
156
+ var _a;
157
+ 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'));
158
+ 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'); });
159
+ const oneKeyButtonParent = oneKeyButton === null || oneKeyButton === void 0 ? void 0 : oneKeyButton.parentElement;
160
+ const connectButtons = oneKeyButtonParent === null || oneKeyButtonParent === void 0 ? void 0 : oneKeyButtonParent.childNodes;
161
+ connectButtons === null || connectButtons === void 0 ? void 0 : connectButtons.forEach((button) => {
162
+ var _a, _b, _c;
163
+ try {
164
+ const ele = button;
165
+ if (ele &&
166
+ ele !== oneKeyButton &&
167
+ !((_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'))) {
168
+ ele.style.display = 'none';
169
+ }
170
+ }
171
+ catch (error) {
172
+ console.error(error);
173
+ }
174
+ });
175
+ };
176
+ try {
177
+ hideNavigationBar();
178
+ }
179
+ catch (error) {
180
+ console.error(error);
181
+ }
182
+ try {
183
+ if ((_a = customSettings === null || customSettings === void 0 ? void 0 : customSettings.hideNotOneKeyWalletConnectButton) !== null && _a !== void 0 ? _a : true) {
184
+ hideNotOneKeyWalletConnectButton();
185
+ }
186
+ }
187
+ catch (error) {
188
+ console.error(error);
189
+ }
190
+ },
65
191
  });
66
192
  }
67
193
  function initHyperliquidBuilderFeeConfig(ethereum) {
@@ -70,6 +196,7 @@ function initHyperliquidBuilderFeeConfig(ethereum) {
70
196
  if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
71
197
  return;
72
198
  }
199
+ hackConnectionButton();
73
200
  ethereum = ethereum || getEthereum();
74
201
  const isEthereumValid = !!ethereum && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && !!(ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey);
75
202
  if (ethereum && isEthereumValid) {
@@ -118,15 +245,46 @@ function checkHyperliquidUserApproveStatus(_a) {
118
245
  });
119
246
  }
120
247
  function logHyperLiquidServerApiAction(_a) {
121
- return __awaiter(this, arguments, void 0, function* ({ payload }) {
248
+ return __awaiter(this, arguments, void 0, function* ({ payload, error }) {
122
249
  if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
123
250
  return Promise.resolve(undefined);
124
251
  }
125
252
  const ethereum = getEthereum();
126
253
  if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
254
+ let errorMessage = '';
255
+ if (error) {
256
+ try {
257
+ errorMessage = JSON.stringify(error);
258
+ }
259
+ catch (error) {
260
+ console.error(error);
261
+ }
262
+ }
127
263
  void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
128
264
  method: 'hl_logApiEvent',
129
- params: [{ apiPayload: payload }],
265
+ params: [
266
+ {
267
+ apiPayload: payload,
268
+ userAddress: ethereum === null || ethereum === void 0 ? void 0 : ethereum.selectedAddress,
269
+ chainId: ethereum === null || ethereum === void 0 ? void 0 : ethereum.chainId,
270
+ errorMessage,
271
+ },
272
+ ],
273
+ }));
274
+ }
275
+ return Promise.resolve(undefined);
276
+ });
277
+ }
278
+ function clearUserMaxBuilderFeeCache() {
279
+ return __awaiter(this, void 0, void 0, function* () {
280
+ if (!hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
281
+ return Promise.resolve(undefined);
282
+ }
283
+ const ethereum = getEthereum();
284
+ if (ethereum && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request) && (ethereum === null || ethereum === void 0 ? void 0 : ethereum.isOneKey)) {
285
+ void (ethereum === null || ethereum === void 0 ? void 0 : ethereum.request({
286
+ method: 'hl_clearUserBuilderFeeCache',
287
+ params: [],
130
288
  }));
131
289
  }
132
290
  return Promise.resolve(undefined);
@@ -136,4 +294,5 @@ exports.default = {
136
294
  initHyperliquidBuilderFeeConfig,
137
295
  checkHyperliquidUserApproveStatus,
138
296
  logHyperLiquidServerApiAction,
297
+ clearUserMaxBuilderFeeCache,
139
298
  };
@@ -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
- Object.assign(jsonBody, jsonBodyToUpdate);
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
- return originalFetch(input, modifiedInit);
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
- if (hyperLiquidDappDetecter_1.default.isBuiltInHyperLiquidSite()) {
117
- return new BuiltInPerpInjected();
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 = () => Boolean(urls.includes(window.location.hostname) || urls.includes('*'));
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
- const originalConsoleLog = console.log;
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, checkWalletSwitchEnable, } from '@onekeyfe/cross-inpage-provider-core';
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 = () => Boolean(urls.includes(window.location.hostname) || urls.includes('*'));
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
  }
@@ -1,5 +1,7 @@
1
1
  // Save original console.log before it might be overridden
2
- const originalConsoleLog = console.log;
2
+ const originalConsoleLog = process.env.NODE_ENV !== 'production' ? console.log : () => {
3
+ //
4
+ };
3
5
  export default {
4
6
  consoleLog: originalConsoleLog,
5
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/inpage-providers-hub",
3
- "version": "2.2.37",
3
+ "version": "2.2.39",
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.37",
31
- "@onekeyfe/cross-inpage-provider-types": "2.2.37",
32
- "@onekeyfe/onekey-algo-provider": "2.2.37",
33
- "@onekeyfe/onekey-alph-provider": "2.2.37",
34
- "@onekeyfe/onekey-aptos-provider": "2.2.37",
35
- "@onekeyfe/onekey-bfc-provider": "2.2.37",
36
- "@onekeyfe/onekey-btc-provider": "2.2.37",
37
- "@onekeyfe/onekey-cardano-provider": "2.2.37",
38
- "@onekeyfe/onekey-conflux-provider": "2.2.37",
39
- "@onekeyfe/onekey-cosmos-provider": "2.2.37",
40
- "@onekeyfe/onekey-eth-provider": "2.2.37",
41
- "@onekeyfe/onekey-neo-provider": "2.2.37",
42
- "@onekeyfe/onekey-nostr-provider": "2.2.37",
43
- "@onekeyfe/onekey-polkadot-provider": "2.2.37",
44
- "@onekeyfe/onekey-private-provider": "2.2.37",
45
- "@onekeyfe/onekey-scdo-provider": "2.2.37",
46
- "@onekeyfe/onekey-solana-provider": "2.2.37",
47
- "@onekeyfe/onekey-sui-provider": "2.2.37",
48
- "@onekeyfe/onekey-ton-provider": "2.2.37",
49
- "@onekeyfe/onekey-tron-provider": "2.2.37",
50
- "@onekeyfe/onekey-webln-provider": "2.2.37",
30
+ "@onekeyfe/cross-inpage-provider-core": "2.2.39",
31
+ "@onekeyfe/cross-inpage-provider-types": "2.2.39",
32
+ "@onekeyfe/onekey-algo-provider": "2.2.39",
33
+ "@onekeyfe/onekey-alph-provider": "2.2.39",
34
+ "@onekeyfe/onekey-aptos-provider": "2.2.39",
35
+ "@onekeyfe/onekey-bfc-provider": "2.2.39",
36
+ "@onekeyfe/onekey-btc-provider": "2.2.39",
37
+ "@onekeyfe/onekey-cardano-provider": "2.2.39",
38
+ "@onekeyfe/onekey-conflux-provider": "2.2.39",
39
+ "@onekeyfe/onekey-cosmos-provider": "2.2.39",
40
+ "@onekeyfe/onekey-eth-provider": "2.2.39",
41
+ "@onekeyfe/onekey-neo-provider": "2.2.39",
42
+ "@onekeyfe/onekey-nostr-provider": "2.2.39",
43
+ "@onekeyfe/onekey-polkadot-provider": "2.2.39",
44
+ "@onekeyfe/onekey-private-provider": "2.2.39",
45
+ "@onekeyfe/onekey-scdo-provider": "2.2.39",
46
+ "@onekeyfe/onekey-solana-provider": "2.2.39",
47
+ "@onekeyfe/onekey-sui-provider": "2.2.39",
48
+ "@onekeyfe/onekey-ton-provider": "2.2.39",
49
+ "@onekeyfe/onekey-tron-provider": "2.2.39",
50
+ "@onekeyfe/onekey-webln-provider": "2.2.39",
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": "0c1b9cafd7a5d6ebcf7fc20c5c279534abf85da5"
58
+ "gitHead": "e6e12930ba5139c204cef7bd3c56b3b21f7c217b"
59
59
  }