@orderly.network/hooks 0.0.38 → 0.0.40
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 +3 -4
- package/dist/index.mjs +42 -17
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
- package/dist/index.d.ts +0 -332
- package/dist/index.js +0 -2109
- package/dist/index.js.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
|
|
2
2
|
export { SWRConfig, SWRConfiguration, default as useSWR } from 'swr';
|
|
3
3
|
import { SWRMutationConfiguration } from 'swr/mutation';
|
|
4
|
-
import { Account, AccountState, ConfigStore, OrderlyKeyStore,
|
|
4
|
+
import { Account, AccountState, ConfigStore, OrderlyKeyStore, getWalletAdapterFunc, 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';
|
|
@@ -71,11 +71,10 @@ interface OrderlyContextState extends OrderlyAppConfig {
|
|
|
71
71
|
klineDataUrl: string;
|
|
72
72
|
configStore: ConfigStore;
|
|
73
73
|
keyStore: OrderlyKeyStore;
|
|
74
|
-
|
|
75
|
-
new (options: any): WalletAdapter;
|
|
76
|
-
};
|
|
74
|
+
getWalletAdapter: getWalletAdapterFunc;
|
|
77
75
|
contractManager: IContract;
|
|
78
76
|
networkId: string;
|
|
77
|
+
brokerId: string;
|
|
79
78
|
onWalletConnect?: () => Promise<any>;
|
|
80
79
|
onWalletDisconnect?: () => Promise<any>;
|
|
81
80
|
onSetChain?: (chainId: number) => Promise<any>;
|
package/dist/index.mjs
CHANGED
|
@@ -6,7 +6,7 @@ import useSWRMutation from 'swr/mutation';
|
|
|
6
6
|
import useConstant from 'use-constant';
|
|
7
7
|
export { default as useConstant } from 'use-constant';
|
|
8
8
|
import { SimpleDI, Account, EventEmitter } from '@orderly.network/core';
|
|
9
|
-
import { AccountStatusEnum, OrderSide, OrderType } from '@orderly.network/types';
|
|
9
|
+
import { AccountStatusEnum, OrderSide, OrderStatus as OrderStatus$1, OrderType } from '@orderly.network/types';
|
|
10
10
|
import useSWRSubscription from 'swr/subscription';
|
|
11
11
|
import { Decimal, zero, getPrecisionByNumber, timeConvertString } from '@orderly.network/utils';
|
|
12
12
|
import { pathOr, propOr, compose, head, prop } from 'ramda';
|
|
@@ -89,7 +89,7 @@ var useQuery = (query, options) => {
|
|
|
89
89
|
);
|
|
90
90
|
};
|
|
91
91
|
var useAccountInstance = () => {
|
|
92
|
-
const { configStore, keyStore, contractManager,
|
|
92
|
+
const { configStore, keyStore, contractManager, getWalletAdapter } = useContext(OrderlyContext);
|
|
93
93
|
if (!configStore)
|
|
94
94
|
throw new Error("configStore is not defined, please use OrderlyProvider");
|
|
95
95
|
if (!keyStore) {
|
|
@@ -104,7 +104,8 @@ var useAccountInstance = () => {
|
|
|
104
104
|
configStore,
|
|
105
105
|
keyStore,
|
|
106
106
|
contractManager,
|
|
107
|
-
|
|
107
|
+
getWalletAdapter
|
|
108
|
+
// walletAdapter
|
|
108
109
|
);
|
|
109
110
|
SimpleDI.registerByName("account", account6);
|
|
110
111
|
}
|
|
@@ -204,8 +205,6 @@ var useAccount = () => {
|
|
|
204
205
|
const {
|
|
205
206
|
configStore,
|
|
206
207
|
keyStore,
|
|
207
|
-
walletAdapter,
|
|
208
|
-
contractManager,
|
|
209
208
|
onWalletConnect,
|
|
210
209
|
onWalletDisconnect,
|
|
211
210
|
onSetChain
|
|
@@ -1195,7 +1194,9 @@ var unsettledPnL = pathOr(0, [0, "aggregated", "unsettledPnL"]);
|
|
|
1195
1194
|
var useCollateral = (options = { dp: 6 }) => {
|
|
1196
1195
|
const { dp } = options;
|
|
1197
1196
|
const positions2 = usePositionStream();
|
|
1198
|
-
const { data: orders } = usePrivateQuery(
|
|
1197
|
+
const { data: orders } = usePrivateQuery(
|
|
1198
|
+
`/v1/orders?status=NEW`
|
|
1199
|
+
);
|
|
1199
1200
|
const { data: accountInfo } = usePrivateQuery("/v1/client/info");
|
|
1200
1201
|
const symbolInfo = useSymbolsInfo();
|
|
1201
1202
|
const { data: markPrices } = useMarkPricesStream();
|
|
@@ -1708,13 +1709,13 @@ var usePrivateInfiniteQuery = (getKey, options) => {
|
|
|
1708
1709
|
);
|
|
1709
1710
|
return result;
|
|
1710
1711
|
};
|
|
1711
|
-
var OrderStatus = /* @__PURE__ */ ((
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
return
|
|
1712
|
+
var OrderStatus = /* @__PURE__ */ ((OrderStatus3) => {
|
|
1713
|
+
OrderStatus3["FILLED"] = "FILLED";
|
|
1714
|
+
OrderStatus3["PARTIAL_FILLED"] = "PARTIAL_FILLED";
|
|
1715
|
+
OrderStatus3["CANCELED"] = "CANCELED";
|
|
1716
|
+
OrderStatus3["NEW"] = "NEW";
|
|
1717
|
+
OrderStatus3["COMPLETED"] = "COMPLETED";
|
|
1718
|
+
return OrderStatus3;
|
|
1718
1719
|
})(OrderStatus || {});
|
|
1719
1720
|
var useOrderStream = ({
|
|
1720
1721
|
status,
|
|
@@ -1940,14 +1941,40 @@ var usePrivateDataObserver = () => {
|
|
|
1940
1941
|
const ee = useEventEmitter();
|
|
1941
1942
|
const { state } = useAccount();
|
|
1942
1943
|
useEffect(() => {
|
|
1943
|
-
console.log("subscribe: executionreport");
|
|
1944
1944
|
const unsubscribe = ws.privateSubscribe("executionreport", {
|
|
1945
1945
|
onMessage: (data) => {
|
|
1946
|
+
const key = ["/v1/orders?status=NEW", state.accountId];
|
|
1947
|
+
mutate2(key, (orders) => {
|
|
1948
|
+
return Promise.resolve().then(() => {
|
|
1949
|
+
if (!orders) {
|
|
1950
|
+
return orders;
|
|
1951
|
+
}
|
|
1952
|
+
if (data.status === OrderStatus$1.NEW) {
|
|
1953
|
+
return [
|
|
1954
|
+
__spreadProps(__spreadValues({}, data), {
|
|
1955
|
+
// average_executed_price:data.ava
|
|
1956
|
+
created_time: data.timestamp,
|
|
1957
|
+
order_id: data.orderId
|
|
1958
|
+
// reduce_only
|
|
1959
|
+
}),
|
|
1960
|
+
...orders
|
|
1961
|
+
];
|
|
1962
|
+
}
|
|
1963
|
+
if (data.status === OrderStatus$1.CANCELLED) {
|
|
1964
|
+
return orders.filter(
|
|
1965
|
+
(order2) => order2.order_id !== data.orderId
|
|
1966
|
+
);
|
|
1967
|
+
}
|
|
1968
|
+
return orders;
|
|
1969
|
+
}).catch((error) => {
|
|
1970
|
+
console.log("error", error, error.stack);
|
|
1971
|
+
});
|
|
1972
|
+
});
|
|
1946
1973
|
ee.emit("orders:changed");
|
|
1947
1974
|
}
|
|
1948
1975
|
});
|
|
1949
1976
|
return () => unsubscribe == null ? void 0 : unsubscribe();
|
|
1950
|
-
}, []);
|
|
1977
|
+
}, [state.accountId]);
|
|
1951
1978
|
useEffect(() => {
|
|
1952
1979
|
console.log("subscribe: position: %s", state.accountId);
|
|
1953
1980
|
if (!state.accountId)
|
|
@@ -1956,9 +1983,7 @@ var usePrivateDataObserver = () => {
|
|
|
1956
1983
|
const unsubscribe = ws.privateSubscribe("position", {
|
|
1957
1984
|
onMessage: (data) => {
|
|
1958
1985
|
const { positions: nextPostions } = data;
|
|
1959
|
-
console.info("refresh positions:", nextPostions, state.accountId);
|
|
1960
1986
|
mutate2(key, (prevPositions) => {
|
|
1961
|
-
console.log("prevPositions:::::", prevPositions);
|
|
1962
1987
|
if (!!prevPositions) {
|
|
1963
1988
|
return __spreadProps(__spreadValues({}, prevPositions), {
|
|
1964
1989
|
rows: prevPositions.rows.map((row) => {
|