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

64 lines
1.5 KiB
TypeScript
Raw Normal View History

import { Bank } from '@blockworks-foundation/mango-v4'
2022-11-18 09:09:39 -08:00
import useMangoAccount from 'hooks/useMangoAccount'
import ActionTokenItem from './ActionTokenItem'
type BankParams = {
2023-01-29 20:13:38 -08:00
bank: Bank
balance: number
borrowedAmount: number
walletBalance: number
maxBorrow: number
maxWithdraw: number
}
const ActionTokenList = ({
banks,
onSelect,
showBorrowRates,
showDepositRates,
valueKey,
}: {
banks: BankParams[]
onSelect: (x: string) => void
showBorrowRates?: boolean
showDepositRates?: boolean
2023-01-29 20:13:38 -08:00
valueKey:
| 'balance'
| 'borrowedAmount'
| 'maxBorrow'
| 'maxWithdraw'
| 'walletBalance'
}) => {
2022-11-18 09:09:39 -08:00
const { mangoAccount } = useMangoAccount()
return mangoAccount ? (
<>
<div className="space-y-2">
{banks?.length ? (
banks
.filter((b: BankParams) => !!b)
.map((b) => {
return (
<ActionTokenItem
2023-01-29 20:13:38 -08:00
bank={b.bank}
customValue={b[valueKey]}
key={b.bank.name}
onSelect={onSelect}
2023-01-29 20:13:38 -08:00
roundUp={valueKey === 'borrowedAmount'}
showBorrowRates={showBorrowRates}
showDepositRates={showDepositRates}
/>
)
})
) : (
<div className="mt-4 rounded border border-th-bkg-2 py-3 text-center text-th-fgd-4">
Nothing to select
</div>
)}
</div>
</>
) : null
}
export default ActionTokenList