+
+
-
+
= T | undefined | null;
const registryStore = useRegistryStore();
diff --git a/src/components/address/AddressHeader.vue b/src/components/address/AddressHeader.vue
index 3b8a452..a156dc1 100644
--- a/src/components/address/AddressHeader.vue
+++ b/src/components/address/AddressHeader.vue
@@ -68,7 +68,7 @@ onBeforeUnmount(() => {
const qrAddress = computed(() =>
normalizeDisplayAddress(props.address, {
removePrefix: false,
- }),
+ }) || "",
);
const displayAddress = computed(() => normalizeDisplayAddress(props.address));
const addressType = computed(() => getAddressType(qrAddress.value));
diff --git a/src/components/address/AddressTransaction.vue b/src/components/address/AddressTransaction.vue
index 01c3c90..c0e28c2 100644
--- a/src/components/address/AddressTransaction.vue
+++ b/src/components/address/AddressTransaction.vue
@@ -25,29 +25,24 @@
diff --git a/src/module/cashTokenActivity.ts b/src/module/cashTokenActivity.ts
new file mode 100644
index 0000000..f317108
--- /dev/null
+++ b/src/module/cashTokenActivity.ts
@@ -0,0 +1,154 @@
+import {
+ literal,
+ maxLength,
+ minLength,
+ object,
+ pipe,
+ safeParse,
+ string,
+ trim,
+} from "valibot";
+import type { GetCashTokenActivityQuery } from "~/graphql/graphql";
+
+export const cashTokenActivityLimits = {
+ blocks: 3,
+ transactionsPerBlock: 20,
+ outputsPerTransaction: 50,
+ categoriesPerPage: 8,
+};
+
+export function cashTokenActivityVariables(network: string) {
+ return {
+ network,
+ blocks: cashTokenActivityLimits.blocks,
+ // One extra row detects truncation; sentinels never enter the metrics.
+ transactions: cashTokenActivityLimits.transactionsPerBlock + 1,
+ outputs: cashTokenActivityLimits.outputsPerTransaction + 1,
+ };
+}
+
+export function summarizeCashTokenActivity(
+ blocks: GetCashTokenActivityQuery["block"],
+) {
+ const window = blocks.slice(0, cashTokenActivityLimits.blocks);
+ const transactions = window.flatMap((block) =>
+ block.transactions.slice(0, cashTokenActivityLimits.transactionsPerBlock),
+ );
+ const outputs = transactions.flatMap(({ transaction }) =>
+ transaction.outputs
+ .slice(0, cashTokenActivityLimits.outputsPerTransaction)
+ .flatMap((output) =>
+ output.token_category
+ ? [
+ {
+ category: output.token_category.slice(2),
+ txid: transaction.hash.slice(2),
+ output,
+ },
+ ]
+ : [],
+ ),
+ );
+ const categories = new Map(
+ outputs.map(({ category, txid }) => [
+ category,
+ {
+ category,
+ latestTxid: txid,
+ transactions: new Set(),
+ fungibleUnits: 0n,
+ nftOutputs: 0,
+ mintingOutputs: 0,
+ },
+ ]),
+ );
+ const seenOutputs = new Set();
+ const seenTransactions = new Set();
+ for (const { category, txid, output } of outputs) {
+ const row = categories.get(category);
+ const outputId = `${txid}:${output.output_index}`;
+ if (!row || seenOutputs.has(outputId)) continue;
+ seenOutputs.add(outputId);
+ seenTransactions.add(txid);
+ // The query orders blocks and transactions newest first.
+ if (row.transactions.size === 0) row.latestTxid = txid;
+ row.transactions.add(txid);
+ if (
+ output.fungible_token_amount !== null &&
+ output.fungible_token_amount !== undefined
+ ) {
+ row.fungibleUnits += BigInt(output.fungible_token_amount);
+ }
+ if (
+ output.nonfungible_token_capability !== null &&
+ output.nonfungible_token_capability !== undefined
+ ) {
+ row.nftOutputs += 1;
+ }
+ if (output.nonfungible_token_capability === "minting")
+ row.mintingOutputs += 1;
+ }
+ return {
+ blocks: window.map(({ hash, height, timestamp }) => ({
+ hash: hash.slice(2),
+ height,
+ timestamp,
+ })),
+ transactionCount: seenTransactions.size,
+ nftOutputs: Array.from(categories.values()).reduce(
+ (sum, row) => sum + row.nftOutputs,
+ 0,
+ ),
+ truncated:
+ window.some(
+ (block) =>
+ block.transactions.length >
+ cashTokenActivityLimits.transactionsPerBlock,
+ ) ||
+ transactions.some(
+ ({ transaction }) =>
+ transaction.outputs.length >
+ cashTokenActivityLimits.outputsPerTransaction,
+ ),
+ // Keep first-observed order; this is activity, not a popularity ranking.
+ categories: Array.from(categories.values(), (row) => ({
+ category: row.category,
+ latestTxid: row.latestTxid,
+ transactionCount: row.transactions.size,
+ fungibleUnits: row.fungibleUnits.toString(),
+ nftOutputs: row.nftOutputs,
+ mintingOutputs: row.mintingOutputs,
+ })),
+ };
+}
+
+export function cashTokenCategoryPage(
+ categories: ReturnType["categories"],
+ requestedPage: number,
+) {
+ const pages = Math.max(
+ 1,
+ Math.ceil(categories.length / cashTokenActivityLimits.categoriesPerPage),
+ );
+ const page = Math.min(pages, Math.max(1, Math.trunc(requestedPage)));
+ return {
+ page,
+ pages,
+ rows: categories.slice(
+ (page - 1) * cashTokenActivityLimits.categoriesPerPage,
+ page * cashTokenActivityLimits.categoriesPerPage,
+ ),
+ };
+}
+
+// Registry metadata is optional and untrusted. It never changes on-chain units.
+export function cashTokenActivityName(category: string, identity: unknown) {
+ const parsed = safeParse(
+ object({
+ name: pipe(string(), trim(), minLength(1), maxLength(120)),
+ token: object({ category: literal(category) }),
+ }),
+ identity,
+ );
+ return parsed.success ? parsed.output.name : "Unnamed token";
+}
diff --git a/src/module/cashTokenActivityQuery.ts b/src/module/cashTokenActivityQuery.ts
new file mode 100644
index 0000000..f683d57
--- /dev/null
+++ b/src/module/cashTokenActivityQuery.ts
@@ -0,0 +1,32 @@
+export const GetCashTokenActivity = gql(`
+ query GetCashTokenActivity($network: String!, $blocks: Int!, $transactions: Int!, $outputs: Int!) {
+ block(
+ where: { accepted_by: { node: { name: { _regex: $network } } } }
+ order_by: [{ height: desc }, { hash: asc }]
+ limit: $blocks
+ ) {
+ hash
+ height
+ timestamp
+ transactions(
+ where: { transaction: { outputs: { token_category: { _is_null: false } } } }
+ order_by: { transaction_index: desc }
+ limit: $transactions
+ ) {
+ transaction {
+ hash
+ outputs(
+ where: { token_category: { _is_null: false } }
+ order_by: { output_index: asc }
+ limit: $outputs
+ ) {
+ output_index
+ token_category
+ fungible_token_amount
+ nonfungible_token_capability
+ }
+ }
+ }
+ }
+ }
+`);
diff --git a/src/pages/index.vue b/src/pages/index.vue
index 90473e1..f9fa225 100644
--- a/src/pages/index.vue
+++ b/src/pages/index.vue
@@ -10,6 +10,7 @@
+
diff --git a/tests/cash-token-activity.test.ts b/tests/cash-token-activity.test.ts
new file mode 100644
index 0000000..9c22696
--- /dev/null
+++ b/tests/cash-token-activity.test.ts
@@ -0,0 +1,353 @@
+import { describe, expect, test } from "bun:test";
+import { readFile } from "node:fs/promises";
+import { buildSchema, graphql, print, validate } from "graphql";
+import type { GetCashTokenActivityQuery } from "../src/graphql/graphql";
+import { GetCashTokenActivityDocument } from "../src/graphql/graphql";
+import {
+ cashTokenActivityLimits,
+ cashTokenActivityName,
+ cashTokenActivityVariables,
+ cashTokenCategoryPage,
+ summarizeCashTokenActivity,
+} from "../src/module/cashTokenActivity";
+import type { bytea } from "../src/types";
+
+const categoryA = `\\x${"a".repeat(64)}` as const;
+const categoryB = `\\x${"b".repeat(64)}` as const;
+
+function output(
+ category: bytea | null,
+ index = "0",
+ values: Partial<
+ GetCashTokenActivityQuery["block"][number]["transactions"][number]["transaction"]["outputs"][number]
+ > = {},
+) {
+ return {
+ output_index: index,
+ token_category: category,
+ fungible_token_amount: null,
+ nonfungible_token_capability: null,
+ ...values,
+ };
+}
+
+function transaction(
+ txid: string,
+ outputs: GetCashTokenActivityQuery["block"][number]["transactions"][number]["transaction"]["outputs"],
+) {
+ return {
+ transaction: { hash: `\\x${txid.padStart(64, "0")}` as const, outputs },
+ };
+}
+
+function block(
+ height: string,
+ transactions: GetCashTokenActivityQuery["block"][number]["transactions"],
+) {
+ return {
+ hash: `\\x${height.padStart(64, "0")}` as const,
+ height,
+ timestamp: "1730000000",
+ transactions,
+ };
+}
+
+describe("bounded CashToken output activity", () => {
+ test("counts transactions once globally and once per category, with exact per-category raw units", () => {
+ const first = transaction("1", [
+ output(categoryA, "0", { fungible_token_amount: "9007199254740993" }),
+ output(categoryA, "1", { fungible_token_amount: "7" }),
+ output(categoryB, "2", { fungible_token_amount: "2" }),
+ ]);
+ const summary = summarizeCashTokenActivity([
+ block("200", [
+ first,
+ transaction("2", [
+ output(categoryA, "0", {
+ fungible_token_amount: "9223372036854775807",
+ }),
+ ]),
+ ]),
+ ]);
+ expect(summary.transactionCount).toBe(2);
+ expect(summary.categories).toEqual([
+ {
+ category: categoryA.slice(2),
+ latestTxid: first.transaction.hash.slice(2),
+ transactionCount: 2,
+ fungibleUnits: "9232379236109516807",
+ nftOutputs: 0,
+ mintingOutputs: 0,
+ },
+ {
+ category: categoryB.slice(2),
+ latestTxid: first.transaction.hash.slice(2),
+ transactionCount: 1,
+ fungibleUnits: "2",
+ nftOutputs: 0,
+ mintingOutputs: 0,
+ },
+ ]);
+ expect(summary.truncated).toBe(false);
+ });
+
+ test("distinguishes NFT-only, FT-only and mixed outputs; minting capability is an output count", () => {
+ const summary = summarizeCashTokenActivity([
+ block("200", [
+ transaction("1", [
+ output(categoryA, "0", { nonfungible_token_capability: "none" }),
+ output(categoryA, "1", { nonfungible_token_capability: "mutable" }),
+ output(categoryA, "2", {
+ nonfungible_token_capability: "minting",
+ fungible_token_amount: "5",
+ }),
+ output(categoryA, "3", { fungible_token_amount: "7" }),
+ ]),
+ ]),
+ ]);
+ expect(summary.categories[0]).toMatchObject({
+ transactionCount: 1,
+ fungibleUnits: "12",
+ nftOutputs: 3,
+ mintingOutputs: 1,
+ });
+ expect(summary.nftOutputs).toBe(3);
+ });
+
+ test("deduplicates identical outpoints and transactions across block inclusions without losing distinct outputs", () => {
+ const tx = transaction("1", [
+ output(categoryA, "0", {
+ nonfungible_token_capability: "none",
+ fungible_token_amount: "3",
+ }),
+ output(categoryA, "1", { fungible_token_amount: "4" }),
+ ]);
+ const summary = summarizeCashTokenActivity([
+ block("200", [tx, tx]),
+ block("199", [tx]),
+ ]);
+ expect(summary.transactionCount).toBe(1);
+ expect(summary.categories[0]).toMatchObject({
+ transactionCount: 1,
+ fungibleUnits: "7",
+ nftOutputs: 1,
+ });
+ });
+
+ test("empty windows and non-token outputs are not fabricated activity", () => {
+ expect(summarizeCashTokenActivity([])).toMatchObject({
+ blocks: [],
+ categories: [],
+ transactionCount: 0,
+ truncated: false,
+ });
+ expect(
+ summarizeCashTokenActivity([
+ block("200", []),
+ block("199", [transaction("1", [output(null)])]),
+ ]),
+ ).toMatchObject({ categories: [], transactionCount: 0, nftOutputs: 0 });
+ });
+
+ test("uses only the accepted block window supplied, including empty blocks; keeps newest observed category transaction", () => {
+ const summary = summarizeCashTokenActivity([
+ block("200", []),
+ block("199", [transaction("2", [output(categoryB)])]),
+ block("198", [
+ transaction("1", [output(categoryB), output(categoryA, "1")]),
+ ]),
+ block("197", [
+ transaction("3", [
+ output(categoryA, "0", { fungible_token_amount: "999" }),
+ ]),
+ ]),
+ ]);
+ expect(summary.blocks.map((item) => item.height)).toEqual([
+ "200",
+ "199",
+ "198",
+ ]);
+ expect(summary.categories.map((item) => item.category)).toEqual([
+ categoryB.slice(2),
+ categoryA.slice(2),
+ ]);
+ expect(summary.categories[0]?.latestTxid).toBe("2".padStart(64, "0"));
+ expect(summary.transactionCount).toBe(2);
+ expect(summary.categories[1]?.fungibleUnits).toBe("0");
+ });
+
+ test("transaction sentinel signals a partial sample but never contributes to categories or totals", () => {
+ const summary = summarizeCashTokenActivity([
+ block("200", [
+ ...Array.from(
+ { length: cashTokenActivityLimits.transactionsPerBlock },
+ (_, index) => transaction(String(index), [output(categoryA)]),
+ ),
+ transaction("999", [
+ output(categoryB, "0", { fungible_token_amount: "999999" }),
+ ]),
+ ]),
+ ]);
+ expect(summary.truncated).toBe(true);
+ expect(summary.transactionCount).toBe(20);
+ expect(summary.categories.map((item) => item.category)).toEqual([
+ categoryA.slice(2),
+ ]);
+ });
+
+ test("output sentinel signals truncation; exact limit alone does not", () => {
+ const outputs = Array.from(
+ { length: cashTokenActivityLimits.outputsPerTransaction },
+ (_, index) =>
+ output(categoryA, String(index), { fungible_token_amount: "1" }),
+ );
+ const complete = summarizeCashTokenActivity([
+ block("200", [transaction("1", outputs)]),
+ ]);
+ const sampled = summarizeCashTokenActivity([
+ block("200", [
+ transaction("1", [
+ ...outputs,
+ output(categoryB, "50", { nonfungible_token_capability: "minting" }),
+ ]),
+ ]),
+ ]);
+ expect(complete.truncated).toBe(false);
+ expect(sampled.truncated).toBe(true);
+ expect(sampled.categories).toEqual(complete.categories);
+ expect(sampled.nftOutputs).toBe(0);
+ expect(sampled.categories[0]?.fungibleUnits).toBe("50");
+ });
+
+ test("category pages do not alter window totals and clamp when the refreshed window shrinks", () => {
+ const summary = summarizeCashTokenActivity([
+ block("200", [
+ transaction(
+ "1",
+ Array.from({ length: 19 }, (_, index) =>
+ output(`\\x${String(index).padStart(64, "0")}`, String(index)),
+ ),
+ ),
+ ]),
+ ]);
+ const first = cashTokenCategoryPage(summary.categories, 1);
+ const second = cashTokenCategoryPage(summary.categories, 2);
+ const third = cashTokenCategoryPage(summary.categories, 99);
+ expect([first.rows.length, second.rows.length, third.rows.length]).toEqual([
+ 8, 8, 3,
+ ]);
+ expect(
+ new Set(
+ [...first.rows, ...second.rows, ...third.rows].map(
+ (row) => row.category,
+ ),
+ ).size,
+ ).toBe(19);
+ expect(summary.transactionCount).toBe(1);
+ expect(
+ cashTokenCategoryPage(summary.categories.slice(0, 2), 3),
+ ).toMatchObject({ page: 1, pages: 1 });
+ expect(cashTokenCategoryPage([], -1)).toEqual({
+ page: 1,
+ pages: 1,
+ rows: [],
+ });
+ });
+});
+
+describe("optional CashToken registry names", () => {
+ test("accepts a matching category's name without trusting decimals or interpreting output units", () => {
+ expect(
+ cashTokenActivityName(categoryA.slice(2), {
+ name: " Example token ",
+ token: { category: categoryA.slice(2), decimals: "invalid" },
+ }),
+ ).toBe("Example token");
+ });
+
+ test.each([
+ undefined,
+ null,
+ {},
+ { name: " " },
+ { name: 123 },
+ { name: "Wrong category", token: { category: categoryB.slice(2) } },
+ { name: "x".repeat(121), token: { category: categoryA.slice(2) } },
+ ])(
+ "missing or invalid metadata uses an explicit fallback: %j",
+ (identity) => {
+ expect(cashTokenActivityName(categoryA.slice(2), identity)).toBe(
+ "Unnamed token",
+ );
+ },
+ );
+});
+
+test("activity query validates against the checked-in schema and executes bounded, ordered, network-filtered selections", async () => {
+ const schema = buildSchema(
+ await readFile(
+ new URL("../schema/chaingraph.graphql", import.meta.url),
+ "utf8",
+ ),
+ );
+ expect(validate(schema, GetCashTokenActivityDocument)).toEqual([]);
+ const requested = { blocks: 0, transactions: 0, outputs: 0 };
+ const response = await graphql({
+ schema,
+ source: print(GetCashTokenActivityDocument),
+ variableValues: cashTokenActivityVariables("chipnet"),
+ rootValue: {
+ block(args: { limit: number; where: unknown; order_by: unknown }) {
+ requested.blocks = args.limit;
+ expect(args.where).toEqual({
+ accepted_by: { node: { name: { _regex: "chipnet" } } },
+ });
+ expect(args.order_by).toEqual([{ height: "desc" }, { hash: "asc" }]);
+ return [
+ {
+ ...block("200", []),
+ transactions(args: {
+ limit: number;
+ where: unknown;
+ order_by: unknown;
+ }) {
+ requested.transactions = args.limit;
+ expect(args.where).toEqual({
+ transaction: {
+ outputs: { token_category: { _is_null: false } },
+ },
+ });
+ expect(args.order_by).toEqual([{ transaction_index: "desc" }]);
+ return [
+ {
+ transaction: {
+ ...transaction("1", []).transaction,
+ outputs(args: {
+ limit: number;
+ where: unknown;
+ order_by: unknown;
+ }) {
+ requested.outputs = args.limit;
+ expect(args.where).toEqual({
+ token_category: { _is_null: false },
+ });
+ expect(args.order_by).toEqual([{ output_index: "asc" }]);
+ return [
+ output(categoryA, "0", {
+ fungible_token_amount: "9007199254740993",
+ }),
+ ];
+ },
+ },
+ },
+ ];
+ },
+ },
+ ];
+ },
+ },
+ });
+ expect(response.errors).toBeUndefined();
+ expect(requested).toEqual({ blocks: 3, transactions: 21, outputs: 51 });
+ expect(response.data?.block).toBeDefined();
+});
From 6116d8402d9f74269936427e068430ca402e8236 Mon Sep 17 00:00:00 2001
From: Salem Mohammed Shamakh <58360393+salemkode@users.noreply.github.com>
Date: Sat, 14 Nov 2026 23:18:29 +0300
Subject: [PATCH 4/4] feat: show live node network status on the homepage
---
docs/network-status.md | 35 +++
nuxt.config.mts | 13 +-
src/components/home/BlocksList.vue | 3 +-
src/components/home/NetworkActivity.vue | 28 +++
src/components/home/NetworkStatus.vue | 64 ++++++
.../home/UnconfirmedTransaction.vue | 69 ++----
src/composables/useHomeNetwork.ts | 64 ++++++
src/composables/useNetworkStatus.ts | 117 ++++++++++
src/module/chaingraph.ts | 78 ++++---
src/pages/index.vue | 15 +-
src/types/apollo.d.ts | 9 +
tests/home-network.test.ts | 144 +++++++++++++
tests/network-status.test.ts | 202 ++++++++++++++++++
13 files changed, 746 insertions(+), 95 deletions(-)
create mode 100644 docs/network-status.md
create mode 100644 src/components/home/NetworkActivity.vue
create mode 100644 src/components/home/NetworkStatus.vue
create mode 100644 src/composables/useHomeNetwork.ts
create mode 100644 src/composables/useNetworkStatus.ts
create mode 100644 src/types/apollo.d.ts
create mode 100644 tests/home-network.test.ts
create mode 100644 tests/network-status.test.ts
diff --git a/docs/network-status.md b/docs/network-status.md
new file mode 100644
index 0000000..c3a0344
--- /dev/null
+++ b/docs/network-status.md
@@ -0,0 +1,35 @@
+# Homepage network status
+
+The compact status panel reports the selected **Mainnet** or **Chipnet** node’s
+current accepted tip, its miner-reported block age, and the node’s mempool count.
+It identifies both the configured Chaingraph host and the node name. These are
+one node’s observations, not global network totals, hashrate, peer count, or a
+guarantee that the node is fully synchronized.
+
+The summary shares the existing mempool subscription with Latest Transactions:
+the highest current accepted block for the selected network, one accepting node
+(`node_internal_id` ascending), and at most nine recent transactions.
+Reorganizations replace the accepted tip, including a lower height. Switching
+networks remounts this feed, immediately
+clearing the previous network’s values and disposing its subscription, connection
+listeners, and timers.
+
+- **Connecting**: no response yet; missing values display “Loading…”.
+- **Live**: a successful subscription result, with no freshness warning.
+- **Reconnecting**: the existing WebSocket reported an interruption; last received
+ values remain labeled until a fresh result arrives.
+- **Unavailable**: a subscription error, or no response within 30 seconds of
+ mounting/reconnecting. Use **Retry connection** to restart this subscription.
+- **No chain data**: a successful response contains no accepted block for the
+ selected network. Missing counts stay unavailable; a reported mempool count of
+ zero remains a real zero.
+- **Stale**: no subscription update for five minutes, or the accepted tip’s block
+ timestamp is at least two hours old. A quiet subscription can also produce the
+ first warning; this is a freshness caution, not proof of an outage. Block age
+ comes from the miner’s timestamp and can differ from actual time.
+
+A component-scoped 15-second clock updates ages and freshness warnings without
+polling the provider. The existing WebSocket handles automatic reconnection;
+terminal errors expose the manual retry button. No extra endpoint or credentials
+are required. Fixture tests cover missing/zero data, failures, stale/recovery,
+reorganizations, network isolation, retry, and lifecycle cleanup.
diff --git a/nuxt.config.mts b/nuxt.config.mts
index 78def20..bcd0c37 100644
--- a/nuxt.config.mts
+++ b/nuxt.config.mts
@@ -2,11 +2,17 @@ import tailwindcss from "@tailwindcss/vite";
import codegen from "vite-plugin-graphql-codegen";
import { watch } from "vite-plugin-watch";
+const chaingraphHttp =
+ process.env.CHAINGRAPH_HTTP || "https://gql.chaingraph.pat.mn/v1/graphql";
+const chaingraphWs =
+ process.env.CHAINGRAPH_WS || "wss://gql.chaingraph.pat.mn/v1/graphql";
+
export default defineNuxtConfig({
ssr: false,
runtimeConfig: {
public: {
+ chaingraphSource: new URL(chaingraphWs).host,
ipfsGateway:
process.env.NUXT_PUBLIC_IPFS_GATEWAY ||
process.env.IPFS_GATEWAY ||
@@ -69,11 +75,8 @@ export default defineNuxtConfig({
apollo: {
clients: {
default: {
- httpEndpoint:
- process.env.CHAINGRAPH_HTTP ||
- "https://gql.chaingraph.pat.mn/v1/graphql",
- wsEndpoint:
- process.env.CHAINGRAPH_WS || "wss://gql.chaingraph.pat.mn/v1/graphql",
+ httpEndpoint: chaingraphHttp,
+ wsEndpoint: chaingraphWs,
},
},
},
diff --git a/src/components/home/BlocksList.vue b/src/components/home/BlocksList.vue
index bdef210..b3c1083 100644
--- a/src/components/home/BlocksList.vue
+++ b/src/components/home/BlocksList.vue
@@ -9,8 +9,7 @@