mango-ui-v3/hooks/useSrmAccount.tsx

23 lines
748 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)
2021-04-12 20:39:08 -07:00
const accountData = srmAccount
? parseTokenAccountData(srmAccount?.data)
: null
const totalSrm = accountData
? nativeToUi(accountData.amount, SRM_DECIMALS)
: 0
const feeTier = getFeeTier(0, totalSrm)
const rates = getFeeRates(feeTier)
return { totalSrm, feeTier, rates }
}
export default useSrmAccount