fix: use real totalCount from Subsquid instead of capped fetch limit
Add totalCount to the GraphQL query so transactionCount reflects the true number of transfers in the period, not the 2000-item fetch cap. This also fixes the average Ğ1/tx calculation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -37,10 +37,9 @@ async function fetchLiveTransactions(periodDays: number): Promise<{
|
|||||||
totalCount: number;
|
totalCount: number;
|
||||||
totalVolume: number;
|
totalVolume: number;
|
||||||
}> {
|
}> {
|
||||||
const rawTransfers = await fetchTransfers(periodDays);
|
const { transfers: rawTransfers, totalCount } = await fetchTransfers(periodDays);
|
||||||
if (rawTransfers.length === 0) return { geolocated: [], totalCount: 0, totalVolume: 0 };
|
if (rawTransfers.length === 0) return { geolocated: [], totalCount: 0, totalVolume: 0 };
|
||||||
|
|
||||||
const totalCount = rawTransfers.length;
|
|
||||||
const totalVolume = rawTransfers.reduce((s, t) => s + t.amount, 0);
|
const totalVolume = rawTransfers.reduce((s, t) => s + t.amount, 0);
|
||||||
|
|
||||||
// Carte SS58 courant → clé Duniter (= _id Cesium+)
|
// Carte SS58 courant → clé Duniter (= _id Cesium+)
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ const SubsquidTransferNodeSchema = z.object({
|
|||||||
const SubsquidResponseSchema = z.object({
|
const SubsquidResponseSchema = z.object({
|
||||||
data: z.object({
|
data: z.object({
|
||||||
transfers: z.object({
|
transfers: z.object({
|
||||||
|
totalCount: z.number().int(),
|
||||||
nodes: z.array(SubsquidTransferNodeSchema),
|
nodes: z.array(SubsquidTransferNodeSchema),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -62,6 +63,7 @@ const TRANSFERS_QUERY = `
|
|||||||
first: $limit
|
first: $limit
|
||||||
filter: { timestamp: { greaterThanOrEqualTo: $since } }
|
filter: { timestamp: { greaterThanOrEqualTo: $since } }
|
||||||
) {
|
) {
|
||||||
|
totalCount
|
||||||
nodes {
|
nodes {
|
||||||
id
|
id
|
||||||
blockNumber
|
blockNumber
|
||||||
@@ -151,10 +153,15 @@ export async function buildIdentityKeyMap(): Promise<Map<string, string>> {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface FetchTransfersResult {
|
||||||
|
transfers: RawTransfer[];
|
||||||
|
totalCount: number;
|
||||||
|
}
|
||||||
|
|
||||||
export async function fetchTransfers(
|
export async function fetchTransfers(
|
||||||
periodDays: number,
|
periodDays: number,
|
||||||
limit = 2000
|
limit = 2000
|
||||||
): Promise<RawTransfer[]> {
|
): Promise<FetchTransfersResult> {
|
||||||
const since = new Date(
|
const since = new Date(
|
||||||
Date.now() - periodDays * 24 * 60 * 60 * 1000
|
Date.now() - periodDays * 24 * 60 * 60 * 1000
|
||||||
).toISOString();
|
).toISOString();
|
||||||
@@ -180,12 +187,15 @@ export async function fetchTransfers(
|
|||||||
|
|
||||||
const parsed = SubsquidResponseSchema.parse(raw);
|
const parsed = SubsquidResponseSchema.parse(raw);
|
||||||
|
|
||||||
return parsed.data.transfers.nodes.map((node) => ({
|
return {
|
||||||
id: node.id,
|
totalCount: parsed.data.transfers.totalCount,
|
||||||
timestamp: new Date(node.timestamp).getTime(),
|
transfers: parsed.data.transfers.nodes.map((node) => ({
|
||||||
amount: parseInt(node.amount, 10) / 100,
|
id: node.id,
|
||||||
fromId: node.fromId ?? '',
|
timestamp: new Date(node.timestamp).getTime(),
|
||||||
toId: node.toId ?? '',
|
amount: parseInt(node.amount, 10) / 100,
|
||||||
fromName: node.from?.linkedIdentity?.name ?? '',
|
fromId: node.fromId ?? '',
|
||||||
}));
|
toId: node.toId ?? '',
|
||||||
|
fromName: node.from?.linkedIdentity?.name ?? '',
|
||||||
|
})),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user