Skip to content
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
2 changes: 1 addition & 1 deletion apps/dashboard/src/@/lib/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ async function fetchContractName(chainId: number, contractAddress: string) {
return name;
}

const formatNumber = (num: number) => {
export const formatNumber = (num: number) => {
if (num >= 1000000) {
return `${(num / 1000000).toLocaleString(undefined, {
maximumFractionDigits: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from "@/components/analytics/date-range-selector";
import { ThirdwebBarChart } from "@/components/blocks/charts/bar-chart";
import { SkeletonContainer } from "@/components/ui/skeleton";
import { formatNumber } from "@/lib/search";
import {
type AnalyticsQueryParams,
type TotalQueryResult,
Expand Down Expand Up @@ -376,7 +377,7 @@ function AnalyticsStatUI(props: { label: string; data: number | undefined }) {
<SkeletonContainer
loadedData={props.data}
render={(v) => {
return <dd className="font-normal text-xl">{v.toLocaleString()}</dd>;
return <dd className="font-normal text-xl">{formatNumber(v)}</dd>;
}}
skeletonData={10000}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export async function getContractEventAnalytics(params: {

if (!res.ok) {
const errorText = await res.text();
throw new Error(`Failed to fetch analytics data: ${errorText}`);
throw new Error(`Failed to fetch events analytics data: ${errorText}`);
}

const json = (await res.json()) as InsightResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ export async function getContractFunctionBreakdown(params: {
startDate?: Date;
endDate?: Date;
}): Promise<FunctionBreakdownEntry[]> {
const daysDifference =
params.startDate && params.endDate
? Math.ceil(
(params.endDate.getTime() - params.startDate.getTime()) /
(1000 * 60 * 60 * 24),
)
: 30;
const queryParams = [
`chain=${params.chainId}`,
"group_by=time",
"group_by=day",
"group_by=function_selector",
"aggregate=toStartOfDay(toDate(block_timestamp)) as time",
"aggregate=count(*) as count",
`limit=${daysDifference * 10}`, // at most 10 functions per day
params.startDate
? `filter_block_timestamp_gte=${getUnixTime(params.startDate)}`
: "",
Expand Down Expand Up @@ -68,17 +74,16 @@ export async function getContractFunctionBreakdown(params: {
if (
typeof value === "object" &&
value !== null &&
"time" in value &&
"day" in value &&
"count" in value &&
"function_selector" in value &&
typeof value.function_selector === "string" &&
typeof value.time === "string" &&
typeof value.count === "number"
typeof value.day === "string"
) {
collectedAggregations.push({
count: value.count,
count: Number(value.count),
function_selector: value.function_selector,
time: value.time,
time: value.day,
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ export async function getContractTransactionAnalytics(params: {
startDate?: Date;
endDate?: Date;
}): Promise<TransactionAnalyticsEntry[]> {
const daysDifference =
params.startDate && params.endDate
? Math.ceil(
(params.endDate.getTime() - params.startDate.getTime()) /
(1000 * 60 * 60 * 24),
)
: 30;
const queryParams = [
`chain=${params.chainId}`,
"group_by=time",
"aggregate=toStartOfDay(toDate(block_timestamp)) as time",
"aggregate=count(block_timestamp) as count",
"group_by=day",
`limit=${daysDifference}`,
params.startDate
? `filter_block_timestamp_gte=${getUnixTime(params.startDate)}`
: "",
Expand All @@ -55,7 +61,8 @@ export async function getContractTransactionAnalytics(params: {
);

if (!res.ok) {
throw new Error("Failed to fetch analytics data");
const errorText = await res.text();
throw new Error(`Failed to fetch transaction analytics data: ${errorText}`);
}

const json = (await res.json()) as InsightResponse;
Expand All @@ -67,14 +74,13 @@ export async function getContractTransactionAnalytics(params: {
if (
typeof tx === "object" &&
tx !== null &&
"time" in tx &&
"day" in tx &&
"count" in tx &&
typeof tx.time === "string" &&
typeof tx.count === "number"
typeof tx.day === "string"
) {
returnValue.push({
count: tx.count,
time: new Date(tx.time),
count: Number(tx.count),
time: new Date(tx.day),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ export async function getContractUniqueWalletAnalytics(params: {
startDate?: Date;
endDate?: Date;
}): Promise<TransactionAnalyticsEntry[]> {
const daysDifference =
params.startDate && params.endDate
? Math.ceil(
(params.endDate.getTime() - params.startDate.getTime()) /
(1000 * 60 * 60 * 24),
)
: 30;
const queryParams = [
`chain=${params.chainId}`,
"group_by=time",
"aggregate=toStartOfDay(toDate(block_timestamp)) as time",
"aggregate=count(distinct from_address) as count",
"group_by=day",
"aggregate=count(distinct from_address)",
`limit=${daysDifference}`,
params.startDate
? `filter_block_timestamp_gte=${getUnixTime(params.startDate)}`
: "",
Expand All @@ -55,10 +62,12 @@ export async function getContractUniqueWalletAnalytics(params: {
);

if (!res.ok) {
throw new Error("Failed to fetch analytics data");
const errorText = await res.text();
throw new Error(`Failed to fetch wallet analytics data: ${errorText}`);
}

const json = (await res.json()) as InsightResponse;
console.log("wallet analytics json", json);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This console.log statement should be removed before merging as it appears to be debugging code. Logging large JSON objects to the console in production code can impact performance and potentially expose sensitive data in browser developer tools.

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

const aggregations = Object.values(json.aggregations[0]);

const returnValue: TransactionAnalyticsEntry[] = [];
Expand All @@ -67,14 +76,13 @@ export async function getContractUniqueWalletAnalytics(params: {
if (
typeof tx === "object" &&
tx !== null &&
"time" in tx &&
"day" in tx &&
"count" in tx &&
typeof tx.time === "string" &&
typeof tx.count === "number"
typeof tx.day === "string"
) {
returnValue.push({
count: tx.count,
time: new Date(tx.time),
count: Number(tx.count),
time: new Date(tx.day),
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export async function getTotalContractEvents(params: {
);

if (!res.ok) {
throw new Error("Failed to fetch analytics data");
const errorText = await res.text();
throw new Error(`Failed to fetch events analytics data: ${errorText}`);
}

const json = (await res.json()) as InsightResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type InsightResponse = {
aggregations: [
{
0: {
total: number;
count: number;
};
},
];
Expand All @@ -19,10 +19,9 @@ export async function getTotalContractTransactions(params: {
contractAddress: string;
chainId: number;
}): Promise<{ count: number }> {
const queryParams = [
`chain=${params.chainId}`,
"aggregate=count(block_number) as total",
].join("&");
const queryParams = [`chain=${params.chainId}`, "aggregate=count()"].join(
"&",
);

const res = await fetch(
`https://insight.${thirdwebDomain}.com/v1/transactions/${params.contractAddress}?${queryParams}`,
Expand All @@ -34,12 +33,15 @@ export async function getTotalContractTransactions(params: {
);

if (!res.ok) {
throw new Error("Failed to fetch analytics data");
const errorText = await res.text();
throw new Error(
`Failed to fetch transactions analytics data: ${errorText}`,
);
}

const json = (await res.json()) as InsightResponse;

return {
count: json.aggregations[0][0].total,
count: json.aggregations[0][0].count,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type InsightResponse = {
aggregations: [
{
0: {
total: number;
count: number;
};
},
];
Expand All @@ -21,7 +21,7 @@ export async function getTotalContractUniqueWallets(params: {
}): Promise<{ count: number }> {
const queryParams = [
`chain=${params.chainId}`,
"aggregate=count(distinct from_address) as total",
"aggregate=count(distinct from_address)",
].join("&");

const res = await fetch(
Expand All @@ -34,12 +34,15 @@ export async function getTotalContractUniqueWallets(params: {
);

if (!res.ok) {
throw new Error("Failed to fetch analytics data");
const errorText = await res.text();
throw new Error(
`Failed to fetch unique wallets analytics data: ${errorText}`,
);
}

const json = (await res.json()) as InsightResponse;

return {
count: json.aggregations[0][0].total,
count: json.aggregations[0][0].count,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,13 @@ export function TransactionsSection(props: { client: ThirdwebClient }) {
}

const response = await fetch(url.toString());

if (!response.ok) {
throw new Error(
`Failed to fetch transactions: ${response.status} - ${await response.text()}`,
);
}

const json = (await response.json()) as {
data?: WalletTransaction[];
};
Expand Down
Loading