-
Total Deposits
+
+
+
- ${formatAmount(deposits)}
+ {denominator === 'fiat' ? '$' : 'Ξ'}
+ {formatAmount(deposits, denominator === 'fiat' ? 2 : 6)}
-
-
- {/*
*/}
+
+
+
+ Net APY
+
+
+
+ {formatAmount(calculateEffectiveAPY(products, balances))}%
+
+
+
+
+
+ Accrued Yield
+
+
+ {isLoading ? (
+
+ ) : (
+
+
+ {denominator === 'fiat' ? '$' : 'Ξ'}
+ {formatAmount(accruedYield, denominator === 'fiat' ? 2 : 6)}
+
+
+ )}
+
-
+
)
}
diff --git a/src/app/earn/components/product-card.tsx b/src/app/earn/components/product-card.tsx
index ad381574c..e9472ab94 100644
--- a/src/app/earn/components/product-card.tsx
+++ b/src/app/earn/components/product-card.tsx
@@ -5,6 +5,7 @@ import { FC, ReactNode } from 'react'
import { ProductTitlePill } from '@/app/earn/components/product-pill'
import { ProductTag } from '@/app/earn/components/product-tag'
+import { LeveragePositions } from '@/app/store/positions-atom'
import { GetApiV2ProductsEarn200 } from '@/gen'
import { formatAmount } from '@/lib/utils'
@@ -14,6 +15,7 @@ export type ProductCardProps = {
icon: ReactNode
}
product: GetApiV2ProductsEarn200[number]
+ position?: LeveragePositions['open'][number]
}
export const ProductCard: FC
= ({ product, pill }) => {
diff --git a/src/app/earn/page.tsx b/src/app/earn/page.tsx
index a9cdba4db..a8fb8c265 100644
--- a/src/app/earn/page.tsx
+++ b/src/app/earn/page.tsx
@@ -1,8 +1,11 @@
'use client'
import { ArrowPathIcon } from '@heroicons/react/20/solid'
-import { AnimatePresence } from 'framer-motion'
+import { useQuery } from '@tanstack/react-query'
import { useEffect } from 'react'
+import { useAccount } from 'wagmi'
+
+import { EarnPositions } from '@/app/store/positions-atom'
import { BalanceCard } from './components/balance-card'
import { ProductCard } from './components/product-card'
@@ -11,6 +14,8 @@ import { useEarnContext } from './provider'
export default function Page() {
const { products, balances } = useEarnContext()
+ const { address: user } = useAccount()
+
useEffect(() => {
document.body.classList.add('dark', 'bg-ic-black')
return () => {
@@ -18,15 +23,43 @@ export default function Page() {
}
}, [])
+ const {
+ data: { open, prices },
+ isFetching,
+ } = useQuery({
+ initialData: {
+ open: [],
+ history: [],
+ prices: {},
+ },
+ enabled: Boolean(user),
+ queryKey: ['earn-history', user],
+ queryFn: async () => {
+ const response = await fetch('/api/earn/history', {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({
+ user,
+ }),
+ })
+ return response.json() as Promise
+ },
+ })
+
return (
-
- {balances.length > 0 && (
-
- )}
-
-
+ {balances.length > 0 && (
+
+ )}
Strategies
@@ -36,6 +69,10 @@ export default function Page() {
+ position.metrics?.tokenAddress === p.tokenAddress,
+ )}
pill={
['wsteth15x', 'iceth'].includes(p.id)
? {
diff --git a/src/app/leverage/components/portfolio-widget/portfolio-widget.tsx b/src/app/leverage/components/portfolio-widget/portfolio-widget.tsx
index e66a18ad0..defedb73e 100644
--- a/src/app/leverage/components/portfolio-widget/portfolio-widget.tsx
+++ b/src/app/leverage/components/portfolio-widget/portfolio-widget.tsx
@@ -15,7 +15,7 @@ import { getLeverageTokens } from '@/app/leverage/constants'
import { EnrichedToken } from '@/app/leverage/types'
import { fetchLeverageTokenPrices } from '@/app/leverage/utils/fetch-leverage-token-prices'
import { getLeverageType } from '@/app/leverage/utils/get-leverage-type'
-import { fetchPositionsAtom } from '@/app/store/positions-atom'
+import { fetchLeveragePositionsAtom } from '@/app/store/positions-atom'
import { ETH } from '@/constants/tokens'
import { useAnalytics } from '@/lib/hooks/use-analytics'
import { useBalances } from '@/lib/hooks/use-balance'
@@ -31,7 +31,7 @@ const OpenPositions = () => {
undefined,
)
const { queryParams, updateQueryParams } = useQueryParams()
- const fetchPositions = useSetAtom(fetchPositionsAtom)
+ const fetchPositions = useSetAtom(fetchLeveragePositionsAtom)
const { logEvent } = useAnalytics()
const indexTokenAddresses = useMemo(() => {
diff --git a/src/app/store/positions-atom.ts b/src/app/store/positions-atom.ts
index d7d85d068..f97424218 100644
--- a/src/app/store/positions-atom.ts
+++ b/src/app/store/positions-atom.ts
@@ -2,7 +2,7 @@ import { atom } from 'jotai'
import { GetApiV2UserAddressPositions200 } from '@/gen'
-export type Positions = {
+export type LeveragePositions = {
open: GetApiV2UserAddressPositions200
history: GetApiV2UserAddressPositions200
stats: {
@@ -10,15 +10,21 @@ export type Positions = {
}
}
-const positionsAtomDefaultValue: Positions = {
+export type EarnPositions = {
+ open: GetApiV2UserAddressPositions200
+ history: GetApiV2UserAddressPositions200
+ prices: Record>
+}
+
+const positionsAtomDefaultValue: LeveragePositions = {
open: [],
history: [],
stats: {},
}
-export const positionsAtom = atom(positionsAtomDefaultValue)
+export const positionsAtom = atom(positionsAtomDefaultValue)
-export const fetchPositionsAtom = atom(
+export const fetchLeveragePositionsAtom = atom(
null,
async (_, set, address: string, chainId: number) => {
try {
@@ -30,7 +36,7 @@ export const fetchPositionsAtom = atom(
chainId,
}),
})
- ).json()) as Positions
+ ).json()) as LeveragePositions
set(positionsAtom, positions)