remove unnecessary group refetching; faster sub account switching

This commit is contained in:
tjs 2022-12-03 16:56:22 -05:00
parent 6b55d1346a
commit 23d406ec47
2 changed files with 9 additions and 3 deletions

View File

@ -19,6 +19,7 @@ import { EnterRightExitLeft } from '@components/shared/Transitions'
import { useRouter } from 'next/router'
import useMangoAccount from 'hooks/useMangoAccount'
import useMangoGroup from 'hooks/useMangoGroup'
import { notify } from 'utils/notifications'
const MangoAccountsListModal = ({
isOpen,
@ -47,7 +48,7 @@ const MangoAccountsListModal = ({
})
try {
const reloadedMangoAccount = await retryFn(() => acc.reload(client))
await actions.fetchOpenOrders(reloadedMangoAccount)
actions.fetchOpenOrders(reloadedMangoAccount)
set((s) => {
s.mangoAccount.current = reloadedMangoAccount
@ -55,6 +56,11 @@ const MangoAccountsListModal = ({
setLastAccountViewed(acc.publicKey.toString())
} catch (e) {
console.warn('Error selecting account', e)
notify({
type: 'info',
title: 'Unable to load account. Please try again.',
description: `${e}`,
})
} finally {
onClose()
}

View File

@ -628,11 +628,11 @@ const mangoStore = create<MangoStore>()(
fetchOpenOrders: async (providedMangoAccount) => {
const set = get().set
const client = get().client
const group = await client.getGroup(GROUP)
const group = get().group
const mangoAccount =
providedMangoAccount || get().mangoAccount.current
if (!mangoAccount) return
if (!mangoAccount || !group) return
try {
const openOrders: Record<string, Order[] | PerpOrder[]> = {}