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

Issue #606: Vaults explorer page #611

Merged
merged 7 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { Fuul } from '@fuul/sdk'
import EarnDetails from './containers/Earn/EarnDetails'
import Marketplace from './containers/Marketplace'
import ScreenLoader from '~/components/Modals/ScreenLoader'
import Explore from '~/containers/Explore'

import 'react-loading-skeleton/dist/skeleton.css'

const ToastContainer = lazy(() => import('react-toastify').then((module) => ({ default: module.ToastContainer })))
Expand Down Expand Up @@ -101,6 +103,7 @@ const App = () => {
<Route exact strict component={Marketplace} path={'/marketplace'} />
<Route exact strict component={CreateVault} path={'/vaults/create'} />
<Route exact strict component={Bridge} path={'/bridge'} />
<Route exact strict component={Explore} path={'/explore'} />
<Route
exact
strict
Expand Down
124 changes: 124 additions & 0 deletions src/containers/Explore/ExplorePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import styled from 'styled-components'
import { useState, useEffect } from 'react'
// @ts-ignore
import { generateSvg } from '@opendollar/svg-generator'
import ExploreTable from './ExploreTable'
import { ethers } from 'ethers'
import { parseRay, formatDataNumber, multiplyRates, transformToAnnualRate } from '~/utils'

const ExplorePage: React.FC<any> = ({ globalSafes, analyticsData }) => {
const [isLoading, setIsLoading] = useState<boolean>(true)
const [tableData, setTableData] = useState([])

const getSafeData = async () => {
setIsLoading(true)
const tableRows = []

if (!globalSafes.vaults || !analyticsData?.tokenAnalyticsData) return

for (const vault of globalSafes.vaults) {
try {
const tokenData = analyticsData.tokenAnalyticsData[vault.collateralType]

if (!tokenData) {
continue
}

const estimatedValue = `${(
+ethers.utils.formatUnits(vault.collateral) *
+ethers.utils.formatUnits(analyticsData.tokenAnalyticsData[vault.collateralType].currentPrice)
).toFixed(2)}`

const stabilityFee = transformToAnnualRate(
multiplyRates(
analyticsData.tokenAnalyticsData[vault.collateralType].stabilityFee.toString(),
analyticsData.redemptionRate?.toString()
) || '0',
27
)

const cratio = (+estimatedValue / +formatDataNumber(vault.debt)) * 100

const svgData = {
vaultID: vault.id,
stabilityFee,
debtAmount: formatDataNumber(vault.debt) + ' OD',
collateralAmount: formatDataNumber(vault.collateral) + ' ' + vault.collateralType,
collateralizationRatio: cratio ?? '∞',
safetyRatio: parseRay(analyticsData.tokenAnalyticsData[vault.collateralType].safetyCRatio),
liqRatio: parseRay(analyticsData.tokenAnalyticsData[vault.collateralType].liquidationCRatio),
}

let svg = null
try {
svg = await generateSvg(svgData)
} catch (e) {
console.error(e)
}

tableRows.push({
id: vault.id,
assetName: vault.collateralType,
image: svg ? svg : null,
})
} catch (e) {
console.error(e)
}
}
// @ts-ignore
setTableData(tableRows)
setIsLoading(false)
}

useEffect(() => {
getSafeData()
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [globalSafes.vaults, analyticsData])

return (
<Container>
<Header>
<Title>Explore Vaults</Title>
</Header>
{tableData.length !== 0 && <ExploreTable data={tableData} />}
{tableData.length === 0 && isLoading && <p>Loading...</p>}
{tableData.length === 0 && !isLoading && <p>No vaults available</p>}
</Container>
)
}

export default ExplorePage

const Container = styled.div`
max-width: 1362px;
margin: 80px auto;
padding: 0 15px;
@media (max-width: 767px) {
margin: 50px auto;
display: flex;
flex-direction: column;
}
color: ${(props) => props.theme.colors.accent};
`

const Title = styled.h2`
font-size: 34px;
font-weight: 700;
font-family: ${(props) => props.theme.family.headers};

color: ${(props) => props.theme.colors.accent};
@media (max-width: 767px) {
font-size: 32px;
}
`

const Header = styled.div`
display: flex;
justify-content: space-between;
@media (max-width: 767px) {
flex-direction: column;
justify-content: left;
}

margin-bottom: 40px;
`
Loading
Loading