Skip to content

Commit

Permalink
fix loading
Browse files Browse the repository at this point in the history
  • Loading branch information
tlrjs committed Sep 13, 2023
1 parent 6664599 commit a9b3a25
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
41 changes: 21 additions & 20 deletions components/MangoProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ const HydrateStore = () => {
useInterval(
() => {
actions.fetchGroup()
actions.reloadMangoAccount()
},
(slowNetwork ? 60 : 30) * SECONDS,
(slowNetwork ? 60 : 20) * SECONDS,
)

// refetches open orders every 30 seconds
// only the selected market's open orders are updated via websocket
useInterval(
() => {
if (mangoAccountAddress) {
actions.fetchOpenOrders()
}
},
(slowNetwork ? 60 : 30) * SECONDS,
)
// useInterval(
// () => {
// if (mangoAccountAddress) {
// actions.fetchOpenOrders()
// }
// },
// (slowNetwork ? 60 : 30) * SECONDS,
// )

// refetch trade history and activity feed when switching accounts
useEffect(() => {
Expand All @@ -81,13 +82,13 @@ const HydrateStore = () => {
}, [mangoAccountAddress])

// reload and parse market fills from the event queue
useInterval(
async () => {
const actions = mangoStore.getState().actions
actions.loadMarketFills()
},
(slowNetwork ? 60 : 20) * SECONDS,
)
// useInterval(
// async () => {
// const actions = mangoStore.getState().actions
// actions.loadMarketFills()
// },
// (slowNetwork ? 60 : 20) * SECONDS,
// )

// estimate the priority fee every 30 seconds
useInterval(
Expand Down Expand Up @@ -133,7 +134,7 @@ const HydrateStore = () => {
// don't fetch serum3OpenOrders if the slot is old
if (context.slot > mangoStore.getState().mangoAccount.lastSlot) {
if (newMangoAccount.serum3Active().length > 0) {
await newMangoAccount.reloadSerum3OpenOrders(client)
// await newMangoAccount.reloadSerum3OpenOrders(client)
// check again that the slot is still the most recent after the reloading open orders
if (context.slot > mangoStore.getState().mangoAccount.lastSlot) {
set((s) => {
Expand All @@ -142,7 +143,7 @@ const HydrateStore = () => {
})
}
}
actions.fetchOpenOrders()
// actions.fetchOpenOrders()
}
},
)
Expand Down Expand Up @@ -173,12 +174,12 @@ const ReadOnlyMangoAccount = () => {
const client = mangoStore.getState().client
const pk = new PublicKey(ma)
const readOnlyMangoAccount = await client.getMangoAccount(pk)
await readOnlyMangoAccount.reloadSerum3OpenOrders(client)
// await readOnlyMangoAccount.reloadSerum3OpenOrders(client)
set((state) => {
state.mangoAccount.current = readOnlyMangoAccount
state.mangoAccount.initialLoad = false
})
await actions.fetchOpenOrders()
// await actions.fetchOpenOrders()
} catch (error) {
console.error('error', error)
}
Expand Down
10 changes: 8 additions & 2 deletions components/StakeForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import useMangoGroup from 'hooks/useMangoGroup'
import FormatNumericValue from './shared/FormatNumericValue'
import { stakeAndCreate } from 'utils/transactions'
import { MangoAccount } from '@blockworks-foundation/mango-v4'
import { AnchorProvider } from '@project-serum/anchor'

const set = mangoStore.getState().set

Expand Down Expand Up @@ -173,10 +174,15 @@ function DepositForm({ onSuccess, token: selectedToken }: DepositFormProps) {
type: 'success',
txid: tx,
})

if (!mangoAccount) {
await actions.fetchMangoAccounts(
(client.program.provider as AnchorProvider).wallet.publicKey,
)
}
await actions.reloadMangoAccount(slot)
actions.fetchWalletTokens(publicKey)
await actions.fetchWalletTokens(publicKey)
setSubmitting(false)
setInputAmount('')
onSuccess()
} catch (e) {
console.error('Error depositing:', e)
Expand Down
23 changes: 10 additions & 13 deletions store/mangoStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ const mangoStore = create<MangoStore>()(
}
} catch (e) {
console.error('Error reloading mango acct', e)
await actions.reloadMangoAccount()
await sleep(100)
} finally {
set((state) => {
state.mangoAccount.initialLoad = false
Expand Down Expand Up @@ -664,19 +662,18 @@ const mangoStore = create<MangoStore>()(
console.error('Error parsing last account', e)
}
}
console.log('newSelectedMangoAccount', newSelectedMangoAccount)

if (newSelectedMangoAccount) {
await newSelectedMangoAccount.reloadSerum3OpenOrders(client)
set((state) => {
state.mangoAccount.current = newSelectedMangoAccount
state.mangoAccount.initialLoad = false
})
actions.fetchOpenOrders()
}
// await newSelectedMangoAccount.reloadSerum3OpenOrders(client)
set((state) => {
state.mangoAccount.current = newSelectedMangoAccount
state.mangoAccount.initialLoad = false
})
// actions.fetchOpenOrders()

await Promise.all(
mangoAccounts.map((ma) => ma.reloadSerum3OpenOrders(client)),
)
// await Promise.all(
// mangoAccounts.map((ma) => ma.reloadSerum3OpenOrders(client)),
// )

set((state) => {
state.mangoAccounts = mangoAccounts
Expand Down

0 comments on commit a9b3a25

Please sign in to comment.