@orderly.network/hooks 0.0.95 → 1.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 +103 -175
- package/dist/index.d.ts +103 -175
- package/dist/index.js +230 -345
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +93 -199
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -7
package/dist/index.js
CHANGED
|
@@ -1,49 +1,56 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var React2 = require('react');
|
|
4
3
|
var useSWR = require('swr');
|
|
5
4
|
var net = require('@orderly.network/net');
|
|
5
|
+
var React = require('react');
|
|
6
6
|
var useSWRMutation = require('swr/mutation');
|
|
7
|
-
var
|
|
7
|
+
var useConstant4 = require('use-constant');
|
|
8
8
|
var core = require('@orderly.network/core');
|
|
9
9
|
var types = require('@orderly.network/types');
|
|
10
10
|
var utils = require('@orderly.network/utils');
|
|
11
11
|
var useSWRSubscription = require('swr/subscription');
|
|
12
12
|
var ramda = require('ramda');
|
|
13
|
-
var
|
|
13
|
+
var perp = require('@orderly.network/perp');
|
|
14
14
|
var useSWRInfinite = require('swr/infinite');
|
|
15
15
|
var useDebounce = require('use-debounce');
|
|
16
16
|
var scanClient = require('@layerzerolabs/scan-client');
|
|
17
17
|
|
|
18
18
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
19
|
|
|
20
|
-
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
21
20
|
var useSWR__default = /*#__PURE__*/_interopDefault(useSWR);
|
|
21
|
+
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
22
22
|
var useSWRMutation__default = /*#__PURE__*/_interopDefault(useSWRMutation);
|
|
23
|
-
var
|
|
23
|
+
var useConstant4__default = /*#__PURE__*/_interopDefault(useConstant4);
|
|
24
24
|
var useSWRSubscription__default = /*#__PURE__*/_interopDefault(useSWRSubscription);
|
|
25
25
|
var useSWRInfinite__default = /*#__PURE__*/_interopDefault(useSWRInfinite);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
31
|
-
};
|
|
32
|
-
var OrderlyContext = React2.createContext({
|
|
27
|
+
// src/useQuery.ts
|
|
28
|
+
var fetcher = (url, init = {}, queryOptions) => net.get(url, init, queryOptions?.formatter);
|
|
29
|
+
var OrderlyContext = React.createContext({
|
|
33
30
|
// configStore: new MemoryConfigStore(),
|
|
34
31
|
});
|
|
35
32
|
var OrderlyProvider = OrderlyContext.Provider;
|
|
36
|
-
|
|
33
|
+
|
|
34
|
+
// src/useConfig.ts
|
|
35
|
+
var useConfig = (key, defaultValue) => {
|
|
36
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
37
|
+
if (typeof key !== "undefined") {
|
|
38
|
+
if (typeof defaultValue !== "undefined") {
|
|
39
|
+
return configStore.getOr(key, defaultValue);
|
|
40
|
+
}
|
|
41
|
+
return configStore.get(key);
|
|
42
|
+
}
|
|
43
|
+
return configStore;
|
|
44
|
+
};
|
|
37
45
|
|
|
38
46
|
// src/useQuery.ts
|
|
39
47
|
var useQuery = (query, options) => {
|
|
40
|
-
const
|
|
48
|
+
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
41
49
|
const { formatter, ...swrOptions } = options || {};
|
|
42
50
|
if (typeof apiBaseUrl === "undefined") {
|
|
43
|
-
throw new Error("please add
|
|
51
|
+
throw new Error("please add OrderlyConfigProvider to your app");
|
|
44
52
|
}
|
|
45
53
|
return useSWR__default.default(
|
|
46
|
-
// `${apiBaseUrl}${query}`,
|
|
47
54
|
query,
|
|
48
55
|
(url, init) => fetcher(url.startsWith("http") ? url : `${apiBaseUrl}${url}`, init, {
|
|
49
56
|
formatter
|
|
@@ -52,10 +59,10 @@ var useQuery = (query, options) => {
|
|
|
52
59
|
);
|
|
53
60
|
};
|
|
54
61
|
var useLazyQuery = (query, options) => {
|
|
55
|
-
const
|
|
62
|
+
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
56
63
|
const { formatter, init, ...swrOptions } = options || {};
|
|
57
64
|
if (typeof apiBaseUrl === "undefined") {
|
|
58
|
-
throw new Error("please add
|
|
65
|
+
throw new Error("please add OrderlyConfigProvider to your app");
|
|
59
66
|
}
|
|
60
67
|
return useSWRMutation__default.default(
|
|
61
68
|
query,
|
|
@@ -75,7 +82,7 @@ var useLazyQuery = (query, options) => {
|
|
|
75
82
|
);
|
|
76
83
|
};
|
|
77
84
|
var useAccountInstance = () => {
|
|
78
|
-
const { configStore, keyStore,
|
|
85
|
+
const { configStore, keyStore, getWalletAdapter } = React.useContext(OrderlyContext);
|
|
79
86
|
if (!configStore)
|
|
80
87
|
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
81
88
|
if (!keyStore) {
|
|
@@ -83,13 +90,12 @@ var useAccountInstance = () => {
|
|
|
83
90
|
"keyStore is not defined, please use OrderlyProvider and provide keyStore"
|
|
84
91
|
);
|
|
85
92
|
}
|
|
86
|
-
const account5 =
|
|
93
|
+
const account5 = useConstant4__default.default(() => {
|
|
87
94
|
let account6 = core.SimpleDI.get("account");
|
|
88
95
|
if (!account6) {
|
|
89
96
|
account6 = new core.Account(
|
|
90
97
|
configStore,
|
|
91
98
|
keyStore,
|
|
92
|
-
contractManager,
|
|
93
99
|
getWalletAdapter
|
|
94
100
|
// walletAdapter
|
|
95
101
|
);
|
|
@@ -118,7 +124,7 @@ var fetcher2 = (url, options) => {
|
|
|
118
124
|
return net.mutate(url, init);
|
|
119
125
|
};
|
|
120
126
|
var useMutation = (url, method = "POST", options) => {
|
|
121
|
-
const
|
|
127
|
+
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
122
128
|
let fullUrl = url;
|
|
123
129
|
if (!url.startsWith("http")) {
|
|
124
130
|
fullUrl = `${apiBaseUrl}${url}`;
|
|
@@ -164,7 +170,7 @@ var useMutation = (url, method = "POST", options) => {
|
|
|
164
170
|
];
|
|
165
171
|
};
|
|
166
172
|
var signatureMiddleware = (useSWRNext) => {
|
|
167
|
-
const
|
|
173
|
+
const apiBaseUrl = useConfig("apiBaseUrl");
|
|
168
174
|
return (key, fetcher3, config) => {
|
|
169
175
|
try {
|
|
170
176
|
const extendedFetcher = async (args) => {
|
|
@@ -177,6 +183,7 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
177
183
|
url
|
|
178
184
|
};
|
|
179
185
|
const signature = await signer.sign(payload);
|
|
186
|
+
console.log("signature:", fullUrl);
|
|
180
187
|
return fetcher3(fullUrl, {
|
|
181
188
|
headers: {
|
|
182
189
|
...signature,
|
|
@@ -194,11 +201,11 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
194
201
|
var useAccount = () => {
|
|
195
202
|
const {
|
|
196
203
|
configStore,
|
|
197
|
-
keyStore
|
|
198
|
-
onWalletConnect,
|
|
199
|
-
onWalletDisconnect,
|
|
200
|
-
onSetChain
|
|
201
|
-
} =
|
|
204
|
+
keyStore
|
|
205
|
+
// onWalletConnect,
|
|
206
|
+
// onWalletDisconnect,
|
|
207
|
+
// onSetChain,
|
|
208
|
+
} = React.useContext(OrderlyContext);
|
|
202
209
|
if (!configStore)
|
|
203
210
|
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
204
211
|
if (!keyStore) {
|
|
@@ -207,45 +214,35 @@ var useAccount = () => {
|
|
|
207
214
|
);
|
|
208
215
|
}
|
|
209
216
|
const account5 = useAccountInstance();
|
|
210
|
-
const [state, setState] =
|
|
217
|
+
const [state, setState] = React.useState(account5.stateValue);
|
|
211
218
|
const statusChangeHandler = (nextState) => {
|
|
212
219
|
setState(() => nextState);
|
|
213
220
|
};
|
|
214
|
-
|
|
221
|
+
React.useEffect(() => {
|
|
215
222
|
account5.on("change:status", statusChangeHandler);
|
|
216
223
|
return () => {
|
|
217
224
|
account5.off("change:status", statusChangeHandler);
|
|
218
225
|
};
|
|
219
226
|
}, []);
|
|
220
|
-
const createOrderlyKey =
|
|
227
|
+
const createOrderlyKey = React.useCallback(
|
|
221
228
|
async (remember) => {
|
|
222
229
|
return account5.createOrderlyKey(remember ? 365 : 30);
|
|
223
230
|
},
|
|
224
231
|
[account5]
|
|
225
232
|
);
|
|
226
|
-
const createAccount =
|
|
233
|
+
const createAccount = React.useCallback(async () => {
|
|
227
234
|
return account5.createAccount();
|
|
228
235
|
}, [account5]);
|
|
229
|
-
const connect = React2.useCallback(async () => {
|
|
230
|
-
return onWalletConnect?.();
|
|
231
|
-
}, [account5]);
|
|
232
|
-
const disconnect = async () => {
|
|
233
|
-
return onWalletDisconnect?.();
|
|
234
|
-
};
|
|
235
|
-
const setChain = async (chainId) => {
|
|
236
|
-
return onSetChain?.(chainId);
|
|
237
|
-
};
|
|
238
236
|
return {
|
|
239
|
-
// account: state!,
|
|
240
237
|
account: account5,
|
|
241
238
|
state,
|
|
242
239
|
// info: {},
|
|
243
240
|
// login,
|
|
244
241
|
createOrderlyKey,
|
|
245
|
-
createAccount
|
|
246
|
-
disconnect,
|
|
247
|
-
connect,
|
|
248
|
-
setChain
|
|
242
|
+
createAccount
|
|
243
|
+
// disconnect,
|
|
244
|
+
// connect,
|
|
245
|
+
// setChain,
|
|
249
246
|
// settlement,
|
|
250
247
|
};
|
|
251
248
|
};
|
|
@@ -255,7 +252,6 @@ var usePrivateQuery = (query, options) => {
|
|
|
255
252
|
const middleware = Array.isArray(options?.use) ? options?.use ?? [] : [];
|
|
256
253
|
return useSWR__default.default(
|
|
257
254
|
() => account5.state.status >= types.AccountStatusEnum.EnableTrading ? [query, account5.state.accountId] : null,
|
|
258
|
-
// query,
|
|
259
255
|
(url, init) => {
|
|
260
256
|
return fetcher(url, init, { formatter });
|
|
261
257
|
},
|
|
@@ -268,36 +264,14 @@ var usePrivateQuery = (query, options) => {
|
|
|
268
264
|
);
|
|
269
265
|
};
|
|
270
266
|
var useBoolean = (initialValue = false) => {
|
|
271
|
-
const [value, setValue] =
|
|
272
|
-
const setTrue =
|
|
273
|
-
const setFalse =
|
|
274
|
-
const toggle =
|
|
267
|
+
const [value, setValue] = React.useState(initialValue);
|
|
268
|
+
const setTrue = React.useCallback(() => setValue(true), []);
|
|
269
|
+
const setFalse = React.useCallback(() => setValue(false), []);
|
|
270
|
+
const toggle = React.useCallback(() => setValue((v) => !v), []);
|
|
275
271
|
return [value, { setTrue, setFalse, toggle }];
|
|
276
272
|
};
|
|
277
|
-
|
|
278
|
-
// src/useTradingView.ts
|
|
279
|
-
var useTradingView = () => {
|
|
280
|
-
return {};
|
|
281
|
-
};
|
|
282
|
-
var useTopicObserve = (topic) => {
|
|
283
|
-
const [data, setData] = React2.useState();
|
|
284
|
-
React2.useEffect(() => {
|
|
285
|
-
return () => {
|
|
286
|
-
};
|
|
287
|
-
}, []);
|
|
288
|
-
return {
|
|
289
|
-
data
|
|
290
|
-
};
|
|
291
|
-
};
|
|
292
|
-
var useAppState = () => {
|
|
293
|
-
const { errors } = React2.useContext(OrderlyContext);
|
|
294
|
-
return {
|
|
295
|
-
errors
|
|
296
|
-
// ready,
|
|
297
|
-
};
|
|
298
|
-
};
|
|
299
273
|
var usePreLoadData = () => {
|
|
300
|
-
const { configStore } =
|
|
274
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
301
275
|
const { error: swapSupportError, data: swapSupportData } = useSWR__default.default(
|
|
302
276
|
`${configStore.get("swapSupportApiUrl")}/swap_support`,
|
|
303
277
|
(url) => fetch(url).then((res) => res.json()),
|
|
@@ -308,7 +282,7 @@ var usePreLoadData = () => {
|
|
|
308
282
|
const { error: tokenError, data: tokenData } = useQuery("/v1/public/token", {
|
|
309
283
|
revalidateOnFocus: false
|
|
310
284
|
});
|
|
311
|
-
const isDone =
|
|
285
|
+
const isDone = React.useMemo(() => {
|
|
312
286
|
return !!swapSupportData && !!tokenData;
|
|
313
287
|
}, [swapSupportData, tokenData]);
|
|
314
288
|
return {
|
|
@@ -316,8 +290,8 @@ var usePreLoadData = () => {
|
|
|
316
290
|
done: isDone
|
|
317
291
|
};
|
|
318
292
|
};
|
|
319
|
-
var useEventEmitter = (
|
|
320
|
-
return
|
|
293
|
+
var useEventEmitter = () => {
|
|
294
|
+
return useConstant4__default.default(() => {
|
|
321
295
|
let ee = core.SimpleDI.get("EE");
|
|
322
296
|
if (!ee) {
|
|
323
297
|
ee = new core.EventEmitter();
|
|
@@ -338,7 +312,7 @@ function parseJSON(value) {
|
|
|
338
312
|
|
|
339
313
|
// src/useSessionStorage.ts
|
|
340
314
|
function useSessionStorage(key, initialValue) {
|
|
341
|
-
const readValue =
|
|
315
|
+
const readValue = React.useCallback(() => {
|
|
342
316
|
if (typeof window === "undefined") {
|
|
343
317
|
return initialValue;
|
|
344
318
|
}
|
|
@@ -350,7 +324,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
350
324
|
return initialValue;
|
|
351
325
|
}
|
|
352
326
|
}, [initialValue, key]);
|
|
353
|
-
const [storedValue, setStoredValue] =
|
|
327
|
+
const [storedValue, setStoredValue] = React.useState(readValue);
|
|
354
328
|
const setValue = (value) => {
|
|
355
329
|
if (typeof window == "undefined") {
|
|
356
330
|
console.warn(
|
|
@@ -365,10 +339,10 @@ function useSessionStorage(key, initialValue) {
|
|
|
365
339
|
console.warn(`Error setting sessionStorage key \u201C${key}\u201D:`, error);
|
|
366
340
|
}
|
|
367
341
|
};
|
|
368
|
-
|
|
342
|
+
React.useEffect(() => {
|
|
369
343
|
setStoredValue(readValue());
|
|
370
344
|
}, []);
|
|
371
|
-
|
|
345
|
+
React.useEffect(() => {
|
|
372
346
|
if (typeof window == "undefined") {
|
|
373
347
|
return;
|
|
374
348
|
}
|
|
@@ -377,7 +351,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
377
351
|
window.removeEventListener("storage", handleStorageChange);
|
|
378
352
|
};
|
|
379
353
|
});
|
|
380
|
-
const handleStorageChange =
|
|
354
|
+
const handleStorageChange = React.useCallback(
|
|
381
355
|
(event) => {
|
|
382
356
|
if (event?.key && event.key !== key) {
|
|
383
357
|
return;
|
|
@@ -389,7 +363,7 @@ function useSessionStorage(key, initialValue) {
|
|
|
389
363
|
return [storedValue, setValue];
|
|
390
364
|
}
|
|
391
365
|
function useLocalStorage(key, initialValue) {
|
|
392
|
-
const readValue =
|
|
366
|
+
const readValue = React.useCallback(() => {
|
|
393
367
|
if (typeof window === "undefined") {
|
|
394
368
|
return initialValue;
|
|
395
369
|
}
|
|
@@ -401,8 +375,8 @@ function useLocalStorage(key, initialValue) {
|
|
|
401
375
|
return initialValue;
|
|
402
376
|
}
|
|
403
377
|
}, [initialValue, key]);
|
|
404
|
-
const [storedValue, setStoredValue] =
|
|
405
|
-
const setValue =
|
|
378
|
+
const [storedValue, setStoredValue] = React.useState(readValue);
|
|
379
|
+
const setValue = React.useCallback(
|
|
406
380
|
(value) => {
|
|
407
381
|
if (typeof window === "undefined") {
|
|
408
382
|
console.warn(
|
|
@@ -419,37 +393,15 @@ function useLocalStorage(key, initialValue) {
|
|
|
419
393
|
},
|
|
420
394
|
[storedValue]
|
|
421
395
|
);
|
|
422
|
-
|
|
396
|
+
React.useEffect(() => {
|
|
423
397
|
setStoredValue(readValue());
|
|
424
398
|
}, []);
|
|
425
399
|
return [storedValue, setValue];
|
|
426
400
|
}
|
|
427
|
-
var useRunOnce = ({ fn, sessionKey }) => {
|
|
428
|
-
const triggered = React2.useRef(false);
|
|
429
|
-
React2.useEffect(() => {
|
|
430
|
-
const hasBeenTriggered = sessionKey ? sessionStorage.getItem(sessionKey) : triggered.current;
|
|
431
|
-
if (!hasBeenTriggered) {
|
|
432
|
-
fn();
|
|
433
|
-
triggered.current = true;
|
|
434
|
-
if (sessionKey) {
|
|
435
|
-
sessionStorage.setItem(sessionKey, "true");
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}, [fn, sessionKey]);
|
|
439
|
-
return null;
|
|
440
|
-
};
|
|
441
|
-
var DataSourceContext = React2.createContext({});
|
|
442
|
-
var DataSourceProvider = (props) => {
|
|
443
|
-
useAccountInstance();
|
|
444
|
-
useConstant__default.default(() => {
|
|
445
|
-
});
|
|
446
|
-
return /* @__PURE__ */ React2__default.default.createElement(DataSourceContext.Provider, { value: {} }, props.children);
|
|
447
|
-
};
|
|
448
401
|
var WS_NAME = "nativeWebsocketClient";
|
|
449
402
|
var useWS = () => {
|
|
450
|
-
|
|
451
|
-
const
|
|
452
|
-
const ws = useConstant__default.default(() => {
|
|
403
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
404
|
+
const ws = useConstant4__default.default(() => {
|
|
453
405
|
let websocketClient = core.SimpleDI.get(WS_NAME);
|
|
454
406
|
const account5 = core.SimpleDI.get(core.Account.instanceName);
|
|
455
407
|
if (!websocketClient) {
|
|
@@ -476,9 +428,49 @@ var useWS = () => {
|
|
|
476
428
|
});
|
|
477
429
|
return ws;
|
|
478
430
|
};
|
|
479
|
-
var
|
|
480
|
-
const
|
|
481
|
-
|
|
431
|
+
var OrderlyConfigProvider = (props) => {
|
|
432
|
+
const [account5, setAccount] = React__default.default.useState(null);
|
|
433
|
+
const { configStore, keyStore, getWalletAdapter, brokerId, networkId } = props;
|
|
434
|
+
if (!brokerId && typeof configStore === "undefined") {
|
|
435
|
+
console.error("[OrderlyConfigProvider]: brokerId is required");
|
|
436
|
+
}
|
|
437
|
+
const innerConfigStore = useConstant4__default.default(() => {
|
|
438
|
+
return configStore || new core.MemoryConfigStore({ brokerId });
|
|
439
|
+
});
|
|
440
|
+
const innerKeyStore = useConstant4__default.default(() => {
|
|
441
|
+
return keyStore || new core.LocalStorageStore(networkId);
|
|
442
|
+
});
|
|
443
|
+
const innerGetWalletAdapter = useConstant4__default.default(() => {
|
|
444
|
+
return getWalletAdapter || ((options) => new core.EtherAdapter(options));
|
|
445
|
+
});
|
|
446
|
+
React.useEffect(() => {
|
|
447
|
+
let account6 = core.SimpleDI.get(core.Account.instanceName);
|
|
448
|
+
if (!account6) {
|
|
449
|
+
account6 = new core.Account(
|
|
450
|
+
innerConfigStore,
|
|
451
|
+
innerKeyStore,
|
|
452
|
+
innerGetWalletAdapter
|
|
453
|
+
);
|
|
454
|
+
core.SimpleDI.registerByName(core.Account.instanceName, account6);
|
|
455
|
+
}
|
|
456
|
+
setAccount(account6);
|
|
457
|
+
}, []);
|
|
458
|
+
if (!account5) {
|
|
459
|
+
return null;
|
|
460
|
+
}
|
|
461
|
+
return /* @__PURE__ */ React__default.default.createElement(
|
|
462
|
+
OrderlyProvider,
|
|
463
|
+
{
|
|
464
|
+
value: {
|
|
465
|
+
configStore: innerConfigStore,
|
|
466
|
+
keyStore: innerKeyStore,
|
|
467
|
+
getWalletAdapter: innerGetWalletAdapter,
|
|
468
|
+
networkId
|
|
469
|
+
// apiBaseUrl,
|
|
470
|
+
}
|
|
471
|
+
},
|
|
472
|
+
props.children
|
|
473
|
+
);
|
|
482
474
|
};
|
|
483
475
|
var useMarkPrice = (symbol) => {
|
|
484
476
|
const ws = useWS();
|
|
@@ -532,9 +524,9 @@ var useTickerStream = (symbol) => {
|
|
|
532
524
|
revalidateOnFocus: false
|
|
533
525
|
}
|
|
534
526
|
);
|
|
535
|
-
const [ticker, setTicker] =
|
|
527
|
+
const [ticker, setTicker] = React.useState();
|
|
536
528
|
const ws = useWS();
|
|
537
|
-
|
|
529
|
+
React.useEffect(() => {
|
|
538
530
|
const unsubscribe = ws.subscribe(
|
|
539
531
|
// { event: "subscribe", topic: "markprices" },
|
|
540
532
|
`${symbol}@ticker`,
|
|
@@ -560,7 +552,7 @@ var useTickerStream = (symbol) => {
|
|
|
560
552
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
561
553
|
const { data: indexPrice } = useIndexPrice(symbol);
|
|
562
554
|
const { data: openInterest } = useOpenInterest(symbol);
|
|
563
|
-
const value =
|
|
555
|
+
const value = React.useMemo(() => {
|
|
564
556
|
if (!info)
|
|
565
557
|
return null;
|
|
566
558
|
if (!ticker)
|
|
@@ -764,23 +756,23 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
764
756
|
if (!symbol) {
|
|
765
757
|
throw new Error("useOrderbookStream requires a symbol");
|
|
766
758
|
}
|
|
767
|
-
const [requestData, setRequestData] =
|
|
768
|
-
const [data, setData] =
|
|
769
|
-
const [isLoading, setIsLoading] =
|
|
770
|
-
const [level, setLevel] =
|
|
759
|
+
const [requestData, setRequestData] = React.useState(null);
|
|
760
|
+
const [data, setData] = React.useState(initial);
|
|
761
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
762
|
+
const [level, setLevel] = React.useState(() => options?.level ?? 10);
|
|
771
763
|
const config = useSymbolsInfo()[symbol];
|
|
772
|
-
const [depth, setDepth] =
|
|
773
|
-
const depths =
|
|
764
|
+
const [depth, setDepth] = React.useState();
|
|
765
|
+
const depths = React.useMemo(() => {
|
|
774
766
|
const tick = config("quote_tick");
|
|
775
767
|
return [tick, tick * 10, tick * 100, tick * 1e3];
|
|
776
768
|
}, [config("quote_tick")]);
|
|
777
|
-
|
|
769
|
+
React.useEffect(() => {
|
|
778
770
|
setDepth(config("quote_tick"));
|
|
779
771
|
}, [config("quote_tick")]);
|
|
780
772
|
const ws = useWS();
|
|
781
773
|
const ticker = useTickerStream(symbol);
|
|
782
774
|
const eventEmitter = useEventEmitter();
|
|
783
|
-
|
|
775
|
+
React.useEffect(() => {
|
|
784
776
|
setIsLoading(true);
|
|
785
777
|
let ignore = false;
|
|
786
778
|
ws.onceSubscribe(
|
|
@@ -815,7 +807,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
815
807
|
};
|
|
816
808
|
}, [symbol, depth]);
|
|
817
809
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
818
|
-
|
|
810
|
+
React.useEffect(() => {
|
|
819
811
|
if (!requestData)
|
|
820
812
|
return;
|
|
821
813
|
let ignore = false;
|
|
@@ -840,14 +832,14 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
840
832
|
subscription?.();
|
|
841
833
|
};
|
|
842
834
|
}, [symbol, requestData]);
|
|
843
|
-
const onItemClick =
|
|
835
|
+
const onItemClick = React.useCallback((item) => {
|
|
844
836
|
eventEmitter.emit("orderbook:item:click", item);
|
|
845
837
|
}, []);
|
|
846
|
-
const onDepthChange =
|
|
838
|
+
const onDepthChange = React.useCallback((depth2) => {
|
|
847
839
|
setDepth(() => depth2);
|
|
848
840
|
}, []);
|
|
849
|
-
const prevMiddlePrice =
|
|
850
|
-
const middlePrice =
|
|
841
|
+
const prevMiddlePrice = React.useRef(0);
|
|
842
|
+
const middlePrice = React.useMemo(() => {
|
|
851
843
|
let asksFrist = 0, bidsFirst = 0;
|
|
852
844
|
if (data.asks.length > 0) {
|
|
853
845
|
asksFrist = data.asks[data.asks.length - 1][0];
|
|
@@ -859,7 +851,7 @@ var useOrderbookStream = (symbol, initial = INIT_DATA, options) => {
|
|
|
859
851
|
return 0;
|
|
860
852
|
return [asksFrist, bidsFirst, ticker["24h_close"]].sort()[1];
|
|
861
853
|
}, [ticker, data]);
|
|
862
|
-
|
|
854
|
+
React.useEffect(() => {
|
|
863
855
|
prevMiddlePrice.current = middlePrice;
|
|
864
856
|
}, [middlePrice]);
|
|
865
857
|
const reducedData = reduceOrderbook(depth, level, {
|
|
@@ -1104,7 +1096,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1104
1096
|
}
|
|
1105
1097
|
});
|
|
1106
1098
|
const { data: markPrices } = useMarkPricesStream();
|
|
1107
|
-
const formatedPositions =
|
|
1099
|
+
const formatedPositions = React.useMemo(() => {
|
|
1108
1100
|
if (!data?.rows || !symbolInfo || !accountInfo)
|
|
1109
1101
|
return null;
|
|
1110
1102
|
const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows : data.rows.filter((item) => {
|
|
@@ -1118,13 +1110,13 @@ var usePositionStream = (symbol, options) => {
|
|
|
1118
1110
|
markPrices
|
|
1119
1111
|
);
|
|
1120
1112
|
const info = symbolInfo?.[item.symbol];
|
|
1121
|
-
const notional =
|
|
1122
|
-
const unrealPnl =
|
|
1113
|
+
const notional = perp.positions.notional(item.position_qty, price);
|
|
1114
|
+
const unrealPnl = perp.positions.unrealizedPnL({
|
|
1123
1115
|
qty: item.position_qty,
|
|
1124
1116
|
openPrice: item.average_open_price,
|
|
1125
1117
|
markPrice: price
|
|
1126
1118
|
});
|
|
1127
|
-
const imr =
|
|
1119
|
+
const imr = perp.account.IMR({
|
|
1128
1120
|
maxLeverage: accountInfo.max_leverage,
|
|
1129
1121
|
baseIMR: info("base_imr"),
|
|
1130
1122
|
IMR_Factor: accountInfo.imr_factor[item.symbol],
|
|
@@ -1132,13 +1124,13 @@ var usePositionStream = (symbol, options) => {
|
|
|
1132
1124
|
ordersNotional: 0,
|
|
1133
1125
|
IMR_factor_power: 4 / 5
|
|
1134
1126
|
});
|
|
1135
|
-
const unrealPnlROI =
|
|
1127
|
+
const unrealPnlROI = perp.positions.unrealizedPnLROI({
|
|
1136
1128
|
positionQty: item.position_qty,
|
|
1137
1129
|
openPrice: item.average_open_price,
|
|
1138
1130
|
IMR: imr,
|
|
1139
1131
|
unrealizedPnL: unrealPnl
|
|
1140
1132
|
});
|
|
1141
|
-
const unsettlementPnL =
|
|
1133
|
+
const unsettlementPnL = perp.positions.unsettlementPnL({
|
|
1142
1134
|
positionQty: item.position_qty,
|
|
1143
1135
|
markPrice: price,
|
|
1144
1136
|
costPosition: item.cost_position,
|
|
@@ -1170,30 +1162,30 @@ var usePositionStream = (symbol, options) => {
|
|
|
1170
1162
|
}
|
|
1171
1163
|
];
|
|
1172
1164
|
}, [data?.rows, symbolInfo, accountInfo, markPrices, symbol, holding]);
|
|
1173
|
-
const [totalCollateral, totalValue, totalUnrealizedROI] =
|
|
1165
|
+
const [totalCollateral, totalValue, totalUnrealizedROI] = React.useMemo(() => {
|
|
1174
1166
|
if (!holding || !markPrices) {
|
|
1175
1167
|
return [utils.zero, utils.zero, 0];
|
|
1176
1168
|
}
|
|
1177
1169
|
const unsettlemnedPnL = ramda.pathOr(0, [1, "unsettledPnL"])(formatedPositions);
|
|
1178
1170
|
const unrealizedPnL = ramda.pathOr(0, [1, "unrealPnL"])(formatedPositions);
|
|
1179
1171
|
const [USDC_holding, nonUSDC] = parseHolding(holding, markPrices);
|
|
1180
|
-
const totalCollateral2 =
|
|
1172
|
+
const totalCollateral2 = perp.account.totalCollateral({
|
|
1181
1173
|
USDCHolding: USDC_holding,
|
|
1182
1174
|
nonUSDCHolding: nonUSDC,
|
|
1183
1175
|
unsettlementPnL: unsettlemnedPnL
|
|
1184
1176
|
});
|
|
1185
|
-
const totalValue2 =
|
|
1177
|
+
const totalValue2 = perp.account.totalValue({
|
|
1186
1178
|
totalUnsettlementPnL: unsettlemnedPnL,
|
|
1187
1179
|
USDCHolding: USDC_holding,
|
|
1188
1180
|
nonUSDCHolding: nonUSDC
|
|
1189
1181
|
});
|
|
1190
|
-
const totalUnrealizedROI2 =
|
|
1182
|
+
const totalUnrealizedROI2 = perp.account.totalUnrealizedROI({
|
|
1191
1183
|
totalUnrealizedPnL: unrealizedPnL,
|
|
1192
1184
|
totalValue: totalValue2.toNumber()
|
|
1193
1185
|
});
|
|
1194
1186
|
return [totalCollateral2, totalValue2, totalUnrealizedROI2];
|
|
1195
1187
|
}, [holding, formatedPositions, markPrices]);
|
|
1196
|
-
const positionsRows =
|
|
1188
|
+
const positionsRows = React.useMemo(() => {
|
|
1197
1189
|
if (!formatedPositions)
|
|
1198
1190
|
return null;
|
|
1199
1191
|
if (!symbolInfo || !accountInfo)
|
|
@@ -1201,7 +1193,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1201
1193
|
const total = totalCollateral.toNumber();
|
|
1202
1194
|
return formatedPositions[0].filter((item) => item.position_qty !== 0).map((item) => {
|
|
1203
1195
|
const info = symbolInfo?.[item.symbol];
|
|
1204
|
-
const MMR =
|
|
1196
|
+
const MMR = perp.positions.MMR({
|
|
1205
1197
|
baseMMR: info("base_mmr"),
|
|
1206
1198
|
baseIMR: info("base_imr"),
|
|
1207
1199
|
IMRFactor: accountInfo.imr_factor[item.symbol],
|
|
@@ -1210,12 +1202,12 @@ var usePositionStream = (symbol, options) => {
|
|
|
1210
1202
|
});
|
|
1211
1203
|
return {
|
|
1212
1204
|
...item,
|
|
1213
|
-
mm:
|
|
1205
|
+
mm: perp.positions.maintenanceMargin({
|
|
1214
1206
|
positionQty: item.position_qty,
|
|
1215
1207
|
markPrice: item.mark_price,
|
|
1216
1208
|
MMR
|
|
1217
1209
|
}),
|
|
1218
|
-
est_liq_price:
|
|
1210
|
+
est_liq_price: perp.positions.liqPrice({
|
|
1219
1211
|
markPrice: item.mark_price,
|
|
1220
1212
|
totalCollateral: total,
|
|
1221
1213
|
positionQty: item.position_qty,
|
|
@@ -1261,7 +1253,7 @@ var useHoldingStream = () => {
|
|
|
1261
1253
|
}
|
|
1262
1254
|
}
|
|
1263
1255
|
);
|
|
1264
|
-
const usdc =
|
|
1256
|
+
const usdc = React.useMemo(() => {
|
|
1265
1257
|
const usdc2 = data?.find((item) => item.token === "USDC");
|
|
1266
1258
|
return usdc2;
|
|
1267
1259
|
}, [data]);
|
|
@@ -1314,12 +1306,8 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
1314
1306
|
);
|
|
1315
1307
|
return result;
|
|
1316
1308
|
};
|
|
1317
|
-
var useOrderStream = ({
|
|
1318
|
-
status,
|
|
1319
|
-
symbol,
|
|
1320
|
-
side,
|
|
1321
|
-
size = 100
|
|
1322
|
-
} = {}) => {
|
|
1309
|
+
var useOrderStream = (params) => {
|
|
1310
|
+
const { status, symbol, side, size = 100 } = params;
|
|
1323
1311
|
const ws = useWS();
|
|
1324
1312
|
const { data: markPrices = {} } = useMarkPricesStream();
|
|
1325
1313
|
const [doCancelOrder] = useMutation("/v1/order", "DELETE");
|
|
@@ -1351,7 +1339,7 @@ var useOrderStream = ({
|
|
|
1351
1339
|
formatter: (data) => data
|
|
1352
1340
|
}
|
|
1353
1341
|
);
|
|
1354
|
-
const orders =
|
|
1342
|
+
const orders = React.useMemo(() => {
|
|
1355
1343
|
if (!ordersResponse.data) {
|
|
1356
1344
|
return null;
|
|
1357
1345
|
}
|
|
@@ -1362,10 +1350,10 @@ var useOrderStream = ({
|
|
|
1362
1350
|
};
|
|
1363
1351
|
});
|
|
1364
1352
|
}, [ordersResponse.data, markPrices]);
|
|
1365
|
-
const total =
|
|
1353
|
+
const total = React.useMemo(() => {
|
|
1366
1354
|
return ordersResponse.data?.[0]?.meta?.total || 0;
|
|
1367
1355
|
}, [ordersResponse.data]);
|
|
1368
|
-
|
|
1356
|
+
React.useEffect(() => {
|
|
1369
1357
|
const unsubscribe = ws.privateSubscribe(
|
|
1370
1358
|
{
|
|
1371
1359
|
id: "executionreport_orders",
|
|
@@ -1426,12 +1414,12 @@ var useOrderStream = ({
|
|
|
1426
1414
|
);
|
|
1427
1415
|
return () => unsubscribe();
|
|
1428
1416
|
}, []);
|
|
1429
|
-
const cancelAllOrders =
|
|
1417
|
+
const cancelAllOrders = React.useCallback(() => {
|
|
1430
1418
|
}, [ordersResponse.data]);
|
|
1431
|
-
const updateOrder =
|
|
1419
|
+
const updateOrder = React.useCallback((orderId, order2) => {
|
|
1432
1420
|
return doUpdateOrder({ ...order2, order_id: orderId });
|
|
1433
1421
|
}, []);
|
|
1434
|
-
const cancelOrder =
|
|
1422
|
+
const cancelOrder = React.useCallback((orderId, symbol2) => {
|
|
1435
1423
|
return doCancelOrder(null, {
|
|
1436
1424
|
order_id: orderId,
|
|
1437
1425
|
symbol: symbol2
|
|
@@ -1474,7 +1462,6 @@ function rePageData(list, total, pageSize) {
|
|
|
1474
1462
|
rows = [];
|
|
1475
1463
|
}
|
|
1476
1464
|
}
|
|
1477
|
-
console.log("rePageData", list, total, newData);
|
|
1478
1465
|
return newData;
|
|
1479
1466
|
}
|
|
1480
1467
|
function editPageData(list, newOrder) {
|
|
@@ -1503,17 +1490,17 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1503
1490
|
const symbolInfo = useSymbolsInfo();
|
|
1504
1491
|
const { data: markPrices } = useMarkPricesStream();
|
|
1505
1492
|
const { usdc } = useHoldingStream();
|
|
1506
|
-
const [totalCollateral, totalValue] =
|
|
1493
|
+
const [totalCollateral, totalValue] = React.useMemo(() => {
|
|
1507
1494
|
return [
|
|
1508
1495
|
ramda.pathOr(utils.zero, [0, "totalCollateral"], positions2),
|
|
1509
1496
|
ramda.pathOr(utils.zero, [0, "totalValue"], positions2)
|
|
1510
1497
|
];
|
|
1511
1498
|
}, [positions2, markPrices]);
|
|
1512
|
-
const totalInitialMarginWithOrders =
|
|
1499
|
+
const totalInitialMarginWithOrders = React.useMemo(() => {
|
|
1513
1500
|
if (!accountInfo || !symbolInfo || !markPrices) {
|
|
1514
1501
|
return 0;
|
|
1515
1502
|
}
|
|
1516
|
-
return
|
|
1503
|
+
return perp.account.totalInitialMarginWithOrders({
|
|
1517
1504
|
positions: positionsPath(positions2),
|
|
1518
1505
|
orders: orders ?? [],
|
|
1519
1506
|
markPrices,
|
|
@@ -1522,14 +1509,14 @@ var useCollateral = (options = { dp: 6 }) => {
|
|
|
1522
1509
|
symbolInfo
|
|
1523
1510
|
});
|
|
1524
1511
|
}, [positions2, orders, markPrices, accountInfo, symbolInfo]);
|
|
1525
|
-
const freeCollateral =
|
|
1526
|
-
return
|
|
1512
|
+
const freeCollateral = React.useMemo(() => {
|
|
1513
|
+
return perp.account.freeCollateral({
|
|
1527
1514
|
totalCollateral,
|
|
1528
1515
|
totalInitialMarginWithOrders
|
|
1529
1516
|
});
|
|
1530
1517
|
}, [totalCollateral, totalInitialMarginWithOrders]);
|
|
1531
|
-
const availableBalance =
|
|
1532
|
-
return
|
|
1518
|
+
const availableBalance = React.useMemo(() => {
|
|
1519
|
+
return perp.account.availableBalance({
|
|
1533
1520
|
USDCHolding: usdc?.holding ?? 0,
|
|
1534
1521
|
unsettlementPnL: pathOr_unsettledPnLPathOr(positions2)
|
|
1535
1522
|
});
|
|
@@ -1550,11 +1537,11 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1550
1537
|
const symbolInfo = useSymbolsInfo();
|
|
1551
1538
|
const { totalCollateral } = useCollateral();
|
|
1552
1539
|
const { data: markPrices } = useMarkPricesStream();
|
|
1553
|
-
const maxQty =
|
|
1540
|
+
const maxQty = React.useMemo(() => {
|
|
1554
1541
|
if (!symbol)
|
|
1555
1542
|
return 0;
|
|
1556
1543
|
const positions2 = positionsPath2(positionsData);
|
|
1557
|
-
const positionQty =
|
|
1544
|
+
const positionQty = perp.account.getQtyFromPositions(positions2, symbol);
|
|
1558
1545
|
if (reduceOnly) {
|
|
1559
1546
|
if (positionQty > 0) {
|
|
1560
1547
|
if (side === types.OrderSide.BUY) {
|
|
@@ -1575,12 +1562,12 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1575
1562
|
if (!markPrices || !markPrices[symbol] || !orders || !accountInfo)
|
|
1576
1563
|
return 0;
|
|
1577
1564
|
const getSymbolInfo = symbolInfo[symbol];
|
|
1578
|
-
const buyOrdersQty =
|
|
1565
|
+
const buyOrdersQty = perp.account.getQtyFromOrdersBySide(
|
|
1579
1566
|
orders,
|
|
1580
1567
|
symbol,
|
|
1581
1568
|
types.OrderSide.BUY
|
|
1582
1569
|
);
|
|
1583
|
-
const sellOrdersQty =
|
|
1570
|
+
const sellOrdersQty = perp.account.getQtyFromOrdersBySide(
|
|
1584
1571
|
orders,
|
|
1585
1572
|
symbol,
|
|
1586
1573
|
types.OrderSide.SELL
|
|
@@ -1591,7 +1578,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1591
1578
|
const otherOrders = orders.filter(
|
|
1592
1579
|
(item) => item.symbol !== symbol
|
|
1593
1580
|
);
|
|
1594
|
-
const otherIMs =
|
|
1581
|
+
const otherIMs = perp.account.otherIMs({
|
|
1595
1582
|
orders: otherOrders,
|
|
1596
1583
|
positions: otherPositions,
|
|
1597
1584
|
symbolInfo,
|
|
@@ -1599,7 +1586,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1599
1586
|
IMR_Factors: accountInfo.imr_factor,
|
|
1600
1587
|
maxLeverage: accountInfo.max_leverage
|
|
1601
1588
|
});
|
|
1602
|
-
return
|
|
1589
|
+
return perp.account.maxQty(side, {
|
|
1603
1590
|
markPrice: markPrices[symbol],
|
|
1604
1591
|
symbol,
|
|
1605
1592
|
baseMaxQty: getSymbolInfo("base_max"),
|
|
@@ -1626,7 +1613,7 @@ var useMaxQty = (symbol, side, reduceOnly = false) => {
|
|
|
1626
1613
|
]);
|
|
1627
1614
|
return maxQty;
|
|
1628
1615
|
};
|
|
1629
|
-
var { maxPrice, minPrice } =
|
|
1616
|
+
var { maxPrice, minPrice } = perp.order;
|
|
1630
1617
|
var BaseOrderCreator = class {
|
|
1631
1618
|
baseOrder(data) {
|
|
1632
1619
|
const order2 = {
|
|
@@ -1787,11 +1774,11 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1787
1774
|
const [doCreateOrder] = useMutation("/v1/order");
|
|
1788
1775
|
const { freeCollateral } = useCollateral();
|
|
1789
1776
|
const symbolInfo = useSymbolsInfo();
|
|
1790
|
-
const baseDP =
|
|
1777
|
+
const baseDP = React.useMemo(
|
|
1791
1778
|
() => utils.getPrecisionByNumber(symbolInfo[symbol]("base_tick", 0)),
|
|
1792
1779
|
[symbolInfo]
|
|
1793
1780
|
);
|
|
1794
|
-
const quoteDP =
|
|
1781
|
+
const quoteDP = React.useMemo(() => {
|
|
1795
1782
|
return utils.getPrecisionByNumber(symbolInfo[symbol]("quote_tick", 0));
|
|
1796
1783
|
}, [symbolInfo]);
|
|
1797
1784
|
const { data: markPrice } = useMarkPrice(symbol);
|
|
@@ -1830,7 +1817,7 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1830
1817
|
});
|
|
1831
1818
|
});
|
|
1832
1819
|
};
|
|
1833
|
-
const calculate =
|
|
1820
|
+
const calculate = React.useCallback(
|
|
1834
1821
|
(values, field, value) => {
|
|
1835
1822
|
const fieldHandler = getCalculateHandler(field);
|
|
1836
1823
|
const newValues = ramda.compose(
|
|
@@ -1864,65 +1851,11 @@ var useOrderEntry = (symbol, side, reduceOnly = false, options) => {
|
|
|
1864
1851
|
symbolConfig: symbolInfo[symbol]()
|
|
1865
1852
|
};
|
|
1866
1853
|
};
|
|
1867
|
-
var useFetures = () => {
|
|
1868
|
-
const { data, isLoading, error } = useQuery(
|
|
1869
|
-
`/v1/public/futures`,
|
|
1870
|
-
{
|
|
1871
|
-
revalidateOnFocus: false
|
|
1872
|
-
}
|
|
1873
|
-
);
|
|
1874
|
-
const [sortedData, setSortedData] = React2.useState(data);
|
|
1875
|
-
useWS();
|
|
1876
|
-
React2.useEffect(() => {
|
|
1877
|
-
}, []);
|
|
1878
|
-
React2.useEffect(() => {
|
|
1879
|
-
if (data) {
|
|
1880
|
-
const sortedData2 = data.sort((a, b) => {
|
|
1881
|
-
return 0;
|
|
1882
|
-
});
|
|
1883
|
-
setSortedData(sortedData2);
|
|
1884
|
-
}
|
|
1885
|
-
}, [data]);
|
|
1886
|
-
const sortBy = React2.useCallback((key) => {
|
|
1887
|
-
}, [data]);
|
|
1888
|
-
const filterBy = React2.useCallback((key) => {
|
|
1889
|
-
}, [data]);
|
|
1890
|
-
return {
|
|
1891
|
-
// ...data,
|
|
1892
|
-
data: sortedData,
|
|
1893
|
-
sortBy,
|
|
1894
|
-
filterBy,
|
|
1895
|
-
isLoading,
|
|
1896
|
-
error
|
|
1897
|
-
};
|
|
1898
|
-
};
|
|
1899
1854
|
|
|
1900
1855
|
// src/orderly/useAccountInfo.ts
|
|
1901
1856
|
var useAccountInfo = () => {
|
|
1902
1857
|
return usePrivateQuery("/v1/client/info");
|
|
1903
1858
|
};
|
|
1904
|
-
|
|
1905
|
-
// src/orderly/useTokenInfo.ts
|
|
1906
|
-
var useTokenInfo = () => {
|
|
1907
|
-
const { data = {} } = useQuery(
|
|
1908
|
-
"/v1/public/token",
|
|
1909
|
-
{
|
|
1910
|
-
focusThrottleInterval: 1e3 * 60 * 60 * 24,
|
|
1911
|
-
revalidateOnFocus: false,
|
|
1912
|
-
formatter(data2) {
|
|
1913
|
-
if (!data2?.rows || !data2?.rows?.length) {
|
|
1914
|
-
return {};
|
|
1915
|
-
}
|
|
1916
|
-
const obj = /* @__PURE__ */ Object.create(null);
|
|
1917
|
-
for (let index = 0; index < data2.rows.length; index++) {
|
|
1918
|
-
data2.rows[index];
|
|
1919
|
-
}
|
|
1920
|
-
return obj;
|
|
1921
|
-
}
|
|
1922
|
-
}
|
|
1923
|
-
);
|
|
1924
|
-
return createGetter(data);
|
|
1925
|
-
};
|
|
1926
1859
|
var useMarketsStream = () => {
|
|
1927
1860
|
const ws = useWS();
|
|
1928
1861
|
const { data: futures } = useQuery(`/v1/public/futures`, {
|
|
@@ -1948,7 +1881,7 @@ var useMarketsStream = () => {
|
|
|
1948
1881
|
unsubscribe?.();
|
|
1949
1882
|
};
|
|
1950
1883
|
});
|
|
1951
|
-
const value =
|
|
1884
|
+
const value = React.useMemo(() => {
|
|
1952
1885
|
if (!futures)
|
|
1953
1886
|
return null;
|
|
1954
1887
|
if (!tickers)
|
|
@@ -1975,7 +1908,7 @@ var useLeverage = () => {
|
|
|
1975
1908
|
const { data, mutate: mutate2 } = usePrivateQuery("/v1/client/info");
|
|
1976
1909
|
const [update] = useMutation("/v1/client/leverage");
|
|
1977
1910
|
const { data: config } = useQuery("/v1/public/config");
|
|
1978
|
-
const updateLeverage =
|
|
1911
|
+
const updateLeverage = React.useCallback((data2) => {
|
|
1979
1912
|
return update(data2).then((res) => {
|
|
1980
1913
|
console.log(res);
|
|
1981
1914
|
if (res.success) {
|
|
@@ -1998,7 +1931,7 @@ var useFundingRate = (symbol) => {
|
|
|
1998
1931
|
if (!symbol) {
|
|
1999
1932
|
throw new Error("useFuturesForSymbol requires a symbol");
|
|
2000
1933
|
}
|
|
2001
|
-
const [countDown, setCountDown] =
|
|
1934
|
+
const [countDown, setCountDown] = React.useState("00:00:00");
|
|
2002
1935
|
const { data } = useQuery(
|
|
2003
1936
|
`/v1/public/funding_rate/${symbol}`,
|
|
2004
1937
|
{
|
|
@@ -2008,7 +1941,7 @@ var useFundingRate = (symbol) => {
|
|
|
2008
1941
|
}
|
|
2009
1942
|
}
|
|
2010
1943
|
);
|
|
2011
|
-
|
|
1944
|
+
React.useEffect(() => {
|
|
2012
1945
|
if (!data)
|
|
2013
1946
|
return;
|
|
2014
1947
|
const { next_funding_time } = data;
|
|
@@ -2038,12 +1971,11 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
2038
1971
|
if (!symbol) {
|
|
2039
1972
|
throw new Error("useTradeStream: symbol is required");
|
|
2040
1973
|
}
|
|
2041
|
-
const [trades, setTrades] =
|
|
2042
|
-
const [isLoading, setIsLoading] =
|
|
2043
|
-
React2.useState(() => symbol);
|
|
1974
|
+
const [trades, setTrades] = React.useState([]);
|
|
1975
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
2044
1976
|
const { limit = 50 } = options;
|
|
2045
1977
|
const ws = useWS();
|
|
2046
|
-
|
|
1978
|
+
React.useEffect(() => {
|
|
2047
1979
|
setIsLoading(true);
|
|
2048
1980
|
setTrades(() => []);
|
|
2049
1981
|
ws.onceSubscribe(
|
|
@@ -2064,7 +1996,7 @@ var useMarketTradeStream = (symbol, options = {}) => {
|
|
|
2064
1996
|
}
|
|
2065
1997
|
);
|
|
2066
1998
|
}, [symbol]);
|
|
2067
|
-
|
|
1999
|
+
React.useEffect(() => {
|
|
2068
2000
|
const unsubscript = ws.subscribe(
|
|
2069
2001
|
{
|
|
2070
2002
|
id: `${symbol}@trade`,
|
|
@@ -2094,19 +2026,19 @@ var useMarginRatio = () => {
|
|
|
2094
2026
|
const [{ rows }] = usePositionStream();
|
|
2095
2027
|
const { data: markPrices } = useMarkPricesStream();
|
|
2096
2028
|
const { totalCollateral } = useCollateral();
|
|
2097
|
-
const marginRatio =
|
|
2029
|
+
const marginRatio = React.useMemo(() => {
|
|
2098
2030
|
if (!rows || !markPrices || !totalCollateral || rows.length === 0) {
|
|
2099
2031
|
return 0;
|
|
2100
2032
|
}
|
|
2101
|
-
const ratio =
|
|
2033
|
+
const ratio = perp.account.totalMarginRatio({
|
|
2102
2034
|
totalCollateral,
|
|
2103
2035
|
markPrices,
|
|
2104
2036
|
positions: rows ?? []
|
|
2105
2037
|
});
|
|
2106
2038
|
return ratio;
|
|
2107
2039
|
}, [rows, markPrices, totalCollateral]);
|
|
2108
|
-
const currentLeverage =
|
|
2109
|
-
return
|
|
2040
|
+
const currentLeverage = React.useMemo(() => {
|
|
2041
|
+
return perp.account.currentLeverage(marginRatio);
|
|
2110
2042
|
}, [marginRatio]);
|
|
2111
2043
|
return { marginRatio, currentLeverage };
|
|
2112
2044
|
};
|
|
@@ -3128,9 +3060,9 @@ var isNativeTokenChecker = (address) => address === nativeTokenAddress;
|
|
|
3128
3060
|
// src/orderly/useChains.ts
|
|
3129
3061
|
var useChains = (networkId, options = {}) => {
|
|
3130
3062
|
const { filter, pick: pick3, crossEnabled, wooSwapEnabled, ...swrOptions } = options;
|
|
3131
|
-
const { configStore
|
|
3063
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
3132
3064
|
const field = options?.pick;
|
|
3133
|
-
const
|
|
3065
|
+
const map = React.useRef(
|
|
3134
3066
|
/* @__PURE__ */ new Map()
|
|
3135
3067
|
);
|
|
3136
3068
|
const { data, error: swapSupportError } = useSWR__default.default(
|
|
@@ -3158,7 +3090,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3158
3090
|
dedupingInterval: 36e5
|
|
3159
3091
|
}
|
|
3160
3092
|
);
|
|
3161
|
-
const chains =
|
|
3093
|
+
const chains = React.useMemo(() => {
|
|
3162
3094
|
if (!orderlyChains)
|
|
3163
3095
|
return void 0;
|
|
3164
3096
|
let orderlyChainsArr = [];
|
|
@@ -3188,7 +3120,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3188
3120
|
if (!options.filter(_chain))
|
|
3189
3121
|
return;
|
|
3190
3122
|
}
|
|
3191
|
-
|
|
3123
|
+
map.current.set(chainId, _chain);
|
|
3192
3124
|
orderlyChainsArr.push(_chain);
|
|
3193
3125
|
});
|
|
3194
3126
|
});
|
|
@@ -3237,7 +3169,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3237
3169
|
});
|
|
3238
3170
|
if (item.token_infos?.length === 0)
|
|
3239
3171
|
return;
|
|
3240
|
-
|
|
3172
|
+
map.current.set(item.network_infos.chain_id, item);
|
|
3241
3173
|
if (typeof options?.filter === "function") {
|
|
3242
3174
|
if (!options.filter(item))
|
|
3243
3175
|
return;
|
|
@@ -3270,9 +3202,9 @@ var useChains = (networkId, options = {}) => {
|
|
|
3270
3202
|
};
|
|
3271
3203
|
}
|
|
3272
3204
|
}, [data, networkId, field, options, orderlyChains, wooSwapEnabled]);
|
|
3273
|
-
const findByChainId =
|
|
3205
|
+
const findByChainId = React.useCallback(
|
|
3274
3206
|
(chainId, field2) => {
|
|
3275
|
-
const chain =
|
|
3207
|
+
const chain = map.current.get(chainId);
|
|
3276
3208
|
if (chain) {
|
|
3277
3209
|
chain.nativeToken = chain.token_infos?.find(
|
|
3278
3210
|
(item) => item.address === nativeTokenAddress
|
|
@@ -3283,7 +3215,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3283
3215
|
}
|
|
3284
3216
|
return chain;
|
|
3285
3217
|
},
|
|
3286
|
-
[chains,
|
|
3218
|
+
[chains, map.current]
|
|
3287
3219
|
);
|
|
3288
3220
|
return [
|
|
3289
3221
|
chains,
|
|
@@ -3297,7 +3229,7 @@ var useChains = (networkId, options = {}) => {
|
|
|
3297
3229
|
};
|
|
3298
3230
|
var useChain = (token) => {
|
|
3299
3231
|
const { data, isLoading } = useQuery("/v1/public/token");
|
|
3300
|
-
const chains =
|
|
3232
|
+
const chains = React.useMemo(() => {
|
|
3301
3233
|
if (!data)
|
|
3302
3234
|
return null;
|
|
3303
3235
|
let item = data.find((chain) => chain.token === token);
|
|
@@ -3316,9 +3248,9 @@ var useChain = (token) => {
|
|
|
3316
3248
|
};
|
|
3317
3249
|
var useWithdraw = () => {
|
|
3318
3250
|
const { account: account5, state } = useAccount();
|
|
3319
|
-
const [isLoading, setIsLoading] =
|
|
3251
|
+
const [isLoading, setIsLoading] = React.useState(false);
|
|
3320
3252
|
const { unsettledPnL, availableBalance } = useCollateral();
|
|
3321
|
-
const withdraw =
|
|
3253
|
+
const withdraw = React.useCallback(
|
|
3322
3254
|
(inputs) => {
|
|
3323
3255
|
return account5.assetsManager.withdraw(inputs).then((res) => {
|
|
3324
3256
|
return res;
|
|
@@ -3327,7 +3259,7 @@ var useWithdraw = () => {
|
|
|
3327
3259
|
[state]
|
|
3328
3260
|
);
|
|
3329
3261
|
const { usdc } = useHoldingStream();
|
|
3330
|
-
const maxAmount =
|
|
3262
|
+
const maxAmount = React.useMemo(() => {
|
|
3331
3263
|
if (!usdc || !usdc.holding)
|
|
3332
3264
|
return 0;
|
|
3333
3265
|
if (unsettledPnL >= 0)
|
|
@@ -3337,18 +3269,18 @@ var useWithdraw = () => {
|
|
|
3337
3269
|
return { withdraw, isLoading, maxAmount, availableBalance, unsettledPnL };
|
|
3338
3270
|
};
|
|
3339
3271
|
var useDeposit = (options) => {
|
|
3340
|
-
const { onlyTestnet } =
|
|
3341
|
-
const [balanceRevalidating, setBalanceRevalidating] =
|
|
3342
|
-
const [allowanceRevalidating, setAllowanceRevalidating] =
|
|
3272
|
+
const { onlyTestnet } = React.useContext(OrderlyContext);
|
|
3273
|
+
const [balanceRevalidating, setBalanceRevalidating] = React.useState(false);
|
|
3274
|
+
const [allowanceRevalidating, setAllowanceRevalidating] = React.useState(false);
|
|
3343
3275
|
const [_, { findByChainId }] = useChains(void 0, {
|
|
3344
3276
|
wooSwapEnabled: true
|
|
3345
3277
|
});
|
|
3346
|
-
const [balance, setBalance] =
|
|
3347
|
-
const [allowance, setAllowance] =
|
|
3278
|
+
const [balance, setBalance] = React.useState("0");
|
|
3279
|
+
const [allowance, setAllowance] = React.useState("0");
|
|
3348
3280
|
const { account: account5, state } = useAccount();
|
|
3349
|
-
const prevAddress =
|
|
3350
|
-
const getBalanceListener =
|
|
3351
|
-
const dst =
|
|
3281
|
+
const prevAddress = React.useRef();
|
|
3282
|
+
const getBalanceListener = React.useRef();
|
|
3283
|
+
const dst = React.useMemo(() => {
|
|
3352
3284
|
const chain = onlyTestnet ? findByChainId(types.ARBITRUM_TESTNET_CHAINID) : findByChainId(types.ARBITRUM_MAINNET_CHAINID);
|
|
3353
3285
|
const USDC = chain?.token_infos.find((token) => token.symbol === "USDC");
|
|
3354
3286
|
if (!chain) {
|
|
@@ -3363,11 +3295,11 @@ var useDeposit = (options) => {
|
|
|
3363
3295
|
// chainId: 42161,
|
|
3364
3296
|
};
|
|
3365
3297
|
}, []);
|
|
3366
|
-
const isNativeToken =
|
|
3298
|
+
const isNativeToken = React.useMemo(
|
|
3367
3299
|
() => isNativeTokenChecker(options?.address || ""),
|
|
3368
3300
|
[options?.address]
|
|
3369
3301
|
);
|
|
3370
|
-
const fetchBalanceHandler =
|
|
3302
|
+
const fetchBalanceHandler = React.useCallback(
|
|
3371
3303
|
async (address, decimals) => {
|
|
3372
3304
|
let balance2;
|
|
3373
3305
|
if (!!address && isNativeTokenChecker(address)) {
|
|
@@ -3381,7 +3313,7 @@ var useDeposit = (options) => {
|
|
|
3381
3313
|
},
|
|
3382
3314
|
[]
|
|
3383
3315
|
);
|
|
3384
|
-
const fetchBalance =
|
|
3316
|
+
const fetchBalance = React.useCallback(
|
|
3385
3317
|
async (address, decimals) => {
|
|
3386
3318
|
if (!address)
|
|
3387
3319
|
return;
|
|
@@ -3400,7 +3332,7 @@ var useDeposit = (options) => {
|
|
|
3400
3332
|
},
|
|
3401
3333
|
[state, balanceRevalidating]
|
|
3402
3334
|
);
|
|
3403
|
-
const fetchBalances =
|
|
3335
|
+
const fetchBalances = React.useCallback(async (tokens) => {
|
|
3404
3336
|
const tasks = [];
|
|
3405
3337
|
for (const token of tokens) {
|
|
3406
3338
|
if (isNativeTokenChecker(token.address)) {
|
|
@@ -3435,7 +3367,7 @@ var useDeposit = (options) => {
|
|
|
3435
3367
|
const allowance2 = await account5.assetsManager.getAllowance(address);
|
|
3436
3368
|
setAllowance(() => allowance2);
|
|
3437
3369
|
};
|
|
3438
|
-
const getVaultAddress =
|
|
3370
|
+
const getVaultAddress = React.useCallback(() => {
|
|
3439
3371
|
if (dst.chainId !== options?.srcChainId) {
|
|
3440
3372
|
return options?.crossChainRouteAddress;
|
|
3441
3373
|
} else {
|
|
@@ -3444,7 +3376,7 @@ var useDeposit = (options) => {
|
|
|
3444
3376
|
}
|
|
3445
3377
|
}
|
|
3446
3378
|
}, [options, dst]);
|
|
3447
|
-
|
|
3379
|
+
React.useEffect(() => {
|
|
3448
3380
|
if (state.status < types.AccountStatusEnum.Connected)
|
|
3449
3381
|
return;
|
|
3450
3382
|
fetchBalance(options?.address, options?.decimals);
|
|
@@ -3467,7 +3399,7 @@ var useDeposit = (options) => {
|
|
|
3467
3399
|
account5.address,
|
|
3468
3400
|
dst
|
|
3469
3401
|
]);
|
|
3470
|
-
const approve =
|
|
3402
|
+
const approve = React.useCallback(
|
|
3471
3403
|
(amount) => {
|
|
3472
3404
|
if (!options?.address) {
|
|
3473
3405
|
throw new Error("address is required");
|
|
@@ -3482,7 +3414,7 @@ var useDeposit = (options) => {
|
|
|
3482
3414
|
},
|
|
3483
3415
|
[account5, getAllowance, options?.address]
|
|
3484
3416
|
);
|
|
3485
|
-
const deposit =
|
|
3417
|
+
const deposit = React.useCallback(
|
|
3486
3418
|
(amount) => {
|
|
3487
3419
|
return account5.assetsManager.deposit(amount).then((res) => {
|
|
3488
3420
|
setAllowance((value) => new utils.Decimal(value).sub(amount).toString());
|
|
@@ -3503,7 +3435,7 @@ var useDeposit = (options) => {
|
|
|
3503
3435
|
loopGetBalance();
|
|
3504
3436
|
}, 3e3);
|
|
3505
3437
|
};
|
|
3506
|
-
|
|
3438
|
+
React.useEffect(() => {
|
|
3507
3439
|
if (!options?.address) {
|
|
3508
3440
|
return;
|
|
3509
3441
|
}
|
|
@@ -3538,7 +3470,7 @@ var useWalletSubscription = (options) => {
|
|
|
3538
3470
|
{
|
|
3539
3471
|
onMessage: (data) => {
|
|
3540
3472
|
options?.onMessage?.(data);
|
|
3541
|
-
next(data);
|
|
3473
|
+
next(null, data);
|
|
3542
3474
|
}
|
|
3543
3475
|
}
|
|
3544
3476
|
);
|
|
@@ -3565,22 +3497,11 @@ var useSettleSubscription = (options) => {
|
|
|
3565
3497
|
return () => unsubscribe();
|
|
3566
3498
|
});
|
|
3567
3499
|
};
|
|
3568
|
-
var useBalance = () => {
|
|
3569
|
-
const ws = useWS();
|
|
3570
|
-
const { data } = useSWRSubscription__default.default("balance", (_, { next }) => {
|
|
3571
|
-
const unsubscribe = ws.privateSubscribe("balance", {
|
|
3572
|
-
onMessage: (data2) => {
|
|
3573
|
-
}
|
|
3574
|
-
});
|
|
3575
|
-
return () => unsubscribe();
|
|
3576
|
-
});
|
|
3577
|
-
return data;
|
|
3578
|
-
};
|
|
3579
3500
|
var usePrivateDataObserver = () => {
|
|
3580
3501
|
const ws = useWS();
|
|
3581
3502
|
const { mutate: mutate2 } = useSWR.useSWRConfig();
|
|
3582
3503
|
const { state } = useAccount();
|
|
3583
|
-
|
|
3504
|
+
React.useEffect(() => {
|
|
3584
3505
|
if (!state.accountId)
|
|
3585
3506
|
return;
|
|
3586
3507
|
const key = ["/v1/positions", state.accountId];
|
|
@@ -3629,39 +3550,11 @@ var usePrivateDataObserver = () => {
|
|
|
3629
3550
|
};
|
|
3630
3551
|
}, [state.accountId]);
|
|
3631
3552
|
};
|
|
3632
|
-
|
|
3633
|
-
// src/apis/index.ts
|
|
3634
|
-
var apis_exports = {};
|
|
3635
|
-
__export(apis_exports, {
|
|
3636
|
-
useFundingRateBySymbol: () => useFundingRateBySymbol,
|
|
3637
|
-
useInfo: () => useInfo,
|
|
3638
|
-
useToken: () => useToken
|
|
3639
|
-
});
|
|
3640
|
-
|
|
3641
|
-
// src/apis/useInfo.ts
|
|
3642
|
-
var useInfo = () => {
|
|
3643
|
-
return useQuery("/v1/public/info", {
|
|
3644
|
-
// refreshInterval: 1000 * 60 * 60 * 24,
|
|
3645
|
-
});
|
|
3646
|
-
};
|
|
3647
|
-
|
|
3648
|
-
// src/apis/useToken.ts
|
|
3649
|
-
var useToken = () => {
|
|
3650
|
-
return useQuery("/v1/public/token");
|
|
3651
|
-
};
|
|
3652
|
-
|
|
3653
|
-
// src/apis/useFundingRateBySymbol.ts
|
|
3654
|
-
var useFundingRateBySymbol = (symbol) => {
|
|
3655
|
-
if (!symbol) {
|
|
3656
|
-
throw new Error("symbol is required");
|
|
3657
|
-
}
|
|
3658
|
-
return useQuery(`/public/funding_rate/${symbol}`);
|
|
3659
|
-
};
|
|
3660
3553
|
var useWooSwapQuery = () => {
|
|
3661
|
-
const { configStore } =
|
|
3554
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
3662
3555
|
const account5 = useAccountInstance();
|
|
3663
3556
|
const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
|
|
3664
|
-
const query =
|
|
3557
|
+
const query = React.useCallback(
|
|
3665
3558
|
(inputs) => {
|
|
3666
3559
|
if (loading)
|
|
3667
3560
|
return;
|
|
@@ -3702,17 +3595,17 @@ var useWooSwapQuery = () => {
|
|
|
3702
3595
|
};
|
|
3703
3596
|
};
|
|
3704
3597
|
var useWooCrossSwapQuery = () => {
|
|
3705
|
-
const { configStore } =
|
|
3598
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
3706
3599
|
const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
|
|
3707
3600
|
const account5 = useAccountInstance();
|
|
3708
|
-
const dstValutDeposit =
|
|
3601
|
+
const dstValutDeposit = React.useCallback(() => {
|
|
3709
3602
|
return {
|
|
3710
3603
|
accountId: account5.accountIdHashStr,
|
|
3711
3604
|
brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
|
|
3712
3605
|
tokenHash: core.utils.parseTokenHash("USDC")
|
|
3713
3606
|
};
|
|
3714
3607
|
}, [account5]);
|
|
3715
|
-
const queryDestinationFee =
|
|
3608
|
+
const queryDestinationFee = React.useCallback(
|
|
3716
3609
|
async (crossChainRouteAddress, dst) => {
|
|
3717
3610
|
if (!account5.walletClient) {
|
|
3718
3611
|
throw new Error("walletClient is not ready");
|
|
@@ -3729,7 +3622,7 @@ var useWooCrossSwapQuery = () => {
|
|
|
3729
3622
|
},
|
|
3730
3623
|
[]
|
|
3731
3624
|
);
|
|
3732
|
-
const query =
|
|
3625
|
+
const query = React.useCallback(
|
|
3733
3626
|
(inputs) => {
|
|
3734
3627
|
if (loading)
|
|
3735
3628
|
return;
|
|
@@ -3790,20 +3683,21 @@ var useWooCrossSwapQuery = () => {
|
|
|
3790
3683
|
};
|
|
3791
3684
|
var useCrossSwap = () => {
|
|
3792
3685
|
const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
|
|
3793
|
-
const [layerStatus, setLayerStatus] =
|
|
3686
|
+
const [layerStatus, setLayerStatus] = React.useState(
|
|
3794
3687
|
"WAITTING" /* INITIALIZING */
|
|
3795
3688
|
);
|
|
3796
3689
|
const ee = useEventEmitter();
|
|
3797
|
-
const [bridgeMessage, setBridgeMessage] =
|
|
3798
|
-
const [status, setStatus] =
|
|
3690
|
+
const [bridgeMessage, setBridgeMessage] = React.useState();
|
|
3691
|
+
const [status, setStatus] = React.useState(
|
|
3799
3692
|
types.WS_WalletStatusEnum.NO
|
|
3800
3693
|
);
|
|
3801
|
-
const txHashFromBridge =
|
|
3694
|
+
const txHashFromBridge = React.useRef();
|
|
3802
3695
|
const account5 = useAccountInstance();
|
|
3803
|
-
const {
|
|
3804
|
-
const
|
|
3805
|
-
const
|
|
3806
|
-
|
|
3696
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
3697
|
+
const networkId = useConfig("networkId");
|
|
3698
|
+
const client = React.useRef(scanClient.createClient(networkId)).current;
|
|
3699
|
+
const timer = React.useRef();
|
|
3700
|
+
React.useEffect(() => {
|
|
3807
3701
|
const handler = (data) => {
|
|
3808
3702
|
const { side, transStatus, trxId } = data;
|
|
3809
3703
|
if (side === "DEPOSIT" && trxId === txHashFromBridge.current) {
|
|
@@ -3815,7 +3709,7 @@ var useCrossSwap = () => {
|
|
|
3815
3709
|
ee.off("wallet:changed", handler);
|
|
3816
3710
|
};
|
|
3817
3711
|
}, [txHashFromBridge.current]);
|
|
3818
|
-
const checkLayerStatus =
|
|
3712
|
+
const checkLayerStatus = React.useCallback((txHash) => {
|
|
3819
3713
|
const check = async (txHash2) => {
|
|
3820
3714
|
try {
|
|
3821
3715
|
const { messages } = await client.getMessagesBySrcTxHash(txHash2);
|
|
@@ -3847,14 +3741,14 @@ var useCrossSwap = () => {
|
|
|
3847
3741
|
};
|
|
3848
3742
|
check(txHash);
|
|
3849
3743
|
}, []);
|
|
3850
|
-
|
|
3744
|
+
React.useEffect(() => {
|
|
3851
3745
|
return () => {
|
|
3852
3746
|
if (timer.current) {
|
|
3853
3747
|
clearTimeout(timer.current);
|
|
3854
3748
|
}
|
|
3855
3749
|
};
|
|
3856
3750
|
}, []);
|
|
3857
|
-
const dstValutDeposit =
|
|
3751
|
+
const dstValutDeposit = React.useCallback(() => {
|
|
3858
3752
|
return {
|
|
3859
3753
|
accountId: account5.accountIdHashStr,
|
|
3860
3754
|
brokerHash: core.utils.parseBrokerHash(configStore.get("brokerId")),
|
|
@@ -4190,13 +4084,13 @@ var woofiDexDepositorAbi = [
|
|
|
4190
4084
|
var useSwap = () => {
|
|
4191
4085
|
const [loading, { setTrue: start, setFalse: stop }] = useBoolean(false);
|
|
4192
4086
|
const account5 = useAccountInstance();
|
|
4193
|
-
const { configStore } =
|
|
4194
|
-
const [status, setStatus] =
|
|
4087
|
+
const { configStore } = React.useContext(OrderlyContext);
|
|
4088
|
+
const [status, setStatus] = React.useState(
|
|
4195
4089
|
types.WS_WalletStatusEnum.NO
|
|
4196
4090
|
);
|
|
4197
|
-
const txHash =
|
|
4091
|
+
const txHash = React.useRef();
|
|
4198
4092
|
const ee = useEventEmitter();
|
|
4199
|
-
|
|
4093
|
+
React.useEffect(() => {
|
|
4200
4094
|
const handler = (data) => {
|
|
4201
4095
|
const { side, transStatus, trxId } = data;
|
|
4202
4096
|
if (side === "DEPOSIT" && trxId === txHash.current) {
|
|
@@ -4208,7 +4102,7 @@ var useSwap = () => {
|
|
|
4208
4102
|
ee.off("wallet:changed", handler);
|
|
4209
4103
|
};
|
|
4210
4104
|
}, [txHash.current]);
|
|
4211
|
-
const dstValutDeposit =
|
|
4105
|
+
const dstValutDeposit = React.useCallback(() => {
|
|
4212
4106
|
const brokerId = configStore.get("brokerId");
|
|
4213
4107
|
return {
|
|
4214
4108
|
accountId: account5.accountIdHashStr,
|
|
@@ -4216,7 +4110,7 @@ var useSwap = () => {
|
|
|
4216
4110
|
tokenHash: core.utils.parseTokenHash("USDC")
|
|
4217
4111
|
};
|
|
4218
4112
|
}, [account5]);
|
|
4219
|
-
const swap =
|
|
4113
|
+
const swap = React.useCallback(
|
|
4220
4114
|
async (woofiDexDepositorAdress, inputs, config) => {
|
|
4221
4115
|
if (!account5.walletClient) {
|
|
4222
4116
|
throw new Error("walletClient is undefined");
|
|
@@ -4268,17 +4162,14 @@ Object.defineProperty(exports, 'useSWR', {
|
|
|
4268
4162
|
});
|
|
4269
4163
|
Object.defineProperty(exports, 'useConstant', {
|
|
4270
4164
|
enumerable: true,
|
|
4271
|
-
get: function () { return
|
|
4165
|
+
get: function () { return useConstant4__default.default; }
|
|
4272
4166
|
});
|
|
4273
|
-
exports.
|
|
4167
|
+
exports.OrderlyConfigProvider = OrderlyConfigProvider;
|
|
4274
4168
|
exports.OrderlyContext = OrderlyContext;
|
|
4275
4169
|
exports.OrderlyProvider = OrderlyProvider;
|
|
4276
|
-
exports.apis = apis_exports;
|
|
4277
4170
|
exports.useAccount = useAccount;
|
|
4278
4171
|
exports.useAccountInfo = useAccountInfo;
|
|
4279
4172
|
exports.useAccountInstance = useAccountInstance;
|
|
4280
|
-
exports.useAppState = useAppState;
|
|
4281
|
-
exports.useBalance = useBalance;
|
|
4282
4173
|
exports.useBoolean = useBoolean;
|
|
4283
4174
|
exports.useChain = useChain;
|
|
4284
4175
|
exports.useChains = useChains;
|
|
@@ -4287,7 +4178,6 @@ exports.useConfig = useConfig;
|
|
|
4287
4178
|
exports.useCrossSwap = useCrossSwap;
|
|
4288
4179
|
exports.useDeposit = useDeposit;
|
|
4289
4180
|
exports.useEventEmitter = useEventEmitter;
|
|
4290
|
-
exports.useFetures = useFetures;
|
|
4291
4181
|
exports.useFundingRate = useFundingRate;
|
|
4292
4182
|
exports.useHoldingStream = useHoldingStream;
|
|
4293
4183
|
exports.useIndexPrice = useIndexPrice;
|
|
@@ -4301,7 +4191,6 @@ exports.useMarketTradeStream = useMarketTradeStream;
|
|
|
4301
4191
|
exports.useMarketsStream = useMarketsStream;
|
|
4302
4192
|
exports.useMaxQty = useMaxQty;
|
|
4303
4193
|
exports.useMutation = useMutation;
|
|
4304
|
-
exports.useOpenInterest = useOpenInterest;
|
|
4305
4194
|
exports.useOrderEntry = useOrderEntry;
|
|
4306
4195
|
exports.useOrderStream = useOrderStream;
|
|
4307
4196
|
exports.useOrderbookStream = useOrderbookStream;
|
|
@@ -4310,15 +4199,11 @@ exports.usePreLoadData = usePreLoadData;
|
|
|
4310
4199
|
exports.usePrivateDataObserver = usePrivateDataObserver;
|
|
4311
4200
|
exports.usePrivateQuery = usePrivateQuery;
|
|
4312
4201
|
exports.useQuery = useQuery;
|
|
4313
|
-
exports.useRunOnce = useRunOnce;
|
|
4314
4202
|
exports.useSessionStorage = useSessionStorage;
|
|
4315
4203
|
exports.useSettleSubscription = useSettleSubscription;
|
|
4316
4204
|
exports.useSwap = useSwap;
|
|
4317
4205
|
exports.useSymbolsInfo = useSymbolsInfo;
|
|
4318
4206
|
exports.useTickerStream = useTickerStream;
|
|
4319
|
-
exports.useTokenInfo = useTokenInfo;
|
|
4320
|
-
exports.useTopicObserve = useTopicObserve;
|
|
4321
|
-
exports.useTradingView = useTradingView;
|
|
4322
4207
|
exports.useWS = useWS;
|
|
4323
4208
|
exports.useWalletSubscription = useWalletSubscription;
|
|
4324
4209
|
exports.useWithdraw = useWithdraw;
|