fix(game): show granted/bought hints in-game — finish the D31 wire removal
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m58s
CI / changes (pull_request) Successful in 2s
CI / unit (pull_request) Successful in 10s
CI / integration (pull_request) Successful in 19s
CI / ui (pull_request) Successful in 1m11s
CI / conformance (pull_request) Successful in 10s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m58s
The in-game hint badge ignored the payments hint wallet: loading a game clobbered app.profile.hintBalance with the deprecated StateView.wallet_balance (zeroed in the D31 domain removal but left in the protocol as a dead 0, then synced over the real balance at game load). Finish the removal honestly. StateView carries the per-game allowance alone (hints_remaining); the purchasable wallet lives solely on the profile and the client adds it (lib/hints). Removed StateView.wallet_balance across every layer — backend StateView/DTO, notify.PlayerState (live events), gateway StateResp + wire.StateView, the client model/codec/mock/localgame — and dropped the now-unused wallet arg from hintsRemaining. The FBS field is tombstoned `(deprecated)` (not deleted) so the vtable slots after it stay stable across a rolling deploy; no accessor is generated. HintResult keeps wallet_balance (the real post-spend payments balance the client adopts into the profile). The StateView type no longer has walletBalance, so the clobber cannot return without a compile error. Tests: hintsRemaining (2-arg); hints.hintsLeft (allowance + live wallet, no strip); the game state/hint integration (allowance-only HintsRemaining); gateway transcode; FBS regen.
This commit is contained in:
+12
-14
@@ -1,33 +1,31 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { hintsLeft, hintGateRemainingMs, hintLockMinutes } from './hints';
|
||||
|
||||
// view carries only the two fields hintsLeft reads.
|
||||
const view = (hintsRemaining: number, walletBalance: number) => ({ hintsRemaining, walletBalance });
|
||||
// view carries only the field hintsLeft reads (the per-game allowance).
|
||||
const view = (hintsRemaining: number) => ({ hintsRemaining });
|
||||
|
||||
describe('hintsLeft', () => {
|
||||
it('is zero without a view', () => {
|
||||
expect(hintsLeft(null, 5)).toBe(0);
|
||||
});
|
||||
|
||||
it('adds the per-game allowance to the live wallet (fresh view)', () => {
|
||||
// hints_remaining 4 = allowance 1 + wallet 3; live wallet matches the snapshot → 1 + 3.
|
||||
expect(hintsLeft(view(4, 3), 3)).toBe(4);
|
||||
it('adds the per-game allowance to the live wallet', () => {
|
||||
expect(hintsLeft(view(1), 3)).toBe(4); // allowance 1 + wallet 3
|
||||
});
|
||||
|
||||
it('reflects the LIVE wallet, not the per-game snapshot (the staleness fix)', () => {
|
||||
// The view was fetched when the wallet was 3 (allowance 1), but a wallet hint was since spent
|
||||
// in another game, so the live wallet is 2: the count must drop to 1 + 2 = 3, not stay at 4.
|
||||
expect(hintsLeft(view(4, 3), 2)).toBe(3);
|
||||
it('reflects the LIVE wallet, not the view (the staleness fix)', () => {
|
||||
// A wallet hint spent in another game since this view was fetched → the live wallet is 2, so the
|
||||
// count is 1 + 2 = 3. The wallet is always passed live (from the profile), never read off the view.
|
||||
expect(hintsLeft(view(1), 2)).toBe(3);
|
||||
});
|
||||
|
||||
it('shows just the wallet when the per-game allowance is used up', () => {
|
||||
// allowance 0 (hints_remaining 3 == snapshot wallet 3); live wallet 3 → 0 + 3.
|
||||
expect(hintsLeft(view(3, 3), 3)).toBe(3);
|
||||
expect(hintsLeft(view(0), 3)).toBe(3); // allowance 0 + wallet 3
|
||||
});
|
||||
|
||||
it('clamps a non-negative allowance and wallet', () => {
|
||||
expect(hintsLeft(view(2, 3), 0)).toBe(0);
|
||||
expect(hintsLeft(view(1, 0), -5)).toBe(1);
|
||||
it('clamps negatives', () => {
|
||||
expect(hintsLeft(view(1), -5)).toBe(1); // a negative wallet clamps to 0
|
||||
expect(hintsLeft(view(-2), 3)).toBe(3); // a negative allowance clamps to 0
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user