Skip to content

feat(wallet): transaction summary aggregation + daily gift ledger + net whitelist (rants 2026-08-22T00:04:21/00:07:08/06:34:37) - #114

Merged
argszero merged 1 commit into
mainfrom
feat/tx-summary
Aug 21, 2026
Merged

argszero merged 1 commit into
mainfrom
feat/tx-summary

Conversation

@argszero

Copy link
Copy Markdown
Owner

Summary

Fix the transaction summary accounting + add full token statistics, per host rants 2026-08-22T00:04:21, 2026-08-22T00:07:08 and 2026-08-22T06:34:37 (project=aitokenpool). These three rants share the same root: income/expense classification and full-aggregation statistics.

Backend:

  • GET /api/transactions response now includes summary — full SQL aggregation (not page-dependent), respecting the current type filter:
    "summary": { "income_pts", "expense_pts", "net_pts", "tokens", "input_tokens", "cached_tokens", "output_tokens" }
    Income whitelist = earn/topup/gift (positive), consume = negative; input = tokens − cached − output
  • type filter now accepts gift
  • Daily gift now writes a transactions row (type='gift') in gift.rs ensure_daily_gift — the ledger finally matches the balance (previously invisible)
  • Dashboard net/series SQL whitelist fixed (06:34:37): only earn was counted positive → topup (+2000) was subtracted as −2000. Now earn/topup/gift positive, consume negative.

Frontend:

  • renderTxSummary uses the backend summary (no longer local page-only sum); falls back to type-based classification (not pts-sign) when summary is absent
  • Token stats displayed: Total / Input / Cached / Output (M/K format)
  • i18n: tx.summary.tokens/input/cached/output zh+en

Tests (138/138 + fmt + clippy + node --check clean):

  • transactions_summary_and_dashboard_net_with_topup: topup(+2000) + consume(0.5, 1000 tok, 200 cached, 100 out) + gift(+1) → income 2001 / expense 0.5 / net 2000.5; token sums; type=consume filter scopes summary; dashboard net = 2000.5 (topup positive)
  • gift_writes_transaction_record: gift grant writes type='gift' tx
  • wallet_summary_and_dashboard updated: net now includes the daily gift (+1) since it's ledgered

Related Issue

Host rants (project=aitokenpool), verbatim summaries:

  • 2026-08-22T00:04:21 — 交易记录汇总条错误:consume 被算进「总收入」+ 每日赠送不入账
  • 2026-08-22T00:07:08 — 交易记录汇总条增加 Token 统计(后端 summary 全量聚合,与 00:04:21 一起实现)
  • 2026-08-22T06:34:37 — 仪表盘「本月净变化」错误:topup 充值被当成负数扣减

Changes

  • Backend summary aggregation (income/expense/net + 4 token fields), full-SQL, type-filter aware
  • Gift ledgered into transactions
  • Dashboard net/series whitelist (earn/topup/gift positive)
  • Frontend summary uses backend data + token stats; type-based fallback
  • i18n zh/en for the new summary labels

Tests

  • cargo test — 138/138 passed
  • cargo fmt --check — clean
  • cargo clippy --all-targets -- -D warnings — clean
  • node --check ui/js/app.js — clean

Checklist

  • Branch name follows convention (feat/tx-summary)
  • Commit message uses Conventional Commits
  • Single responsibility, minimal change

…ummary fix (rants 2026-08-22T00:04:21/00:07:08/06:34:37)

- /api/transactions: response adds 'summary' — full SQL aggregation (not
  page-dependent), respects the type filter; income whitelist
  (earn/topup/gift) positive, consume negative; token totals
  (tokens/input/cached/output, input = tokens - cached - output)
- type filter now accepts 'gift'
- gift.rs ensure_daily_gift: writes a transactions row (type='gift') so
  the ledger matches the balance (was invisible before)
- dashboard: net/series SQL whitelist fixed — topup/gift no longer
  counted as negative (only earn was positive before)
- ui renderTxSummary: uses backend summary + shows token stats
  (Total/Input/Cached/Output, M/K format); type-based fallback instead
  of pts-sign based
- i18n: tx.summary.tokens/input/cached/output zh+en
- tests: +transactions_summary_and_dashboard_net_with_topup (summary +
  type filter + dashboard net), +gift_writes_transaction_record; updated
  wallet_summary_and_dashboard net to include the daily gift (+1)
- 138/138 tests + fmt + clippy + node --check clean
@argszero
argszero merged commit 1e155ae into main Aug 21, 2026
1 check passed
@argszero
argszero deleted the feat/tx-summary branch August 21, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant