Skip to content
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

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion components/HealthLvl/HealthLvl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import React, { FC } from 'react';
import * as style from './HealthLvl.css';
import { HealthLvlProps, HealthLvlPoint } from './types';

// const { formatPercent: fp } = formatNumber;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused import


const HealthLvl: FC<HealthLvlProps> = (props) => {
const { healthLvl } = props;

Expand Down Expand Up @@ -30,7 +32,7 @@ const HealthLvl: FC<HealthLvlProps> = (props) => {
</div>
);
}
return <div className={style.valueCell}>0</div>;
return <div className={style.valueCell}>NaN</div>;
bowtiedpyro marked this conversation as resolved.
Show resolved Hide resolved
};

return <>{healthLvl && getStatus(healthLvl)}</>;
Expand Down
10 changes: 5 additions & 5 deletions components/HealthLvl/types.ts
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
}
64 changes: 48 additions & 16 deletions pages/borrow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oke, we should call upon the contract and extract the value there

Copy link
Collaborator

Choose a reason for hiding this comment

The 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();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems unrelated, please create an issue for new found bugs

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to this pr

Copy link
Collaborator Author

@bowtiedpyro bowtiedpyro Dec 9, 2022

Choose a reason for hiding this comment

The 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,
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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'],
Expand All @@ -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>
)
Expand Down Expand Up @@ -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'],
Expand Down