Skip to content

Commit 063a55a

Browse files
authored
Merge pull request #105 from VoiceDeck/feat/upgrade-hypercerts
WIP Feat/upgrade hypercerts
2 parents dd7de8e + 1bfdc7f commit 063a55a

26 files changed

+1607
-348
lines changed

bun.lockb

65.6 KB
Binary file not shown.

components/report-details/funding-data-wrapper.tsx

+57-57
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,73 @@ import type { Report } from "@/types";
55
import { Loader2 } from "lucide-react";
66

77
interface FundingDataWrapperProps {
8-
hypercertId: Partial<Report>["hypercertId"];
9-
children: React.ReactNode;
10-
totalAmount: Partial<Report>["totalCost"];
11-
fundedAmount: Partial<Report>["fundedSoFar"];
8+
hypercertId: Partial<Report>["hypercertId"];
9+
children: React.ReactNode;
10+
totalAmount: Partial<Report>["totalCost"];
11+
fundedAmount: Partial<Report>["fundedSoFar"];
1212
}
1313

1414
const FundingDataWrapper: React.FC<FundingDataWrapperProps> = ({
15-
hypercertId,
16-
totalAmount,
17-
fundedAmount,
18-
children,
15+
hypercertId,
16+
totalAmount,
17+
fundedAmount,
18+
children,
1919
}: FundingDataWrapperProps) => {
20-
if (!hypercertId) {
21-
return <div>No hypercertId found </div>;
22-
}
23-
if (!totalAmount) {
24-
return <div>No total cost found</div>;
25-
}
20+
if (!hypercertId) {
21+
return <div>No hypercertId found </div>;
22+
}
23+
if (!totalAmount) {
24+
return <div>No total cost found</div>;
25+
}
2626

27-
const { genesisFractionQuery, hypercertClaimQuery } =
28-
useFetchFundingData(hypercertId);
27+
const { genesisFractionQuery, hypercertClaimQuery } =
28+
useFetchFundingData(hypercertId);
2929

30-
const { data: genesisFractionResponse, isPending: fractionsPending } =
31-
genesisFractionQuery;
32-
const { data: hypercertClaimResponse, isPending: claimPending } =
33-
hypercertClaimQuery;
30+
const { data: genesisFractionResponse, isPending: fractionsPending } =
31+
genesisFractionQuery;
32+
const { data: hypercertClaimResponse, isPending: claimPending } =
33+
hypercertClaimQuery;
34+
const genesisFraction = genesisFractionResponse?.data[0];
35+
const hypercertClaim = hypercertClaimResponse;
3436

35-
const genesisFraction = genesisFractionResponse?.claimTokens[0];
36-
const hypercertClaim = hypercertClaimResponse?.claim;
37+
if (fractionsPending || claimPending)
38+
return (
39+
<section className="h-20 shadow-md max-w-3xl flex justify-center items-center bg-vd-beige-100 gap-2 rounded-lg ease-in duration-300">
40+
<div className="animate-spin">
41+
<Loader2 size={18} />
42+
</div>
43+
Loading funding data...
44+
</section>
45+
);
3746

38-
if (fractionsPending || claimPending)
39-
return (
40-
<section className="h-20 shadow-md max-w-3xl flex justify-center items-center bg-vd-beige-100 gap-2 rounded-lg ease-in duration-300">
41-
<div className="animate-spin">
42-
<Loader2 size={18} />
43-
</div>
44-
Loading funding data...
45-
</section>
46-
);
47+
if (!hypercertClaim) {
48+
return <div>Missing data for calculations</div>;
49+
}
50+
console.log("hypercertClaim", hypercertClaim);
4751

48-
if (!hypercertClaim) {
49-
return <div>Missing data for calculations</div>;
50-
}
52+
const totalUnits = hypercertClaim.units ? Number(hypercertClaim.units) : 0;
53+
const pricePerUnit = totalAmount / Number(totalUnits);
54+
const percentProgress = ((fundedAmount || 0) / totalAmount) * 100;
55+
const minUnitAmount = 1 / pricePerUnit;
56+
const dollarAmountNeeded = (totalAmount - (fundedAmount || 0)).toFixed(2);
5157

52-
const totalUnits = hypercertClaim.totalUnits;
53-
const pricePerUnit = totalAmount / Number(totalUnits);
54-
const percentProgress = ((fundedAmount || 0) / totalAmount) * 100;
55-
const minUnitAmount = 1 / pricePerUnit;
56-
const dollarAmountNeeded = (totalAmount - (fundedAmount || 0)).toFixed(2);
57-
58-
return (
59-
<FundingProvider
60-
value={{
61-
genesisFraction,
62-
hypercertClaim,
63-
pricePerUnit,
64-
totalUnits,
65-
totalAmount,
66-
// unitsRemaining,
67-
percentProgress,
68-
minUnitAmount,
69-
dollarAmountNeeded,
70-
}}
71-
>
72-
{children}
73-
</FundingProvider>
74-
);
58+
return (
59+
<FundingProvider
60+
value={{
61+
genesisFraction,
62+
hypercertClaim,
63+
pricePerUnit,
64+
totalUnits,
65+
totalAmount,
66+
// unitsRemaining,
67+
percentProgress,
68+
minUnitAmount,
69+
dollarAmountNeeded,
70+
}}
71+
>
72+
{children}
73+
</FundingProvider>
74+
);
7575
};
7676

7777
export default FundingDataWrapper;

components/report-details/support/form.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ async function getOrdersForReport(
124124
const { data: orders } = await hypercertClient.api.fetchOrdersByHypercertId(
125125
{
126126
hypercertId,
127-
chainId,
128127
},
129128
);
130129
return orders;

config/constants.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { optimism, sepolia } from "viem/chains";
2+
import { Chain } from "viem";
3+
import { Environment } from "@hypercerts-org/sdk";
4+
5+
export const WC_PROJECT_ID = process.env.NEXT_PUBLIC_WC_PROJECT_ID;
6+
export const ENVIRONMENT = process.env.NEXT_PUBLIC_ENVIRONMENT as Environment;
7+
8+
export const testNetChains = [sepolia] as const;
9+
export const prodNetChains = [optimism] as const;
10+
11+
export const SUPPORTED_CHAINS = (
12+
ENVIRONMENT === "production" ? prodNetChains : testNetChains
13+
) as readonly [Chain, ...Chain[]];
14+
const allChains = [
15+
...testNetChains.map((x) => x.id),
16+
...prodNetChains.map((x) => x.id),
17+
] as const;
18+
19+
export type SupportedChainIdType = (typeof allChains)[number];

config/hypercerts.ts

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { parseUnits } from "viem";
2+
import { CONSTANTS } from "@hypercerts-org/sdk";
3+
import { ENVIRONMENT } from "@/config/constants";
4+
5+
const HYPERCERT_API_URL =
6+
CONSTANTS.ENDPOINTS[ENVIRONMENT as keyof typeof CONSTANTS.ENDPOINTS];
7+
8+
export const HYPERCERTS_API_URL_REST = `${HYPERCERT_API_URL}/v1`;
9+
export const HYPERCERTS_API_URL_GRAPH = `${HYPERCERT_API_URL}/v1/graphql`;
10+
11+
export const DEFAULT_NUM_FRACTIONS = parseUnits("1", 8);
12+
13+
export const DEFAULT_DISPLAY_CURRENCY = "usd";

contexts/funding-context.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"use client";
2-
import type { Claim } from "@/types";
3-
import type { ClaimToken } from "@hypercerts-org/sdk";
42
import { type ReactNode, createContext, useContext } from "react";
53

64
// Define the shape of the context
75
interface FundingContextType {
8-
genesisFraction?: ClaimToken;
9-
hypercertClaim: Claim;
6+
genesisFraction?: any;
7+
hypercertClaim: any;
108
pricePerUnit: number;
119
totalUnits: number;
1210
totalAmount: number;

0 commit comments

Comments
 (0)