Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotfix: update render data ladder when disconnect #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/contexts/walletContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -315,14 +314,14 @@ export const WalletProvider = ({ children }) => {
*/
const disableConnectWallet = () => {
refIsConnect.current = false;
refIsDisconnect.current = true;
refRenderLadder.current = null;
setIsContent(false);
localStorage.removeItem('provider');
setDataPnL({});
setDataOrders([]);
setDataPosition([]);
setDataMarket([]);
setDataLadder([]);
setAccountSelect('');
setUSDBalance(0);
setCashBalance(0);
Expand Down
32 changes: 17 additions & 15 deletions src/utils/trader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down