2022-07-22 23:15:51 -07:00
|
|
|
import { Bank } from '@blockworks-foundation/mango-v4'
|
2022-10-28 14:46:38 -07:00
|
|
|
import Image from 'next/legacy/image'
|
2022-08-11 22:48:00 -07:00
|
|
|
import { useMemo } from 'react'
|
2022-11-18 11:11:06 -08:00
|
|
|
import useJupiterMints from 'hooks/useJupiterMints'
|
2023-01-24 16:54:24 -08:00
|
|
|
import FormatNumericValue from '@components/shared/FormatNumericValue'
|
2022-07-22 23:15:51 -07:00
|
|
|
|
2022-08-17 22:58:44 -07:00
|
|
|
const ActionTokenItem = ({
|
2022-07-22 23:15:51 -07:00
|
|
|
bank,
|
2022-08-17 22:58:44 -07:00
|
|
|
customValue,
|
2022-07-22 23:15:51 -07:00
|
|
|
onSelect,
|
2023-01-24 18:54:06 -08:00
|
|
|
roundUp,
|
2022-08-17 22:58:44 -07:00
|
|
|
showBorrowRates,
|
|
|
|
showDepositRates,
|
2022-07-22 23:15:51 -07:00
|
|
|
}: {
|
|
|
|
bank: Bank
|
2022-08-17 22:58:44 -07:00
|
|
|
customValue: number
|
2022-08-18 13:50:34 -07:00
|
|
|
onSelect: (x: string) => void
|
2023-01-24 18:54:06 -08:00
|
|
|
roundUp?: boolean
|
2022-08-17 22:58:44 -07:00
|
|
|
showBorrowRates?: boolean
|
|
|
|
showDepositRates?: boolean
|
2022-07-22 23:15:51 -07:00
|
|
|
}) => {
|
2022-08-11 22:48:00 -07:00
|
|
|
const { mint, name } = bank
|
2022-11-18 11:11:06 -08:00
|
|
|
const { mangoTokens } = useJupiterMints()
|
2022-08-11 22:48:00 -07:00
|
|
|
|
|
|
|
const logoUri = useMemo(() => {
|
|
|
|
let logoURI
|
2022-11-18 11:11:06 -08:00
|
|
|
if (mangoTokens?.length) {
|
2022-11-19 11:20:36 -08:00
|
|
|
logoURI = mangoTokens.find((t) => t.address === mint.toString())?.logoURI
|
2022-08-11 22:48:00 -07:00
|
|
|
}
|
|
|
|
return logoURI
|
2022-11-18 11:11:06 -08:00
|
|
|
}, [mint, mangoTokens])
|
2022-08-11 22:48:00 -07:00
|
|
|
|
2022-07-22 23:15:51 -07:00
|
|
|
return (
|
|
|
|
<button
|
2023-01-05 17:19:39 -08:00
|
|
|
className="default-transition flex w-full items-center rounded-md border border-th-bkg-4 bg-th-bkg-1 px-4 py-3 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)}
|
2022-08-17 22:58:44 -07:00
|
|
|
disabled={customValue <= 0}
|
2022-07-22 23:15:51 -07:00
|
|
|
>
|
2023-01-05 17:19:39 -08: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">
|
|
|
|
<Image
|
|
|
|
alt=""
|
|
|
|
width="24"
|
|
|
|
height="24"
|
2022-08-11 22:48:00 -07:00
|
|
|
src={logoUri || `/icons/${name.toLowerCase()}.svg`}
|
2022-07-22 23:15:51 -07:00
|
|
|
/>
|
|
|
|
</div>
|
2022-07-23 22:45:11 -07:00
|
|
|
<p className="text-th-fgd-1">{name}</p>
|
2022-07-22 23:15:51 -07:00
|
|
|
</div>
|
2022-08-17 22:58:44 -07:00
|
|
|
{showDepositRates ? (
|
2023-01-05 17:19:39 -08:00
|
|
|
<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} />%
|
2022-08-17 22:58:44 -07:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{showBorrowRates ? (
|
2023-01-05 17:19:39 -08:00
|
|
|
<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} />%
|
2022-08-17 22:58:44 -07:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2023-01-05 17:19:39 -08:00
|
|
|
<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-01-24 18:54:06 -08:00
|
|
|
decimals={bank.mintDecimals}
|
|
|
|
roundUp={roundUp}
|
2023-01-24 16:54:24 -08:00
|
|
|
/>
|
2023-01-05 17:19:39 -08:00
|
|
|
</p>
|
2022-08-11 22:48:00 -07:00
|
|
|
</div>
|
2022-07-22 23:15:51 -07:00
|
|
|
</button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-08-17 22:58:44 -07:00
|
|
|
export default ActionTokenItem
|