Skip to content

Commit

Permalink
fix: add streaming for swap page
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukTheCoder committed Dec 31, 2024
1 parent 868c599 commit b4039e5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DetailsType } from 'src/types';

export interface PropsType {
details: DetailsType;
id: string;
}

Expand Down
13 changes: 11 additions & 2 deletions src/app/swap/[id]/_components/SwapDetailSummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import React from 'react';
import { DesktopColumns, mobileColumns } from './SwapDetail.helper';
import { PropsType } from './SwapDetail.type';
import ButtonCopyIcon from 'src/components/common/ButtonCopyIcon';
import { getTxDetails } from 'src/services';
import { notFound } from 'next/navigation';

async function SwapDetailSummary(props: PropsType) {
const { id } = props;

const details = await getTxDetails(props.id);

if (details.message === 'Transaction not found!') {
notFound();
}

function SwapDetailSummary(props: PropsType) {
const { details, id } = props;
const { from, to } = details;

return (
Expand Down
2 changes: 1 addition & 1 deletion src/app/swap/[id]/_components/SwapSteps/SwapSteps.type.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AssetType, ExplorerUrlsType, StepType, SwapStatus } from 'src/types';

export interface PropsType {
steps: StepType[];
id: string;
}

export interface SwapStepItemProps {
Expand Down
13 changes: 11 additions & 2 deletions src/app/swap/[id]/_components/SwapSteps/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@ import React from 'react';
import { PropsType } from './SwapSteps.type';
import SwapStepItem from './SwapStepItem';
import { StepType } from 'src/types';
import { getTxDetails } from 'src/services';
import { notFound } from 'next/navigation';

async function SwapSteps(props: PropsType) {
const details = await getTxDetails(props.id);

if (details.message === 'Transaction not found!') {
notFound();
}

const { steps } = details;

function SwapSteps(props: PropsType) {
const { steps } = props;
return (
<div className="w-full bg-baseForeground px-15 py-20 md:p-35 mt-20 md:mt-[40px] rounded-soft md:rounded-normal">
<h2 className="text-12 md:text-28 font-semibold text-primary-500">
Expand Down
15 changes: 5 additions & 10 deletions src/app/swap/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { ChevronRightIcon } from 'src/components/icons';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { getTxDetails } from 'src/services';
import SwapDetailSummary from './_components/SwapDetailSummary';
import SwapSteps from './_components/SwapSteps';
import { Suspense } from 'react';

export async function generateMetadata({ params }: { params: { id: string } }) {
return {
Expand All @@ -12,12 +11,6 @@ export async function generateMetadata({ params }: { params: { id: string } }) {
}

const Page = async ({ params }: { params: { id: string } }) => {
const details = await getTxDetails(params.id);

if (details.message === 'Transaction not found!') {
notFound();
}

return (
<div>
<div className="w-full flex justify-center">
Expand All @@ -32,8 +25,10 @@ const Page = async ({ params }: { params: { id: string } }) => {
</span>
</div>

<SwapDetailSummary id={params.id} details={details} />
<SwapSteps steps={details.steps} />
<Suspense>
<SwapDetailSummary id={params.id} />
<SwapSteps id={params.id} />
</Suspense>
</div>
</div>
</div>
Expand Down

0 comments on commit b4039e5

Please sign in to comment.