load orderbook for market
This commit is contained in:
parent
9dc5b1479b
commit
9755aef1be
|
@ -100,11 +100,11 @@ const DepositModal = ({ isOpen, onClose }) => {
|
||||||
Number(inputAmount)
|
Number(inputAmount)
|
||||||
)
|
)
|
||||||
.then(async (_response: string) => {
|
.then(async (_response: string) => {
|
||||||
await sleep(1000)
|
|
||||||
actions.fetchWalletBalances()
|
|
||||||
actions.fetchMarginAccounts()
|
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
onClose()
|
onClose()
|
||||||
|
await sleep(750)
|
||||||
|
actions.fetchWalletBalances()
|
||||||
|
actions.fetchMarginAccounts()
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
setSubmitting(false)
|
setSubmitting(false)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
import { Market } from '@project-serum/serum'
|
import { Market } from '@project-serum/serum'
|
||||||
import { AccountInfo } from '@solana/web3.js'
|
import { AccountInfo, PublicKey } from '@solana/web3.js'
|
||||||
import useConnection from './useConnection'
|
import useConnection from './useConnection'
|
||||||
import useMangoStore from '../stores/useMangoStore'
|
import useMangoStore from '../stores/useMangoStore'
|
||||||
import useSerumStore from '../stores/useSerumStore'
|
import useSerumStore from '../stores/useSerumStore'
|
||||||
|
@ -12,14 +12,16 @@ const _SLOW_REFRESH_INTERVAL = 60 * SECONDS
|
||||||
|
|
||||||
const mangoGroupMarketsSelector = (s) => s.selectedMangoGroup.markets
|
const mangoGroupMarketsSelector = (s) => s.selectedMangoGroup.markets
|
||||||
const websocketConnectionSelector = (s) => s.connection.websocket
|
const websocketConnectionSelector = (s) => s.connection.websocket
|
||||||
|
const selectedMarketAddressSelector = (s) => s.selectedMarket.address
|
||||||
|
|
||||||
const useHydrateStore = () => {
|
const useHydrateStore = () => {
|
||||||
const setMangoStore = useMangoStore((s) => s.set)
|
const setMangoStore = useMangoStore((s) => s.set)
|
||||||
const setSerumStore = useSerumStore((s) => s.set)
|
const setSerumStore = useSerumStore((s) => s.set)
|
||||||
const marketsForSelectedMangoGroup = useMangoStore(mangoGroupMarketsSelector)
|
const marketsForSelectedMangoGroup = useMangoStore(mangoGroupMarketsSelector)
|
||||||
const websocketConnection = useMangoStore(websocketConnectionSelector)
|
const websocketConnection = useMangoStore(websocketConnectionSelector)
|
||||||
|
const selectedMarketAddress = useMangoStore(selectedMarketAddressSelector)
|
||||||
const actions = useMangoStore((s) => s.actions)
|
const actions = useMangoStore((s) => s.actions)
|
||||||
const { connection } = useConnection()
|
const { connection, dexProgramId } = useConnection()
|
||||||
const { marketList } = useMarketList()
|
const { marketList } = useMarketList()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -31,6 +33,35 @@ const useHydrateStore = () => {
|
||||||
actions.fetchMangoGroup()
|
actions.fetchMangoGroup()
|
||||||
}, 60 * SECONDS)
|
}, 60 * SECONDS)
|
||||||
|
|
||||||
|
// load the selected market and orderbook
|
||||||
|
useEffect(() => {
|
||||||
|
Market.load(
|
||||||
|
connection,
|
||||||
|
new PublicKey(selectedMarketAddress),
|
||||||
|
{},
|
||||||
|
new PublicKey(dexProgramId)
|
||||||
|
)
|
||||||
|
.then(async (market) => {
|
||||||
|
const bidAccount = market['_decoded'].bids
|
||||||
|
const bidInfo = await connection.getAccountInfo(bidAccount)
|
||||||
|
const askAccount = market['_decoded'].asks
|
||||||
|
const askInfo = await connection.getAccountInfo(askAccount)
|
||||||
|
|
||||||
|
setMangoStore((state) => {
|
||||||
|
state.selectedMarket.current = market
|
||||||
|
state.accountInfos[askAccount.toString()] = askInfo
|
||||||
|
state.accountInfos[bidAccount.toString()] = bidInfo
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.log({
|
||||||
|
message: 'Error loading market',
|
||||||
|
description: e.message,
|
||||||
|
type: 'error',
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}, [selectedMarketAddress])
|
||||||
|
|
||||||
// load all markets for mangoGroup
|
// load all markets for mangoGroup
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Promise.all(
|
Promise.all(
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
} from '../utils/wallet-adapters'
|
} from '../utils/wallet-adapters'
|
||||||
import { WalletAdapter } from '../@types/types'
|
import { WalletAdapter } from '../@types/types'
|
||||||
import useInterval from './useInterval'
|
import useInterval from './useInterval'
|
||||||
|
import { sleep } from '@blockworks-foundation/mango-client'
|
||||||
|
|
||||||
const SECONDS = 1000
|
const SECONDS = 1000
|
||||||
const ASSET_URL =
|
const ASSET_URL =
|
||||||
|
@ -105,6 +106,7 @@ export default function useWallet() {
|
||||||
'...' +
|
'...' +
|
||||||
wallet.publicKey.toString().substr(-5),
|
wallet.publicKey.toString().substr(-5),
|
||||||
})
|
})
|
||||||
|
sleep(500)
|
||||||
// wait for margin account before fetching trade history
|
// wait for margin account before fetching trade history
|
||||||
await actions.fetchMarginAccounts()
|
await actions.fetchMarginAccounts()
|
||||||
actions.fetchWalletBalances()
|
actions.fetchWalletBalances()
|
||||||
|
|
Loading…
Reference in New Issue