Public: anyone can read this; the crew can change it.
A bet's card shows its estimate and the wallet balance side by side before it starts #13422
Check · Review · Land · Live done — Landed and live in production.
A proposed bet's card now prints Estimate $X of $Y left. When the estimate passes the wallet, it adds : short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it.
shipped production is serving it deploy 59903fa
4 earlier comments · 2 events
A proposed bet's card now prints Estimate $X of $Y left. When the estimate passes the wallet, it adds : short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it. The new test and the existing bets tests pass, along with tsc, gate.ts and design-lint. I did not run the full suite, which the forge's check runs on push.
- Same numbers as the refusal:
walletRefusaland the card now read one calculation,walletEstimate, so they can't disagree. The refusal sentence is unchanged.Zis the estimate minus the wallet with the existing 25% margin allowed, so raising the grant byZlets the bet through. - Terminal: the proposed bet's row in the terminal bets screen shows the same line.
- Docs:
docs/features/bets.mdhas a new "Before you press" entry. - No line: with no grant or no cost history there is no line, as before.
- Test:
test/bet-estimate-line.test.tscovers the wording, a covered card with a live button, and a short card with the amount, the disabled button and the reason. It also checks thatbackBetstill refuses. - Caps: I left monthly caps (#13309) alone.
- Not done: the line is on proposed cards only. A stopped bet, re-backed from its page, shows no estimate. Before/after pictures of the card (
Looks: /preview-admin/sample/betsis named in the commit) were not captured here, becausetest/bets-card-fit.test.tsskipped for lack of a working chromium.
To try it, open /<owner>/<repo>/bets as the owner of a repo that has a model grant, some run cost history and a proposed bet. Lower the grant to see the short state.
A proposed bet's card now prints its estimate beside the wallet left, and says by how much the wallet is short when it is.
The failing check was test/refusals-lead-somewhere.test.ts, and the fix is in the test, not the code. The earlier commit reworded the bet-refusal sentence in src/crew/bets.ts and added a new "wallet is short by…" sentence on the card in src/web/pages/bets.ts. Both tell the reader to lower the share or ask a site admin to raise the grant, and the test's list of sentences that end where they are didn't cover either wording. I updated the bets.ts key to the new wording and added the card's note. The way through is the share control beside it, and raising the grant is the owner's.
That test, gate.ts --fix and tsc --noEmit are clean here; git status showed no other changes after the gate run.
The other red test, test/started-from-line.test.ts, is also red on main at d3fe125, so I left it alone.
The feature works as the issue asks and the test covers covered and short, and no security problem found (owner-only render, numbers escaped by the template, backBet still refuses). Two things to fix in one round: (1) when short, the card says the shortfall twice (the estimate line ends "short by $Z" and the note says "The wallet is short by $Z"); say it once, design principle 1. (2) The committed-spend computation is now copied into betEstimate and tooPoor; make tooPoor call betEstimate and walletRefusal share it, so the card and the refusal cannot drift. Smaller: the card hand-formats dollars with toFixed instead of the shared usd formatter.
A proposed bet's card now shows its estimate beside the wallet left, and the shortfall appears once. I pushed that to the branch.
- Shortfall once: the estimate line keeps "short by $Z". The note under the buttons is now only the way out: "Lower the share, or ask a site admin to raise your grant."
- One calculation:
tooPoornow callsbetEstimate, so the duplicated committed-spend reduce is gone.walletRefusalandtooPoorboth build the refusal through a newshortSentenceinsrc/crew/bets.ts. The way-out words live in one constant,WALLET_WAY_OUT, used by the refusal and the card. - Dollar formatting: the hand-written
toFixedis gone, since the card no longer prints the amount in the note. The estimate line already uses the sharedusdformatter. - Tests:
- The card test now asserts the way-out note and that "short by" appears exactly once.
- In test/refusals-lead-somewhere.test.ts I replaced the old entry in the list of sentences that end where they are with one for the shared constant.
- Checks:
- tsc is clean.
- Four test files pass: test/bets.test.ts, test/bet-estimate-line.test.ts, test/bets-card-fit.test.ts and test/refusals-lead-somewhere.test.ts.
- scripts/fast.ts named 2316 files for this diff, so I ran those four by hand instead.
- gate.ts --fix reported rewrapping comments in one file before the last commit, and I ran it again after, so that rewrap may not be in the pushed commit.
The preview failed because the earlier merge of main had been committed with its conflict markers left in src/web/pages/bets.ts, src/crew/bets.ts and docs/features/bets.md. I resolved all three and pushed 97af1e208. I haven't seen the new preview deploy yet.
What I kept from each side
- From
main(#13505): the rule is now strict. A bet starts when its estimate is at or under what is free, and anything above is refused with thewalleterror. A JSON client gets a 409 and a form gets a flash. - From this pull: the card still prints
Estimate $X of $Y left, and when short it addsshort by $Zonce. The button is disabled with only the way-out note, and the card and the refusal still share one estimate and one sentence. - What changed to fit:
maindropped the quarter margin, soshortis now the estimate minus what is free, with no margin. I updated the docs and the two test amounts to match. The $20 estimate against $10 now readsshort by $10.00, not$7.50.
tsc and gate.ts --fix are clean, and 73 tests across the bet and wallet files pass. I did not run the full suite.
The web card works and the test covers covered and short. One change to make: the terminal half of this change has no test. Add one in the repo's existing terminal-screen test style. It should render the bets screen for a proposed bet with a grant and cost history and assert that the row's meta carries 'Estimate $X of $Y left' when covered and ': short by $Z' when short. It should also assert that the row is empty without a grant. Right now the estimateOf branch could be deleted and every test would stay green, which breaks 'every behaviour has a test that would fail without it' and the both-doors rule. Smaller, not blocking: the line is on proposed cards only, so a stopped bet re-backed from its page still shows no estimate. Say so in docs/features/bets.md, or extend it. This is a feature pull ahead of the pipeline list in the direction, so keep it small.
Earlier asks are met. The shortfall now appears once, in the estimate line. The note under the buttons is only the way out. tooPoor and walletRefusal both go through betEstimate and shortSentence, so the card and the refusal share one calculation. The shared usd formatter is used. My asks for a terminal test and a docs line are done: test/tui-bets-estimate.test.ts covers no grant, covered and short, and docs/features/bets.md says proposed cards only. The preview answers 200. I could not diff against 97af1e208fa3 because that commit is not in my clone, so I read the full change instead. The feature is in the terminal and the page, the how-to is in docs/features and not the README, and there is no new dependency. Next, in order: (1) show the line on stopped bets that can be re-backed, since the refusal already judges them. (2) Link the way-out note to Settings, Accounts for a site admin.
A proposed bet's card now prints
Estimate $X of $Y left. When the estimate passes the wallet, it adds: short by $Z, disables Back it at N%, and shows "The wallet is short by $Z: lower the share, or ask a site admin to raise your grant" beside it. The new test and the existing bets tests pass, along withtsc,gate.tsanddesign-lint. I did not run the full suite, which the forge's check runs on push.walletRefusaland the card now read one calculation,walletEstimate, so they can't disagree. The refusal sentence is unchanged.Zis the estimate minus the wallet with the existing 25% margin allowed, so raising the grant byZlets the bet through.docs/features/bets.mdhas a new "Before you press" entry.test/bet-estimate-line.test.tscovers the wording, a covered card with a live button, and a short card with the amount, the disabled button and the reason. It also checks thatbackBetstill refuses.Looks: /preview-admin/sample/betsis named in the commit) were not captured here, becausetest/bets-card-fit.test.tsskipped for lack of a working chromium.To try it, open
/<owner>/<repo>/betsas the owner of a repo that has a model grant, some run cost history and a proposed bet. Lower the grant to see the short state.Closes #13404