From 8f27393c22995a2242a885fbbf51473f3a1635bc Mon Sep 17 00:00:00 2001 From: Tyler Shipe Date: Thu, 27 Jan 2022 12:24:15 -0500 Subject: [PATCH] reload open orders more frequently --- components/BalancesTable.tsx | 2 -- hooks/useHydrateStore.tsx | 8 ++++---- public/locales/en/common.json | 2 +- stores/useMangoStore.tsx | 14 ++++++++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/components/BalancesTable.tsx b/components/BalancesTable.tsx index f559cb9b..e3383325 100644 --- a/components/BalancesTable.tsx +++ b/components/BalancesTable.tsx @@ -131,9 +131,7 @@ const BalancesTable = ({ }) } } finally { - actions.reloadMangoAccount() actions.reloadOrders() - setSubmitting(false) } } diff --git a/hooks/useHydrateStore.tsx b/hooks/useHydrateStore.tsx index 1927bff4..4bd9c2dd 100644 --- a/hooks/useHydrateStore.tsx +++ b/hooks/useHydrateStore.tsx @@ -59,21 +59,21 @@ const useHydrateStore = () => { useInterval(() => { if (mangoAccount) { - actions.fetchTradeHistory() actions.reloadOrders() - actions.updateOpenOrders() } - }, 60 * SECONDS) + }, 30 * SECONDS) useInterval(() => { if (mangoAccount) { actions.reloadMangoAccount() - actions.fetchWalletTokens() + actions.fetchTradeHistory() + actions.updateOpenOrders() } }, 90 * SECONDS) useInterval(() => { actions.fetchMangoGroup() + actions.fetchWalletTokens() }, 120 * SECONDS) useEffect(() => { diff --git a/public/locales/en/common.json b/public/locales/en/common.json index d02127c7..771b19a4 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -266,7 +266,7 @@ "perpetual-futures": "Perpetual Futures", "perps": "Perps", "pnl-error": "Error settling PNL", - "pnl-help": "Settling will update your USDC balance to reflect the unsettled PnL amount.", + "pnl-help": "Redeeming will update your USDC balance to reflect the redeemed PnL amount.", "pnl-success": "Successfully settled PNL", "portfolio": "Portfolio", "position": "Position", diff --git a/stores/useMangoStore.tsx b/stores/useMangoStore.tsx index 98e117c1..4ebc0800 100644 --- a/stores/useMangoStore.tsx +++ b/stores/useMangoStore.tsx @@ -366,11 +366,10 @@ const useMangoStore = create((set, get) => { const mangoClient = get().connection.client const wallet = get().wallet.current const actions = get().actions - const walletPk = wallet?.publicKey - if (!walletPk) return + if (!wallet?.publicKey || !mangoGroup) return return mangoClient - .getMangoAccountsForOwner(mangoGroup, walletPk, true) + .getMangoAccountsForOwner(mangoGroup, wallet?.publicKey, true) .then((mangoAccounts) => { if (mangoAccounts.length > 0) { const sortedAccounts = mangoAccounts @@ -566,16 +565,23 @@ const useMangoStore = create((set, get) => { } }, async reloadOrders() { + const set = get().set const mangoAccount = get().selectedMangoAccount.current const connection = get().connection.current if (mangoAccount) { - await Promise.all([ + const [spotOpenOrdersAccounts, advancedOrders] = await Promise.all([ mangoAccount.loadOpenOrders( connection, new PublicKey(serumProgramId) ), mangoAccount.loadAdvancedOrders(connection), ]) + mangoAccount.spotOpenOrdersAccounts = spotOpenOrdersAccounts + mangoAccount.advancedOrders = advancedOrders + set((state) => { + state.selectedMangoAccount.current = mangoAccount + state.selectedMangoAccount.lastUpdatedAt = new Date().toISOString() + }) } }, async updateOpenOrders() {