@orderly.network/hooks 2.5.2 → 2.5.3-alpha.0
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 +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +41 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -34
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -32,7 +32,7 @@ declare global {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
declare const _default: "2.5.
|
|
35
|
+
declare const _default: "2.5.3-alpha.0";
|
|
36
36
|
|
|
37
37
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
38
38
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -866,13 +866,13 @@ declare const useChain: (token: string) => {
|
|
|
866
866
|
isLoading: boolean;
|
|
867
867
|
};
|
|
868
868
|
|
|
869
|
-
type UseWithdrawOptions
|
|
869
|
+
type UseWithdrawOptions = {
|
|
870
870
|
srcChainId?: number;
|
|
871
871
|
token?: string;
|
|
872
872
|
/** orderly token decimals */
|
|
873
873
|
decimals?: number;
|
|
874
874
|
};
|
|
875
|
-
declare const useWithdraw: (options: UseWithdrawOptions
|
|
875
|
+
declare const useWithdraw: (options: UseWithdrawOptions) => {
|
|
876
876
|
dst: {
|
|
877
877
|
symbol: string;
|
|
878
878
|
decimals: number;
|
|
@@ -886,7 +886,6 @@ declare const useWithdraw: (options: UseWithdrawOptions$1) => {
|
|
|
886
886
|
amount: string;
|
|
887
887
|
allowCrossChainWithdraw: boolean;
|
|
888
888
|
}) => Promise<any>;
|
|
889
|
-
isLoading: boolean;
|
|
890
889
|
maxAmount: number;
|
|
891
890
|
unsettledPnL: number;
|
|
892
891
|
availableBalance: number;
|
|
@@ -936,10 +935,10 @@ declare const useDeposit: (options: DepositOptions) => {
|
|
|
936
935
|
setQuantity: react.Dispatch<react.SetStateAction<string>>;
|
|
937
936
|
};
|
|
938
937
|
|
|
939
|
-
interface
|
|
938
|
+
interface ConvertOptions {
|
|
940
939
|
token?: string;
|
|
941
940
|
}
|
|
942
|
-
declare const useConvert: (options:
|
|
941
|
+
declare const useConvert: (options: ConvertOptions) => {
|
|
943
942
|
maxAmount: number;
|
|
944
943
|
convert: (inputs: {
|
|
945
944
|
amount: number;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ declare global {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
declare const _default: "2.5.
|
|
35
|
+
declare const _default: "2.5.3-alpha.0";
|
|
36
36
|
|
|
37
37
|
declare const fetcher: (url: string, init: RequestInit | undefined, queryOptions: useQueryOptions<any>) => Promise<any>;
|
|
38
38
|
type useQueryOptions<T> = SWRConfiguration & {
|
|
@@ -866,13 +866,13 @@ declare const useChain: (token: string) => {
|
|
|
866
866
|
isLoading: boolean;
|
|
867
867
|
};
|
|
868
868
|
|
|
869
|
-
type UseWithdrawOptions
|
|
869
|
+
type UseWithdrawOptions = {
|
|
870
870
|
srcChainId?: number;
|
|
871
871
|
token?: string;
|
|
872
872
|
/** orderly token decimals */
|
|
873
873
|
decimals?: number;
|
|
874
874
|
};
|
|
875
|
-
declare const useWithdraw: (options: UseWithdrawOptions
|
|
875
|
+
declare const useWithdraw: (options: UseWithdrawOptions) => {
|
|
876
876
|
dst: {
|
|
877
877
|
symbol: string;
|
|
878
878
|
decimals: number;
|
|
@@ -886,7 +886,6 @@ declare const useWithdraw: (options: UseWithdrawOptions$1) => {
|
|
|
886
886
|
amount: string;
|
|
887
887
|
allowCrossChainWithdraw: boolean;
|
|
888
888
|
}) => Promise<any>;
|
|
889
|
-
isLoading: boolean;
|
|
890
889
|
maxAmount: number;
|
|
891
890
|
unsettledPnL: number;
|
|
892
891
|
availableBalance: number;
|
|
@@ -936,10 +935,10 @@ declare const useDeposit: (options: DepositOptions) => {
|
|
|
936
935
|
setQuantity: react.Dispatch<react.SetStateAction<string>>;
|
|
937
936
|
};
|
|
938
937
|
|
|
939
|
-
interface
|
|
938
|
+
interface ConvertOptions {
|
|
940
939
|
token?: string;
|
|
941
940
|
}
|
|
942
|
-
declare const useConvert: (options:
|
|
941
|
+
declare const useConvert: (options: ConvertOptions) => {
|
|
943
942
|
maxAmount: number;
|
|
944
943
|
convert: (inputs: {
|
|
945
944
|
amount: number;
|
package/dist/index.js
CHANGED
|
@@ -61,9 +61,9 @@ var __export = (target, all) => {
|
|
|
61
61
|
// src/version.ts
|
|
62
62
|
if (typeof window !== "undefined") {
|
|
63
63
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
64
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.
|
|
64
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.3-alpha.0";
|
|
65
65
|
}
|
|
66
|
-
var version_default = "2.5.
|
|
66
|
+
var version_default = "2.5.3-alpha.0";
|
|
67
67
|
var fetcher = (url, init2 = {}, queryOptions) => net.get(url, init2, queryOptions?.formatter);
|
|
68
68
|
var OrderlyContext = React.createContext({
|
|
69
69
|
// configStore: new MemoryConfigStore(),
|
|
@@ -320,7 +320,7 @@ var useWS = () => {
|
|
|
320
320
|
if ((nextState.status === types.AccountStatusEnum.EnableTrading || nextState.status === types.AccountStatusEnum.EnableTradingWithoutConnected) && account9.accountId) {
|
|
321
321
|
websocketClient.openPrivate(account9.accountId);
|
|
322
322
|
} else {
|
|
323
|
-
websocketClient.closePrivate(
|
|
323
|
+
websocketClient.closePrivate(3887, "switch account");
|
|
324
324
|
}
|
|
325
325
|
});
|
|
326
326
|
if (typeof window !== "undefined") {
|
|
@@ -374,7 +374,7 @@ var useAccount = () => {
|
|
|
374
374
|
const ws = useWS();
|
|
375
375
|
const switchAccount = React.useCallback(
|
|
376
376
|
async (accountId) => {
|
|
377
|
-
ws.closePrivate(
|
|
377
|
+
ws.closePrivate(3887, "switch account");
|
|
378
378
|
return account9.switchAccount(accountId);
|
|
379
379
|
},
|
|
380
380
|
[account9]
|
|
@@ -774,8 +774,10 @@ function useWsStatus() {
|
|
|
774
774
|
}
|
|
775
775
|
}
|
|
776
776
|
});
|
|
777
|
-
return () =>
|
|
778
|
-
|
|
777
|
+
return () => {
|
|
778
|
+
ws.off("status:change", () => {
|
|
779
|
+
});
|
|
780
|
+
};
|
|
779
781
|
}, []);
|
|
780
782
|
return wsStatus;
|
|
781
783
|
}
|
|
@@ -4582,13 +4584,15 @@ var useHoldingStream = () => {
|
|
|
4582
4584
|
|
|
4583
4585
|
// src/orderly/useMaxWithdrawal.ts
|
|
4584
4586
|
var { maxWithdrawalUSDC, maxWithdrawalOtherCollateral, collateralRatio: collateralRatio2 } = perp.account;
|
|
4585
|
-
|
|
4587
|
+
var useMaxWithdrawal = (token) => {
|
|
4586
4588
|
const { unsettledPnL, freeCollateral } = useCollateral();
|
|
4587
4589
|
const tokenInfo = useTokenInfo(token);
|
|
4588
4590
|
const { data: indexPrices } = useIndexPricesStream();
|
|
4589
4591
|
const { usdc, data: holdings = [] } = useHoldingStream();
|
|
4590
4592
|
const holding = React.useMemo(() => {
|
|
4591
|
-
return holdings
|
|
4593
|
+
return holdings.find(
|
|
4594
|
+
(item) => item.token?.toUpperCase() === token.toUpperCase()
|
|
4595
|
+
);
|
|
4592
4596
|
}, [holdings, token]);
|
|
4593
4597
|
const usdcBalance = usdc?.holding ?? 0;
|
|
4594
4598
|
const indexPrice = React.useMemo(() => {
|
|
@@ -4608,8 +4612,11 @@ function useMaxWithdrawal(token) {
|
|
|
4608
4612
|
collateralCap: tokenInfo?.user_max_qty ?? holdingQty,
|
|
4609
4613
|
indexPrice
|
|
4610
4614
|
});
|
|
4611
|
-
}, [
|
|
4615
|
+
}, [tokenInfo, indexPrice, holding]);
|
|
4612
4616
|
const maxAmount = React.useMemo(() => {
|
|
4617
|
+
if (!token) {
|
|
4618
|
+
return 0;
|
|
4619
|
+
}
|
|
4613
4620
|
if (token === "USDC") {
|
|
4614
4621
|
return maxWithdrawalUSDC({
|
|
4615
4622
|
USDCBalance: usdcBalance,
|
|
@@ -4628,19 +4635,17 @@ function useMaxWithdrawal(token) {
|
|
|
4628
4635
|
freeCollateral,
|
|
4629
4636
|
unsettledPnL,
|
|
4630
4637
|
memoizedCollateralRatio,
|
|
4631
|
-
holdings,
|
|
4632
4638
|
indexPrice,
|
|
4633
4639
|
token,
|
|
4634
4640
|
holding
|
|
4635
4641
|
]);
|
|
4636
4642
|
return maxAmount;
|
|
4637
|
-
}
|
|
4643
|
+
};
|
|
4638
4644
|
|
|
4639
4645
|
// src/orderly/useWithdraw.ts
|
|
4640
4646
|
var useWithdraw = (options) => {
|
|
4641
|
-
const { srcChainId, token, decimals } = options;
|
|
4647
|
+
const { srcChainId, token = "", decimals } = options;
|
|
4642
4648
|
const { account: account9, state } = useAccount();
|
|
4643
|
-
const [isLoading, setIsLoading] = React.useState(false);
|
|
4644
4649
|
const { unsettledPnL, availableBalance, freeCollateral } = useCollateral();
|
|
4645
4650
|
const networkId = useConfig("networkId");
|
|
4646
4651
|
const [_, { findByChainId }] = useChains(void 0);
|
|
@@ -4700,12 +4705,16 @@ var useWithdraw = (options) => {
|
|
|
4700
4705
|
throw err;
|
|
4701
4706
|
});
|
|
4702
4707
|
},
|
|
4703
|
-
[
|
|
4708
|
+
[
|
|
4709
|
+
account9.assetsManager,
|
|
4710
|
+
decimals,
|
|
4711
|
+
state?.connectWallet?.name,
|
|
4712
|
+
targetChain?.network_infos.name
|
|
4713
|
+
]
|
|
4704
4714
|
);
|
|
4705
4715
|
return {
|
|
4706
4716
|
dst,
|
|
4707
4717
|
withdraw,
|
|
4708
|
-
isLoading,
|
|
4709
4718
|
maxAmount,
|
|
4710
4719
|
unsettledPnL,
|
|
4711
4720
|
availableBalance,
|
|
@@ -4723,6 +4732,7 @@ var useDeposit = (options) => {
|
|
|
4723
4732
|
const [depositFeeRevalidating, setDepositFeeRevalidating] = React.useState(false);
|
|
4724
4733
|
const [balance, setBalance] = React.useState("0");
|
|
4725
4734
|
const [allowance, setAllowance] = React.useState("0");
|
|
4735
|
+
const balanceRef = React.useRef("");
|
|
4726
4736
|
const { account: account9, state } = useAccount();
|
|
4727
4737
|
const { track: track2 } = useTrack();
|
|
4728
4738
|
const prevAddress = React.useRef();
|
|
@@ -4771,19 +4781,6 @@ var useDeposit = (options) => {
|
|
|
4771
4781
|
},
|
|
4772
4782
|
[]
|
|
4773
4783
|
);
|
|
4774
|
-
const fetchBalance = React.useCallback(
|
|
4775
|
-
async (address, decimals) => {
|
|
4776
|
-
if (!address)
|
|
4777
|
-
return;
|
|
4778
|
-
try {
|
|
4779
|
-
const balance2 = await fetchBalanceHandler(address, decimals);
|
|
4780
|
-
setBalance(() => balance2);
|
|
4781
|
-
} catch (e) {
|
|
4782
|
-
setBalance(() => "0");
|
|
4783
|
-
}
|
|
4784
|
-
},
|
|
4785
|
-
[state]
|
|
4786
|
-
);
|
|
4787
4784
|
const fetchBalances = React.useCallback(async (tokens) => {
|
|
4788
4785
|
const tasks = [];
|
|
4789
4786
|
for (const token of tokens) {
|
|
@@ -4851,7 +4848,8 @@ var useDeposit = (options) => {
|
|
|
4851
4848
|
]);
|
|
4852
4849
|
const queryBalance = useDebounce.useDebouncedCallback(
|
|
4853
4850
|
(address, decimals) => {
|
|
4854
|
-
|
|
4851
|
+
fetchBalanceHandler(address, decimals).then((balance2) => {
|
|
4852
|
+
setBalance(balance2);
|
|
4855
4853
|
setBalanceRevalidating(false);
|
|
4856
4854
|
});
|
|
4857
4855
|
},
|
|
@@ -4996,11 +4994,14 @@ var useDeposit = (options) => {
|
|
|
4996
4994
|
isNativeToken,
|
|
4997
4995
|
vaultAddress
|
|
4998
4996
|
]);
|
|
4999
|
-
const loopGetBalance = async () => {
|
|
4997
|
+
const loopGetBalance = async (timeout) => {
|
|
5000
4998
|
if (getBalanceListener.current) {
|
|
5001
4999
|
clearTimeout(getBalanceListener.current);
|
|
5002
5000
|
}
|
|
5003
|
-
const time = account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3;
|
|
5001
|
+
const time = timeout ?? (account9.walletAdapter?.chainNamespace === types.ChainNamespace.solana ? 1e4 : 3e3);
|
|
5002
|
+
if (balanceRef.current === "") {
|
|
5003
|
+
setBalanceRevalidating(true);
|
|
5004
|
+
}
|
|
5004
5005
|
getBalanceListener.current = setTimeout(async () => {
|
|
5005
5006
|
try {
|
|
5006
5007
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -5008,8 +5009,14 @@ var useDeposit = (options) => {
|
|
|
5008
5009
|
options.decimals
|
|
5009
5010
|
);
|
|
5010
5011
|
setBalance(balance2);
|
|
5012
|
+
balanceRef.current = balance2;
|
|
5011
5013
|
loopGetBalance();
|
|
5012
5014
|
} catch (err) {
|
|
5015
|
+
loopGetBalance(1e3);
|
|
5016
|
+
} finally {
|
|
5017
|
+
if (balanceRef.current !== "") {
|
|
5018
|
+
setBalanceRevalidating(false);
|
|
5019
|
+
}
|
|
5013
5020
|
}
|
|
5014
5021
|
}, time);
|
|
5015
5022
|
};
|
|
@@ -5049,7 +5056,7 @@ var useDeposit = (options) => {
|
|
|
5049
5056
|
if (!options.address) {
|
|
5050
5057
|
return;
|
|
5051
5058
|
}
|
|
5052
|
-
loopGetBalance();
|
|
5059
|
+
loopGetBalance(0);
|
|
5053
5060
|
return () => {
|
|
5054
5061
|
if (getBalanceListener.current) {
|
|
5055
5062
|
clearTimeout(getBalanceListener.current);
|
|
@@ -5165,7 +5172,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
|
|
|
5165
5172
|
|
|
5166
5173
|
// src/orderly/useTransfer.ts
|
|
5167
5174
|
var useTransfer = (options) => {
|
|
5168
|
-
const { fromAccountId, token } = options || {};
|
|
5175
|
+
const { fromAccountId, token = "" } = options || {};
|
|
5169
5176
|
const { unsettledPnL, holding } = useCollateral();
|
|
5170
5177
|
const [doTransfer, { isMutating: submitting }] = useSubAccountMutation(
|
|
5171
5178
|
"/v1/internal_transfer",
|
|
@@ -7031,7 +7038,7 @@ var useSubAccountWS = (options) => {
|
|
|
7031
7038
|
websocketClient.current.openPrivate(accountId);
|
|
7032
7039
|
}
|
|
7033
7040
|
return () => {
|
|
7034
|
-
websocketClient.current.closePrivate(
|
|
7041
|
+
websocketClient.current.closePrivate(3887, "switch account");
|
|
7035
7042
|
};
|
|
7036
7043
|
}, [accountId, state.status]);
|
|
7037
7044
|
return websocketClient.current;
|