MigrationListBorrowItem.tsx
1 import { useMemo } from 'react'; 2 import { MigrationUserReserve, V3Rates } from 'src/store/v3MigrationSelectors'; 3 import { MigrationSelectedBorrowAsset } from 'src/store/v3MigrationSlice'; 4 5 import { MigrationListItem } from './MigrationListItem'; 6 7 type MigrationListBorrowItemProps = { 8 userReserve: MigrationUserReserve; 9 selectedBorrowAssets: MigrationSelectedBorrowAsset[]; 10 toggleSelectedBorrowPosition: (asset: MigrationSelectedBorrowAsset) => void; 11 v3Rates?: V3Rates; 12 enteringIsolation: boolean; 13 }; 14 15 export const MigrationListBorrowItem = ({ 16 selectedBorrowAssets, 17 userReserve, 18 toggleSelectedBorrowPosition, 19 v3Rates, 20 enteringIsolation, 21 }: MigrationListBorrowItemProps) => { 22 const isChecked = useMemo(() => { 23 return ( 24 !userReserve.migrationDisabled && 25 selectedBorrowAssets.findIndex( 26 (selectedAsset) => selectedAsset.debtKey === userReserve.reserve.variableDebtTokenAddress 27 ) >= 0 28 ); 29 }, [ 30 selectedBorrowAssets, 31 userReserve.migrationDisabled, 32 userReserve.reserve.variableDebtTokenAddress, 33 ]); 34 35 const handleCheckboxClick = () => { 36 toggleSelectedBorrowPosition(userReserve); 37 }; 38 39 const amount = userReserve.variableBorrows; 40 const amountInUSD = userReserve.variableBorrowsUSD; 41 42 return ( 43 <MigrationListItem 44 key={userReserve.debtKey} 45 checked={isChecked} 46 userReserve={userReserve} 47 amount={amount} 48 amountInUSD={amountInUSD} 49 onCheckboxClick={handleCheckboxClick} 50 disabled={userReserve.migrationDisabled} 51 enabledAsCollateral={userReserve.usageAsCollateralEnabledOnUser} 52 borrowApyType={userReserve.interestRate} 53 v3Rates={v3Rates} 54 enteringIsolation={enteringIsolation} 55 isSupplyList={false} 56 /> 57 ); 58 };