2022-08-18 15:26:03 -07:00
|
|
|
import { Bank } from '@blockworks-foundation/mango-v4'
|
2022-09-12 08:53:57 -07:00
|
|
|
import mangoStore from '@store/mangoStore'
|
2022-08-17 22:58:44 -07:00
|
|
|
import ActionTokenItem from './ActionTokenItem'
|
|
|
|
|
2022-08-18 15:26:03 -07:00
|
|
|
type BankParams = {
|
|
|
|
key: string
|
|
|
|
value: Bank[]
|
|
|
|
walletBalance?: number
|
|
|
|
maxAmount?: number
|
|
|
|
accountBalance?: number
|
|
|
|
}
|
|
|
|
|
2022-08-17 22:58:44 -07:00
|
|
|
const ActionTokenList = ({
|
|
|
|
banks,
|
|
|
|
onSelect,
|
|
|
|
sortByKey,
|
|
|
|
showBorrowRates,
|
|
|
|
showDepositRates,
|
2022-08-22 19:23:26 -07:00
|
|
|
valueKey,
|
2022-08-17 22:58:44 -07:00
|
|
|
}: {
|
2022-08-18 15:26:03 -07:00
|
|
|
banks: BankParams[]
|
2022-08-18 13:50:34 -07:00
|
|
|
onSelect: (x: string) => void
|
2022-08-22 19:23:26 -07:00
|
|
|
sortByKey: 'maxAmount' | 'walletBalanceValue' | 'accountBalanceValue'
|
2022-08-17 22:58:44 -07:00
|
|
|
showBorrowRates?: boolean
|
|
|
|
showDepositRates?: boolean
|
2022-08-22 19:23:26 -07:00
|
|
|
valueKey: 'maxAmount' | 'walletBalance' | 'accountBalance'
|
2022-08-17 22:58:44 -07:00
|
|
|
}) => {
|
|
|
|
const mangoAccount = mangoStore((s) => s.mangoAccount.current)
|
|
|
|
|
|
|
|
return mangoAccount ? (
|
|
|
|
<>
|
|
|
|
<div className="space-y-2">
|
2022-08-22 19:23:26 -07:00
|
|
|
{banks?.length ? (
|
|
|
|
banks
|
|
|
|
.filter((b: BankParams) => !!b)
|
|
|
|
.sort((a: any, b: any) => b[sortByKey] - a[sortByKey])
|
|
|
|
.map((bank: any) => (
|
|
|
|
<ActionTokenItem
|
|
|
|
bank={bank.value[0]}
|
|
|
|
customValue={bank[valueKey]}
|
|
|
|
key={bank.value[0].name}
|
|
|
|
onSelect={onSelect}
|
|
|
|
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>
|
|
|
|
)}
|
2022-08-17 22:58:44 -07:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
) : null
|
|
|
|
}
|
|
|
|
|
|
|
|
export default ActionTokenList
|