-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT] - Borrow page: Health lvl #71
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
export interface HealthLvlProps { | ||
healthLvl: number; | ||
healthLvl: number; | ||
} | ||
|
||
export enum HealthLvlPoint { | ||
Safe = 100, | ||
Warning = 70, | ||
Danger = 40, | ||
Min = 0 | ||
Safe = 100, | ||
Warning = 70, | ||
Danger = 40, | ||
Min = 0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,13 +34,19 @@ import useDisplayStore from '../../store/displayStore'; | |
import { getContractsByHTokenAddr } from '../../helpers/generalHelper'; | ||
import HealthLvl from 'components/HealthLvl/HealthLvl'; | ||
import c from 'classnames'; | ||
import { useGetNFTPrice } from '../../hooks/useHtokenHelper'; | ||
import { useGetBorrowAmount } from 'hooks/useCoupon'; | ||
import useToast from 'hooks/useToast'; | ||
|
||
const { formatPercent: fp, formatERC20: fs } = formatNumber; | ||
const Markets: NextPage = () => { | ||
const COLLATERAL_FACTOR = 0.65; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not use hard coded values. for EVM we can get this from the contracts. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oke, we should call upon the contract and extract the value there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see example: #73 |
||
const { currentUser, setCurrentUser } = useContext(UserContext); | ||
const [tableData, setTableData] = useState<MarketTableRow[]>([]); | ||
const [isMyCollectionsFilterEnabled, setIsMyCollectionsFilterEnabled] = useState(false); | ||
const [expandedRowKeys, setExpandedRowKeys] = useState<readonly antdKey[]>([]); | ||
const { toast, ToastComponent } = useToast(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems unrelated, please create an issue for new found bugs There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not, we need it in the useEffect otherwise can't integrate the loader - see commit below |
||
const NFTId = useLoanFlowStore((state) => state.NFTId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unrelated to this pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's not, we need it in the useEffect otherwise can't integrate the loader - see commit below. Also used for the call of borrowamount |
||
const { | ||
HERC20ContractAddr: HERC20ContractAddress, | ||
setHERC20ContractAddr, | ||
|
@@ -72,6 +78,26 @@ const Markets: NextPage = () => { | |
currentUser, | ||
unit | ||
); | ||
const [nftPrice, isLoadingNFTPrice] = useGetNFTPrice( | ||
htokenHelperContractAddress, | ||
HERC20ContractAddress | ||
); | ||
const [borrowAmount, isLoadingBorrowAmount] = useGetBorrowAmount( | ||
HERC20ContractAddress, | ||
NFTId, | ||
unit | ||
); | ||
/* initial all financial value here */ | ||
const borrowedValue = parseFloat(borrowAmount); | ||
|
||
useEffect(() => { | ||
if (isLoadingNFTPrice || isLoadingBorrowAmount || isLoadingPositions) { | ||
toast.processing(); | ||
} else { | ||
toast.clear(); | ||
} | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isLoadingNFTPrice, isLoadingBorrowAmount, isLoadingPositions]); | ||
|
||
/* End insert data into table */ | ||
/* Begin filter function */ | ||
|
@@ -280,7 +306,7 @@ const Markets: NextPage = () => { | |
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
[isMyCollectionsFilterEnabled, tableData, searchQuery] | ||
); | ||
|
||
// positions in each market desktop | ||
const expandColumns: ColumnType<MarketTablePosition>[] = [ | ||
{ | ||
dataIndex: ['name', 'image', 'tokenId'], | ||
|
@@ -296,7 +322,9 @@ const Markets: NextPage = () => { | |
</div> | ||
<div className={style.nameCellText}> | ||
<div className={style.collectionName}>{`${row['name']} #${row['tokenId']}`}</div> | ||
<HealthLvl healthLvl={0} /> | ||
<HealthLvl | ||
healthLvl={((nftPrice - parseInt(row.debt) / COLLATERAL_FACTOR) / nftPrice) * 100} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
|
@@ -345,25 +373,29 @@ const Markets: NextPage = () => { | |
) | ||
} | ||
]; | ||
|
||
// positions in each market mobile | ||
const expandColumnsMobile: ColumnType<MarketTablePosition>[] = [ | ||
{ | ||
dataIndex: ['name', 'image', 'tokenId'], | ||
key: 'tokenId', | ||
render: (text, row) => ( | ||
<div className={style.expandedRowNameCell}> | ||
<div className={style.expandedRowIcon} /> | ||
<div className={style.collectionLogo}> | ||
<HexaBoxContainer> | ||
<Image src={row['image']} layout="fill" alt="nft icon" /> | ||
</HexaBoxContainer> | ||
</div> | ||
<div className={style.nameCellText}> | ||
<div className={style.collectionName}>{`${row['name']} #${row['tokenId']}`}</div> | ||
<HealthLvl healthLvl={row.healthLvl || 0} /> | ||
render: (text, row) => { | ||
return ( | ||
<div className={style.expandedRowNameCell}> | ||
<div className={style.expandedRowIcon} /> | ||
<div className={style.collectionLogo}> | ||
<HexaBoxContainer> | ||
<Image src={row['image']} layout="fill" alt="nft icon" /> | ||
</HexaBoxContainer> | ||
</div> | ||
<div className={style.nameCellText}> | ||
<div className={style.collectionName}>{`${row['name']} #${row['tokenId']}`}</div> | ||
<HealthLvl | ||
healthLvl={((nftPrice - parseInt(row.debt) / COLLATERAL_FACTOR) / nftPrice) * 100} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
); | ||
} | ||
}, | ||
{ | ||
dataIndex: ['tokenId', 'couponId'], | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import