refactor(usage): remove CLI-side suffix filtering now that auth proxy handles it

The auth proxy intercepts GET /usage and returns only entries belonging to
the authenticated npub's clients, with owner suffixes stripped. The TUI no
longer needs to filter entries client-side.

- Remove getNpubSuffix and loadConfig from tui/usage/data.ts imports
- Remove old suffix-based filtering logic from fetchUsage()
- Remove unused getNpubSuffix from cli.ts imports
This commit is contained in:
redshift
2026-05-03 16:21:38 +08:00
parent 306dec5943
commit 9fac004f05
3 changed files with 7 additions and 17 deletions
Executable → Regular
+3 -1
View File
@@ -1,5 +1,6 @@
{
"lockfileVersion": 0,
"lockfileVersion": 1,
"configVersion": 0,
"workspaces": {
"": {
"dependencies": {
@@ -8,6 +9,7 @@
"applesauce-core": "^5.1.0",
"applesauce-relay": "^5.1.0",
"commander": "^14.0.2",
"nostr-tools": "^2.12.0",
"qrcode": "^1.5.4",
"rxjs": "^7.8.1",
"zustand": "^5.0.5",
-1
View File
@@ -7,7 +7,6 @@ import {
isDaemonRunning,
loadConfig,
getDaemonBaseUrl,
getNpubSuffix,
getUserNpub,
} from "./utils/daemon-client";
import {
+4 -15
View File
@@ -1,5 +1,5 @@
import type { UsageTrackingEntry } from "../../daemon/types.ts";
import { callDaemon, getNpubSuffix, isDaemonRunning, loadConfig } from "../../utils/daemon-client.ts";
import { callDaemon, isDaemonRunning } from "../../utils/daemon-client.ts";
import type { ClientStats, DayStats, ModelStats, ProviderStats, UsageStats } from "./types.ts";
export interface BalanceKey {
@@ -82,21 +82,10 @@ export async function fetchUsage(limit = 10000): Promise<UsageStats | null> {
const result = await callDaemon(`/usage?limit=${limit}`);
if (result.error) return null;
// The daemon returns { output: [...] } where output is the entries array directly.
// In remote daemon mode, client IDs are suffixed with the last 7 chars of our npub.
// Fetch the full daemon result, but only display/aggregate entries for our clients.
// The auth proxy filters usage to the authenticated npub's clients and
// returns client IDs without the owner suffix.
const entries = result.output as UsageTrackingEntry[] | undefined;
const entriesArray = Array.isArray(entries) ? entries : [];
const suffix = getNpubSuffix(await loadConfig());
const suffixStr = suffix ? `-${suffix}` : null;
const visibleEntries = suffixStr
? entriesArray
.filter((entry) => entry.client?.endsWith(suffixStr))
.map((entry) => ({
...entry,
client: entry.client?.slice(0, -suffixStr.length),
}))
: entriesArray;
const visibleEntries = Array.isArray(entries) ? entries : [];
// Calculate totals from visible entries
const totals = visibleEntries.reduce(