@orderly.network/hooks 0.0.32 → 0.0.34
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +12 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +12 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
2
|
export { SWRConfiguration, default as useSWR } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
-
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter } from '@orderly.network/core';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import react__default, { FC, PropsWithChildren } from 'react';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { WS } from '@orderly.network/net';
|
|
9
|
-
import { OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
9
|
+
import { OrderSide, OrderEntity, API, WSMessage } from '@orderly.network/types';
|
|
10
10
|
import * as swr__internal from 'swr/_internal';
|
|
11
11
|
import * as swr_subscription from 'swr/subscription';
|
|
12
12
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
2
|
export { SWRConfiguration, default as useSWR } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
-
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, WalletAdapter, IContract, EventEmitter } from '@orderly.network/core';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import react__default, { FC, PropsWithChildren } from 'react';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { WS } from '@orderly.network/net';
|
|
9
|
-
import { OrderSide, OrderEntity, API } from '@orderly.network/types';
|
|
9
|
+
import { OrderSide, OrderEntity, API, WSMessage } from '@orderly.network/types';
|
|
10
10
|
import * as swr__internal from 'swr/_internal';
|
|
11
11
|
import * as swr_subscription from 'swr/subscription';
|
|
12
12
|
|
package/dist/index.js
CHANGED
|
@@ -186,7 +186,8 @@ var signatureMiddleware = (useSWRNext) => {
|
|
|
186
186
|
const { apiBaseUrl } = React2.useContext(OrderlyContext);
|
|
187
187
|
return (key, fetcher4, config) => {
|
|
188
188
|
try {
|
|
189
|
-
const extendedFetcher = (
|
|
189
|
+
const extendedFetcher = (args) => __async(void 0, null, function* () {
|
|
190
|
+
let url = Array.isArray(args) ? args[0] : args;
|
|
190
191
|
let account5 = core.SimpleDI.get("account");
|
|
191
192
|
let fullUrl = `${apiBaseUrl}${url}`;
|
|
192
193
|
const signer = account5.signer;
|
|
@@ -280,7 +281,7 @@ var usePrivateQuery = (query, options) => {
|
|
|
280
281
|
const account5 = useAccount();
|
|
281
282
|
const middleware = Array.isArray(options == null ? void 0 : options.use) ? (_b = options == null ? void 0 : options.use) != null ? _b : [] : [];
|
|
282
283
|
return useSWR__default.default(
|
|
283
|
-
() => account5.state.status >= types.AccountStatusEnum.EnableTrading ? query : null,
|
|
284
|
+
() => account5.state.status >= types.AccountStatusEnum.EnableTrading ? [query, account5.state.accountId] : null,
|
|
284
285
|
// query,
|
|
285
286
|
(url, init) => {
|
|
286
287
|
return fetcher(url, init, { formatter });
|
|
@@ -687,6 +688,8 @@ var mergeItems = (data, update) => {
|
|
|
687
688
|
const [price, quantity] = item;
|
|
688
689
|
const index = data.findIndex(([p], index2) => p === price);
|
|
689
690
|
if (index === -1) {
|
|
691
|
+
if (quantity === 0)
|
|
692
|
+
continue;
|
|
690
693
|
data.push(item);
|
|
691
694
|
} else {
|
|
692
695
|
if (quantity === 0) {
|
|
@@ -1020,6 +1023,7 @@ var parseHolding = (holding, markPrices) => {
|
|
|
1020
1023
|
var usePositionStream = (symbol, options) => {
|
|
1021
1024
|
var _a;
|
|
1022
1025
|
const symbolInfo = useSymbolsInfo();
|
|
1026
|
+
useAccount();
|
|
1023
1027
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1024
1028
|
const { data: holding } = usePrivateQuery(
|
|
1025
1029
|
"/v1/client/holding",
|
|
@@ -1033,7 +1037,9 @@ var usePositionStream = (symbol, options) => {
|
|
|
1033
1037
|
const { data, error } = usePrivateQuery(`/v1/positions`, __spreadProps(__spreadValues({
|
|
1034
1038
|
// revalidateOnFocus: false,
|
|
1035
1039
|
// revalidateOnReconnect: false,
|
|
1036
|
-
dedupingInterval: 5e3
|
|
1040
|
+
dedupingInterval: 5e3,
|
|
1041
|
+
keepPreviousData: false,
|
|
1042
|
+
revalidateIfStale: true
|
|
1037
1043
|
}, options), {
|
|
1038
1044
|
formatter: (data2) => data2,
|
|
1039
1045
|
onError: (err) => {
|
|
@@ -1044,10 +1050,8 @@ var usePositionStream = (symbol, options) => {
|
|
|
1044
1050
|
const formatedPositions = React2.useMemo(() => {
|
|
1045
1051
|
if (!(data == null ? void 0 : data.rows) || !symbolInfo || !accountInfo)
|
|
1046
1052
|
return null;
|
|
1047
|
-
const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows.filter((item) => {
|
|
1048
|
-
return item.
|
|
1049
|
-
}) : data.rows.filter((item) => {
|
|
1050
|
-
return item.symbol === symbol && item.position_qty !== 0;
|
|
1053
|
+
const filteredData = typeof symbol === "undefined" || symbol === "" ? data.rows : data.rows.filter((item) => {
|
|
1054
|
+
return item.symbol === symbol;
|
|
1051
1055
|
});
|
|
1052
1056
|
let unrealPnL_total = utils.zero, notional_total = utils.zero, unsettlementPnL_total = utils.zero;
|
|
1053
1057
|
const formatted = filteredData.map((item) => {
|
|
@@ -1123,7 +1127,7 @@ var usePositionStream = (symbol, options) => {
|
|
|
1123
1127
|
if (!symbolInfo || !accountInfo)
|
|
1124
1128
|
return formatedPositions[0];
|
|
1125
1129
|
const total = totalCollateral.toNumber();
|
|
1126
|
-
return formatedPositions[0].map((item) => {
|
|
1130
|
+
return formatedPositions[0].filter((item) => item.position_qty !== 0).map((item) => {
|
|
1127
1131
|
const info = symbolInfo == null ? void 0 : symbolInfo[item.symbol];
|
|
1128
1132
|
const MMR = futures.positions.MMR({
|
|
1129
1133
|
baseMMR: info("base_mmr"),
|