revert trade history api changes

This commit is contained in:
tjs 2022-02-10 10:05:06 -05:00
parent bd1a14224b
commit 9248782932
1 changed files with 11 additions and 27 deletions

View File

@ -522,28 +522,14 @@ const useMangoStore = create<MangoStore>((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<MangoStore>((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