fix errors with loading serum oo accounts

This commit is contained in:
tjs 2022-10-27 14:39:43 -04:00
parent 679e44cd63
commit a8b2670a84
1 changed files with 11 additions and 10 deletions

View File

@ -573,6 +573,8 @@ const mangoStore = create<MangoStore>()(
) )
if (!mangoAccounts?.length) return if (!mangoAccounts?.length) return
mangoAccounts.forEach((ma) => ma.reloadAccountData(client))
let newSelectedMangoAccount = selectedMangoAccount let newSelectedMangoAccount = selectedMangoAccount
if (!selectedMangoAccount) { if (!selectedMangoAccount) {
const lastAccount = localStorage.getItem(LAST_ACCOUNT_KEY) const lastAccount = localStorage.getItem(LAST_ACCOUNT_KEY)
@ -587,9 +589,6 @@ const mangoStore = create<MangoStore>()(
} }
if (newSelectedMangoAccount) { if (newSelectedMangoAccount) {
await retryFn(() =>
newSelectedMangoAccount!.reloadAccountData(client)
)
await actions.fetchSerumOpenOrders(newSelectedMangoAccount) await actions.fetchSerumOpenOrders(newSelectedMangoAccount)
} }
@ -638,6 +637,7 @@ const mangoStore = create<MangoStore>()(
try { try {
let openOrders: Record<string, Order[]> = {} let openOrders: Record<string, Order[]> = {}
for (const serum3Orders of mangoAccount.serum3) { for (const serum3Orders of mangoAccount.serum3) {
if (serum3Orders.marketIndex === 65535) continue
const market = group.getSerum3MarketByMarketIndex( const market = group.getSerum3MarketByMarketIndex(
serum3Orders.marketIndex serum3Orders.marketIndex
) )
@ -650,13 +650,14 @@ const mangoStore = create<MangoStore>()(
openOrders[market.serumMarketExternal.toString()] = orders openOrders[market.serumMarketExternal.toString()] = orders
} }
} }
if (Object.keys(openOrders).length) {
const serumOpenOrderAccounts = const serumOpenOrderAccounts =
await mangoAccount.loadSerum3OpenOrdersAccounts(client) await mangoAccount.loadSerum3OpenOrdersAccounts(client)
set((s) => { set((s) => {
s.mangoAccount.openOrders = openOrders s.mangoAccount.openOrders = openOrders
s.mangoAccount.openOrderAccounts = serumOpenOrderAccounts s.mangoAccount.openOrderAccounts = serumOpenOrderAccounts
}) })
}
} catch (e) { } catch (e) {
console.error('Failed loading open orders ', e) console.error('Failed loading open orders ', e)
} }