@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.mjs
CHANGED
|
@@ -36,9 +36,9 @@ var __export = (target, all) => {
|
|
|
36
36
|
// src/version.ts
|
|
37
37
|
if (typeof window !== "undefined") {
|
|
38
38
|
window.__ORDERLY_VERSION__ = window.__ORDERLY_VERSION__ || {};
|
|
39
|
-
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.
|
|
39
|
+
window.__ORDERLY_VERSION__["@orderly.network/hooks"] = "2.5.3-alpha.0";
|
|
40
40
|
}
|
|
41
|
-
var version_default = "2.5.
|
|
41
|
+
var version_default = "2.5.3-alpha.0";
|
|
42
42
|
var fetcher = (url, init2 = {}, queryOptions) => get(url, init2, queryOptions?.formatter);
|
|
43
43
|
var OrderlyContext = createContext({
|
|
44
44
|
// configStore: new MemoryConfigStore(),
|
|
@@ -295,7 +295,7 @@ var useWS = () => {
|
|
|
295
295
|
if ((nextState.status === AccountStatusEnum.EnableTrading || nextState.status === AccountStatusEnum.EnableTradingWithoutConnected) && account9.accountId) {
|
|
296
296
|
websocketClient.openPrivate(account9.accountId);
|
|
297
297
|
} else {
|
|
298
|
-
websocketClient.closePrivate(
|
|
298
|
+
websocketClient.closePrivate(3887, "switch account");
|
|
299
299
|
}
|
|
300
300
|
});
|
|
301
301
|
if (typeof window !== "undefined") {
|
|
@@ -349,7 +349,7 @@ var useAccount = () => {
|
|
|
349
349
|
const ws = useWS();
|
|
350
350
|
const switchAccount = useCallback(
|
|
351
351
|
async (accountId) => {
|
|
352
|
-
ws.closePrivate(
|
|
352
|
+
ws.closePrivate(3887, "switch account");
|
|
353
353
|
return account9.switchAccount(accountId);
|
|
354
354
|
},
|
|
355
355
|
[account9]
|
|
@@ -749,8 +749,10 @@ function useWsStatus() {
|
|
|
749
749
|
}
|
|
750
750
|
}
|
|
751
751
|
});
|
|
752
|
-
return () =>
|
|
753
|
-
|
|
752
|
+
return () => {
|
|
753
|
+
ws.off("status:change", () => {
|
|
754
|
+
});
|
|
755
|
+
};
|
|
754
756
|
}, []);
|
|
755
757
|
return wsStatus;
|
|
756
758
|
}
|
|
@@ -4557,13 +4559,15 @@ var useHoldingStream = () => {
|
|
|
4557
4559
|
|
|
4558
4560
|
// src/orderly/useMaxWithdrawal.ts
|
|
4559
4561
|
var { maxWithdrawalUSDC, maxWithdrawalOtherCollateral, collateralRatio: collateralRatio2 } = account;
|
|
4560
|
-
|
|
4562
|
+
var useMaxWithdrawal = (token) => {
|
|
4561
4563
|
const { unsettledPnL, freeCollateral } = useCollateral();
|
|
4562
4564
|
const tokenInfo = useTokenInfo(token);
|
|
4563
4565
|
const { data: indexPrices } = useIndexPricesStream();
|
|
4564
4566
|
const { usdc, data: holdings = [] } = useHoldingStream();
|
|
4565
4567
|
const holding = useMemo(() => {
|
|
4566
|
-
return holdings
|
|
4568
|
+
return holdings.find(
|
|
4569
|
+
(item) => item.token?.toUpperCase() === token.toUpperCase()
|
|
4570
|
+
);
|
|
4567
4571
|
}, [holdings, token]);
|
|
4568
4572
|
const usdcBalance = usdc?.holding ?? 0;
|
|
4569
4573
|
const indexPrice = useMemo(() => {
|
|
@@ -4583,8 +4587,11 @@ function useMaxWithdrawal(token) {
|
|
|
4583
4587
|
collateralCap: tokenInfo?.user_max_qty ?? holdingQty,
|
|
4584
4588
|
indexPrice
|
|
4585
4589
|
});
|
|
4586
|
-
}, [
|
|
4590
|
+
}, [tokenInfo, indexPrice, holding]);
|
|
4587
4591
|
const maxAmount = useMemo(() => {
|
|
4592
|
+
if (!token) {
|
|
4593
|
+
return 0;
|
|
4594
|
+
}
|
|
4588
4595
|
if (token === "USDC") {
|
|
4589
4596
|
return maxWithdrawalUSDC({
|
|
4590
4597
|
USDCBalance: usdcBalance,
|
|
@@ -4603,19 +4610,17 @@ function useMaxWithdrawal(token) {
|
|
|
4603
4610
|
freeCollateral,
|
|
4604
4611
|
unsettledPnL,
|
|
4605
4612
|
memoizedCollateralRatio,
|
|
4606
|
-
holdings,
|
|
4607
4613
|
indexPrice,
|
|
4608
4614
|
token,
|
|
4609
4615
|
holding
|
|
4610
4616
|
]);
|
|
4611
4617
|
return maxAmount;
|
|
4612
|
-
}
|
|
4618
|
+
};
|
|
4613
4619
|
|
|
4614
4620
|
// src/orderly/useWithdraw.ts
|
|
4615
4621
|
var useWithdraw = (options) => {
|
|
4616
|
-
const { srcChainId, token, decimals } = options;
|
|
4622
|
+
const { srcChainId, token = "", decimals } = options;
|
|
4617
4623
|
const { account: account9, state } = useAccount();
|
|
4618
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
4619
4624
|
const { unsettledPnL, availableBalance, freeCollateral } = useCollateral();
|
|
4620
4625
|
const networkId = useConfig("networkId");
|
|
4621
4626
|
const [_, { findByChainId }] = useChains(void 0);
|
|
@@ -4675,12 +4680,16 @@ var useWithdraw = (options) => {
|
|
|
4675
4680
|
throw err;
|
|
4676
4681
|
});
|
|
4677
4682
|
},
|
|
4678
|
-
[
|
|
4683
|
+
[
|
|
4684
|
+
account9.assetsManager,
|
|
4685
|
+
decimals,
|
|
4686
|
+
state?.connectWallet?.name,
|
|
4687
|
+
targetChain?.network_infos.name
|
|
4688
|
+
]
|
|
4679
4689
|
);
|
|
4680
4690
|
return {
|
|
4681
4691
|
dst,
|
|
4682
4692
|
withdraw,
|
|
4683
|
-
isLoading,
|
|
4684
4693
|
maxAmount,
|
|
4685
4694
|
unsettledPnL,
|
|
4686
4695
|
availableBalance,
|
|
@@ -4698,6 +4707,7 @@ var useDeposit = (options) => {
|
|
|
4698
4707
|
const [depositFeeRevalidating, setDepositFeeRevalidating] = useState(false);
|
|
4699
4708
|
const [balance, setBalance] = useState("0");
|
|
4700
4709
|
const [allowance, setAllowance] = useState("0");
|
|
4710
|
+
const balanceRef = useRef("");
|
|
4701
4711
|
const { account: account9, state } = useAccount();
|
|
4702
4712
|
const { track: track2 } = useTrack();
|
|
4703
4713
|
const prevAddress = useRef();
|
|
@@ -4746,19 +4756,6 @@ var useDeposit = (options) => {
|
|
|
4746
4756
|
},
|
|
4747
4757
|
[]
|
|
4748
4758
|
);
|
|
4749
|
-
const fetchBalance = useCallback(
|
|
4750
|
-
async (address, decimals) => {
|
|
4751
|
-
if (!address)
|
|
4752
|
-
return;
|
|
4753
|
-
try {
|
|
4754
|
-
const balance2 = await fetchBalanceHandler(address, decimals);
|
|
4755
|
-
setBalance(() => balance2);
|
|
4756
|
-
} catch (e) {
|
|
4757
|
-
setBalance(() => "0");
|
|
4758
|
-
}
|
|
4759
|
-
},
|
|
4760
|
-
[state]
|
|
4761
|
-
);
|
|
4762
4759
|
const fetchBalances = useCallback(async (tokens) => {
|
|
4763
4760
|
const tasks = [];
|
|
4764
4761
|
for (const token of tokens) {
|
|
@@ -4826,7 +4823,8 @@ var useDeposit = (options) => {
|
|
|
4826
4823
|
]);
|
|
4827
4824
|
const queryBalance = useDebouncedCallback(
|
|
4828
4825
|
(address, decimals) => {
|
|
4829
|
-
|
|
4826
|
+
fetchBalanceHandler(address, decimals).then((balance2) => {
|
|
4827
|
+
setBalance(balance2);
|
|
4830
4828
|
setBalanceRevalidating(false);
|
|
4831
4829
|
});
|
|
4832
4830
|
},
|
|
@@ -4971,11 +4969,14 @@ var useDeposit = (options) => {
|
|
|
4971
4969
|
isNativeToken,
|
|
4972
4970
|
vaultAddress
|
|
4973
4971
|
]);
|
|
4974
|
-
const loopGetBalance = async () => {
|
|
4972
|
+
const loopGetBalance = async (timeout) => {
|
|
4975
4973
|
if (getBalanceListener.current) {
|
|
4976
4974
|
clearTimeout(getBalanceListener.current);
|
|
4977
4975
|
}
|
|
4978
|
-
const time = account9.walletAdapter?.chainNamespace === ChainNamespace.solana ? 1e4 : 3e3;
|
|
4976
|
+
const time = timeout ?? (account9.walletAdapter?.chainNamespace === ChainNamespace.solana ? 1e4 : 3e3);
|
|
4977
|
+
if (balanceRef.current === "") {
|
|
4978
|
+
setBalanceRevalidating(true);
|
|
4979
|
+
}
|
|
4979
4980
|
getBalanceListener.current = setTimeout(async () => {
|
|
4980
4981
|
try {
|
|
4981
4982
|
const balance2 = await fetchBalanceHandler(
|
|
@@ -4983,8 +4984,14 @@ var useDeposit = (options) => {
|
|
|
4983
4984
|
options.decimals
|
|
4984
4985
|
);
|
|
4985
4986
|
setBalance(balance2);
|
|
4987
|
+
balanceRef.current = balance2;
|
|
4986
4988
|
loopGetBalance();
|
|
4987
4989
|
} catch (err) {
|
|
4990
|
+
loopGetBalance(1e3);
|
|
4991
|
+
} finally {
|
|
4992
|
+
if (balanceRef.current !== "") {
|
|
4993
|
+
setBalanceRevalidating(false);
|
|
4994
|
+
}
|
|
4988
4995
|
}
|
|
4989
4996
|
}, time);
|
|
4990
4997
|
};
|
|
@@ -5024,7 +5031,7 @@ var useDeposit = (options) => {
|
|
|
5024
5031
|
if (!options.address) {
|
|
5025
5032
|
return;
|
|
5026
5033
|
}
|
|
5027
|
-
loopGetBalance();
|
|
5034
|
+
loopGetBalance(0);
|
|
5028
5035
|
return () => {
|
|
5029
5036
|
if (getBalanceListener.current) {
|
|
5030
5037
|
clearTimeout(getBalanceListener.current);
|
|
@@ -5140,7 +5147,7 @@ var useSubAccountMutation = (url, method = "POST", options) => {
|
|
|
5140
5147
|
|
|
5141
5148
|
// src/orderly/useTransfer.ts
|
|
5142
5149
|
var useTransfer = (options) => {
|
|
5143
|
-
const { fromAccountId, token } = options || {};
|
|
5150
|
+
const { fromAccountId, token = "" } = options || {};
|
|
5144
5151
|
const { unsettledPnL, holding } = useCollateral();
|
|
5145
5152
|
const [doTransfer, { isMutating: submitting }] = useSubAccountMutation(
|
|
5146
5153
|
"/v1/internal_transfer",
|
|
@@ -7006,7 +7013,7 @@ var useSubAccountWS = (options) => {
|
|
|
7006
7013
|
websocketClient.current.openPrivate(accountId);
|
|
7007
7014
|
}
|
|
7008
7015
|
return () => {
|
|
7009
|
-
websocketClient.current.closePrivate(
|
|
7016
|
+
websocketClient.current.closePrivate(3887, "switch account");
|
|
7010
7017
|
};
|
|
7011
7018
|
}, [accountId, state.status]);
|
|
7012
7019
|
return websocketClient.current;
|