Skip to content

Commit

Permalink
chore: hydrate application
Browse files Browse the repository at this point in the history
  • Loading branch information
thelostone-mc committed Nov 17, 2023
1 parent f6a7caa commit 7e1572a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 15 deletions.
31 changes: 28 additions & 3 deletions src/app/[chainId]/[poolId]/[applicationId]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,35 @@
import ApplicationDetails from "@/components/application/Application";
import ApplicationDetail from "@/components/application/ApplicationDetail";
import Container from "@/components/shared/Container";
import { graphqlEndpoint, getMicroGrantRecipientQuery } from "@/utils/query";
import request from "graphql-request";

export default async function Application({
params,
}: {
params: { chainId: string; poolId: string; applicationId: string };
}) {
let recipient;
let isError = false;

try {
const response: any = await request(
graphqlEndpoint,
getMicroGrantRecipientQuery,
{
chainId: params.chainId,
poolId: params.poolId,
recipientId: params.applicationId,
}
);
recipient = response?.microGrantRecipient;
} catch (error) {
isError = true;
console.error(error);
}

export default function ApplicationDetail() {
return (
<Container>
<ApplicationDetails />
<ApplicationDetail application={recipient} isError={isError} />
</Container>
);
}
25 changes: 25 additions & 0 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ export type TPoolData = {
};
};

export type TApplicationData = {
microGrant: {
chainId: string;
poolId: string;
allocationStartTime: number;
allocationEndTime: number;
pool: {
tokenMetadata: {
name?: string;
symbol?: string;
decimals?: number;
};
token: `0x${string}`;
amount: string;
};
};
recipientId: string;
recipientAddress: string;
requestedAmount: string;
metadataPointer: string;
blockTimestamp: string;
isUsingRegistryAnchor: boolean;
status: string;
};

export type TAllocatedData = {
recipientId: `0x${string}`;
recipientAddress: `0x${string}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,41 @@
"use client";

import { classNames, statusColorsScheme } from "@/utils/common";
import { useParams } from "next/navigation";
import { classNames, humanReadableAmount, statusColorsScheme } from "@/utils/common";
import Breadcrumb from "../shared/Breadcrumb";
import Image from "next/image";
import NotificationToast from "../shared/NotificationToast";
import { TApplicationData } from "@/app/types";
import { formatEther } from "viem";

export default function Application() {
const params = useParams();
export default function ApplicationDetail(props: {
application: TApplicationData,
isError: boolean,
}) {

const chainId = params["chainId"];
const poolId = params["poolId"];
console.log(props.application);

const microGrantRecipient = props.application;
const microGrant = microGrantRecipient.microGrant;

const tokenMetadata = microGrant.pool.tokenMetadata;
const amount = humanReadableAmount(microGrant.pool.amount, tokenMetadata.decimals);
const token = tokenMetadata.symbol ?? "ETH";

// TODO: wire in name + description
const applicationName = "Papa Kush";

const application = {
name: applicationName,
status: "Pending", // "Accepted"
amountRequested: "$192",
status: microGrantRecipient.status,
amountRequested: `${formatEther(BigInt(amount))} ${token}`,
href: "#",
breadcrumbs: [
{ id: 1, name: "Home", href: "/" },
{ id: 2, name: `Pool ${poolId}`, href: `/${chainId}/${poolId}` },
{ id: 2, name: `Pool ${microGrant.poolId}`, href: `/${microGrant.chainId}/${microGrant.poolId}` },
{ id: 3, name: applicationName, href: "#" },
],
logo: {
src: "https://www.mikeduran.com/wp-content/uploads/2019/02/Solarpunk-1.jpg",
src: "https://www.mikeduran.com/wp-content/uploads/2019/02/Solarpink-1.jpg",
alt: "Two each of gray, white, and black shirts laying flat.",
},
description:
Expand All @@ -49,6 +60,11 @@ export default function Application() {

return (
<div className="bg-white">

{props.isError && (
<NotificationToast success={false} title="Unable to fetch application" />
)}

<div className="pt-6">
<Breadcrumb breadcrumbs={application.breadcrumbs} />

Expand Down
1 change: 0 additions & 1 deletion src/components/pool/PoolList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const PoolList = async () => {
getMicroGrantsQuery,
{},
);
console.log("response ================", response);
pools = response["microGrants"];
} catch (e) {
isError = true;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function classNames(...classes: string[]) {
export const statusColorsScheme = {
Paid: "text-blue-700 bg-blue-50 ring-blue-600/20",
Accepted: "text-green-700 bg-green-50 ring-green-600/20",
Pending: "text-yellow-600 bg-yellow-50 ring-yellow-500/10",
Pending: "text-yellow-600 bg-yellow-50 ring-yellow-600/20",
Rejected: "text-red-700 bg-red-50 ring-red-600/20",
Active: "text-green-700 bg-green-50 ring-green-600/20",
Closed: "text-red-700 bg-red-50 ring-red-600/20",
Expand Down
11 changes: 11 additions & 0 deletions src/utils/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export const getMicroGrantRecipientQuery = gql`
poolId: $poolId
recipientId: $recipientId
) {
microGrant {
poolId
chainId
allocationStartTime
allocationEndTime
pool {
tokenMetadata
token
amount
}
}
recipientId
recipientAddress
requestedAmount
Expand Down

0 comments on commit 7e1572a

Please sign in to comment.