mango-ui-v3/components/FeeDiscountsTable.tsx

122 lines
4.2 KiB
TypeScript
Raw Normal View History

2021-06-07 15:06:00 -07:00
import { percentFormat } from '../utils/index'
import useSrmAccount from '../hooks/useSrmAccount'
2021-10-18 13:38:03 -07:00
import {
MSRM_DECIMALS,
SRM_DECIMALS,
} from '@project-serum/serum/lib/token-instructions'
2021-06-12 10:46:06 -07:00
import Tooltip from './Tooltip'
import { InformationCircleIcon } from '@heroicons/react/outline'
import { useTranslation } from 'next-i18next'
2021-10-18 13:38:03 -07:00
import Button from './Button'
import useMangoStore from '../stores/useMangoStore'
2021-10-18 14:21:37 -07:00
import { msrmMints, ZERO_BN } from '@blockworks-foundation/mango-client'
2021-10-18 13:38:03 -07:00
import DepositMsrmModal from './DepositMsrmModal'
import WithdrawMsrmModal from './WithdrawMsrmModal'
import { useState } from 'react'
2021-06-07 15:06:00 -07:00
const FeeDiscountsTable = () => {
const { t } = useTranslation('common')
2021-10-18 13:38:03 -07:00
const mangoAccount = useMangoStore((s) => s.selectedMangoAccount.current)
const connected = useMangoStore((s) => s.wallet.connected)
2021-10-18 14:21:37 -07:00
const walletTokens = useMangoStore((s) => s.wallet.tokens)
2021-10-18 13:38:03 -07:00
const { totalSrm, totalMsrm, rates } = useSrmAccount()
const [showDeposit, setShowDeposit] = useState(false)
const [showWithdraw, setShowWithdraw] = useState(false)
2021-10-18 14:21:37 -07:00
const cluster = useMangoStore.getState().connection.cluster
const ownerMsrmAccount = walletTokens.find((t) =>
t.account.mint.equals(msrmMints[cluster])
)
2021-06-07 15:06:00 -07:00
return (
<div
2021-12-07 20:00:02 -08:00
className={`flex justify-center bg-th-bkg-1 py-6 rounded-md divide-x divide-gray-500`}
2021-06-07 15:06:00 -07:00
>
2021-10-18 13:38:03 -07:00
<div className="pr-10">
<div className="text-center text-lg">{t('serum-fees')}</div>
2021-10-18 13:38:03 -07:00
<div
className={`flex flex-col sm:flex-row justify-between text-th-fgd-4 text-center mt-4`}
>
<div className="px-4">
<div>
{totalMsrm > 0 ? 'MSRM' : 'SRM'} {t('deposits')}
</div>
2021-10-18 13:38:03 -07:00
<div className="text-th-fgd-3 text-normal">
{totalMsrm > 0
? totalMsrm.toLocaleString(undefined, {
maximumFractionDigits: MSRM_DECIMALS,
})
: totalSrm.toLocaleString(undefined, {
maximumFractionDigits: SRM_DECIMALS,
})}
</div>
2021-06-07 15:06:00 -07:00
</div>
2021-10-18 13:38:03 -07:00
<div className="px-4 mt-4 sm:mt-0">
<div>{t('maker-fee')}</div>
2021-10-18 13:38:03 -07:00
<div className="text-th-fgd-3 text-normal">
{rates ? percentFormat.format(rates.maker) : null}
</div>
2021-06-07 15:06:00 -07:00
</div>
2021-10-18 13:38:03 -07:00
<div className="px-4 mt-4 sm:mt-0">
2021-06-12 10:46:06 -07:00
<div className="flex items-center">
<div>{t('taker-fee')}</div>
2021-10-18 13:38:03 -07:00
<div className="flex items-center">
<Tooltip
content={t('tooltip-serum-rebate', {
taker_percent: percentFormat.format(rates.taker),
})}
2021-10-18 13:38:03 -07:00
>
<div>
<InformationCircleIcon
className={`h-5 w-5 ml-2 text-th-fgd-4 cursor-help`}
/>
</div>
</Tooltip>
</div>
</div>
<div className="text-th-fgd-3 text-normal">
2021-12-08 09:27:48 -08:00
{rates
? new Intl.NumberFormat(undefined, {
style: 'percent',
minimumFractionDigits: 2,
maximumFractionDigits: 3,
}).format(rates.takerWithRebate)
: null}
2021-10-18 13:38:03 -07:00
</div>
</div>
</div>
{connected && mangoAccount ? (
2021-10-18 13:38:03 -07:00
<div className="flex justify-center mt-6">
2021-10-18 14:21:37 -07:00
<Button
onClick={() => setShowDeposit(true)}
disabled={!ownerMsrmAccount}
>
{t('deposit')} MSRM
2021-10-18 14:21:37 -07:00
</Button>
2021-10-18 13:38:03 -07:00
{mangoAccount.msrmAmount.gt(ZERO_BN) ? (
<Button onClick={() => setShowWithdraw(true)} className="ml-2">
{t('withdraw')} MSRM
2021-10-18 13:38:03 -07:00
</Button>
) : null}
</div>
) : null}
</div>
{showDeposit ? (
<DepositMsrmModal
isOpen={showDeposit}
onClose={() => setShowDeposit(false)}
/>
) : null}
{showWithdraw ? (
<WithdrawMsrmModal
isOpen={showWithdraw}
onClose={() => setShowWithdraw(false)}
/>
) : null}
2021-06-07 15:06:00 -07:00
</div>
)
}
export default FeeDiscountsTable