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

Add data fetching #37

Closed
wants to merge 7 commits into from
Closed
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
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
"daisyui": "^3.7.3",
"eslint": "8.48.0",
"eslint-config-next": "13.4.16",
"ethers": "^6.7.1",
"graphql": "^16.8.0",
"graphql-request": "^6.1.0",
"heroicons": "^2.0.18",
"next": "13.4.16",
"postcss": "8.4.29",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.11.0",
"swr": "^2.2.2",
"tailwindcss": "3.3.3",
"typescript": "5.2.2"
},
Expand Down
25 changes: 0 additions & 25 deletions src/Context/PoolContext.tsx

This file was deleted.

31 changes: 0 additions & 31 deletions src/Context/ProfileContext.tsx

This file was deleted.

18 changes: 18 additions & 0 deletions src/app/global-error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use client";

export default function GlobalError({
error,
reset,
}: {
error: Error & { digest?: string };
reset: () => void;
}) {
return (
<html>
<body>
<h2>Something went wrong!</h2>
<button onClick={() => reset()}>Try again</button>
</body>
</html>
);
}
3 changes: 3 additions & 0 deletions src/app/pool/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function PoolDetail({ params }: { params: { slug: string } }) {
return <h1>My Page</h1>;
}
30 changes: 30 additions & 0 deletions src/app/pool/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"; // Error components must be Client Components

import { useEffect } from "react";

export default function Error({
error,
reset,
}: {
error: Error;
reset: () => void;
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
}, [error]);

return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
);
}
19 changes: 16 additions & 3 deletions src/app/pool/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
"use client";
import { Loading } from "@/components/Loading";
import Pool from "@/components/Pool/Pool";
import { getPoolDataQuery } from "@/utils/query";
import { graphqlEndpoint } from "@/utils/utils";
import { request } from "graphql-request";
import { Suspense } from "react";

export default function PoolHome() {
return <Pool />;
export default async function PoolHome() {
// FIXME: THE API DOES NOT RETURN THE POOL NAME AND STATUS

const data: any = await request(graphqlEndpoint, getPoolDataQuery);
const { pools } = data;

return (
<Suspense fallback={<Loading />}>
codenamejason marked this conversation as resolved.
Show resolved Hide resolved
<Pool data={pools} />
</Suspense>
);
}
8 changes: 8 additions & 0 deletions src/app/profile/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function ProfileDetail({ params }: { params: { id: string } }) {
return (
<div>
<h1>Profile Detail</h1>
<p>Profile ID: {params.id}</p>
</div>
)
}
30 changes: 30 additions & 0 deletions src/app/profile/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"; // Error components must be Client Components

import { useEffect } from "react";

export default function Error({
error,
reset,
}: {
error: Error;
reset: () => void;
}) {
useEffect(() => {
// Log the error to an error reporting service
console.error(error);
}, [error]);

return (
<div>
<h2>Something went wrong!</h2>
<button
onClick={
// Attempt to recover by trying to re-render the segment
() => reset()
}
>
Try again
</button>
</div>
);
}
27 changes: 24 additions & 3 deletions src/app/profile/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
"use client";
import { Loading } from "@/components/Loading";
import Profile from "@/components/Registry/Profile";
import { graphqlEndpoint } from "@/utils/utils";
import { request, gql } from "graphql-request";
import { Suspense } from "react";

export default function ProfileHome() {
return <Profile />;
export default async function ProfileHome() {
const query = gql`
{
profiles {
profileId
anchor
name
chainId
creator
}
}
`;
const data: any = await request(graphqlEndpoint, query);
const { profiles } = data;

return (
<Suspense fallback={<Loading />}>
<Profile data={profiles} />
</Suspense>
);
}
7 changes: 5 additions & 2 deletions src/components/Address.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getNetworks } from "@/api/networks";
import { Slug } from "@/types/types";
import { getNetworks } from "@/utils/networks";
import { TbCopy, TbExternalLink } from "react-icons/tb";

export const convertAddressToShortString = (address: string) => {
Expand Down Expand Up @@ -91,3 +90,7 @@ export const AddressResponsive = (props: {
</div>
);
};

export const truncatedString = (str: string) => {
return <div className="truncate font-mono w-32">{str}</div>;
}
2 changes: 1 addition & 1 deletion src/components/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NetworkContext } from "@/Context/NetworkContext";
import { getNetworksBySlug } from "@/api/networks";
import { getNetworksBySlug } from "@/utils/networks";
import { useContext } from "react";
import { AddressResponsive } from "./Address";
import Table from "./Table";
Expand Down
23 changes: 23 additions & 0 deletions src/components/Loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export const Loading = () => {
return (
<div role="status">
<svg
aria-hidden="true"
className="inline w-8 h-8 mr-2 text-gray-200 animate-spin dark:text-gray-600 fill-blue-600"
viewBox="0 0 100 101"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
fill="currentColor"
/>
<path
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
fill="currentFill"
/>
</svg>
<span className="sr-only">Loading...</span>
</div>
);
};
72 changes: 23 additions & 49 deletions src/components/Pool/Pool.tsx
Original file line number Diff line number Diff line change
@@ -1,77 +1,51 @@
import { PoolContext } from "@/Context/PoolContext";
import { ChevronDownIcon } from "@heroicons/react/20/solid";
import { useContext } from "react";
"use client";
import Table from "../Table";
import { TTableData } from "@/types/types";
import { Address, convertBytesToShortString } from "../Address";
import { convertChainIdToNetworkName } from "@/utils";
import Status from "../Status";
import { convertChainIdToNetworkName, formatAmount, shortenPoolName } from "@/utils/utils";
// import Status from "../Status";

const Pool = () => {
// const { pools } = useContext(PoolContext);

const pools = [
{
id: 1,
address: "0xAEc621EC8D9dE4B524f4864791171045d6BBBe27",
name: "DonationVotingMerklePayout",
token: "0x0000000000000000000000000000000000000000",
amount: 500,
status: true,
profileOwner: "0x0000000000000000000000000000000000000000",
strategyIdentifier:
"0xd71275a698bbfb611216b5ed38a4b48cc165febd4c3da5bc13bc8398792e6bca",
chainId: 5,
},
{
id: 2,
address: "0xAEc621EC8D9dE4B524f4864791171045d6BBBe27",
name: "DonationVotingMerklePayout",
token: "0x0000000000000000000000000000000000000000",
amount: 20,
status: false,
profileOwner: "0x0000000000000000000000000000000000000000",
strategyIdentifier:
"0xd71275a698bbfb611216b5ed38a4b48cc165febd4c3da5bc13bc8398792e6bca",
chainId: 5,
},
];

const data: TTableData = {
const Pool = (data: any) => {
const tableData: TTableData = {
name: "Pools",
description:
"A list of all the pools in the registry on all supported networks",
"A list of all the ools in the registry on all supported networks",
headers: [
"ID",
"Address",
"Name",
// "Name",
"Token",
"Amount",
"Status",
// "Status",
"Profile Name",
"Profile Owner",
"Identifier",
"Strategy",
"Network",
],
rows: pools.map((pool) => {
rows: Object.values(data.data).map((pool: any) => {
return [
pool.id,
pool.poolId,
// eslint-disable-next-line react/jsx-key
<Address address={pool.address} chainId={pool.chainId} />,
pool.name,
<Address address={pool.strategy} chainId={pool.chainId} />,
// pool.name, FIXME: THE API DOES NOT RETURN THE POOL NAME
// shortenPoolName("Pool Name is really long"),
// eslint-disable-next-line react/jsx-key
<Address address={pool.token} chainId={pool.chainId} />,
pool.amount,
// eslint-disable-next-line react/jsx-key
<Status status={pool.status} />,
formatAmount(pool.amount),
// eslint-disable-next-line react/jsx-key
shortenPoolName(pool.profile.name),
// eslint-disable-next-line react/jsx-key
<Address address={pool.profile.owner} chainId={pool.chainId} />,
// eslint-disable-next-line react/jsx-key
<Address address={pool.strategy} chainId={pool.chainId} />,
// eslint-disable-next-line react/jsx-key
<Address address={pool.profileOwner} chainId={pool.chainId} />,
convertBytesToShortString(pool.strategyIdentifier),
convertChainIdToNetworkName(pool.chainId),
];
}),
};

return <Table data={data} />;
return <Table data={tableData} />;
};

export default Pool;
Loading