2022-08-26 12:15:50 -07:00
|
|
|
import { MangoAccount } from '@blockworks-foundation/mango-v4'
|
2023-01-05 20:01:03 -08:00
|
|
|
import { PublicKey } from '@solana/web3.js'
|
2022-09-12 08:53:57 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2023-01-05 20:01:03 -08:00
|
|
|
import { useMemo } from 'react'
|
2022-08-26 12:15:50 -07:00
|
|
|
|
|
|
|
export default function useMangoAccount(): {
|
|
|
|
mangoAccount: MangoAccount | undefined
|
|
|
|
initialLoad: boolean
|
2023-01-05 20:01:03 -08:00
|
|
|
mangoAccountPk: PublicKey | undefined
|
|
|
|
mangoAccountAddress: string
|
2023-11-15 07:48:57 -08:00
|
|
|
lastSlot: number
|
2022-08-26 12:15:50 -07:00
|
|
|
} {
|
2022-11-19 17:40:06 -08:00
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
2023-11-15 07:48:57 -08:00
|
|
|
const lastSlot = mangoStore((s) => s.mangoAccount.lastSlot)
|
2022-11-19 17:40:06 -08:00
|
|
|
const initialLoad = mangoStore((s) => s.mangoAccount.initialLoad)
|
2022-08-26 12:15:50 -07:00
|
|
|
|
2023-01-05 20:01:03 -08:00
|
|
|
const mangoAccountPk = useMemo(() => {
|
|
|
|
return mangoAccount?.publicKey
|
|
|
|
}, [mangoAccount?.publicKey])
|
|
|
|
|
|
|
|
const mangoAccountAddress = useMemo(() => {
|
|
|
|
return mangoAccountPk?.toString() || ''
|
|
|
|
}, [mangoAccountPk])
|
|
|
|
|
2023-03-04 10:42:46 -08:00
|
|
|
return {
|
|
|
|
mangoAccount,
|
2023-11-15 07:48:57 -08:00
|
|
|
lastSlot,
|
2023-03-04 10:42:46 -08:00
|
|
|
initialLoad,
|
|
|
|
mangoAccountAddress,
|
|
|
|
mangoAccountPk,
|
|
|
|
}
|
2022-08-26 12:15:50 -07:00
|
|
|
}
|