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

fix: support development environment #68

Merged
merged 1 commit into from
Mar 22, 2024
Merged
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
12 changes: 11 additions & 1 deletion components/report-details/support/dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,17 @@ const SupportContent = ({
</div>
);
}
return <SupportReportForm hypercertId={hypercertId} />;
// TODO: remove this when we don't need dummy order
if (process.env.DEPLOY_ENV === "production") {
return <SupportReportForm hypercertId={hypercertId} />;
}
return (
<SupportReportForm
hypercertId={
"0xa16dfb32eb140a6f3f2ac68f41dad8c7e83c4941-39472754562828861761751454462085112528896"
}
/>
);
};

const ReportSupportUI = ({
Expand Down
3 changes: 2 additions & 1 deletion components/report-details/support/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ const SupportReportForm = ({ hypercertId }: SupportReportFormProps) => {
const { form, onSubmit, isProcessing } = useSupportForm(
Number(dollarAmountNeeded),
pricePerUnit,
orders?.[0],
// TODO: remove this when we don't need dummy order
process.env.DEPLOY_ENV === "production" ? orders?.[0] : orders?.[5],
handleBuyFraction,
address,
hypercertId,
Expand Down
2 changes: 1 addition & 1 deletion hooks/use-support-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { Address } from "viem";
import { z } from "zod";
import type { useHandleBuyFraction } from "./use-buy-fraction";

interface SupportFormInputs {
export interface SupportFormInputs {
fractionPayment: number;
comment: string;
hideName: boolean;
Expand Down
22 changes: 20 additions & 2 deletions lib/impact-reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ export const fetchReports = async (): Promise<Report[]> => {

// step 3: get orders from marketplace
const orders = await getOrders(reports);

// TODO: remove this when we don't need dummy order
if (process.env.DEPLOY_ENV === "production") {
reports = reports.map((report) => {
for (const order of orders) {
if (order && order.hypercertId === report.hypercertId) {
Expand All @@ -118,8 +121,23 @@ export const fetchReports = async (): Promise<Report[]> => {
}
return report;
});

console.log(`report order ${JSON.stringify(reports[0].order)}`);
} else {
reports = reports.map((report) => {
for (const order of orders) {
if (order) {
report.order = order;
break;
}
}
// not fully funded reports should have an order
if (!report.order && report.fundedSoFar < report.totalCost) {
throw new Error(
`[server] No order found for hypercert ${report.hypercertId}`,
);
}
return report;
});
}
console.log(`[server] total fetched reports: ${reports.length}`);
}

Expand Down
21 changes: 18 additions & 3 deletions lib/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,31 @@ export async function getOrders(reports: Report[]): Promise<(Order | null)[]> {
);
console.log(`[server] existing Hypercert orders: ${orders.length}`);
} else {
// fetch only orders for reports that are not fully funded

// TODO: remove this when we don't need dummy order
if (process.env.DEPLOY_ENV === "production") {
// fetch only orders for reports that are not fully funded
orders = await Promise.all(
reports.map((report) =>
report.fundedSoFar < report.totalCost
? fetchOrder(report.hypercertId)
: null
)
);
console.log(`[server] fetched orders: ${orders.length}`);
} else {
// fetch only orders for reports that are not fully funded
orders = await Promise.all(
reports.map((report) =>
report.fundedSoFar < report.totalCost
? fetchOrder(report.hypercertId)
? fetchOrder("0xa16dfb32eb140a6f3f2ac68f41dad8c7e83c4941-39472754562828861761751454462085112528896")
: null
)
);
console.log(`[server] fetched orders: ${orders.length}`);
console.log(`[server] fetched orders: ${orders.filter(order => order !== null).length}`);
}
}

return orders;
} catch (error) {
console.error(`[server] Failed to fetch orders: ${error}`);
Expand Down
2 changes: 1 addition & 1 deletion next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const nextConfig = {
images: {
remotePatterns: [
{
hostname: "directus.voicedeck.org",
hostname: process.env.DEPLOY_ENV === "production" ? "directus.voicedeck.org" : "directus.vd-dev.org",
protocol: "https",
}
]
Expand Down
Loading