-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(demo-game): obfuscate dice outcome #79
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Caution Review failedThe pull request is closed. 📝 WalkthroughWalkthroughThe pull request introduces refactoring in two components of a demo game application: the Changes
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
apps/demo-game/src/pages/admin/dice/[id]/[...roll].tsx (1)
72-73
: Consider handling invalid or missing query parameters
Currently, the component returns a simple<div>Loading...</div>
ifrouter.query.roll[0]
is absent. You might want to differentiate between a truly loading state and an invalid state whereroll
is missing or malformed, to inform the user appropriately.apps/demo-game/src/pages/admin/games/[id].tsx (2)
395-406
: Ensure safe usage of Base64 encoding
Storing complex data in Base64 is convenient, but can grow large for bigger objects. Also, consider whether the encoded data might ever be manipulated in transit (e.g., tampered). If data security or integrity is crucial, you may want encryption or server-side validation.
451-451
: Add security consideration for external links
When usingtarget="_blank"
, consider addingrel="noopener noreferrer"
to prevent potential reverse tabnabbing security concerns.- href={`/admin/dice/${segment.id}/${encoded}`} target="_blank" + href={`/admin/dice/${segment.id}/${encoded}`} target="_blank" rel="noopener noreferrer"
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
apps/demo-game/src/pages/admin/dice/[id]/[...roll].tsx
(1 hunks)apps/demo-game/src/pages/admin/games/[id].tsx
(11 hunks)
🔇 Additional comments (11)
apps/demo-game/src/pages/admin/dice/[id]/[...roll].tsx (1)
76-84
: Verify object shape before destructuring
You rely on decodedData
having specific properties (diceBonds
, diceShared
, etc.). Ensure you validate or check for them and consider fallback values to avoid runtime errors if the fields are missing.
apps/demo-game/src/pages/admin/games/[id].tsx (10)
11-12
: Migrated form fields look good
Switching from custom NewFromikNumberField
/NewFormikTextField
to FormikNumberField
/FormikTextField
standardizes form usage and improves consistency.
686-686
: Good consistency in field labels
Adding a field for "Period Name" with FormikTextField
is consistent with the rest of the form approach.
693-693
: Numeric field transition looks proper
Switching to FormikNumberField
for segment count is clear and ensures numeric validation is easily handled.
712-712
: Seed field uses correct numeric type
Making "Seed" a numeric field clarifies that it must be an integer.
726-726
: Interest field benefits from numeric validation
Using FormikNumberField
for "Saving Interest" makes sense to prevent invalid inputs.
740-740
: Bonds trend field updated
The numeric input for Bond Trend ensures consistent user input.
749-749
: Bonds gap field updated
Gap is now explicitly numeric, reducing user input errors.
763-763
: Stocks trend numeric field
Expanding numeric input usage to Stock Trend aligns with the rest of the scenario parameters.
772-772
: Stocks gap numeric field
Using a numeric field for Stock Gap is consistent and helps with validations.
829-829
: Countdown field design
Applying FormikNumberField
for the countdown fosters clarity on input constraints and is aligned with the rest of the form.
const gapStocks = parseFloat(nums[12]) | ||
if (!router.query?.roll?.[0]) return <div>Loading...</div> | ||
|
||
const decodedData = JSON.parse(atob(router.query?.roll?.[0])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add error handling for decoding
Performing JSON.parse(atob(...))
can throw if the encoded string is corrupted or not valid JSON, leading to a runtime error. Consider wrapping this in a try/catch block or adding defensive checks to gracefully handle such cases.
- const decodedData = JSON.parse(atob(router.query?.roll?.[0]))
+ let decodedData
+ try {
+ decodedData = JSON.parse(atob(router.query?.roll?.[0]))
+ } catch (err) {
+ console.error('Error decoding data', err)
+ return <div>Invalid data</div>
+ }
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const decodedData = JSON.parse(atob(router.query?.roll?.[0])) | |
let decodedData | |
try { | |
decodedData = JSON.parse(atob(router.query?.roll?.[0])) | |
} catch (err) { | |
console.error('Error decoding data', err) | |
return <div>Invalid data</div> | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM :)
fd57408
to
301cc66
Compare
Quality Gate passedIssues Measures |
Summary by CodeRabbit
New Features
Bug Fixes
Refactor