mango-ui-v3/hooks/useSrmAccount.tsx

19 lines
693 B
TypeScript
Raw Normal View History

import useMangoStore from '../stores/useMangoStore'
2021-04-09 17:01:00 -07:00
import { nativeToUi } from '@blockworks-foundation/mango-client'
import { SRM_DECIMALS } from '@project-serum/serum/lib/token-instructions'
import { getFeeTier, getFeeRates } from '@project-serum/serum'
2021-04-09 17:01:00 -07:00
import { parseTokenAccountData } from '../utils/tokens'
const useSrmAccount = () => {
const srmAccount = useMangoStore((s) => s.selectedMangoGroup.srmAccount)
const accountData = parseTokenAccountData(srmAccount.data)
const totalSrm = nativeToUi(accountData.amount, SRM_DECIMALS)
const feeTier = getFeeTier(0, totalSrm)
const rates = getFeeRates(feeTier)
return { totalSrm, feeTier, rates }
}
export default useSrmAccount