mango-ui-v3/hooks/useMarketList.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-04-06 15:11:42 -07:00
import { useMemo } from 'react'
import useConnection from './useConnection'
import { PublicKey } from '@solana/web3.js'
import useMangoStore from '../stores/useMangoStore'
import { IDS } from '@blockworks-foundation/mango-client'
const useMarketList = () => {
const mangoGroupName = useMangoStore((state) => state.selectedMangoGroup.name)
const { cluster, programId, dexProgramId } = useConnection()
const spotMarkets = useMemo(
() => IDS[cluster]?.mango_groups[mangoGroupName]?.spot_market_symbols || {},
[cluster, mangoGroupName]
)
const symbols = useMemo(
() => IDS[cluster]?.mango_groups[mangoGroupName]?.symbols || {},
[cluster, mangoGroupName]
)
2021-04-06 15:11:42 -07:00
const marketList = useMemo(
() =>
Object.entries(spotMarkets).map(([name, address]) => {
return {
address: new PublicKey(address as string),
programId: new PublicKey(dexProgramId as string),
deprecated: false,
name,
}
}),
[spotMarkets, dexProgramId]
)
return {
programId,
marketList,
spotMarkets,
symbols,
2021-04-06 15:11:42 -07:00
}
}
export default useMarketList