@orderly.network/hooks 2.0.1-preview.3 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +462 -88
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +441 -89
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -9
package/dist/index.js
CHANGED
|
@@ -20,16 +20,36 @@ var immer$1 = require('immer');
|
|
|
20
20
|
var defaultEvmAdapter = require('@orderly.network/default-evm-adapter');
|
|
21
21
|
var defaultSolanaAdapter = require('@orderly.network/default-solana-adapter');
|
|
22
22
|
var web3ProviderEthers = require('@orderly.network/web3-provider-ethers');
|
|
23
|
+
var amplitude = require('@amplitude/analytics-browser');
|
|
23
24
|
var qr = require('@akamfoad/qr');
|
|
24
25
|
|
|
25
26
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
26
27
|
|
|
28
|
+
function _interopNamespace(e) {
|
|
29
|
+
if (e && e.__esModule) return e;
|
|
30
|
+
var n = Object.create(null);
|
|
31
|
+
if (e) {
|
|
32
|
+
Object.keys(e).forEach(function (k) {
|
|
33
|
+
if (k !== 'default') {
|
|
34
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
35
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function () { return e[k]; }
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
n.default = e;
|
|
43
|
+
return Object.freeze(n);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
28
47
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
29
48
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
30
49
|
var useConstant__default = /*#__PURE__*/_interopDefault(useConstant);
|
|
31
50
|
var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
|
|
32
51
|
var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
|
|
52
|
+
var amplitude__namespace = /*#__PURE__*/_interopNamespace(amplitude);
|
|
33
53
|
|
|
34
54
|
var __defProp = Object.defineProperty;
|
|
35
55
|
var __export = (target, all) => {
|
|
@@ -40,10 +60,10 @@ var __export = (target, all) => {
|
|
|
40
60
|
// src/version.ts
|
|
41
61
|
if (typeof window !== "undefined") {
|
|
42
62
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
43
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.1
|
|
63
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.0.1";
|
|
44
64
|
}
|
|
45
|
-
var version_default = "2.0.1
|
|
46
|
-
var fetcher = (url,
|
|
65
|
+
var version_default = "2.0.1";
|
|
66
|
+
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
47
67
|
var OrderlyContext = React.createContext({
|
|
48
68
|
// configStore: new MemoryConfigStore(),
|
|
49
69
|
});
|
|
@@ -75,7 +95,7 @@ var useQuery = (query, options) => {
|
|
|
75
95
|
}
|
|
76
96
|
return useSWR__default.default(
|
|
77
97
|
query,
|
|
78
|
-
(url,
|
|
98
|
+
(url, init2) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init2, {
|
|
79
99
|
formatter
|
|
80
100
|
}),
|
|
81
101
|
swrOptions
|
|
@@ -83,7 +103,7 @@ var useQuery = (query, options) => {
|
|
|
83
103
|
};
|
|
84
104
|
var useLazyQuery = (query, options) => {
|
|
85
105
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
86
|
-
const { formatter, init, ...swrOptions } = options || {};
|
|
106
|
+
const { formatter, init: init2, ...swrOptions } = options || {};
|
|
87
107
|
if (typeof apiBaseUrl === "undefined") {
|
|
88
108
|
throw new Error("please add OrderlyConfigProvider to your app");
|
|
89
109
|
}
|
|
@@ -97,7 +117,7 @@ var useLazyQuery = (query, options) => {
|
|
|
97
117
|
).join("&");
|
|
98
118
|
url = `${url}?${queryString}`;
|
|
99
119
|
}
|
|
100
|
-
return fetcher(url,
|
|
120
|
+
return fetcher(url, init2, {
|
|
101
121
|
formatter
|
|
102
122
|
});
|
|
103
123
|
},
|
|
@@ -129,20 +149,20 @@ var useAccountInstance = () => {
|
|
|
129
149
|
return account5;
|
|
130
150
|
};
|
|
131
151
|
var fetcher2 = (url, options) => {
|
|
132
|
-
const
|
|
152
|
+
const init2 = {
|
|
133
153
|
method: options.arg.method,
|
|
134
154
|
headers: {
|
|
135
155
|
...options.arg.signature
|
|
136
156
|
}
|
|
137
157
|
};
|
|
138
158
|
if (options.arg.data) {
|
|
139
|
-
|
|
159
|
+
init2.body = JSON.stringify(options.arg.data);
|
|
140
160
|
}
|
|
141
161
|
if (typeof options.arg.params === "object" && Object.keys(options.arg.params).length) {
|
|
142
162
|
let search = new URLSearchParams(options.arg.params);
|
|
143
163
|
url = `${url}?${search.toString()}`;
|
|
144
164
|
}
|
|
145
|
-
return net.mutate(url,
|
|
165
|
+
return net.mutate(url, init2);
|
|
146
166
|
};
|
|
147
167
|
var useMutation = (url, method = "POST", options) => {
|
|
148
168
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
@@ -220,6 +240,16 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
220
240
|
}
|
|
221
241
|
};
|
|
222
242
|
};
|
|
243
|
+
var useEventEmitter = () => {
|
|
244
|
+
return useConstant__default.default(() => {
|
|
245
|
+
let ee = core.SimpleDI.get("EE");
|
|
246
|
+
if (!ee) {
|
|
247
|
+
ee = new core.EventEmitter();
|
|
248
|
+
core.SimpleDI.registerByName("EE", ee);
|
|
249
|
+
}
|
|
250
|
+
return ee;
|
|
251
|
+
});
|
|
252
|
+
};
|
|
223
253
|
var useAccount = () => {
|
|
224
254
|
const {
|
|
225
255
|
configStore,
|
|
@@ -237,7 +267,13 @@ var useAccount = () => {
|
|
|
237
267
|
}
|
|
238
268
|
const account5 = useAccountInstance();
|
|
239
269
|
const [state, setState] = React.useState(account5.stateValue);
|
|
270
|
+
const ee = useEventEmitter();
|
|
240
271
|
const statusChangeHandler = (nextState) => {
|
|
272
|
+
if (types.AccountStatusEnum.Connected === nextState.status) {
|
|
273
|
+
ee.emit(types.EnumTrackerKeys.WALLET_CONNECT, {
|
|
274
|
+
...nextState
|
|
275
|
+
});
|
|
276
|
+
}
|
|
241
277
|
setState(() => nextState);
|
|
242
278
|
};
|
|
243
279
|
React.useEffect(() => {
|
|
@@ -248,9 +284,13 @@ var useAccount = () => {
|
|
|
248
284
|
}, []);
|
|
249
285
|
const createOrderlyKey = React.useCallback(
|
|
250
286
|
async (remember) => {
|
|
287
|
+
ee.emit(types.EnumTrackerKeys.SIGNIN_SUCCESS, {
|
|
288
|
+
...state,
|
|
289
|
+
...account5
|
|
290
|
+
});
|
|
251
291
|
return account5.createOrderlyKey(remember ? 365 : 30);
|
|
252
292
|
},
|
|
253
|
-
[account5]
|
|
293
|
+
[account5, state]
|
|
254
294
|
);
|
|
255
295
|
const createAccount = React.useCallback(async () => {
|
|
256
296
|
return account5.createAccount();
|
|
@@ -274,8 +314,8 @@ var usePrivateQuery = (query, options) => {
|
|
|
274
314
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
275
315
|
return useSWR__default.default(
|
|
276
316
|
() => account5.state.status >= types.AccountStatusEnum.EnableTrading ? [query, account5.state.accountId] : null,
|
|
277
|
-
(url,
|
|
278
|
-
return fetcher(url,
|
|
317
|
+
(url, init2) => {
|
|
318
|
+
return fetcher(url, init2, { formatter });
|
|
279
319
|
},
|
|
280
320
|
{
|
|
281
321
|
...swrOptions,
|
|
@@ -297,8 +337,8 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
297
337
|
}
|
|
298
338
|
return [queryKey, account5.state.accountId];
|
|
299
339
|
},
|
|
300
|
-
(url,
|
|
301
|
-
return restOptions.fetcher?.(url,
|
|
340
|
+
(url, init2) => {
|
|
341
|
+
return restOptions.fetcher?.(url, init2) || net.get(url, init2, formatter);
|
|
302
342
|
},
|
|
303
343
|
{
|
|
304
344
|
...restOptions,
|
|
@@ -325,10 +365,10 @@ var usePreLoadData = () => {
|
|
|
325
365
|
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
326
366
|
const { data: systemInfo } = useSWR__default.default(
|
|
327
367
|
"/v1/public/system_info",
|
|
328
|
-
async (url,
|
|
368
|
+
async (url, init2) => {
|
|
329
369
|
const data = await fetch(
|
|
330
370
|
url.startsWith("http") ? url : `${apiBaseUrl}${url}`,
|
|
331
|
-
|
|
371
|
+
init2
|
|
332
372
|
);
|
|
333
373
|
return await data.json();
|
|
334
374
|
},
|
|
@@ -359,16 +399,6 @@ var usePreLoadData = () => {
|
|
|
359
399
|
done: isDone
|
|
360
400
|
};
|
|
361
401
|
};
|
|
362
|
-
var useEventEmitter = () => {
|
|
363
|
-
return useConstant__default.default(() => {
|
|
364
|
-
let ee = core.SimpleDI.get("EE");
|
|
365
|
-
if (!ee) {
|
|
366
|
-
ee = new core.EventEmitter();
|
|
367
|
-
core.SimpleDI.registerByName("EE", ee);
|
|
368
|
-
}
|
|
369
|
-
return ee;
|
|
370
|
-
});
|
|
371
|
-
};
|
|
372
402
|
|
|
373
403
|
// src/utils/json.ts
|
|
374
404
|
function parseJSON(value) {
|
|
@@ -466,6 +496,21 @@ function useLocalStorage(key, initialValue) {
|
|
|
466
496
|
}, [key]);
|
|
467
497
|
return [storedValue, setValue];
|
|
468
498
|
}
|
|
499
|
+
|
|
500
|
+
// src/useNetworkInfo.ts
|
|
501
|
+
var useNetworkInfo = (networkId) => {
|
|
502
|
+
const [allChains, { findByChainId }] = useChains(networkId, {
|
|
503
|
+
pick: "network_infos",
|
|
504
|
+
filter: (chain) => chain.network_infos?.bridge_enable || chain.network_infos?.bridgeless
|
|
505
|
+
});
|
|
506
|
+
return (chainId) => {
|
|
507
|
+
const chain = findByChainId(chainId);
|
|
508
|
+
return {
|
|
509
|
+
id: chainId,
|
|
510
|
+
info: chain
|
|
511
|
+
};
|
|
512
|
+
};
|
|
513
|
+
};
|
|
469
514
|
var WS_NAME = "nativeWebsocketClient";
|
|
470
515
|
var useWS = () => {
|
|
471
516
|
const { configStore } = React.useContext(OrderlyContext);
|
|
@@ -571,6 +616,16 @@ var BaseMergeHandler = class {
|
|
|
571
616
|
if (!data.created_time) {
|
|
572
617
|
data.created_time = data.timestamp;
|
|
573
618
|
}
|
|
619
|
+
if (data.status === types.OrderStatus.FILLED && !data.updated_time) {
|
|
620
|
+
data.updated_time = data.timestamp;
|
|
621
|
+
}
|
|
622
|
+
if (data.child_orders && data.child_orders.length) {
|
|
623
|
+
data.child_orders.map((child) => {
|
|
624
|
+
if (child.algo_status === types.OrderStatus.FILLED && child.is_activated && !child.updated_time) {
|
|
625
|
+
child.updated_time = data.timestamp;
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
}
|
|
574
629
|
if (data.type && data.type.endsWith("_ORDER")) {
|
|
575
630
|
data.type = data.type.replace("_ORDER", "");
|
|
576
631
|
}
|
|
@@ -600,7 +655,8 @@ var BaseMergeHandler = class {
|
|
|
600
655
|
return this.update(prevData);
|
|
601
656
|
case "FILLED": {
|
|
602
657
|
if (this.orderIsExisting(prevData)) {
|
|
603
|
-
if (key.startsWith("orders:INCOMPLETE") || key.startsWith("orders:NEW")
|
|
658
|
+
if (key.startsWith("orders:INCOMPLETE") || key.startsWith("orders:NEW") || // all orders key
|
|
659
|
+
key.startsWith("orders:")) {
|
|
604
660
|
if (this.isFullFilled()) {
|
|
605
661
|
return this.remove(prevData);
|
|
606
662
|
}
|
|
@@ -1601,6 +1657,18 @@ var PortfolioCalculator = class extends BaseCalculator {
|
|
|
1601
1657
|
(output) => output.positionCalculator_all
|
|
1602
1658
|
);
|
|
1603
1659
|
let holding = portfolio.holding;
|
|
1660
|
+
if (scope === "portfolio" /* PORTFOLIO */ && data.holding && Array.isArray(holding)) {
|
|
1661
|
+
holding = holding.map((item) => {
|
|
1662
|
+
if (data.holding[item.token]) {
|
|
1663
|
+
return {
|
|
1664
|
+
...item,
|
|
1665
|
+
holding: data.holding[item.token].holding,
|
|
1666
|
+
frozen: data.holding[item.token].frozen
|
|
1667
|
+
};
|
|
1668
|
+
}
|
|
1669
|
+
return item;
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1604
1672
|
const accountInfo = ctx.accountInfo;
|
|
1605
1673
|
const symbolsInfo = ctx.symbolsInfo;
|
|
1606
1674
|
return this.format({
|
|
@@ -2218,13 +2286,39 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
2218
2286
|
});
|
|
2219
2287
|
React.useEffect(() => {
|
|
2220
2288
|
const updateData = [
|
|
2221
|
-
|
|
2222
|
-
|
|
2289
|
+
[
|
|
2290
|
+
reducedData.asks?.[reducedData.asks.length - 1]?.[0],
|
|
2291
|
+
reducedData.bids?.[0]?.[0]
|
|
2292
|
+
],
|
|
2293
|
+
[
|
|
2294
|
+
reducedData.asks?.[reducedData.asks.length - 2]?.[0],
|
|
2295
|
+
reducedData.bids?.[1]?.[0]
|
|
2296
|
+
],
|
|
2297
|
+
[
|
|
2298
|
+
reducedData.asks?.[reducedData.asks.length - 3]?.[0],
|
|
2299
|
+
reducedData.bids?.[2]?.[0]
|
|
2300
|
+
],
|
|
2301
|
+
[
|
|
2302
|
+
reducedData.asks?.[reducedData.asks.length - 4]?.[0],
|
|
2303
|
+
reducedData.bids?.[3]?.[0]
|
|
2304
|
+
],
|
|
2305
|
+
[
|
|
2306
|
+
reducedData.asks?.[reducedData.asks.length - 5]?.[0],
|
|
2307
|
+
reducedData.bids?.[4]?.[0]
|
|
2308
|
+
]
|
|
2223
2309
|
];
|
|
2224
2310
|
eventEmitter.emit("orderbook:update", updateData);
|
|
2225
2311
|
}, [
|
|
2226
2312
|
reducedData.asks?.[reducedData.asks.length - 1]?.[0],
|
|
2227
|
-
reducedData.
|
|
2313
|
+
reducedData.asks?.[reducedData.asks.length - 2]?.[0],
|
|
2314
|
+
reducedData.asks?.[reducedData.asks.length - 3]?.[0],
|
|
2315
|
+
reducedData.asks?.[reducedData.asks.length - 4]?.[0],
|
|
2316
|
+
reducedData.asks?.[reducedData.asks.length - 5]?.[0],
|
|
2317
|
+
reducedData.bids?.[0]?.[0],
|
|
2318
|
+
reducedData.bids?.[1]?.[0],
|
|
2319
|
+
reducedData.bids?.[2]?.[0],
|
|
2320
|
+
reducedData.bids?.[3]?.[0],
|
|
2321
|
+
reducedData.bids?.[4]?.[0]
|
|
2228
2322
|
]);
|
|
2229
2323
|
const middlePrice = React.useMemo(() => {
|
|
2230
2324
|
let asksFrist = 0, bidsFirst = 0;
|
|
@@ -2569,6 +2663,7 @@ var MarketsType = /* @__PURE__ */ ((MarketsType2) => {
|
|
|
2569
2663
|
MarketsType2[MarketsType2["FAVORITES"] = 0] = "FAVORITES";
|
|
2570
2664
|
MarketsType2[MarketsType2["RECENT"] = 1] = "RECENT";
|
|
2571
2665
|
MarketsType2[MarketsType2["ALL"] = 2] = "ALL";
|
|
2666
|
+
MarketsType2[MarketsType2["NEW_LISTING"] = 3] = "NEW_LISTING";
|
|
2572
2667
|
return MarketsType2;
|
|
2573
2668
|
})(MarketsType || {});
|
|
2574
2669
|
var MarketsStorageKey = "orderly_markets";
|
|
@@ -2605,6 +2700,9 @@ var useMarketsStore = () => {
|
|
|
2605
2700
|
const getRecent = () => {
|
|
2606
2701
|
return getStoreByKey("recent", []);
|
|
2607
2702
|
};
|
|
2703
|
+
const getNewListing = () => {
|
|
2704
|
+
return getStoreByKey("newListing", []);
|
|
2705
|
+
};
|
|
2608
2706
|
const getTabSort = () => {
|
|
2609
2707
|
return getStoreByKey("tabSort", {});
|
|
2610
2708
|
};
|
|
@@ -2614,6 +2712,7 @@ var useMarketsStore = () => {
|
|
|
2614
2712
|
);
|
|
2615
2713
|
const [favorites, setFavorites] = React.useState(getFavorites);
|
|
2616
2714
|
const [recent, setRecent] = React.useState(getRecent);
|
|
2715
|
+
const [newListing, setNewListing] = React.useState(getNewListing);
|
|
2617
2716
|
const [tabSort, setTabSort] = React.useState(getTabSort);
|
|
2618
2717
|
const updateFavoriteTabs = (tab, operator) => {
|
|
2619
2718
|
const tabs = updateTabs(favoriteTabs, tab, operator);
|
|
@@ -2658,10 +2757,18 @@ var useMarketsStore = () => {
|
|
|
2658
2757
|
favoriteTabs,
|
|
2659
2758
|
favorites,
|
|
2660
2759
|
recent,
|
|
2760
|
+
newListing,
|
|
2661
2761
|
tabSort,
|
|
2662
2762
|
selectedFavoriteTab
|
|
2663
2763
|
});
|
|
2664
|
-
}, [
|
|
2764
|
+
}, [
|
|
2765
|
+
favoriteTabs,
|
|
2766
|
+
favorites,
|
|
2767
|
+
recent,
|
|
2768
|
+
newListing,
|
|
2769
|
+
tabSort,
|
|
2770
|
+
selectedFavoriteTab
|
|
2771
|
+
]);
|
|
2665
2772
|
React.useEffect(() => {
|
|
2666
2773
|
const event = ({ id: srcId, key, data }) => {
|
|
2667
2774
|
if (srcId === id) {
|
|
@@ -2675,6 +2782,8 @@ var useMarketsStore = () => {
|
|
|
2675
2782
|
setFavorites(data);
|
|
2676
2783
|
} else if (key === "recent") {
|
|
2677
2784
|
setRecent(data);
|
|
2785
|
+
} else if (key === "newListing") {
|
|
2786
|
+
setNewListing(data);
|
|
2678
2787
|
}
|
|
2679
2788
|
};
|
|
2680
2789
|
ee.on("markets:changed", event);
|
|
@@ -2686,6 +2795,7 @@ var useMarketsStore = () => {
|
|
|
2686
2795
|
favoriteTabs,
|
|
2687
2796
|
favorites,
|
|
2688
2797
|
recent,
|
|
2798
|
+
newListing,
|
|
2689
2799
|
tabSort,
|
|
2690
2800
|
selectedFavoriteTab,
|
|
2691
2801
|
updateFavorites: setFavorites,
|
|
@@ -2702,12 +2812,18 @@ var useMarkets = (type = 2 /* ALL */) => {
|
|
|
2702
2812
|
const symbolsInfo = useSymbolsInfo();
|
|
2703
2813
|
const [markets, setMarkets] = React.useState([]);
|
|
2704
2814
|
const store = useMarketsStore();
|
|
2705
|
-
const { favorites, recent } = store;
|
|
2815
|
+
const { favorites, recent, newListing } = store;
|
|
2706
2816
|
React.useEffect(() => {
|
|
2707
2817
|
const markets2 = addFieldToMarkets(futures, symbolsInfo);
|
|
2708
|
-
const filterList = filterMarkets({
|
|
2818
|
+
const filterList = filterMarkets({
|
|
2819
|
+
markets: markets2,
|
|
2820
|
+
favorites,
|
|
2821
|
+
recent,
|
|
2822
|
+
newListing,
|
|
2823
|
+
type
|
|
2824
|
+
});
|
|
2709
2825
|
setMarkets(filterList);
|
|
2710
|
-
}, [futures, symbolsInfo, favorites, recent, type]);
|
|
2826
|
+
}, [futures, symbolsInfo, favorites, recent, newListing, type]);
|
|
2711
2827
|
return [markets, store];
|
|
2712
2828
|
};
|
|
2713
2829
|
var addFieldToMarkets = (futures, symbolsInfo) => {
|
|
@@ -2729,24 +2845,31 @@ var addFieldToMarkets = (futures, symbolsInfo) => {
|
|
|
2729
2845
|
});
|
|
2730
2846
|
};
|
|
2731
2847
|
var filterMarkets = (params) => {
|
|
2732
|
-
const { markets, favorites, recent, type } = params;
|
|
2848
|
+
const { markets, favorites, recent, newListing, type } = params;
|
|
2733
2849
|
let curData = [];
|
|
2734
2850
|
if (type === 2 /* ALL */) {
|
|
2735
2851
|
curData = markets;
|
|
2852
|
+
} else if (type === 3 /* NEW_LISTING */) {
|
|
2853
|
+
curData = markets.filter((item) => isNewListing(item.created_time)).sort((a, b) => b.created_time - a.created_time);
|
|
2736
2854
|
} else {
|
|
2737
|
-
const storageData = type === 0 /* FAVORITES */ ? favorites : recent;
|
|
2855
|
+
const storageData = type === 0 /* FAVORITES */ ? favorites : type === 1 /* RECENT */ ? recent : newListing;
|
|
2738
2856
|
const keys = storageData.map((item) => item.name);
|
|
2739
2857
|
curData = markets?.filter((item) => keys.includes(item.symbol));
|
|
2740
2858
|
}
|
|
2741
2859
|
const favoriteKeys = favorites.map((item) => item.name);
|
|
2742
2860
|
return curData?.map((item) => ({
|
|
2743
2861
|
...item,
|
|
2744
|
-
isFavorite: type
|
|
2862
|
+
isFavorite: type === 0 /* FAVORITES */ ? true : favoriteKeys.includes(item.symbol)
|
|
2745
2863
|
}));
|
|
2746
2864
|
};
|
|
2747
2865
|
function isEmpty(value) {
|
|
2748
2866
|
return value === void 0 || value === null;
|
|
2749
2867
|
}
|
|
2868
|
+
var isNewListing = (createdTime) => {
|
|
2869
|
+
const thirtyDaysInMs = 30 * 24 * 60 * 60 * 1e3;
|
|
2870
|
+
const now = Date.now();
|
|
2871
|
+
return now - createdTime < thirtyDaysInMs;
|
|
2872
|
+
};
|
|
2750
2873
|
function get8hFunding2(est_funding_rate, funding_period) {
|
|
2751
2874
|
let funding8h = 0;
|
|
2752
2875
|
if (isEmpty(est_funding_rate)) {
|
|
@@ -2950,6 +3073,41 @@ var useFundingRate = (symbol) => {
|
|
|
2950
3073
|
countDown
|
|
2951
3074
|
};
|
|
2952
3075
|
};
|
|
3076
|
+
|
|
3077
|
+
// src/orderly/useFundingRateHistory.ts
|
|
3078
|
+
var calculatePositiveRate = (periodData, period) => {
|
|
3079
|
+
if (!periodData || !period)
|
|
3080
|
+
return 0;
|
|
3081
|
+
const daysMap = {
|
|
3082
|
+
"1d": 1,
|
|
3083
|
+
"3d": 3,
|
|
3084
|
+
"7d": 7,
|
|
3085
|
+
"14d": 14,
|
|
3086
|
+
"30d": 30,
|
|
3087
|
+
"90d": 90
|
|
3088
|
+
};
|
|
3089
|
+
const totalTimes = daysMap[period] * 3;
|
|
3090
|
+
return periodData.positive / totalTimes;
|
|
3091
|
+
};
|
|
3092
|
+
var useFundingRateHistory = () => {
|
|
3093
|
+
const {
|
|
3094
|
+
data: historyData,
|
|
3095
|
+
isLoading,
|
|
3096
|
+
...rest
|
|
3097
|
+
} = useQuery("/v1/public/market_info/funding_history");
|
|
3098
|
+
return {
|
|
3099
|
+
data: historyData ?? [],
|
|
3100
|
+
isLoading,
|
|
3101
|
+
getPositiveRates: (data, period) => {
|
|
3102
|
+
if (!data?.length)
|
|
3103
|
+
return {};
|
|
3104
|
+
return data.reduce((acc, item) => {
|
|
3105
|
+
acc[item.symbol] = calculatePositiveRate(item.funding[period], period);
|
|
3106
|
+
return acc;
|
|
3107
|
+
}, {});
|
|
3108
|
+
}
|
|
3109
|
+
};
|
|
3110
|
+
};
|
|
2953
3111
|
var findTPSLFromOrders = (orders, symbol) => {
|
|
2954
3112
|
const order = findPositionTPSLFromOrders(orders, symbol);
|
|
2955
3113
|
if (!order)
|
|
@@ -3134,10 +3292,10 @@ var useOrderStream = (params, options) => {
|
|
|
3134
3292
|
side,
|
|
3135
3293
|
size = 50,
|
|
3136
3294
|
page,
|
|
3137
|
-
dateRange
|
|
3138
|
-
includes: includes2 = ["ALL"],
|
|
3139
|
-
excludes = []
|
|
3295
|
+
dateRange
|
|
3140
3296
|
} = params;
|
|
3297
|
+
const [includes2, setIncludes] = React.useState(params.includes ?? ["ALL"]);
|
|
3298
|
+
const [excludes, setExcludes] = React.useState(params.excludes ?? []);
|
|
3141
3299
|
const { data: markPrices } = useMarkPricesStream();
|
|
3142
3300
|
const { registerKeyHandler, unregisterKeyHandler } = useDataCenterContext();
|
|
3143
3301
|
const [
|
|
@@ -3581,6 +3739,7 @@ var useMarginRatio = () => {
|
|
|
3581
3739
|
}, [rows, notional]);
|
|
3582
3740
|
return { marginRatio, currentLeverage, mmr };
|
|
3583
3741
|
};
|
|
3742
|
+
var TestNetWhiteList = [421614, 901901901, 1516];
|
|
3584
3743
|
function useChains(networkId, options = {}) {
|
|
3585
3744
|
const { pick: pickField, ...swrOptions } = options;
|
|
3586
3745
|
const {
|
|
@@ -3605,19 +3764,35 @@ function useChains(networkId, options = {}) {
|
|
|
3605
3764
|
"https://api-evm.orderly.org/v1/public/token",
|
|
3606
3765
|
{ ...commonSwrOpts }
|
|
3607
3766
|
);
|
|
3767
|
+
const { data: testTokenChainsRes } = useQuery(
|
|
3768
|
+
"https://testnet-api-evm.orderly.org/v1/public/token",
|
|
3769
|
+
{ ...commonSwrOpts }
|
|
3770
|
+
);
|
|
3608
3771
|
const brokerId = configStore.get("brokerId");
|
|
3609
3772
|
const needFetchFromAPI = options.forceAPI || !customChains;
|
|
3610
3773
|
const { data: chainInfos, error: chainInfoErr } = useQuery(
|
|
3611
3774
|
needFetchFromAPI ? `https://api-evm.orderly.org/v1/public/chain_info${brokerId !== "orderly" ? `?broker_id=${brokerId}` : ""}` : null,
|
|
3612
3775
|
{ ...commonSwrOpts }
|
|
3613
3776
|
);
|
|
3777
|
+
const { data: testChainInfos } = useQuery(
|
|
3778
|
+
needFetchFromAPI ? `https://testnet-api-evm.orderly.org/v1/public/chain_info${brokerId !== "orderly" ? `?broker_id=${brokerId}` : ""}` : null,
|
|
3779
|
+
{ ...commonSwrOpts }
|
|
3780
|
+
);
|
|
3614
3781
|
const chains = React.useMemo(() => {
|
|
3615
|
-
const tokenChains = fillChainsInfo(
|
|
3616
|
-
|
|
3782
|
+
const tokenChains = fillChainsInfo(
|
|
3783
|
+
tokenChainsRes,
|
|
3784
|
+
filterFun.current,
|
|
3785
|
+
chainInfos
|
|
3786
|
+
);
|
|
3787
|
+
const testTokenChains = fillChainsInfo(
|
|
3788
|
+
testTokenChainsRes,
|
|
3789
|
+
void 0,
|
|
3790
|
+
testChainInfos
|
|
3791
|
+
);
|
|
3792
|
+
let testnetArr = needFetchFromAPI ? filterAndUpdateChains(testTokenChains, testChainInfos, void 0, true) : customChains?.testnet;
|
|
3617
3793
|
tokenChains?.forEach((item) => {
|
|
3618
3794
|
const chainId = item.network_infos?.chain_id;
|
|
3619
3795
|
chainsMap.current.set(chainId, item);
|
|
3620
|
-
updateTestnetInfo(testnetArr, chainId, item);
|
|
3621
3796
|
});
|
|
3622
3797
|
testnetArr.forEach((chain) => {
|
|
3623
3798
|
chainsMap.current.set(chain.network_infos?.chain_id, chain);
|
|
@@ -3632,10 +3807,12 @@ function useChains(networkId, options = {}) {
|
|
|
3632
3807
|
mainnetArr.forEach((item) => {
|
|
3633
3808
|
const chainId = item.network_infos?.chain_id;
|
|
3634
3809
|
chainsMap.current.set(chainId, item);
|
|
3635
|
-
updateTestnetInfo(testnetArr, chainId, item);
|
|
3636
3810
|
});
|
|
3637
3811
|
mainnetArr = filterByAllowedChains(mainnetArr, allowedChains?.mainnet);
|
|
3638
|
-
testnetArr = filterByAllowedChains(
|
|
3812
|
+
testnetArr = filterByAllowedChains(
|
|
3813
|
+
testnetArr,
|
|
3814
|
+
allowedChains?.testnet ?? TestNetWhiteList.map((id) => ({ id }))
|
|
3815
|
+
);
|
|
3639
3816
|
if (!!pickField) {
|
|
3640
3817
|
testnetArr = testnetArr.map((item) => item[pickField]);
|
|
3641
3818
|
mainnetArr = mainnetArr.map((item) => item[pickField]);
|
|
@@ -3654,6 +3831,8 @@ function useChains(networkId, options = {}) {
|
|
|
3654
3831
|
networkId,
|
|
3655
3832
|
tokenChainsRes,
|
|
3656
3833
|
chainInfos,
|
|
3834
|
+
testChainInfos,
|
|
3835
|
+
testTokenChainsRes,
|
|
3657
3836
|
customChains,
|
|
3658
3837
|
pickField,
|
|
3659
3838
|
allowedChains
|
|
@@ -3699,15 +3878,17 @@ function _checkChainSupport(chainId, chains) {
|
|
|
3699
3878
|
return chain.network_infos.chain_id === chainId;
|
|
3700
3879
|
});
|
|
3701
3880
|
}
|
|
3702
|
-
function fillChainsInfo(chains, filter) {
|
|
3881
|
+
function fillChainsInfo(chains, filter, chainInfos) {
|
|
3703
3882
|
let _chains = [];
|
|
3704
3883
|
chains?.forEach((item) => {
|
|
3705
3884
|
item.chain_details.forEach((chain) => {
|
|
3706
3885
|
const chainId = Number(chain.chain_id);
|
|
3707
|
-
const chainInfo =
|
|
3886
|
+
const chainInfo = chainInfos?.find(
|
|
3887
|
+
(item2) => item2.chain_id == chainId
|
|
3888
|
+
);
|
|
3708
3889
|
const _chain = {
|
|
3709
3890
|
network_infos: {
|
|
3710
|
-
name: chain.chain_name ?? chainInfo?.
|
|
3891
|
+
name: chain.chain_name ?? chainInfo?.name ?? "--",
|
|
3711
3892
|
chain_id: chainId,
|
|
3712
3893
|
withdrawal_fee: chain.withdrawal_fee,
|
|
3713
3894
|
cross_chain_withdrawal_fee: chain.cross_chain_withdrawal_fee,
|
|
@@ -3731,7 +3912,7 @@ function fillChainsInfo(chains, filter) {
|
|
|
3731
3912
|
});
|
|
3732
3913
|
return _chains;
|
|
3733
3914
|
}
|
|
3734
|
-
function filterAndUpdateChains(chains, chainInfos, filter) {
|
|
3915
|
+
function filterAndUpdateChains(chains, chainInfos, filter, isTestNet) {
|
|
3735
3916
|
const filterChains = [];
|
|
3736
3917
|
chains.forEach((chain) => {
|
|
3737
3918
|
let _chain = { ...chain };
|
|
@@ -3747,9 +3928,9 @@ function filterAndUpdateChains(chains, chainInfos, filter) {
|
|
|
3747
3928
|
public_rpc_url,
|
|
3748
3929
|
currency_symbol,
|
|
3749
3930
|
bridge_enable: true,
|
|
3750
|
-
mainnet:
|
|
3751
|
-
explorer_base_url
|
|
3752
|
-
est_txn_mins: null
|
|
3931
|
+
mainnet: !isTestNet,
|
|
3932
|
+
explorer_base_url
|
|
3933
|
+
// est_txn_mins: null,
|
|
3753
3934
|
};
|
|
3754
3935
|
}
|
|
3755
3936
|
if (typeof filter === "function") {
|
|
@@ -3762,16 +3943,6 @@ function filterAndUpdateChains(chains, chainInfos, filter) {
|
|
|
3762
3943
|
});
|
|
3763
3944
|
return filterChains;
|
|
3764
3945
|
}
|
|
3765
|
-
function updateTestnetInfo(testnetArr, chainId, chain) {
|
|
3766
|
-
if (utils.isTestnet(chainId)) {
|
|
3767
|
-
const index = testnetArr?.findIndex(
|
|
3768
|
-
(item) => item.network_infos.chain_id === chainId
|
|
3769
|
-
);
|
|
3770
|
-
if (index > -1) {
|
|
3771
|
-
testnetArr[index] = chain;
|
|
3772
|
-
}
|
|
3773
|
-
}
|
|
3774
|
-
}
|
|
3775
3946
|
function filterByAllowedChains(chains, allowedChains) {
|
|
3776
3947
|
if (!allowedChains) {
|
|
3777
3948
|
return chains;
|
|
@@ -3856,14 +4027,7 @@ var useWithdraw = (options) => {
|
|
|
3856
4027
|
const { unsettledPnL, availableBalance, freeCollateral } = useCollateral();
|
|
3857
4028
|
const networkId = useConfig("networkId");
|
|
3858
4029
|
const [_, { findByChainId }] = useChains(void 0);
|
|
3859
|
-
const
|
|
3860
|
-
(inputs) => {
|
|
3861
|
-
return account5.assetsManager.withdraw(inputs).then((res) => {
|
|
3862
|
-
return res;
|
|
3863
|
-
});
|
|
3864
|
-
},
|
|
3865
|
-
[state]
|
|
3866
|
-
);
|
|
4030
|
+
const ee = useEventEmitter();
|
|
3867
4031
|
useHoldingStream();
|
|
3868
4032
|
const maxAmount = React.useMemo(() => {
|
|
3869
4033
|
return freeCollateral;
|
|
@@ -3901,6 +4065,28 @@ var useWithdraw = (options) => {
|
|
|
3901
4065
|
network: targetChain?.network_infos?.shortName
|
|
3902
4066
|
};
|
|
3903
4067
|
}, [targetChain]);
|
|
4068
|
+
const withdraw = React.useCallback(
|
|
4069
|
+
(inputs) => {
|
|
4070
|
+
return account5.assetsManager.withdraw(inputs).then((res) => {
|
|
4071
|
+
if (res.success) {
|
|
4072
|
+
ee.emit(types.EnumTrackerKeys.WITHDRAW_SUCCESS, {
|
|
4073
|
+
wallet: state?.connectWallet?.name,
|
|
4074
|
+
network: targetChain?.network_infos.name,
|
|
4075
|
+
quantity: inputs.amount
|
|
4076
|
+
});
|
|
4077
|
+
}
|
|
4078
|
+
return res;
|
|
4079
|
+
}).catch((err) => {
|
|
4080
|
+
ee.emit(types.EnumTrackerKeys.WITHDRAW_FAILED, {
|
|
4081
|
+
wallet: state?.connectWallet?.name,
|
|
4082
|
+
network: targetChain?.network_infos.name,
|
|
4083
|
+
msg: JSON.stringify(err)
|
|
4084
|
+
});
|
|
4085
|
+
throw err;
|
|
4086
|
+
});
|
|
4087
|
+
},
|
|
4088
|
+
[state, targetChain, state]
|
|
4089
|
+
);
|
|
3904
4090
|
return {
|
|
3905
4091
|
dst,
|
|
3906
4092
|
withdraw,
|
|
@@ -3915,6 +4101,7 @@ var useDeposit = (options) => {
|
|
|
3915
4101
|
const networkId = useConfig("networkId");
|
|
3916
4102
|
const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
|
|
3917
4103
|
const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
|
|
4104
|
+
const ee = useEventEmitter();
|
|
3918
4105
|
const [_, { findByChainId }] = useChains(void 0);
|
|
3919
4106
|
const [quantity, setQuantity] = React.useState("");
|
|
3920
4107
|
const [depositFee, setDepositFee] = React.useState(0n);
|
|
@@ -4113,9 +4300,21 @@ var useDeposit = (options) => {
|
|
|
4113
4300
|
throw new Error("Insufficient allowance");
|
|
4114
4301
|
}
|
|
4115
4302
|
return account5.assetsManager.deposit(quantity, depositFee).then((res) => {
|
|
4303
|
+
ee.emit(types.EnumTrackerKeys.DEPOSIT_SUCCESS, {
|
|
4304
|
+
wallet: state?.connectWallet?.name,
|
|
4305
|
+
network: targetChain?.network_infos.name,
|
|
4306
|
+
quantity
|
|
4307
|
+
});
|
|
4116
4308
|
updateAllowanceWhenTxSuccess(res.hash);
|
|
4117
4309
|
setBalance((value) => new utils.Decimal(value).sub(quantity).toString());
|
|
4118
4310
|
return res;
|
|
4311
|
+
}).catch((e) => {
|
|
4312
|
+
ee.emit(types.EnumTrackerKeys.DEPOSIT_FAILED, {
|
|
4313
|
+
wallet: state?.connectWallet?.name,
|
|
4314
|
+
network: targetChain?.network_infos?.name,
|
|
4315
|
+
msg: JSON.stringify(e)
|
|
4316
|
+
});
|
|
4317
|
+
throw e;
|
|
4119
4318
|
});
|
|
4120
4319
|
}, [account5, fetchBalance, quantity, depositFee, options?.address]);
|
|
4121
4320
|
const loopGetBalance = async () => {
|
|
@@ -5398,6 +5597,50 @@ var BracketMarketOrderCreator = class extends MarketOrderCreator {
|
|
|
5398
5597
|
return { ...value, ...bracketData };
|
|
5399
5598
|
}
|
|
5400
5599
|
};
|
|
5600
|
+
var BBOOrderCreator = class extends BaseOrderCreator {
|
|
5601
|
+
create(values2) {
|
|
5602
|
+
const order = {
|
|
5603
|
+
...this.baseOrder(values2),
|
|
5604
|
+
level: values2.level
|
|
5605
|
+
};
|
|
5606
|
+
return ramda.pick(
|
|
5607
|
+
[
|
|
5608
|
+
"symbol",
|
|
5609
|
+
"order_quantity",
|
|
5610
|
+
"visible_quantity",
|
|
5611
|
+
"reduce_only",
|
|
5612
|
+
"side",
|
|
5613
|
+
"order_type",
|
|
5614
|
+
"level"
|
|
5615
|
+
],
|
|
5616
|
+
order
|
|
5617
|
+
);
|
|
5618
|
+
}
|
|
5619
|
+
async validate(values2, configs) {
|
|
5620
|
+
return this.baseValidate(values2, configs).then((errors) => {
|
|
5621
|
+
delete errors["total"];
|
|
5622
|
+
let { order_quantity, order_price, reduce_only, level } = values2;
|
|
5623
|
+
const { symbol } = configs;
|
|
5624
|
+
const { min_notional, base_tick, quote_dp, quote_tick, base_dp } = symbol || {};
|
|
5625
|
+
const notionalHintStr = checkNotional({
|
|
5626
|
+
base_tick,
|
|
5627
|
+
quote_tick,
|
|
5628
|
+
price: order_price,
|
|
5629
|
+
qty: order_quantity,
|
|
5630
|
+
min_notional,
|
|
5631
|
+
quote_dp,
|
|
5632
|
+
base_dp
|
|
5633
|
+
});
|
|
5634
|
+
if (notionalHintStr !== void 0 && !reduce_only) {
|
|
5635
|
+
errors.total = {
|
|
5636
|
+
type: "min",
|
|
5637
|
+
message: notionalHintStr
|
|
5638
|
+
};
|
|
5639
|
+
}
|
|
5640
|
+
return errors;
|
|
5641
|
+
});
|
|
5642
|
+
}
|
|
5643
|
+
};
|
|
5401
5644
|
|
|
5402
5645
|
// src/services/orderCreator/factory.ts
|
|
5403
5646
|
var OrderFactory = class {
|
|
@@ -5407,11 +5650,13 @@ var OrderFactory = class {
|
|
|
5407
5650
|
return new BracketLimitOrderCreator();
|
|
5408
5651
|
case `${types.AlgoOrderRootType.BRACKET}:${types.OrderType.MARKET}`:
|
|
5409
5652
|
return new BracketMarketOrderCreator();
|
|
5410
|
-
case types.OrderType.LIMIT:
|
|
5653
|
+
case types.OrderType.LIMIT:
|
|
5411
5654
|
return new LimitOrderCreator();
|
|
5412
|
-
}
|
|
5413
5655
|
case types.OrderType.MARKET:
|
|
5414
5656
|
return new MarketOrderCreator();
|
|
5657
|
+
case types.OrderType.ASK:
|
|
5658
|
+
case types.OrderType.BID:
|
|
5659
|
+
return new BBOOrderCreator();
|
|
5415
5660
|
case types.OrderType.IOC:
|
|
5416
5661
|
return new IOCOrderCreator();
|
|
5417
5662
|
case types.OrderType.FOK:
|
|
@@ -5931,7 +6176,9 @@ var usePrivateDataObserver = (options) => {
|
|
|
5931
6176
|
const ws = useWS();
|
|
5932
6177
|
const ee = useEventEmitter();
|
|
5933
6178
|
const { state, account: account5 } = useAccount();
|
|
5934
|
-
const { setAccountInfo, restoreHolding,
|
|
6179
|
+
const { setAccountInfo, restoreHolding, cleanAll } = useAppStore(
|
|
6180
|
+
(state2) => state2.actions
|
|
6181
|
+
);
|
|
5935
6182
|
const statusActions = useApiStatusActions();
|
|
5936
6183
|
const calculatorService = useCalculatorService();
|
|
5937
6184
|
const positionsActions = usePositionActions();
|
|
@@ -5990,7 +6237,7 @@ var usePrivateDataObserver = (options) => {
|
|
|
5990
6237
|
onMessage: (data) => {
|
|
5991
6238
|
const holding2 = data?.balances ?? {};
|
|
5992
6239
|
if (holding2) {
|
|
5993
|
-
|
|
6240
|
+
calculatorService.calc("portfolio" /* PORTFOLIO */, { holding: holding2 });
|
|
5994
6241
|
}
|
|
5995
6242
|
}
|
|
5996
6243
|
}
|
|
@@ -6324,8 +6571,8 @@ var ProxyConfigStore = class {
|
|
|
6324
6571
|
}
|
|
6325
6572
|
};
|
|
6326
6573
|
var ExtendedConfigStore = class extends core.DefaultConfigStore {
|
|
6327
|
-
constructor(
|
|
6328
|
-
super(
|
|
6574
|
+
constructor(init2) {
|
|
6575
|
+
super(init2);
|
|
6329
6576
|
}
|
|
6330
6577
|
get(key) {
|
|
6331
6578
|
if (key === MarketsStorageKey) {
|
|
@@ -6429,6 +6676,91 @@ var OrderlyConfigProvider = (props) => {
|
|
|
6429
6676
|
}
|
|
6430
6677
|
);
|
|
6431
6678
|
};
|
|
6679
|
+
var apiKeyMap = {
|
|
6680
|
+
dev: "4d6b7db0fdd6e9de2b6a270414fd51e0",
|
|
6681
|
+
qa: "96476b00bc2701360f9b480629ae5263",
|
|
6682
|
+
staging: "dffc00e003479b86d410c448e00f2304",
|
|
6683
|
+
prod: "3ab9ae56ed16cc57bc2ac97ffc1098c2"
|
|
6684
|
+
};
|
|
6685
|
+
var TrackerContext = React.createContext({});
|
|
6686
|
+
var OrderlyTrackerProvider = ({ children }) => {
|
|
6687
|
+
const listenKeys = Object.keys(types.TrackerListenerKeyMap);
|
|
6688
|
+
const ee = useEventEmitter();
|
|
6689
|
+
const env = useGetEnv();
|
|
6690
|
+
const walletConnectRef = React.useRef(false);
|
|
6691
|
+
const { account: account5, state } = useAccount();
|
|
6692
|
+
const networkId = useConfig("networkId");
|
|
6693
|
+
const brokerId = useConfig("brokerId");
|
|
6694
|
+
const getChainInfo = useNetworkInfo(networkId);
|
|
6695
|
+
const handleEvent = React.useCallback(
|
|
6696
|
+
(key, params) => {
|
|
6697
|
+
account5?.accountId && amplitude__namespace.setUserId(account5?.accountId);
|
|
6698
|
+
if (key === types.EnumTrackerKeys.WALLET_CONNECT) {
|
|
6699
|
+
if (walletConnectRef.current)
|
|
6700
|
+
return;
|
|
6701
|
+
const info = getChainInfo(
|
|
6702
|
+
params?.connectWallet?.chainId
|
|
6703
|
+
).info;
|
|
6704
|
+
const { address = "", connectWallet } = params;
|
|
6705
|
+
const identify2 = {
|
|
6706
|
+
address,
|
|
6707
|
+
broker_id: brokerId,
|
|
6708
|
+
sdk_version: window?.__ORDERLY_VERSION__?.["@orderly.network/net"] ?? ""
|
|
6709
|
+
};
|
|
6710
|
+
const identifyEvent = new amplitude__namespace.Identify();
|
|
6711
|
+
Object.keys(identify2).map((subKey) => {
|
|
6712
|
+
identifyEvent.set(subKey, identify2[subKey]);
|
|
6713
|
+
});
|
|
6714
|
+
amplitude__namespace.identify(identifyEvent);
|
|
6715
|
+
const eventProperties = {
|
|
6716
|
+
wallet: connectWallet?.name,
|
|
6717
|
+
network: info?.network_infos?.name
|
|
6718
|
+
};
|
|
6719
|
+
amplitude__namespace.track(types.TrackerListenerKeyMap[key], eventProperties);
|
|
6720
|
+
walletConnectRef.current = true;
|
|
6721
|
+
return;
|
|
6722
|
+
}
|
|
6723
|
+
if (key === types.EnumTrackerKeys.SIGNIN_SUCCESS) {
|
|
6724
|
+
const info = getChainInfo(
|
|
6725
|
+
params?.connectWallet?.chainId
|
|
6726
|
+
).info;
|
|
6727
|
+
amplitude__namespace.track(types.TrackerListenerKeyMap[key], {
|
|
6728
|
+
wallet: params?.connectWallet?.name,
|
|
6729
|
+
network: info?.network_infos?.name
|
|
6730
|
+
});
|
|
6731
|
+
return;
|
|
6732
|
+
}
|
|
6733
|
+
amplitude__namespace.track(types.TrackerListenerKeyMap[key], params);
|
|
6734
|
+
},
|
|
6735
|
+
[account5?.accountId, brokerId, state?.connectWallet?.name]
|
|
6736
|
+
);
|
|
6737
|
+
React.useEffect(() => {
|
|
6738
|
+
amplitude__namespace.init(apiKeyMap[env], { serverZone: "EU" });
|
|
6739
|
+
listenKeys.forEach((key) => {
|
|
6740
|
+
ee.on(key, (params = {}) => {
|
|
6741
|
+
setTimeout(() => {
|
|
6742
|
+
handleEvent(key, params);
|
|
6743
|
+
}, 2e3);
|
|
6744
|
+
});
|
|
6745
|
+
});
|
|
6746
|
+
return () => {
|
|
6747
|
+
listenKeys.forEach((key) => {
|
|
6748
|
+
ee.off(key);
|
|
6749
|
+
});
|
|
6750
|
+
};
|
|
6751
|
+
}, [env]);
|
|
6752
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
6753
|
+
TrackerContext.Provider,
|
|
6754
|
+
{
|
|
6755
|
+
value: {
|
|
6756
|
+
track: (key, params) => {
|
|
6757
|
+
amplitude__namespace.track(key, params);
|
|
6758
|
+
}
|
|
6759
|
+
},
|
|
6760
|
+
children
|
|
6761
|
+
}
|
|
6762
|
+
);
|
|
6763
|
+
};
|
|
6432
6764
|
var WalletConnectorContext = React.createContext({});
|
|
6433
6765
|
var useWalletConnector = () => {
|
|
6434
6766
|
return React.useContext(WalletConnectorContext);
|
|
@@ -7395,7 +7727,7 @@ var DataPaint = class extends BasePaint {
|
|
|
7395
7727
|
);
|
|
7396
7728
|
}
|
|
7397
7729
|
if (typeof options.data?.position.pnl !== "undefined") {
|
|
7398
|
-
const prefix = options.data?.position.pnl
|
|
7730
|
+
const prefix = options.data?.position.pnl >= 0 ? "+" : "";
|
|
7399
7731
|
let text = `${prefix}${utils.commify(options.data?.position.pnl)} ${options.data?.position.currency}`;
|
|
7400
7732
|
let fontWeight = 600;
|
|
7401
7733
|
if (prevElementBoundingBox.width) {
|
|
@@ -13112,13 +13444,13 @@ var OmnichainLedgerV1ABI_default = [
|
|
|
13112
13444
|
type: "function"
|
|
13113
13445
|
}
|
|
13114
13446
|
];
|
|
13115
|
-
var
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
return
|
|
13121
|
-
})(
|
|
13447
|
+
var ENVType2 = /* @__PURE__ */ ((ENVType3) => {
|
|
13448
|
+
ENVType3["prod"] = "prod";
|
|
13449
|
+
ENVType3["staging"] = "staging";
|
|
13450
|
+
ENVType3["qa"] = "qa";
|
|
13451
|
+
ENVType3["dev"] = "dev";
|
|
13452
|
+
return ENVType3;
|
|
13453
|
+
})(ENVType2 || {});
|
|
13122
13454
|
var useGetEnv = () => {
|
|
13123
13455
|
const { configStore } = React.useContext(OrderlyContext);
|
|
13124
13456
|
const baseUrl = configStore.get("apiBaseUrl") || "https://api-evm.orderly.org";
|
|
@@ -13339,6 +13671,8 @@ var getOrderCreator = (order) => {
|
|
|
13339
13671
|
let type;
|
|
13340
13672
|
if (isBracketOrder(order)) {
|
|
13341
13673
|
type = `${types.AlgoOrderRootType.BRACKET}:${order.order_type}`;
|
|
13674
|
+
} else if (order.order_type === types.OrderType.LIMIT) {
|
|
13675
|
+
type = order.order_type_ext || order.order_type;
|
|
13342
13676
|
} else {
|
|
13343
13677
|
type = order.order_type;
|
|
13344
13678
|
}
|
|
@@ -13744,8 +14078,10 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
13744
14078
|
validated: false,
|
|
13745
14079
|
errors: null
|
|
13746
14080
|
});
|
|
13747
|
-
const askAndBid = React.useRef([]);
|
|
14081
|
+
const askAndBid = React.useRef([[]]);
|
|
13748
14082
|
const lastChangedField = React.useRef();
|
|
14083
|
+
const lastOrderTypeExt = React.useRef();
|
|
14084
|
+
const lastLevel = React.useRef();
|
|
13749
14085
|
const actions = useMarkPriceActions();
|
|
13750
14086
|
const symbolConfig = useSymbolsInfo();
|
|
13751
14087
|
const accountInfo = useAccountInfo();
|
|
@@ -13773,8 +14109,35 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
13773
14109
|
formattedOrder.side,
|
|
13774
14110
|
formattedOrder.reduce_only
|
|
13775
14111
|
);
|
|
14112
|
+
const updateOrderPrice = () => {
|
|
14113
|
+
const order_type_ext = formattedOrder.order_type_ext ?? lastOrderTypeExt.current;
|
|
14114
|
+
const level = formattedOrder.level ?? lastLevel.current;
|
|
14115
|
+
if (![types.OrderType.ASK, types.OrderType.BID].includes(order_type_ext) || level === void 0) {
|
|
14116
|
+
return;
|
|
14117
|
+
}
|
|
14118
|
+
lastOrderTypeExt.current = order_type_ext;
|
|
14119
|
+
lastLevel.current = level;
|
|
14120
|
+
const index = order_type_ext === types.OrderType.ASK ? 0 : 1;
|
|
14121
|
+
const price = askAndBid.current?.[level]?.[index];
|
|
14122
|
+
if (price && !isNaN(price)) {
|
|
14123
|
+
setValue("order_price", price, {
|
|
14124
|
+
shouldUpdateLastChangedField: false
|
|
14125
|
+
});
|
|
14126
|
+
}
|
|
14127
|
+
};
|
|
14128
|
+
const updateOrderPriceByOrderBook = () => {
|
|
14129
|
+
const { order_type, order_type_ext, order_quantity } = formattedOrder;
|
|
14130
|
+
const isBBO = order_type === types.OrderType.LIMIT && [types.OrderType.ASK, types.OrderType.BID].includes(order_type_ext);
|
|
14131
|
+
if (lastChangedField.current !== "total" && isBBO) {
|
|
14132
|
+
updateOrderPrice();
|
|
14133
|
+
}
|
|
14134
|
+
};
|
|
14135
|
+
React.useEffect(() => {
|
|
14136
|
+
updateOrderPrice();
|
|
14137
|
+
}, [formattedOrder.order_type_ext, formattedOrder.level]);
|
|
13776
14138
|
const onOrderBookUpdate = useDebounce.useDebouncedCallback((data) => {
|
|
13777
14139
|
askAndBid.current = data;
|
|
14140
|
+
updateOrderPriceByOrderBook();
|
|
13778
14141
|
}, 200);
|
|
13779
14142
|
React.useEffect(() => {
|
|
13780
14143
|
ee.on("orderbook:update", onOrderBookUpdate);
|
|
@@ -13888,7 +14251,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
13888
14251
|
const markPrice2 = actions.getMarkPriceBySymbol(symbol);
|
|
13889
14252
|
if (!markPrice2 || !accountInfo)
|
|
13890
14253
|
return null;
|
|
13891
|
-
return calcEstLiqPrice(formattedOrder, askAndBid.current, {
|
|
14254
|
+
return calcEstLiqPrice(formattedOrder, askAndBid.current[0], {
|
|
13892
14255
|
baseIMR: symbolInfo?.base_imr,
|
|
13893
14256
|
baseMMR: symbolInfo?.base_mmr,
|
|
13894
14257
|
markPrice: markPrice2,
|
|
@@ -13900,7 +14263,7 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
13900
14263
|
});
|
|
13901
14264
|
}, [formattedOrder, accountInfo, positions2, totalCollateral, symbol]);
|
|
13902
14265
|
const estLeverage = React.useMemo(() => {
|
|
13903
|
-
return calcEstLeverage(formattedOrder, askAndBid.current, {
|
|
14266
|
+
return calcEstLeverage(formattedOrder, askAndBid.current[0], {
|
|
13904
14267
|
totalCollateral,
|
|
13905
14268
|
positions: positions2,
|
|
13906
14269
|
symbol
|
|
@@ -13943,6 +14306,14 @@ var useOrderEntry2 = (symbol, options = {}) => {
|
|
|
13943
14306
|
}
|
|
13944
14307
|
const order = generateOrder(creator, prepareData());
|
|
13945
14308
|
const result = await doCreateOrder(order);
|
|
14309
|
+
if (result.success) {
|
|
14310
|
+
ee.emit(types.EnumTrackerKeys.PLACEORDER_SUCCESS, {
|
|
14311
|
+
side: order.side,
|
|
14312
|
+
order_type: order.order_type,
|
|
14313
|
+
tp_sl: hasTPSL(formattedOrder),
|
|
14314
|
+
reduce_only: !!order.reduce_only
|
|
14315
|
+
});
|
|
14316
|
+
}
|
|
13946
14317
|
if (result.success && resetOnSuccess) {
|
|
13947
14318
|
reset();
|
|
13948
14319
|
resetMetaState();
|
|
@@ -14143,13 +14514,14 @@ Object.defineProperty(exports, "useConstant", {
|
|
|
14143
14514
|
exports.AssetHistoryStatusEnum = AssetHistoryStatusEnum;
|
|
14144
14515
|
exports.DefaultLayoutConfig = DefaultLayoutConfig;
|
|
14145
14516
|
exports.DistributionId = DistributionId;
|
|
14146
|
-
exports.ENVType =
|
|
14517
|
+
exports.ENVType = ENVType2;
|
|
14147
14518
|
exports.ExtendedConfigStore = ExtendedConfigStore;
|
|
14148
14519
|
exports.MarketsStorageKey = MarketsStorageKey;
|
|
14149
14520
|
exports.MarketsType = MarketsType;
|
|
14150
14521
|
exports.OrderlyConfigProvider = OrderlyConfigProvider;
|
|
14151
14522
|
exports.OrderlyContext = OrderlyContext;
|
|
14152
14523
|
exports.OrderlyProvider = OrderlyProvider;
|
|
14524
|
+
exports.OrderlyTrackerProvider = OrderlyTrackerProvider;
|
|
14153
14525
|
exports.StatusContext = StatusContext;
|
|
14154
14526
|
exports.StatusProvider = StatusProvider;
|
|
14155
14527
|
exports.TWType = TWType;
|
|
@@ -14181,6 +14553,7 @@ exports.useEpochInfo = useEpochInfo;
|
|
|
14181
14553
|
exports.useEventEmitter = useEventEmitter;
|
|
14182
14554
|
exports.useFundingFeeHistory = useFundingFeeHistory;
|
|
14183
14555
|
exports.useFundingRate = useFundingRate;
|
|
14556
|
+
exports.useFundingRateHistory = useFundingRateHistory;
|
|
14184
14557
|
exports.useFundingRates = useFundingRates;
|
|
14185
14558
|
exports.useGetClaimed = useGetClaimed;
|
|
14186
14559
|
exports.useGetEnv = useGetEnv;
|
|
@@ -14204,6 +14577,7 @@ exports.useMarketsStream = useMarketsStream;
|
|
|
14204
14577
|
exports.useMaxQty = useMaxQty;
|
|
14205
14578
|
exports.useMediaQuery = useMediaQuery;
|
|
14206
14579
|
exports.useMutation = useMutation;
|
|
14580
|
+
exports.useNetworkInfo = useNetworkInfo;
|
|
14207
14581
|
exports.useOrderEntity = useOrderEntity;
|
|
14208
14582
|
exports.useOrderEntry = useOrderEntry2;
|
|
14209
14583
|
exports.useOrderEntry_deprecated = useOrderEntry;
|