Skip to content

Commit

Permalink
Earn Protocol WIP #7 (#532)
Browse files Browse the repository at this point in the history
7 of N pull requests.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Introduced the `StrategyDetailsPage` component for detailed strategy
information.
- Added the `StrategyDetailsView` component to enhance the presentation
of strategy details.
- Launched the `ToggleButton` component for interactive toggle
functionality.
	- Introduced the `Timeframes` component for selecting chart timeframes.
- Enhanced navigation with a new "Yield Trend" item and improved
descriptions.
- Updated `StrategyExposure` to utilize `InlineButtons` for filter
selection.

- **Style**
- Introduced new styles for the `ToggleButton`, `Timeframes`, and
`InlineButtons` components.
	- Improved hover state styling for navigation items.

- **Bug Fixes**
- Replaced the `StrategyGridDetails` component with
`StrategyGridPreview`, ensuring consistent rendering of strategy
information.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: sebastianPiekarczyk <sebastian@oazoapps.com>
  • Loading branch information
marcinciarka and piekczyk authored Oct 11, 2024
1 parent e947a75 commit 8d4f6a4
Show file tree
Hide file tree
Showing 38 changed files with 1,301 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ export const NavigationWrapper: FC = () => {
{
url: '/rebalancing-activity',
id: 'rebalancing-activity',
title: 'Rebalancing activity',
title: 'Rebalancing Activity',
description: 'Text for rebalancing activity',
icon: 'rebalancing',
},
{
url: '/yield-trend',
id: 'yield-trend',
title: 'Yield Trend',
description: 'Text for rebalancing activity',
icon: 'rebalancing',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Expander, StrategyGridDetails, Text } from '@summerfi/app-earn-ui'
import { Expander, StrategyGridPreview, Text } from '@summerfi/app-earn-ui'

import FormContainer from '@/components/organisms/Form/FormContainer'
import {
Expand Down Expand Up @@ -137,7 +137,7 @@ const EarnStrategyPage = ({ params }: EarnStrategyPageProps) => {
const [id, symbol, network, apy, risk] = params.strategy.split('-')

return (
<StrategyGridDetails
<StrategyGridPreview
strategy={
{
id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useMemo } from 'react'
import { StrategyGridDetails } from '@summerfi/app-earn-ui'
import { type NetworkNames } from '@summerfi/app-types'

import { StrategyDetailsView } from '@/components/layout/StrategyDetailsView/StrategyDetailsView'
import { strategiesList } from '@/constants/dev-strategies-list'

type StrategyDetailsPageProps = {
params: {
network: NetworkNames | 'all-networks'
strategy_id: string
}
}

const StrategyDetailsPage = ({ params }: StrategyDetailsPageProps) => {
const selectedStrategyData = useMemo(() => {
return strategiesList.find((strategy) => strategy.id === params.strategy_id)
}, [params])

return (
<StrategyGridDetails strategy={selectedStrategyData as (typeof strategiesList)[number]}>
<StrategyDetailsView />
</StrategyGridDetails>
)
}

export default StrategyDetailsPage
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use client'

import { useMemo } from 'react'
import { Expander, StrategyGridDetails, Text } from '@summerfi/app-earn-ui'
import { Expander, StrategyGridPreview, Text, WithArrow } from '@summerfi/app-earn-ui'
import Link from 'next/link'

import { MockedLineChart } from '@/components/organisms/Charts/MockedLineChart'
import FormContainer from '@/components/organisms/Form/FormContainer'
Expand Down Expand Up @@ -136,14 +137,37 @@ const userActivityRawData: UserActivityRawData[] = [
},
]

const detailsLinks = [
{
label: 'How it all works',
id: 'how-it-works',
},
{
label: 'Advanced yield data',
id: 'advanced-yield-data',
},
{
label: 'Yield sources',
id: 'yield-sources',
},
{
label: 'Security',
id: 'security',
},
{
label: 'FAQ',
id: 'faq',
},
]

const EarnStrategyPage = ({ params }: EarnStrategyPageProps) => {
// open/manage view (not connected)
const selectedStrategyData = useMemo(() => {
return strategiesList.find((strategy) => strategy.id === params.strategy_id)
}, [params])

return (
<StrategyGridDetails
<StrategyGridPreview
strategy={selectedStrategyData as (typeof strategiesList)[number]}
leftContent={
<div
Expand All @@ -154,17 +178,60 @@ const EarnStrategyPage = ({ params }: EarnStrategyPageProps) => {
width: '100%',
}}
>
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 'var(--spacing-space-medium)',
}}
>
<Text variant="h5">About the strategy</Text>
<Text
variant="p2"
style={{
color: 'var(--color-text-secondary)',
}}
>
The Summer Earn Protocol is a permissionless passive lending product, which sets out
to offer effortless and secure optimised yield, while diversifying risk.
</Text>
<div
style={{
display: 'flex',
flexDirection: 'row',
justifyContent: 'space-between',
}}
>
{detailsLinks.map(({ label, id }) => (
<Link
key={label}
href={`/earn/${selectedStrategyData?.network}/strategy/${selectedStrategyData?.id}/details#${id}`}
>
<Text
as="p"
variant="p3semi"
style={{
color: 'var(--color-text-link)',
textDecoration: 'none',
cursor: 'pointer',
paddingRight: 'var(--spacing-space-medium)',
}}
>
<WithArrow>{label}</WithArrow>
</Text>
</Link>
))}
</div>
</div>
<Expander
title={
<Text as="p" variant="p1semi">
Chart i guess
Historical yield
</Text>
}
defaultExpanded
>
<div style={{ height: '400px' }}>
<MockedLineChart />
</div>
<MockedLineChart />
</Expander>
<Expander
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ export const NavigationWrapper: FC = () => {
{
url: '/rebalancing-activity',
id: 'rebalancing-activity',
title: 'Rebalancing activity',
title: 'Rebalancing Activity',
description: 'Text for rebalancing activity',
icon: 'rebalancing',
},
{
url: '/yield-trend',
id: 'yield-trend',
title: 'Yield Trend',
description: 'Text for rebalancing activity',
icon: 'rebalancing',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
'use client'
import { Card } from '@summerfi/app-earn-ui'

import { StrategyDetailsHowItWorks } from '@/components/organisms/StrategyDetailsHowItWorks/StrategyDetailsHowItWorks'
import { type IndividualYieldsRawData } from '@/components/organisms/StrategyDetailsYields/mapper'
import { StrategyDetailsYields } from '@/components/organisms/StrategyDetailsYields/StrategyDetailsYields'

const yieldsRawData: IndividualYieldsRawData[] = [
{
strategy: 'Summer.fi USDC Strategy',
currentApy: '0.32',
avgApyPer30d: '0.103',
avgApyPer1y: '0.093',
allTimeMedianApy: '0.0643',
yieldLowHigh: {
low: '0.0643',
high: '0.1355',
},
},
{
strategy: 'Pendle USDC0++',
currentApy: '0.32',
avgApyPer30d: '0.103',
avgApyPer1y: '0.093',
allTimeMedianApy: '0.0643',
yieldLowHigh: {
low: '0.0643',
high: '0.1355',
},
},
{
strategy: 'AAVE v3 USDC',
currentApy: '0.32',
avgApyPer30d: '0.103',
avgApyPer1y: '0.093',
allTimeMedianApy: '0.0643',
yieldLowHigh: {
low: '0.0643',
high: '0.1355',
},
},
{
strategy: 'MetaMorpho Gauntlet MKR Blended',
currentApy: '0.32',
avgApyPer30d: '0.103',
avgApyPer1y: '0.093',
allTimeMedianApy: '0.0643',
yieldLowHigh: {
low: '0.0643',
high: '0.1355',
},
},
{
strategy: 'All Defi Median',
currentApy: '0.32',
avgApyPer30d: '0.103',
avgApyPer1y: '0.093',
allTimeMedianApy: '0.0643',
yieldLowHigh: {
low: '0.0643',
high: '0.1355',
},
},
]

export const StrategyDetailsView = () => {
return (
<>
<StrategyDetailsHowItWorks />
<StrategyDetailsYields rawData={yieldsRawData} />
<div id="yield-sources">
<Card variant="cardPrimary">
<div style={{ margin: '500px' }}>Yield Sources</div>
</Card>
</div>
<div id="security">
<Card variant="cardPrimary">
<div style={{ margin: '500px' }}>Security</div>
</Card>
</div>
<div id="faq">
<Card variant="cardPrimary">
<div style={{ margin: '500px' }}>Faq</div>
</Card>
</div>
</>
)
}
26 changes: 26 additions & 0 deletions apps/earn-protocol/components/organisms/Charts/ChartHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { SimpleGrid, Timeframes, ToggleButton } from '@summerfi/app-earn-ui'
import { type TimeframesType } from '@summerfi/app-types'

type ChartHeaderProps = {
compare: boolean
setCompare: (value: boolean) => void
timeframe: TimeframesType
setTimeframe: (timeframe: string) => void
}

export const ChartHeader = ({ compare, timeframe, setCompare, setTimeframe }: ChartHeaderProps) => {
return (
<SimpleGrid columns={2} rows={1}>
<ToggleButton
title="Compare to others"
checked={compare}
onChange={() => setCompare(!compare)}
/>
<Timeframes
timeframes={['90d', '6m', '1y', '3y']}
activeTimeframe={timeframe}
setActiveTimeframe={setTimeframe}
/>
</SimpleGrid>
)
}
90 changes: 90 additions & 0 deletions apps/earn-protocol/components/organisms/Charts/ComparisonChart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { type TimeframesType } from '@summerfi/app-types'
import {
Area,
ComposedChart,
Legend,
Line,
ResponsiveContainer,
Tooltip,
XAxis,
YAxis,
} from 'recharts'

type ComparisonChartProps = {
data: unknown[]
dataNames: string[]
colors: { [key: string]: string }
compare: boolean
timeframe: TimeframesType
}

export const ComparisonChart = ({ data, dataNames, colors, compare }: ComparisonChartProps) => {
return (
<div style={{ width: '100%', height: '400px' }}>
<ResponsiveContainer width="100%" height="90%">
<ComposedChart
data={data}
margin={{
top: 50,
right: 0,
left: 0,
bottom: 0,
}}
>
<defs>
<linearGradient id="summerYieldGradient" x1="0" y1="0" x2="0" y2="1">
<stop offset="0%" stopColor="#FF49A4" stopOpacity={0.8} />
<stop offset="100%" stopColor="#333333" stopOpacity={0.4} />
</linearGradient>
</defs>

<XAxis dataKey="name" fontSize={12} interval={0} />
<YAxis strokeWidth={0} width={45} tickFormatter={(label: string) => `${label}%`} />
<Tooltip
formatter={(val) => `${Number(val).toFixed(2)}`}
useTranslate3d
contentStyle={{
zIndex: 1000,
backgroundColor: 'var(--color-surface-subtler)',
borderRadius: '5px',
padding: '20px 30px',
border: 'none',
}}
/>
{dataNames.map((dataName, dataIndex) =>
dataName === 'Summer USDS Strategy' ? (
<Area
key={dataName}
type="natural"
animationDuration={300}
animationBegin={dataIndex * 50}
animationEasing="ease-out"
dataKey={dataName}
strokeWidth={1}
stroke={colors[`${dataName}-color` as keyof typeof colors]}
fillOpacity={1}
fill="url(#summerYieldGradient)"
/>
) : (
<Line
animationId={dataIndex}
key={dataName}
animationDuration={300}
animationBegin={dataIndex * 50}
animationEasing="ease-out"
type="natural"
dataKey={dataName}
strokeDasharray="3 3"
stroke={colors[`${dataName}-color` as keyof typeof colors]}
strokeWidth={compare ? 1 : 0}
dot={false}
connectNulls
/>
),
)}
<Legend iconType="circle" iconSize={8} align="center" layout="horizontal" height={60} />
</ComposedChart>
</ResponsiveContainer>
</div>
)
}
Loading

0 comments on commit 8d4f6a4

Please sign in to comment.