From 92487829326085a5f7addb267d2a6c3517f461e2 Mon Sep 17 00:00:00 2001 From: tjs Date: Thu, 10 Feb 2022 10:05:06 -0500 Subject: [PATCH] revert trade history api changes --- stores/useMangoStore.tsx | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/stores/useMangoStore.tsx b/stores/useMangoStore.tsx index b6d49deb..55616589 100644 --- a/stores/useMangoStore.tsx +++ b/stores/useMangoStore.tsx @@ -522,28 +522,14 @@ const useMangoStore = create((set, get) => { const set = get().set if (!selectedMangoAccount) return - fetch( - `https://event-history-api.herokuapp.com/perp_trades/${selectedMangoAccount.publicKey.toString()}` - ) - .then((response) => response.json()) - .then((jsonPerpHistory) => { - const perpHistory = jsonPerpHistory?.data || [] - - set((state) => { - state.tradeHistory = [...state.tradeHistory, ...perpHistory] - }) - }) - .catch((e) => { - console.error('Error fetching trade history', e) - }) - + let serumTradeHistory = [] if (selectedMangoAccount.spotOpenOrdersAccounts.length) { const openOrdersAccounts = selectedMangoAccount.spotOpenOrdersAccounts.filter(isDefined) const publicKeys = openOrdersAccounts.map((act) => act.publicKey.toString() ) - Promise.all( + serumTradeHistory = await Promise.all( publicKeys.map(async (pk) => { const response = await fetch( `https://event-history-api.herokuapp.com/trades/open_orders/${pk.toString()}` @@ -552,18 +538,16 @@ const useMangoStore = create((set, get) => { return parsedResponse?.data ? parsedResponse.data : [] }) ) - .then((serumTradeHistory) => { - set((state) => { - state.tradeHistory = [ - ...serumTradeHistory, - ...state.tradeHistory, - ] - }) - }) - .catch((e) => { - console.error('Error fetching trade history', e) - }) } + const perpHistory = await fetch( + `https://event-history-api.herokuapp.com/perp_trades/${selectedMangoAccount.publicKey.toString()}` + ) + let parsedPerpHistory = await perpHistory.json() + parsedPerpHistory = parsedPerpHistory?.data || [] + + set((state) => { + state.tradeHistory = [...serumTradeHistory, ...parsedPerpHistory] + }) }, async reloadMangoAccount() { const set = get().set