From 8d7cf46686eadd248ff87a0be89086c302109b68 Mon Sep 17 00:00:00 2001 From: hxromyhuynh Date: Thu, 8 Jun 2023 16:36:56 +0700 Subject: [PATCH] hotfix: update render data ladder when disconnect --- src/contexts/walletContext.jsx | 9 ++++----- src/utils/trader.js | 32 +++++++++++++++++--------------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/contexts/walletContext.jsx b/src/contexts/walletContext.jsx index 73d5a99..6fe5e78 100644 --- a/src/contexts/walletContext.jsx +++ b/src/contexts/walletContext.jsx @@ -64,8 +64,7 @@ export const WalletProvider = ({ children }) => { const refTimeOutGetLadder = useRef(null); const refTimeOutGetLadderNoneWallet = useRef(null); const refInterValGetLadderNoneWallet = useRef(null); - - // const refTimeOutGetYourFills = useRef(null); + const refIsDisconnect = useRef(true); const refRenderLadder = useRef(); @@ -268,11 +267,12 @@ export const WalletProvider = ({ children }) => { */ const connectWallet = (wallet) => { refRenderLadder.current = null; + refIsDisconnect.current = false; window.clearTimeout(refTimeOutGetLadder.current); traderFunction.connect(`${wallet}`.toLowerCase(), async (data) => { refIsConnect.current = true; setLoading(false); - if (refIsConnect.current) { + if (refIsConnect.current && !refIsDisconnect.current) { window.clearInterval(refInterValGetLadderNoneWallet.current); localStorage.setItem('provider', `${wallet}`.toLowerCase()); setIsContent(true); @@ -295,7 +295,6 @@ export const WalletProvider = ({ children }) => { typeof refRenderLadder.current.getDataLadder === 'function' ) { refRenderLadder.current.getDataLadder((data) => { - // console.log('Δ‘ata', data); if (refIsConnect.current) { setMarkPriceList(data?.markPriceList); setDataLadder(data.ticks); @@ -315,6 +314,7 @@ export const WalletProvider = ({ children }) => { */ const disableConnectWallet = () => { refIsConnect.current = false; + refIsDisconnect.current = true; refRenderLadder.current = null; setIsContent(false); localStorage.removeItem('provider'); @@ -322,7 +322,6 @@ export const WalletProvider = ({ children }) => { setDataOrders([]); setDataPosition([]); setDataMarket([]); - setDataLadder([]); setAccountSelect(''); setUSDBalance(0); setCashBalance(0); diff --git a/src/utils/trader.js b/src/utils/trader.js index 95fc228..dc78d63 100644 --- a/src/utils/trader.js +++ b/src/utils/trader.js @@ -80,22 +80,24 @@ class TraderFunction { async returnDataOrder() { if (this.trader) { const rows = []; - const openOrders = await this.trader.getOpenOrders(); - - openOrders.forEach((order) => { - let side = 'BUY'; - if (!order.isBid) { - side = 'SELL'; - } - rows.push({ - instrument: order.productName, - productIndex: order.productIndex, - id: order.id, - price: order.price, - qty: order.qty, - side: side, + const openOrders = await this.trader?.getOpenOrders?.(); + + if (openOrders) { + openOrders.forEach((order) => { + let side = 'BUY'; + if (!order.isBid) { + side = 'SELL'; + } + rows.push({ + instrument: order.productName, + productIndex: order.productIndex, + id: order.id, + price: order.price, + qty: order.qty, + side: side, + }); }); - }); + } return rows; }