Skip to content

Commit 3b4736f

Browse files
committed
fix: minor fixes
- imporve server-side caching behaviour - fix the URL to Hypercert - fix the URL to original report - remove fractional representation
1 parent 32a67f7 commit 3b4736f

File tree

5 files changed

+25
-50
lines changed

5 files changed

+25
-50
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const FundingDataWrapper: React.FC<FundingDataWrapperProps> = ({
5353
const pricePerUnit = totalAmount / Number(totalUnits);
5454
const percentProgress = ((fundedAmount || 0) / totalAmount) * 100;
5555
const minUnitAmount = 1 / pricePerUnit;
56-
const dollarAmountNeeded = (totalAmount - (fundedAmount || 0)).toFixed(2);
56+
const dollarAmountNeeded = String((totalAmount - (fundedAmount || 0)));
5757

5858
return (
5959
<FundingProvider

components/report-details/report-sidebar.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ImpactDetails = ({ report }: { report: Report }) => {
5151
))}
5252
</ul>
5353
<a
54-
href={`https://testnet.hypercerts.org/app/view#claimId=${report.hypercertId}`}
54+
href={`https://app.hypercerts.org/hypercerts/${report.hypercertId}`}
5555
target="_blank"
5656
rel="noopener noreferrer"
5757
className={cn(
@@ -75,7 +75,7 @@ const ImpactDetails = ({ report }: { report: Report }) => {
7575
"pl-0 text-vd-orange-800 hover:text-vd-orange-900 dark:text-vd-beige-100 dark:hover:text-vd-beige-100 gap-1 group",
7676
)}
7777
>
78-
<span>What is a Hypercert?</span>
78+
<span>What is Hypercert?</span>
7979
<ArrowUpRight
8080
size={18}
8181
className="opacity-70 group-hover:translate-x-0.5 group-hover:opacity-100 group-hover:-translate-y-0.5 transition-transform duration-300 ease-in-out"

components/report-details/support/transaction-status.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const TransactionStatus = ({
4848
>
4949
<a
5050
// TODO: UPDATE FOR MAINNET WHEN READY
51-
href={`https://sepolia.etherscan.io/tx/${transactionHash}`}
51+
href={`https://optimistic.etherscan.io/tx/${transactionHash}`}
5252
target="_blank"
5353
rel="noopener noreferrer"
5454
className="w-full h-full flex gap-2 justify-center items-center"

lib/directus.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export async function processNewContribution(
8383
// update the funded amount of the hypercert in server memory
8484
await updateFundedAmount(hypercertId, amount);
8585
// add the contribution to the cache
86-
updateContribution(hypercertId, contribution);
86+
await updateContribution(hypercertId, contribution);
8787
} catch (error) {
8888
console.error(`[server] failed to process new contribution: ${error}`);
8989
throw new Error(`[server] failed to process new contribution: ${error}`);

lib/impact-reports.ts

+20-45
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
import "server-only";
22

33
import {
4-
HypercertClaimdata,
54
HypercertClient,
6-
type HypercertMetadata,
75
} from "@hypercerts-org/sdk";
86
import { Mutex } from "async-mutex";
97

108
import type { Report } from "@/types";
119
import { getCMSReports, getFundedAmountByHCId } from "./directus";
1210
import { getOrders } from "./marketplace";
1311
import { delay } from "./utils";
14-
import { getHypercertsByCreator } from "@/hypercerts/getHypercertsByCreator";
1512
import { getHypercertsByOwner } from "@/hypercerts/getHypercertsByOwner";
1613
import { FragmentOf } from "gql.tada";
1714

@@ -61,38 +58,19 @@ export const fetchReports = async (): Promise<Report[]> => {
6158
// step 3: get orders from marketplace
6259
const orders = await getOrders(_reports);
6360

64-
// TODO: remove this when we don't need dummy order
65-
if (process.env.DEPLOY_ENV === "production") {
66-
const orderMap = new Map(orders.map(order => [order?.hypercertId, order]));
67-
68-
69-
reports = _reports.map(report => {
70-
const order = orderMap.get(report.hypercertId);
71-
if (order) {
72-
report.order = order;
73-
} else if (report.fundedSoFar < report.totalCost) {
74-
console.warn(`[server] No order found for hypercert ${report.hypercertId}`);
75-
}
76-
return report;
77-
});
78-
79-
} else {
80-
reports = _reports.map((report) => {
81-
for (const order of orders) {
82-
if (order) {
83-
report.order = order;
84-
break;
85-
}
86-
}
87-
// warn if there is no order for a report that is not fully funded
88-
if (!report.order && report.fundedSoFar < report.totalCost) {
89-
console.warn(
90-
`[server] No order found for hypercert ${report.hypercertId}`,
91-
);
92-
}
93-
return report;
94-
});
95-
}
61+
const orderMap = new Map(orders.map(order => [order?.hypercertId, order]));
62+
63+
64+
reports = _reports.map(report => {
65+
const order = orderMap.get(report.hypercertId);
66+
if (order) {
67+
report.order = order;
68+
} else if (report.fundedSoFar < report.totalCost) {
69+
console.warn(`[server] No order found for hypercert ${report.hypercertId}`);
70+
}
71+
return report;
72+
});
73+
9674
console.log(`[server] total fetched reports: ${reports.length}`);
9775
}
9876

@@ -111,7 +89,7 @@ export const fetchReports = async (): Promise<Report[]> => {
11189
*/
11290
export const fetchReportBySlug = async (slug: string): Promise<Report> => {
11391
try {
114-
const reports = await fetchReports();
92+
let reports = await getReports();
11593

11694
const foundReport = reports.find((report: Report) => report.slug === slug);
11795
if (!foundReport) {
@@ -129,9 +107,9 @@ export const fetchReportByHCId = async (
129107
hypercertId: string,
130108
): Promise<Report> => {
131109
try {
132-
const reports = await fetchReports();
110+
let reports = await getReports();
133111

134-
const foundReport = reports.find(
112+
const foundReport = reports?.find(
135113
(report: Report) => report.hypercertId === hypercertId,
136114
);
137115
if (!foundReport) {
@@ -148,11 +126,8 @@ export const fetchReportByHCId = async (
148126
}
149127
};
150128

151-
export const getReports = (): Report[] => {
152-
if (reports) {
153-
return reports;
154-
}
155-
return [];
129+
export const getReports = async (): Promise<Report[]> => {
130+
return reports ? reports ?? [] as Report[] : await fetchReports();
156131
};
157132

158133
/**
@@ -277,7 +252,6 @@ const updateReports = async (): Promise<Report[]> => {
277252
title: claim?.metadata?.name,
278253
summary: claim?.metadata?.description,
279254
image: "https://directus.voicedeck.org/assets/" + cmsReport.image,
280-
originalReportUrl: claim?.metadata?.external_url,
281255
category: claim?.metadata?.work_scope?.[0],
282256
workTimeframe: `${(new Date(Number(claim.metadata?.work_timeframe_from) * 1000)).toLocaleDateString()} - ${(new Date(Number(claim.metadata?.work_timeframe_to) * 1000)).toLocaleDateString()}`,
283257
impactScope: claim?.metadata?.impact_scope?.[0],
@@ -298,6 +272,7 @@ const updateReports = async (): Promise<Report[]> => {
298272
dateUpdated: cmsReport.date_updated,
299273
byline: cmsReport.byline,
300274
totalCost: Number(cmsReport.total_cost),
275+
originalReportUrl: cmsReport.original_report_url,
301276
fundedSoFar: await getFundedAmountByHCId(claim.hypercert_id as string),
302277
} as Report;
303278
});
@@ -327,7 +302,7 @@ export const updateFundedAmount = async (
327302
const release = await reportsMutex.acquire();
328303

329304
try {
330-
const reports = getReports();
305+
const reports = await getReports();
331306
const report = reports.find((r) => r.hypercertId === hypercertId);
332307
if (report) {
333308
report.fundedSoFar += amount;

0 commit comments

Comments
 (0)