Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
34 changes: 34 additions & 0 deletions src/app/[lng]/earn/borrow/[chainId]/[marketId]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { BorrowMarketPage } from '@/app/ui/earn/BorrowMarketPage';
import { EarnPageSkeleton } from '@/app/ui/earn';
import { notFound } from 'next/navigation';
import { Suspense } from 'react';

type Params = Promise<{ chainId: string; marketId: string }>;

export const dynamicParams = true;
export const revalidate = 300;

export async function generateStaticParams(): Promise<Params[]> {
return [];
}

export default async function Page({ params }: { params: Params }) {
const { chainId, marketId } = await params;

console.log('25. BorrowMarketPage page', { chainId, marketId });

if (!chainId || !marketId) {
return notFound();
}

const parsedChainId = Number(chainId);
if (isNaN(parsedChainId)) {
return notFound();
}

return (
<Suspense fallback={<EarnPageSkeleton />}>
<BorrowMarketPage chainId={parsedChainId} marketId={marketId} />
</Suspense>
);
}
12 changes: 12 additions & 0 deletions src/app/lib/getLoopoorMarket.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { HttpResponse, LoopoorMarket } from '@/types/jumper-backend';
import { makeClient } from './client';

export type GetLoopoorMarketResult = HttpResponse<LoopoorMarket, unknown>;

export async function getLoopoorMarket(
chainId: number,
marketId: string,
): Promise<GetLoopoorMarketResult> {
const client = makeClient();
return client.v1.loopoorControllerGetMarketV1(chainId, marketId);
}
18 changes: 18 additions & 0 deletions src/app/lib/getLoopoorMarketHistory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import type {
HttpResponse,
LoopoorMarketHistory,
} from '@/types/jumper-backend';
import { makeClient } from './client';

export type GetLoopoorMarketHistoryResult = HttpResponse<
LoopoorMarketHistory,
unknown
>;

export async function getLoopoorMarketHistory(
chainId: number,
marketId: string,
): Promise<GetLoopoorMarketHistoryResult> {
const client = makeClient();
return client.v1.loopoorControllerGetMarketHistoryV1(chainId, marketId);
}
11 changes: 11 additions & 0 deletions src/app/lib/getLoopoorMarkets.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import type { HttpResponse, LoopoorMarket } from '@/types/jumper-backend';
import { makeClient } from './client';

export type GetLoopoorMarketsResult = HttpResponse<LoopoorMarket[], unknown>;

export async function getLoopoorMarkets(
chainId: number,
): Promise<GetLoopoorMarketsResult> {
const client = makeClient();
return client.v1.loopoorControllerListMarketsV1({ chainId: String(chainId) });
}
19 changes: 19 additions & 0 deletions src/app/lib/getLoopoorMaxLeverage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {
HttpResponse,
LoopoorMaxLeverageResponse,
} from '@/types/jumper-backend';
import { makeClient } from './client';

export type GetLoopoorMaxLeverageResult = HttpResponse<
LoopoorMaxLeverageResponse,
unknown
>;

export async function getLoopoorMaxLeverage(
chainId: number,
marketId: string,
query?: { slippage?: number; safetyBuffer?: number },
): Promise<GetLoopoorMaxLeverageResult> {
const client = makeClient();
return client.v1.loopoorControllerGetMaxLeverageV1(chainId, marketId, query);
}
21 changes: 21 additions & 0 deletions src/app/lib/getLoopoorStats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type {
HttpResponse,
LoopoorStatsResponse,
} from '@/types/jumper-backend';
import { makeClient } from './client';

export type GetLoopoorStatsResult = HttpResponse<LoopoorStatsResponse, unknown>;

export async function getLoopoorStats(
chainId: number,
marketId: string,
query: {
leverageFactor: number;
amount?: string;
slippage?: number;
safetyBuffer?: number;
},
): Promise<GetLoopoorStatsResult> {
const client = makeClient();
return client.v1.loopoorControllerGetStatsV1(chainId, marketId, query);
}
57 changes: 57 additions & 0 deletions src/app/ui/earn/BorrowMarketPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { notFound } from 'next/navigation';
import type { FC } from 'react';
import { getLoopoorMarket } from 'src/app/lib/getLoopoorMarket';
import { BorrowDetailsChart } from 'src/components/EarnDetails/BorrowDetailsChart';
import { BorrowDetailsIntro } from 'src/components/EarnDetails/BorrowDetailsIntro';
import { EarnDetailsSection } from 'src/components/EarnDetails/EarnDetailsSection';
import { GoBack } from 'src/components/composite/GoBack/GoBack';
import { AppPaths } from 'src/const/urls';
import { getChainsQuery } from 'src/hooks/useChains';
import { getChainById } from 'src/utils/tokenAndChain';
import { transformLoopoorMarketToOpportunity } from 'src/utils/loopoor/transformLoopoorMarket';
import type { ChainId } from '@lifi/sdk';

interface BorrowMarketPageProps {
chainId: number;
marketId: string;
}

export const BorrowMarketPage: FC<BorrowMarketPageProps> = async ({
chainId,
marketId,
}) => {
const result = await getLoopoorMarket(chainId, marketId).catch((error) => {
console.error('getLoopoorMarket failed', chainId, marketId, error);
return { ok: false as const, data: undefined, error };
});

if (!result.ok || !result.data) {
return notFound();
}

console.log('26. BorrowMarketPage market data', result.data);

const { chains } = await getChainsQuery().catch(() => ({ chains: [] }));
const chain = getChainById(chains, chainId as ChainId);
const chainKey = chain?.key ?? String(chainId);

const opportunity = transformLoopoorMarketToOpportunity(
//@ts-ignore - TODO: LF-14853: type this properly
result.data.data,
chainKey,
{
name: 'Morpho',
logo: 'https://strapi-staging.jumper.exchange/uploads/protocols_morpho_22aad9e9df.png',
},
);

return (
<>
<EarnDetailsSection>
<GoBack path={AppPaths.Earn} dataTestId="borrow-back-button" />
<BorrowDetailsIntro opportunity={opportunity} marketId={marketId} />
<BorrowDetailsChart chainId={chainId} marketId={marketId} />
</EarnDetailsSection>
</>
);
};
3 changes: 2 additions & 1 deletion src/app/ui/earn/EarnsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { FC } from 'react';

import { EarnOpportunitiesAll } from './EarnOpportunitiesAll/EarnOpportunitiesAll';
import { EarnTopOpportunities } from './EarnTopOpportunities';
import { LoopoorMarketBanner } from './LoopoorMarketBanner';
import { EarnPageTracking } from '@/components/headless/tracking/EarnPageTracking';

interface EarnsPageProps {}
Expand All @@ -10,6 +10,7 @@ export const EarnsPage: FC<EarnsPageProps> = () => {
return (
<>
<EarnTopOpportunities />
<LoopoorMarketBanner />
<EarnOpportunitiesAll />
<EarnPageTracking />
</>
Expand Down
Loading
Loading