Fix stock swap panel crash when a default chain is off the board
The redesigned swap panel priced its initial Tower/Continental pair before picking a real choice, so any buy step where the player held shares and either chain was off the board threw and left the viewer on "Loading game". Never price a chain off the board, and add a browser check for such a position.
This commit is contained in:
parent
637cae325a
commit
2894388bab
2 changed files with 9 additions and 1 deletions
|
|
@ -43,7 +43,8 @@
|
|||
const cash = $derived(
|
||||
cost === 0 ? t("swap.even") : t(cost > 0 ? "swap.pay" : "swap.receive", { amount: money(Math.abs(cost)) })
|
||||
);
|
||||
const priceOf = (chain: ChainId) => sharePrice(chain, chainSize(game.board, chain));
|
||||
// Chains off the board have no price; they are never offered, but the defaults may name one.
|
||||
const priceOf = (chain: ChainId) => (active.includes(chain) ? sharePrice(chain, chainSize(game.board, chain)) : 0);
|
||||
const after = $derived.by(() => {
|
||||
const effect = selected && moveEffect(game, selected);
|
||||
return effect ? holdingsAfter(game, effect) : undefined;
|
||||
|
|
@ -53,6 +54,9 @@
|
|||
if (remaining <= 0) {
|
||||
return t("swap.noneLeft");
|
||||
}
|
||||
if (!active.includes(from) || !active.includes(to)) {
|
||||
return t("swap.unavailable");
|
||||
}
|
||||
if (game.bank[to] <= 0) {
|
||||
return t("swap.bankEmpty", { chain: chainName(to) });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -390,6 +390,10 @@ try {
|
|||
window.acquireDev.load(state);
|
||||
}, preparedPosition("scoring"));
|
||||
assert.equal(await page.locator(".stock-swap").count(), 0, "off never adds UI to existing games");
|
||||
// A random buy step where the panel's default chains (Tower, Continental) are not both on the
|
||||
// board: the swap panel must not price a chain off the board.
|
||||
await open("players=4&moves=16&stockSwap=3");
|
||||
assert.equal(await page.locator(".stock-swap").count(), 1, "swaps render when a default chain is off the board");
|
||||
report.scenarios.push(
|
||||
"stock swaps in 17 languages and both themes at 1280/390/320px, pay/receive previews, shared allowance, undo without saved history and a separate three-share purchase"
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue