2 Commits
Author SHA1 Message Date
391f08b801 fix(profiles): count wallets with a function that exists, and gate the class (#760)
The profile page counted a visitor-visible wallet by calling an RPC named
`get_entity_wallets`. That function appears in no migration and returns
PGRST202 in production — it has never existed. The call sat inside a
try/catch whose comment read "if it errs we just show 0", so the error
path was not a fallback, it was the only path, for as long as the code
has been there.

The count is not cosmetic. ProfileLayout hides the Wallets tab from
visitors unless walletCount > 0 or the profile still carries a legacy
bitcoin_address/lightning_address. A profile whose receive methods live
in the modern wallets table therefore showed a visitor no way to pay it.
Confirmed on the live site: testuser123 has an active on-chain wallet and
their public profile offers only Overview / Timeline / Info.

Measured 2026-08-26: 3 of 83 profiles have an active wallet and only 1
has a legacy address, so 2 profiles are affected today. Small only
because wallet adoption is small — it scales with exactly the number we
want to grow, and would have quietly blunted any push to grow it.

Counted through the same admin-client path GET /api/wallets already uses
rather than by writing the missing function. That route's comment states
the intent — "the API is the one public surface, so raw PostgREST can no
longer enumerate balances or other wallet internals" — and a SECURITY
DEFINER function would open a second public surface over a table holding
nwc_connection_uri, a write-only secret. Counting adds no surface: it
returns a number, never a row. Failures are logged rather than swallowed,
so a permanently-broken count cannot hide again.

Asking production which functions PostgREST exposes turned up three more
RPCs that do not exist: update_presence and set_typing_indicator (so
presence and typing indicators are inert), and create_timeline_event on a
fallback branch. Four instances is a class, so check:rpc-exists joins
`verify`: every `.rpc('name')` must have a CREATE FUNCTION in
supabase/migrations. The three remaining are baselined with their
consequence written down — each needs its own migration and design.

The gate is parser-based so CI needs no database, and `--verify` proves
the parser against the live one: 37 called names checked against 80 live
functions, migrations and database agreeing on every one. Proven by
mutation too — re-adding the removed call turns it red.

Its own first run said "RPCs called: 0" and passed. It had reached for
blankNonCode, which blanks string CONTENTS, so it had erased every name
it was looking for — green because blind, the exact failure it exists to
catch. The shared tokenizer now offers blankComments for the case where
the string literal IS the thing you are looking for.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 01:36:23 +00:00
df6edd3c7f fix(wallets): stop dividing a BTC balance by a goal denominated in francs (#758)
A wallet's balance is BTC. Its goal is not: `goal_amount` is denominated
in `goal_currency`, and the wallet form defaults that to fiat. Both
surfaces that drew the progress bar divided one straight into the other:

    const progressPercent = (wallet.balance_btc / wallet.goal_amount) * 100

Measured against production today: 18 of 33 wallets carry a goal, every
one of them in fiat (CHF 11, USD 6, EUR 1), and not one in BTC. So every
savings-goal bar in the app was computed from BTC divided by francs —
including the one on the PUBLIC profile, which is the second copy of the
same expression.

It is invisible right now only because every one of those balances is
still 0.00, and zero over anything is zero. It starts lying on the first
deposit: a wallet holding 0.025 BTC toward a CHF 2 500 goal would have
read "0.001% funded" while sitting at the whole target. That case is
pinned as a test.

Both sides now meet in the goal's own currency before they meet in one
expression, via a single lib/wallet-goal.ts rather than a third inline
copy. When no rate is available the helper returns null instead of a
number: useCurrencyConversion signals a missing rate with 0 precisely so
callers do not guess, and 0 read as a percentage would tell someone they
have saved nothing when they may be fully funded.

Fixing the same line in two files is where the Never-Twice rule says to
automate, so check:currency-units joins `verify`: it fails on arithmetic
between a BTC-suffixed identifier and a bare `*_amount`. Proven by
mutation — restoring the original expression turns it red, and it caught
the naive version of its own scanner on the first run (it stripped only
`//`, and the first thing it read was a block comment describing the
bug). That is why blankNonCode moved to scripts/lib/: one tokenizer, so
a third scanner cannot reinvent the version that already cost a day.

Co-authored-by: Georgy Butaev <41178744+g-but@users.noreply.github.com>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-08-26 01:06:41 +00:00