mango-v4-ui/components/account/ActionTokenItem.tsx

70 lines
2.1 KiB
TypeScript
Raw Normal View History

2022-07-22 23:15:51 -07:00
import { Bank } from '@blockworks-foundation/mango-v4'
2023-01-24 16:54:24 -08:00
import FormatNumericValue from '@components/shared/FormatNumericValue'
2023-07-04 21:40:47 -07:00
import TokenLogo from '@components/shared/TokenLogo'
2023-11-27 03:33:33 -08:00
import { floorToDecimal } from 'utils/numbers'
2022-07-22 23:15:51 -07:00
const ActionTokenItem = ({
2022-07-22 23:15:51 -07:00
bank,
customValue,
2022-07-22 23:15:51 -07:00
onSelect,
roundUp,
showBorrowRates,
showDepositRates,
2022-07-22 23:15:51 -07:00
}: {
bank: Bank
customValue: number
onSelect: (x: string) => void
roundUp?: boolean
showBorrowRates?: boolean
showDepositRates?: boolean
2022-07-22 23:15:51 -07:00
}) => {
2023-07-04 21:40:47 -07:00
const { name } = bank
2023-11-27 03:33:33 -08:00
const decimals = floorToDecimal(customValue, bank.mintDecimals).toNumber()
? bank.mintDecimals
: undefined
2022-08-11 22:48:00 -07:00
2022-07-22 23:15:51 -07:00
return (
<button
2023-04-19 18:12:45 -07:00
className="flex w-full items-center rounded-md border border-th-bkg-4 bg-th-bkg-1 px-4 py-3 focus-visible:border-th-fgd-4 disabled:cursor-not-allowed disabled:opacity-30 md:hover:border-th-fgd-4 md:disabled:hover:border-th-bkg-4"
2022-07-22 23:15:51 -07:00
onClick={() => onSelect(name)}
disabled={customValue <= 0}
2022-07-22 23:15:51 -07:00
>
<div
className={`flex ${
!showBorrowRates && !showDepositRates ? 'w-1/2' : 'w-1/4'
} items-center`}
>
2022-07-22 23:15:51 -07:00
<div className="mr-2.5 flex flex-shrink-0 items-center">
2023-07-04 21:40:47 -07:00
<TokenLogo bank={bank} />
2022-07-22 23:15:51 -07:00
</div>
2023-05-13 05:17:04 -07:00
<p className="text-left text-th-fgd-1">{name}</p>
2022-07-22 23:15:51 -07:00
</div>
{showDepositRates ? (
<div className="w-1/4 text-right font-mono">
2022-11-30 19:32:32 -08:00
<p className="text-th-up">
2023-01-24 17:12:13 -08:00
<FormatNumericValue value={bank.getDepositRateUi()} decimals={2} />%
</p>
</div>
) : null}
{showBorrowRates ? (
<div className="w-1/4 text-right font-mono">
2022-11-30 19:32:32 -08:00
<p className="text-th-down">
2023-01-24 17:12:13 -08:00
<FormatNumericValue value={bank.getBorrowRateUi()} decimals={2} />%
</p>
</div>
) : null}
<div className="w-1/2 pl-3 text-right">
<p className="truncate font-mono text-th-fgd-1">
2023-01-24 16:54:24 -08:00
<FormatNumericValue
value={customValue}
2023-11-27 03:33:33 -08:00
decimals={decimals}
roundUp={roundUp}
2023-01-24 16:54:24 -08:00
/>
</p>
2022-08-11 22:48:00 -07:00
</div>
2022-07-22 23:15:51 -07:00
</button>
)
}
export default ActionTokenItem