Add configurable auto-rebuy preferences per table - #486
Merged
Conversation
- auto-rebuy.ts: pure decideAutoRebuy() decision logic for the three modes (always rebuy to max, rebuy below N big blinds, never), respecting the table's max_rebuys limit, the contract's per-rebuy cap (never exceeding max_buy_in), and the player's wallet balance - auto-rebuy-store.ts: per-table, per-address localStorage preference persistence, mirroring alias-store.ts's pattern - onchain.ts: adds getTableConfig/getPlayerRebuyCount/getTokenBalance (read-only simulateTransaction calls) and rebuyOnChain (submits the contract's existing rebuy entrypoint), following the same patterns already used for join_table/player_action - use-auto-rebuy.ts: hook that checks the preference once per genuine transition into the "waiting" phase (the same phase the contract itself requires for a rebuy) and submits one if triggered - AutoRebuySettings.tsx: per-table settings UI; wired into Table.tsx via an "AUTO-REBUY" button next to the existing hand-history button Closes HitEmPoka#164
|
@gboigwe Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a per-table "AUTO-REBUY" settings button letting players configure one of three rules, checked once per genuine transition into the "waiting" phase (the same phase — alongside "settlement" — the contract's own
rebuyentrypoint requires):max_buy_inwhenever the stack drops below it.max_buy_inonce the stack drops below a configurable big-blind threshold.The decision (
decideAutoRebuyinauto-rebuy.ts) respects, in order: the table'smax_rebuyslimit (read via the existingget_player_buy_in/max_rebuyson-chain fields), the contract's per-rebuy cap (never requesting more thanmax_buy_in - currentStack, which never exceeds one fullmax_buy_in), and the player's wallet balance (read via the payment token's standard SEP-41balancemethod) before submitting anything on-chain.Issue
Closes #164
Scope note on "opponent ranges" — n/a here, but a similar honest scoping note applies to big-blind resolution
getTableConfigreads the big blind from the blinds schedule's first level (blinds_schedule.levels[0].big_blind). This is correct for the common fixed-blinds case. An escalating (tournament-style) multi-level schedule's currently active level would need the same level-selection logic the contract applies internally, which isn't replicated here — documented directly in the code (RebuyRelevantTableConfig.bigBlind's doc comment) rather than silently assumed.Test plan
npx vitest run— 150 passed, same 4 pre-existing failures as onmain(audio-controls.test.tsx,reconnect-state.test.ts— unrelated, unchanged by this work)auto-rebuy.test.ts(12 tests): all three modes, respectingmax_rebuys(including the0 = unlimitedcase), respecting wallet balance (including the exact-match boundary), and not requesting a negative/zero rebuy when already at or above maxauto-rebuy-store.test.ts(7 tests): round-tripping each mode, per-table and per-address isolation, and graceful fallback toneveron corrupted/unrecognized stored dataauto-rebuy-settings.test.tsx(5 tests): default selection, saving each mode, the threshold input's conditional visibility, and close behavioruse-auto-rebuy.test.ts(7 tests, mockingonchain.tsas the network boundary): no-op onnever, submits the correct rebuy amount, doesn't submit when already at max or when the wallet balance is insufficient, checks exactly once per entry into"waiting"(not on every re-render), re-checks on a fresh transition back into"waiting", and surfaces a network error vialastErrorinstead of throwingnpx tsc --noEmit— caught and fixed a real type error in my own first draft (arenderHooktest'sinitialPropstype was inferred too narrowly for its laterrerendercall). All remaining errors are pre-existing and unrelated (token-selector.test.tsx,page.tsxtokenChoicetyping,Table.tsxreplayEntry/setReplayEntry,reconnect-state.ts) — not touched, since this PR doesn't cause them.onchain.ts(getTableConfig,getPlayerRebuyCount,getTokenBalance,rebuyOnChain) can't be exercised against a live Soroban RPC node in this environment. They're built by closely following the exactsimulateTransaction/scValToNative/submitWalletTxpatterns already established and tested elsewhere in this codebase (transaction-simulation.ts,onchain.ts's existingjoinTableOnChain/playerActionOnChain), matched against the actual contract signatures incontracts/poker-table/src/lib.rs(get_table,get_player_buy_in,rebuy) rather than guessed.