From 724bb77ef4c2edb1515bec5f69b8efe8f9fe9d5c Mon Sep 17 00:00:00 2001 From: Maximilian Schneider Date: Thu, 23 Sep 2021 22:52:16 +0200 Subject: [PATCH] fetch open orders on wallet connect --- hooks/useWallet.tsx | 1 + stores/useMangoStore.tsx | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/hooks/useWallet.tsx b/hooks/useWallet.tsx index a261ec82..979bab06 100644 --- a/hooks/useWallet.tsx +++ b/hooks/useWallet.tsx @@ -104,6 +104,7 @@ export default function useWallet() { }) // set connected before fetching data await actions.fetchMangoAccounts() + actions.reloadOrders() actions.fetchTradeHistory() actions.fetchWalletTokens() notify({ diff --git a/stores/useMangoStore.tsx b/stores/useMangoStore.tsx index e930b0e8..e504f82f 100644 --- a/stores/useMangoStore.tsx +++ b/stores/useMangoStore.tsx @@ -440,7 +440,15 @@ const useMangoStore = create((set, get) => { const connection = get().connection.current const reloadedMangoAccount = await mangoAccount.reload(connection) + await get().actions.reloadOrders() + set((state) => { + state.selectedMangoAccount.current = reloadedMangoAccount + }) + }, + async reloadOrders() { + const mangoAccount = get().selectedMangoAccount.current + const connection = get().connection.current await Promise.all([ mangoAccount.loadOpenOrders( connection, @@ -448,10 +456,6 @@ const useMangoStore = create((set, get) => { ), mangoAccount.loadAdvancedOrders(connection), ]) - - set((state) => { - state.selectedMangoAccount.current = reloadedMangoAccount - }) }, // DEPRECATED async _updateOpenOrders() {