mango-ui-v3/components/MarketFee.tsx

43 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-17 12:37:07 -07:00
import {
getMarketIndexBySymbol,
PerpMarket,
} from '@blockworks-foundation/mango-client'
import useSrmAccount from '../hooks/useSrmAccount'
import useMangoStore from '../stores/useMangoStore'
2021-08-18 07:33:03 -07:00
import { percentFormat } from '../utils'
2021-08-17 12:37:07 -07:00
export default function MarketFee() {
const { rates } = useSrmAccount()
const mangoGroup = useMangoStore((s) => s.selectedMangoGroup.current)
const mangoGroupConfig = useMangoStore((s) => s.selectedMangoGroup.config)
const marketConfig = useMangoStore((s) => s.selectedMarket.config)
const market = useMangoStore((s) => s.selectedMarket.current)
const marketIndex = getMarketIndexBySymbol(
mangoGroupConfig,
marketConfig.baseSymbol
)
let takerFee, makerFee
if (market instanceof PerpMarket) {
2021-08-18 07:33:03 -07:00
takerFee = parseFloat(
mangoGroup.perpMarkets[marketIndex].takerFee.toFixed()
)
makerFee = parseFloat(
mangoGroup.perpMarkets[marketIndex].makerFee.toFixed()
)
2021-08-17 12:37:07 -07:00
} else {
2021-08-18 07:33:03 -07:00
takerFee = rates.taker
makerFee = rates.maker
2021-08-17 12:37:07 -07:00
}
return (
2021-10-01 08:32:15 -07:00
<div className="flex text-xs text-th-fgd-4 px-6 mt-2.5">
<div className="block sm:flex mx-auto text-center">
2021-08-18 07:33:03 -07:00
<div>Maker Fee: {percentFormat.format(makerFee)}</div>
<div className="hidden sm:block px-2">|</div>
2021-08-18 07:33:03 -07:00
<div>Taker Fee: {percentFormat.format(takerFee)}</div>
2021-10-01 08:32:15 -07:00
</div>
2021-08-17 12:37:07 -07:00
</div>
)
}