generated from scaffold-eth/scaffold-eth
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* lending page * sort by borrow amount * lend and borrow improvements * add back midas
- Loading branch information
1 parent
08ecc85
commit 0ab8999
Showing
8 changed files
with
746 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import { Box, Link, LinkProps } from "@mui/material"; | ||
import { styled } from "@mui/material/styles"; | ||
import { Accordion, Chip, Icon, OHMChipProps } from "@olympusdao/component-library"; | ||
import { IconName } from "@olympusdao/component-library/lib/components/Icon"; | ||
import { FC, ReactNode } from "react"; | ||
import { NavLink, useLocation } from "react-router-dom"; | ||
|
||
const PREFIX = "NavItem"; | ||
|
||
const classes = { | ||
root: `${PREFIX}-root`, | ||
title: `${PREFIX}-title`, | ||
}; | ||
|
||
const Root = styled("div", { shouldForwardProp: prop => prop !== "match" })<MatchProps>(({ theme, match }) => ({ | ||
[`&.${classes.root}`]: { | ||
alignItems: "center", | ||
marginBottom: "12px", | ||
"& .link-container": { | ||
paddingRight: "12px", | ||
}, | ||
"& a.active": { | ||
"& .link-container": { | ||
backgroundColor: theme.colors.gray[600], | ||
}, | ||
textDecoration: "none", | ||
}, | ||
"& .MuiAccordion-root": { | ||
background: "transparent", | ||
"& .MuiAccordionDetails-root a.active .activePill": { | ||
marginLeft: "-35px", | ||
marginRight: "35px", | ||
}, | ||
"& .MuiAccordionSummary-expandIconWrapper": { | ||
padding: "0px 18px", | ||
}, | ||
}, | ||
"& .MuiAccordion-root &:last-child": { | ||
paddingBottom: "0px", | ||
}, | ||
"& .MuiAccordionSummary-root": { | ||
"&.Mui-expanded": { | ||
marginBottom: "6px", | ||
}, | ||
"& a.active .link-container": { | ||
backgroundColor: theme.colors.gray[600], | ||
marginRight: "-48px", | ||
}, | ||
}, | ||
|
||
"& .MuiAccordionDetails-root": { | ||
"& .link-container .title": { | ||
fontSize: "13px", | ||
lineHeight: 1, | ||
}, | ||
"& a.active .link-container": { | ||
backgroundColor: theme.colors.gray[600], | ||
}, | ||
paddingLeft: "20px", | ||
display: "block", | ||
"& .nav-item-container": { | ||
paddingTop: "3px", | ||
paddingBottom: "3px", | ||
paddingRight: "0px", | ||
}, | ||
}, | ||
|
||
"& svg": { | ||
marginRight: "12px", | ||
}, | ||
"& svg.accordion-arrow": { | ||
marginRight: "0px", | ||
}, | ||
"& .external-site-link": { | ||
"& .external-site-link-icon": { | ||
opacity: "0", | ||
}, | ||
"&:hover .external-site-link-icon": { | ||
marginLeft: "5px", | ||
opacity: "1", | ||
}, | ||
}, | ||
}, | ||
|
||
[`& .${classes.title}`]: { | ||
lineHeight: "33px", | ||
paddingLeft: "12px", | ||
paddingTop: "3px", | ||
paddingBottom: "3px", | ||
fontSize: "15px", | ||
}, | ||
})); | ||
|
||
interface MatchProps { | ||
match: boolean; | ||
} | ||
|
||
export interface OHMNavItemProps extends LinkProps { | ||
label: string; | ||
customIcon?: ReactNode; | ||
icon?: IconName; | ||
chip?: string | ReactNode; | ||
className?: string; | ||
to?: any; | ||
/**Will Override to prop. Used for External Links */ | ||
href?: string; | ||
children?: ReactNode; | ||
defaultExpanded?: boolean; | ||
chipColor?: OHMChipProps["template"]; | ||
} | ||
|
||
/** | ||
* Primary NavItem Component for UI. | ||
*/ | ||
const NavItem: FC<OHMNavItemProps> = ({ | ||
chip, | ||
className = "", | ||
customIcon, | ||
icon, | ||
label, | ||
to, | ||
children, | ||
defaultExpanded = true, | ||
chipColor, | ||
...props | ||
}) => { | ||
const currentLocation = useLocation(); | ||
const match = currentLocation.pathname === to || currentLocation.pathname === `/${to}`; | ||
|
||
const linkProps = props.href | ||
? { | ||
href: props.href, | ||
target: "_blank", | ||
className: `external-site-link ${className}`, | ||
} | ||
: { | ||
component: NavLink, | ||
to: to, | ||
className: `button-dapp-menu ${className}`, | ||
}; | ||
const LinkItem = () => ( | ||
<Link {...linkProps} {...props} underline="hover"> | ||
<Box | ||
display="flex" | ||
flexDirection="row" | ||
alignItems="center" | ||
alignContent="center" | ||
justifyContent="space-around" | ||
className="link-container" | ||
> | ||
<Box display="flex" width={"100%"} alignItems="center" className={`${classes.title} title`}> | ||
{customIcon ? customIcon : icon && <Icon name={icon} style={{ fontSize: "21px" }} />} | ||
{label} | ||
{props.href && <Icon className="external-site-link-icon" name="arrow-up" />} | ||
</Box> | ||
{chip && <Chip size="small" label={chip} template={chipColor} />} | ||
</Box> | ||
</Link> | ||
); | ||
return ( | ||
<Root className={`${classes.root} nav-item-container`} match={match}> | ||
{children ? ( | ||
<Accordion defaultExpanded={defaultExpanded} arrowOnlyCollapse summary={<LinkItem />}> | ||
{children} | ||
</Accordion> | ||
) : ( | ||
<LinkItem /> | ||
)} | ||
</Root> | ||
); | ||
}; | ||
|
||
export default NavItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import axios from "axios"; | ||
import { DefiLlamaPool, getOhmPools } from "src/hooks/useGetLPStats"; | ||
|
||
type LendAndBorrow = { | ||
apyBaseBorrow: number; | ||
apyRewardBorrow: number; | ||
borrowFactor: number | null; | ||
debtCeilingUsd: number | null; | ||
ltv: number; | ||
mintedCoin: string | null; | ||
pool: string; | ||
rewardTokens: string[]; | ||
totalBorrowUsd: number; | ||
totalSupplyUsd: number; | ||
underlyingTokens: string[]; | ||
}; | ||
export const useGetLendAndBorrowStats = () => { | ||
const defillamaAPI = "https://yields.llama.fi/lendBorrow"; | ||
const { data, isFetched, isLoading } = useQuery(["GetLendBorrowStats"], async () => { | ||
const ohmPools = await getOhmPools(); | ||
console.log(ohmPools, "ohmPools"); | ||
const lendAndBorrowPools = await axios.get<LendAndBorrow[]>(defillamaAPI).then(res => { | ||
return res.data; | ||
}); | ||
const ohmLendAndBorrowPools = ohmPools.filter(pool => | ||
lendAndBorrowPools.some(lendAndBorrowPool => lendAndBorrowPool.pool === pool.id), | ||
); | ||
const poolsAndLendBorrowStats = ohmLendAndBorrowPools.map(pool => { | ||
const lendBorrowPool = lendAndBorrowPools.find(lendAndBorrowPool => lendAndBorrowPool.pool === pool.id); | ||
return { ...pool, lendAndBorrow: lendBorrowPool }; | ||
}); | ||
return poolsAndLendBorrowStats; | ||
}); | ||
|
||
return { data, isFetched, isLoading }; | ||
}; | ||
|
||
export interface LendAndBorrowPool extends DefiLlamaPool { | ||
lendAndBorrow: LendAndBorrow; | ||
} |
Oops, something went wrong.