Skip to content
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

Dusky Client Improvements #268

Merged
merged 57 commits into from
Sep 13, 2024
Merged

Dusky Client Improvements #268

merged 57 commits into from
Sep 13, 2024

Conversation

starknetdev
Copy link
Member

@starknetdev starknetdev commented Sep 13, 2024

Now client includes the tree mapping where paths are displayed in the prescience.

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new Paths component for managing and displaying encounter paths.
    • Added draggable functionality to the EncounterDialog for improved user interaction.
    • Enhanced the ItemDisplay component to provide detailed information about item attributes.
    • Added new environment variable NEXT_PUBLIC_NETWORK for mainnet configuration.
  • Improvements

    • Updated the MarketplaceTable to include a new column for "Special" items.
    • Enhanced potion cost display in the PurchaseHealth component for better user experience.
    • Improved encounter management with new state variables and memoized computations in EncounterTable.
    • Modified editor settings for more control over code actions on save.
  • Bug Fixes

    • Addressed potential security risks by modifying .gitignore settings for environment files.
  • Style

    • Updated visual styles across the application, including color adjustments in CSS files.

Copy link

vercel bot commented Sep 13, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
loot-survivor ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 13, 2024 4:14pm

Copy link

coderabbitai bot commented Sep 13, 2024

Warning

Rate limit exceeded

@starknetdev has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 51 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 159d61a and 7f03cb6.

Walkthrough

The changes involve modifications to various configuration files, the introduction of new components and utility functions, and enhancements to existing components in a user interface application. Key updates include the removal of .env file exclusions from version control, the addition of new dependencies, restructuring of components for improved layout, and the introduction of new features like draggable dialogs and enhanced encounter management. Additionally, several interfaces have been updated to accommodate new functionalities, such as handling multiple revenue addresses.

Changes

Files Change Summary
.gitignore Removed exclusions for .env and .env*, allowing these files to be tracked by Git.
.vscode/settings.json Added settings for editor.codeActionsOnSave to control auto-fixes and import organization explicitly.
ui/.env Introduced a new environment variable NEXT_PUBLIC_NETWORK set to "mainnet".
ui/.vscode/settings.json Minor formatting change with a newline added at the end of the file.
ui/package.json Added new dependencies: @scure/starknet, @starknet-react/chains, react-draggable, and zod.
ui/src/app/GlitchEffect.css Changed background color from green to light blue.
ui/src/app/components/actions/Prescience.tsx Simplified layout by removing unnecessary nested <div> and added w-full class to outer <div>.
ui/src/app/components/adventurer/ItemDisplay.tsx Enhanced item display logic to show more detailed attributes, including power and experience points.
ui/src/app/components/encounters/EncounterTable.tsx Improved state management and rendering logic for encounters, including new state variables.
ui/src/app/components/encounters/EncounterDialog.tsx Introduced draggable functionality using react-draggable, with dynamic positioning based on window size.
ui/src/app/components/encounters/Paths.tsx New component for managing and displaying encounter paths with detailed information.
ui/src/app/components/encounters/utils.tsx Added utility functions for managing adventurer attributes and item purchases.
ui/src/app/components/marketplace/MarketplaceRow.tsx Added display for special effects associated with marketplace items.
ui/src/app/components/marketplace/MarketplaceTable.tsx Expanded table headings to include a new column for "Special" items.
ui/src/app/components/navigation/Header.tsx Restructured imports and added new components for improved navigation functionality.
ui/src/app/components/onboarding/Intro.tsx Reorganized import statements for clarity.
ui/src/app/globals.css Modified text-shadow and outline-color properties for a consistent color scheme.
ui/src/app/tailwind.config.js Standardized quotation marks and modified utility styles for consistency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant UI
    participant EncounterSystem
    participant RevenueManagement

    User->>UI: Interacts with the application
    UI->>EncounterSystem: Requests encounter data
    EncounterSystem-->>UI: Returns encounter details
    UI->>RevenueManagement: Handles revenue addresses
    RevenueManagement-->>UI: Provides selected revenue address
    UI-->>User: Displays updated encounter information
Loading

🐇 In the meadow where the code does play,
Changes hop and dance in a bright array.
With colors shifting, and features anew,
Our rabbit hearts leap, for there's much to do!
So gather 'round, friends, let’s code and create,
For every new line, we celebrate fate! 🌼✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

- make intro text less foreign
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (3)
ui/src/app/hooks/useWindowSize.ts (1)

9-12: Consider using default values for initial state.

Instead of using a ternary operator to check if window is defined, you could use default values for the initial state. This would make the code a bit cleaner and easier to read.

- const [windowSize, setWindowSize] = useState<WindowSize>({
-   width: typeof window !== "undefined" ? window.innerWidth : 0,
-   height: typeof window !== "undefined" ? window.innerHeight : 0,
- });
+ const [windowSize, setWindowSize] = useState<WindowSize>({
+   width: 0,
+   height: 0,
+ });
ui/src/app/components/adventurer/ItemDisplay.tsx (1)

165-198: Excellent work on enhancing the item attribute display!

The changes provide a more organized and informative presentation of the item's attributes, improving the user experience.

Consider the following suggestions for further improvement:

  1. Remove the commented-out code for displaying current XP (lines 182-190) as it's no longer needed.

  2. Extract the calculation for XP to next level (lines 193-196) into a separate function for better modularity and reusability. For example:

const getXpToNextLevel = (currentXp: number) => {
  return Math.floor(calculateLevel(currentXp) + 1) ** 2 - currentXp;
};

Then, you can use it like this:

<span>
  {item && ` XP to Next Lvl: ${getXpToNextLevel(item.xp ?? 0)}`}
</span>
ui/src/app/components/encounters/EncounterTable.tsx (1)

Line range hint 25-359: The changes look good and enhance the component's functionality.

The introduction of new state variables and memoized computations improves performance and maintainability. The rendering logic for the encounter table has been refined to provide more contextual information about encounters, enhancing the user interface.

Please address the missing key property for the element in the iterable at line 156 as indicated by the static analysis hint. Add a unique key prop to the <> fragment to help React identify which item was moved when the order of the items changes.

-<>
+<React.Fragment key={encounter.id}>
Tools
Biome

[error] 156-156: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between fc47c84 and cc7842c.

Files ignored due to path filters (2)
  • ui/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
  • ui/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
Files selected for processing (31)
  • .gitignore (0 hunks)
  • .vscode/settings.json (1 hunks)
  • ui/.env (1 hunks)
  • ui/.gitignore (0 hunks)
  • ui/.vscode/settings.json (1 hunks)
  • ui/package.json (3 hunks)
  • ui/src/app/GlitchEffect.css (1 hunks)
  • ui/src/app/components/actions/Prescience.tsx (1 hunks)
  • ui/src/app/components/adventurer/ItemDisplay.tsx (1 hunks)
  • ui/src/app/components/encounters/EncounterTable.tsx (3 hunks)
  • ui/src/app/components/encounters/EnounterDialog.tsx (1 hunks)
  • ui/src/app/components/encounters/Paths.tsx (1 hunks)
  • ui/src/app/components/encounters/utils.tsx (1 hunks)
  • ui/src/app/components/marketplace/MarketplaceRow.tsx (1 hunks)
  • ui/src/app/components/marketplace/MarketplaceTable.tsx (1 hunks)
  • ui/src/app/components/navigation/Header.tsx (1 hunks)
  • ui/src/app/components/onboarding/Intro.tsx (1 hunks)
  • ui/src/app/components/start/Spawn.tsx (3 hunks)
  • ui/src/app/components/upgrade/PurchaseHealth.tsx (3 hunks)
  • ui/src/app/containers/AdventurerScreen.tsx (1 hunks)
  • ui/src/app/containers/CollectionsLeaderboardScreen.tsx (1 hunks)
  • ui/src/app/globals.css (1 hunks)
  • ui/src/app/head.tsx (1 hunks)
  • ui/src/app/hooks/useWindowSize.ts (1 hunks)
  • ui/src/app/lib/networkConfig.ts (4 hunks)
  • ui/src/app/lib/utils/index.ts (2 hunks)
  • ui/src/app/lib/utils/processFutures.ts (11 hunks)
  • ui/src/app/lib/utils/syscalls.ts (3 hunks)
  • ui/src/app/page.tsx (3 hunks)
  • ui/src/app/types/index.ts (2 hunks)
  • ui/tailwind.config.js (1 hunks)
Files not reviewed due to no reviewable changes (2)
  • .gitignore
  • ui/.gitignore
Files skipped from review due to trivial changes (6)
  • ui/.vscode/settings.json
  • ui/src/app/GlitchEffect.css
  • ui/src/app/components/actions/Prescience.tsx
  • ui/src/app/components/onboarding/Intro.tsx
  • ui/src/app/containers/CollectionsLeaderboardScreen.tsx
  • ui/tailwind.config.js
Additional context used
Biome
ui/src/app/components/encounters/EncounterTable.tsx

[error] 156-156: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

ui/src/app/components/encounters/Paths.tsx

[error] 222-233: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

Additional comments not posted (62)
.vscode/settings.json (1)

6-9: Verify that the explicit code action settings align with the team's workflow.

The new editor.codeActionsOnSave settings are valid and give you more control over when fix actions and import organization are triggered. This can help maintain code quality and consistency.

However, please ensure that running these actions explicitly aligns with your team's workflow and doesn't introduce any unintended changes. It may be worth discussing these settings with your team to ensure everyone is on the same page.

ui/src/app/hooks/useWindowSize.ts (1)

1-31: Great job on creating a reusable custom hook!

The useWindowSize hook is well-implemented and follows best practices. It provides a clean way for components to access the current window size and react to changes.

ui/src/app/components/encounters/EnounterDialog.tsx (3)

2-4: LGTM!

The imports are necessary for the draggable functionality and responsive design of the encounter dialog. The useWindowSize custom hook will be used to determine the dialog's initial position based on screen size, and the Draggable component from the react-draggable library will make the dialog draggable.


10-23: LGTM!

The memoized position object is a good approach to determine the dialog's initial position based on the window width. The responsive positioning logic ensures that the dialog is placed appropriately for large, medium, and small screens. The chosen breakpoints (1024px and 768px) are commonly used for responsive design.


26-36: LGTM!

The Draggable component with the memoized position object ensures that the dialog is initially positioned correctly and can be dragged by the user. The absolute positioning and higher z-index of the MdClose icon make it always accessible to close the dialog. The fixed width, max height, and overflow-y settings of the dialog content container maintain a consistent appearance and allow for scrolling within the encounter table when needed.

ui/package.json (4)

16-16: LGTM!

The @scure/starknet dependency provides a secure implementation of the StarkNet cryptographic primitives and utilities in JavaScript. Adding this dependency is a good choice for integrating StarkNet functionalities into the project.


17-17: LGTM!

The @starknet-react/chains dependency provides a set of React components and hooks for interacting with StarkNet chains. Adding this dependency is a good choice for using React components and hooks for StarkNet chain interactions in the project.


42-42: LGTM!

The react-draggable dependency provides a simple component for making elements draggable in React. Adding this dependency is a good choice for implementing draggable components to enhance user interface interactions in the project.


55-55: LGTM!

The zod dependency is a TypeScript-first schema validation library with static type inference. Adding this dependency is a good choice for using Zod for schema validation and static type inference in the project.

ui/src/app/head.tsx (1)

60-60: LGTM!

The change to the theme-color meta tag is minor and does not affect the functionality of the application. The new color #add8e6 (light blue) may provide a softer color scheme compared to the previous color #33FF33 (green), potentially enhancing the visual aesthetics of the application.

ui/src/app/lib/networkConfig.ts (4)

17-19: LGTM!

The change to revenueAddresses for the sepolia network configuration is consistent with the overall modifications made to the revenueAddress property. The array structure allows for easily adding more revenue addresses in the future if needed.


46-51: Looks good!

The change to revenueAddresses for the mainnet network configuration is consistent with the overall modifications made to the revenueAddress property. The array now contains multiple addresses, providing flexibility in managing revenue on the mainnet.


75-75: Verify the placeholder address.

The change to revenueAddresses for the katana network configuration is consistent with the overall modifications. However, please ensure that the placeholder address "0x0" is intended and will be updated with the correct revenue address before deployment.


101-101: Verify the placeholder address.

The change to revenueAddresses for the localKatana network configuration is consistent with the overall modifications. However, please ensure that the placeholder address "0x0" is intended and will be updated with the correct revenue address for local testing.

ui/src/app/components/encounters/utils.tsx (4)

17-64: LGTM!

The function correctly updates the adventurer's stats based on the provided upgrades, potions, and purchased items. It handles edge cases, such as undefined input adventurer, and ensures that the adventurer's health is capped at the maximum value based on their vitality. The function also calculates the total cost of the purchased items and deducts it from the adventurer's gold.


66-80: LGTM!

The function correctly converts the array of purchased items to an array of item objects with additional data. It retrieves the item name from the game data and the item data using the getItemData function. The function also adds an equip property to each item object based on the corresponding value from the purchased item.


82-128: LGTM!

The function correctly updates the adventurer's equipped items based on the purchased items. It retrieves the currently equipped items from the query data and updates them by checking for corresponding purchased items with the same slot that should be equipped. If a matching purchased item is found, it replaces the equipped item with the purchased item, setting default values for special2, special3, and xp. The function also adds any purchased items that are not already present in the updated items array.


130-150: LGTM!

The function correctly generates decision paths for an adventurer based on their updated stats, items, and game data. It first checks the validity of the input parameters and returns an empty array if either the updated adventurer object or items array is falsy. The function then generates a decision tree using the getDecisionTree function and retrieves the decision paths with their corresponding outcomes using the getOutcomesWithPath function. Finally, it sorts the decision paths based on the adventurer's health at the end of each path in descending order and returns the sorted array.

ui/src/app/containers/AdventurerScreen.tsx (1)

22-23: Verify the implementation changes for handling the new spawn method parameters.

The changes to the AdventurerScreenProps interface look good:

  • Changing revenueAddress from string to string[] allows for passing multiple revenue addresses, providing more flexibility.
  • Adding the optional costToPlay parameter enables a new feature while maintaining backward compatibility.

However, please ensure that the corresponding implementation changes have been made to handle these new parameters correctly:

Verification successful

Implementation and usage of spawn function verified successfully.

The spawn function implementation in ui/src/app/lib/utils/syscalls.ts has been correctly updated to handle the new parameters:

  • It accepts revenueAddresses: string[] and costToPlay?: number.
  • The implementation selects a random revenue address from the array and uses costToPlay in the checkBalances function.

The usage of spawn in ui/src/app/containers/AdventurerScreen.tsx is consistent with the new implementation, as seen in the AdventurerScreenProps interface:

spawn: (
  formData: FormData,
  goldenTokenId: string,
  revenueAddresses: string[],
  costToPlay?: number
) => Promise<void>;

This confirms that the changes to the AdventurerScreenProps interface have been properly implemented and are being used correctly throughout the codebase.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the `spawn` method implementation has been updated to handle the new parameters.

# Test: Search for the `spawn` method implementation. Expect: Updated parameter handling.
ast-grep --lang typescript --pattern $'function spawn($_, $_, revenueAddresses, costToPlay) {
  $$$
}'

Length of output: 103


Script:

#!/bin/bash
# Description: Search for different implementations of the `spawn` function and its usages

# Search for class method implementation
echo "Searching for class method implementation:"
ast-grep --lang typescript --pattern 'class $_ {
  $$$
  spawn($_, $_, revenueAddresses, costToPlay) {
    $$$
  }
  $$$
}'

# Search for arrow function implementation
echo "Searching for arrow function implementation:"
ast-grep --lang typescript --pattern 'const spawn = ($_, $_, revenueAddresses, costToPlay) => {
  $$$
}'

# Search for function usage
echo "Searching for spawn function usage:"
rg "spawn\s*\(" -t ts -t tsx -A 5

Length of output: 571


Script:

#!/bin/bash
# Description: Broader search for spawn function and AdventurerScreenProps

# Search for any implementation of spawn function
echo "Searching for any spawn function implementation:"
ast-grep --lang typescript --pattern 'function spawn($$$) {
  $$$
}'

# Search for spawn in all TypeScript and TypeScript React files
echo "Searching for spawn in all .ts and .tsx files:"
fd -e ts -e tsx | xargs grep -n "spawn"

# Search for AdventurerScreenProps interface
echo "Searching for AdventurerScreenProps interface:"
ast-grep --lang typescript --pattern 'interface AdventurerScreenProps {
  $$$
}'

Length of output: 2360


Script:

#!/bin/bash
# Description: Check spawn implementation and usage, and search for AdventurerScreenProps

# View spawn implementation in syscalls.ts
echo "Spawn implementation in syscalls.ts:"
sed -n '/const spawn = async/,/^  }/p' ui/src/app/lib/utils/syscalls.ts

# Check spawn usage in AdventurerScreen.tsx
echo "Spawn usage in AdventurerScreen.tsx:"
sed -n '/spawn:/,/)/p' ui/src/app/containers/AdventurerScreen.tsx

# Search for AdventurerScreenProps with a more flexible pattern
echo "Searching for AdventurerScreenProps:"
ast-grep --lang typescript --pattern 'type AdventurerScreenProps = {
  $$$
}'

ast-grep --lang typescript --pattern 'interface AdventurerScreenProps'

Length of output: 2369

ui/src/app/globals.css (2)

11-11: LGTM!

The change in the text-shadow color is valid and does not introduce any syntax errors. It seems to be a part of an overall color scheme adjustment in the UI.


13-13: LGTM!

The change in the outline-color is valid and does not introduce any syntax errors. It is consistent with the text-shadow color change and seems to be a part of an overall color scheme adjustment in the UI.

ui/src/app/components/upgrade/PurchaseHealth.tsx (4)

39-41: LGTM!

The potion cost calculations for the current and next level are implemented correctly using the getPotionPrice utility function and the adventurer's current level and charisma.


97-110: Great job with the responsive potion cost display!

The potion costs for the current and next level, as well as the total cost, are displayed correctly. The responsive design adjusts the layout and text appropriately based on screen size, ensuring a consistent and user-friendly experience across devices.


1-6: Icons imported and used correctly.

The required icons are imported from the Icons module and used appropriately in the component. There are no unused imports in this code segment.


8-11: Imports are correct and used appropriately.

The required constants, utility functions, and types are imported correctly and used appropriately in the component. There are no unused imports in this code segment.

ui/src/app/components/marketplace/MarketplaceTable.tsx (1)

45-53: LGTM!

The addition of the "Special" heading to the headings array is a minor modification that enhances the data representation within the component. It does not affect the underlying logic or control flow of the component.

ui/src/app/components/start/Spawn.tsx (3)

1-18: LGTM!

The reorganization of import statements improves the readability and clarity of the import section without affecting the functionality of the code.


84-84: LGTM!

The change to pass networkConfig[network!].revenueAddresses as the revenueAddresses argument in the spawn function call is correct and consistent with the updated function signature.


25-25: Verify the usage of revenueAddresses in the codebase.

The change from revenueAddress to revenueAddresses in the spawn function signature is a good improvement. It allows for more flexibility in handling multiple revenue addresses.

Please ensure that all calls to the spawn function have been updated to pass an array of revenue addresses instead of a single address.

Run the following script to verify the usage of revenueAddresses:

Verification successful

Changes to revenueAddresses have been correctly implemented

The verification process confirms that the transition from revenueAddress to revenueAddresses has been successfully implemented across the codebase. Key findings include:

  • The SpawnProps interface in Spawn.tsx correctly defines revenueAddresses as an array of strings.
  • The spawn function in syscalls.ts has been updated to accept and use the revenueAddresses array.
  • All calls to the spawn function in Spawn.tsx now pass the revenueAddresses array from the network configuration.
  • The networkConfig object in networkConfig.ts has been updated to include revenueAddresses as an array for different network configurations.

These changes ensure consistent handling of multiple revenue addresses throughout the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all calls to the `spawn` function pass an array of revenue addresses.

# Test: Search for the function calls. Expect: Only occurrences with an array argument.
rg --type typescript -A 5 $'spawn\\(.*revenueAddresses'

Length of output: 90


Script:

#!/bin/bash
# Description: Verify the usage of revenueAddress(es) in TypeScript files

# Search for revenueAddress in .ts and .tsx files
echo "Searching for revenueAddress:"
rg -t ts -t tsx 'revenueAddress[^es]' -C 5

echo "\nSearching for revenueAddresses:"
rg -t ts -t tsx 'revenueAddresses' -C 5

# Search for spawn function calls
echo "\nSearching for spawn function calls:"
rg -t ts -t tsx 'spawn\s*\(' -C 5

Length of output: 435


Script:

#!/bin/bash
# Description: Verify the usage of revenueAddress(es) and spawn function calls in TypeScript files

# Search for revenueAddress in .ts and .tsx files
echo "Searching for revenueAddress:"
rg --glob '*.{ts,tsx}' 'revenueAddress[^es]' -C 5

echo "\nSearching for revenueAddresses:"
rg --glob '*.{ts,tsx}' 'revenueAddresses' -C 5

# Search for spawn function calls
echo "\nSearching for spawn function calls:"
rg --glob '*.{ts,tsx}' 'spawn\s*\(' -C 5

Length of output: 8554

ui/src/app/types/index.ts (2)

73-73: LGTM!

The addition of the optional level property to the Item interface is a valid enhancement that allows for more detailed representation of item attributes. The type number is appropriate for the level value, and marking it as optional ensures flexibility in item definitions.


230-235: Looks good!

The introduction of the ItemPurchaseObject interface is a positive addition that expands the functionality related to item management. The included properties tier, type, slot, and equip provide relevant information for item purchases, and their types are appropriately defined. This interface will likely facilitate more detailed tracking or processing of item purchases in the application.

ui/src/app/lib/utils/index.ts (2)

1-13: LGTM!

The reordering of import statements does not affect the functionality of the code. It may improve readability or maintainability.


633-637: LGTM!

The getRandomInt function is correctly implemented and will generate a random integer within the specified range. It enhances the utility of the module by providing a method for generating random integers, which could be useful in various game-related functionalities.

ui/src/app/components/navigation/Header.tsx (4)

1-46: LGTM!

The Header component has been restructured to be more modular and feature-rich. The changes introduce new features like ApibaraStatus, TransactionCart, and TransactionHistory, and update the component to use new hooks like useController and useNetworkAccount. The component has also been updated to handle new functionalities like multicall, mintLords, etc.


14-14: Verify the usage of new hooks.

The component has been updated to use new hooks like useController, useNetworkAccount, useUiSounds, and useConnect. Ensure that these hooks are being used correctly and that they are providing the expected functionality.

Run the following script to verify the usage of new hooks:

Also applies to: 17-17, 21-21, 41-41

Verification successful

New hooks are being used correctly and consistently.

The review of the codebase confirms that the new hooks (useController, useNetworkAccount, useUiSounds, and useConnect) are being imported and used appropriately across various components and containers in the application. Their usage is consistent with their intended purposes:

  • useController for managing game controls and conditions
  • useNetworkAccount for handling account-related information
  • useUiSounds for managing sound effects
  • useConnect for wallet connection and network interactions

No issues or inconsistencies were found in the usage of these hooks.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new hooks.

# Test: Search for the usage of `useController` hook. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'useController'

# Test: Search for the usage of `useNetworkAccount` hook. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'useNetworkAccount'

# Test: Search for the usage of `useUiSounds` hook. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'useUiSounds'

# Test: Search for the usage of `useConnect` hook. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'useConnect'

Length of output: 306


Script:

#!/bin/bash
# Description: Verify the usage of new hooks in TypeScript files

# Search for the usage of `useController` hook
echo "Searching for useController:"
rg -A 5 'useController' --glob '*.{ts,tsx}'

echo "\nSearching for useNetworkAccount:"
rg -A 5 'useNetworkAccount' --glob '*.{ts,tsx}'

echo "\nSearching for useUiSounds:"
rg -A 5 'useUiSounds' --glob '*.{ts,tsx}'

echo "\nSearching for useConnect:"
rg -A 5 'useConnect' --glob '*.{ts,tsx}'

Length of output: 43386


Line range hint 59-108: Verify the usage of new state.

The component has been updated to handle new state like apibaraStatus, showLordsBuy, notification, loadingMessage, etc. Ensure that these state variables are being used correctly and that they are providing the expected functionality.

Run the following script to verify the usage of new state:

Verification successful

New state variables are correctly implemented and used.

The new state variables (apibaraStatus, showLordsBuy, notification, and loadingMessage) have been verified to be properly implemented and used throughout the codebase. They are initialized, updated, and utilized in relevant components and functions, providing the expected functionality for handling Apibara status, Lords buying, notifications, and loading states.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new state.

# Test: Search for the usage of `apibaraStatus` state. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'apibaraStatus'

# Test: Search for the usage of `showLordsBuy` state. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'showLordsBuy'

# Test: Search for the usage of `notification` state. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'notification'

# Test: Search for the usage of `loadingMessage` state. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'loadingMessage'

Length of output: 306


Script:

#!/bin/bash
# Description: Verify the usage of new state variables in TypeScript files

# Find TypeScript files and search for apibaraStatus
echo "Searching for apibaraStatus:"
fd -e ts -e tsx | xargs rg -n -C 3 'apibaraStatus'

echo "\nSearching for showLordsBuy:"
fd -e ts -e tsx | xargs rg -n -C 3 'showLordsBuy'

echo "\nSearching for notification:"
fd -e ts -e tsx | xargs rg -n -C 3 'notification'

echo "\nSearching for loadingMessage:"
fd -e ts -e tsx | xargs rg -n -C 3 'loadingMessage'

Length of output: 66757


Line range hint 48-58: Verify the usage of new props.

The component has been updated to handle new props like multicall, mintLords, ethBalance, lordsBalance, gameContract, and costToPlay. Ensure that these props are being used correctly and that they are providing the expected functionality.

Run the following script to verify the usage of new props:

Verification successful

This script should provide us with the necessary information to verify the usage of the new props in the Header component and related files.


New props are correctly implemented and used in the Header component

The verification process confirms that the new props (multicall, mintLords, ethBalance, lordsBalance, gameContract, and costToPlay) are properly implemented and used in the Header component:

  • All props are correctly defined in the HeaderProps interface.
  • The props are properly destructured in the Header component function parameters.
  • Each prop is utilized at least once within the component for its intended purpose:
    • multicall: Used for executing multiple calls (line 325)
    • mintLords: Used for minting Lords tokens (line 403)
    • ethBalance and lordsBalance: Used to display user balances (lines 386 and 415)
    • gameContract: Used to access the contract address (line 266)
    • costToPlay: Used to calculate the Lords game cost (line 102)

The implementation appears to be correct and consistent with the expected functionality.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of new props.

# Test: Search for the usage of `multicall` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'multicall'

# Test: Search for the usage of `mintLords` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'mintLords'

# Test: Search for the usage of `ethBalance` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'ethBalance'

# Test: Search for the usage of `lordsBalance` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'lordsBalance'

# Test: Search for the usage of `gameContract` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'gameContract'

# Test: Search for the usage of `costToPlay` prop. Expect: Only occurrences of the correct usage.
rg --type typescript -A 5 $'costToPlay'

Length of output: 445


Script:

#!/bin/bash
# Description: Verify the usage of new props in the Header component and related files.

# Find TypeScript and JavaScript files in the ui/src/app/components/navigation directory
echo "Searching for TypeScript and JavaScript files in the navigation directory:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation

echo "\nSearching for usage of new props:"

# Search for multicall prop
echo "\nUsage of 'multicall' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'multicall' -n -C 2

# Search for mintLords prop
echo "\nUsage of 'mintLords' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'mintLords' -n -C 2

# Search for ethBalance prop
echo "\nUsage of 'ethBalance' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'ethBalance' -n -C 2

# Search for lordsBalance prop
echo "\nUsage of 'lordsBalance' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'lordsBalance' -n -C 2

# Search for gameContract prop
echo "\nUsage of 'gameContract' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'gameContract' -n -C 2

# Search for costToPlay prop
echo "\nUsage of 'costToPlay' prop:"
fd '\.(ts|tsx|js|jsx)$' ui/src/app/components/navigation | xargs rg 'costToPlay' -n -C 2

Length of output: 8206

ui/src/app/components/encounters/Paths.tsx (4)

1-37: LGTM!

The imports and state management using the useState hook look good.


38-430: Rendering logic for the path table looks good!

The memoized variables and the rendering logic for the path table are implemented correctly. The table displays relevant information for each path and handles different encounter types appropriately.

Tools
Biome

[error] 222-233: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)


434-579: Beast encounter details rendering looks good!

The rendering logic for the selected beast encounter details is implemented correctly. The tables display relevant information for the fight and flee attacks, and the code handles different attack types appropriately.


586-586: Component export looks good!

The component is correctly exported as the default export, following the standard practice.

ui/src/app/page.tsx (7)

133-174: LGTM!

The usage of useMemo to memoize the allMenuItems array is a good practice to optimize performance by avoiding unnecessary re-computations. The conditional inclusion of the "Tournament" menu item based on the onKatana state is implemented correctly.


176-211: LGTM!

The mobileMenuItems array is memoized using useMemo, which is a good practice for performance optimization. The conditional inclusion of the "Tournament" menu item based on the onKatana state is implemented correctly, similar to the allMenuItems array.


870-872: LGTM!

The EncounterDialog component is rendered conditionally based on the encounterTable state, and it is centered on the screen using absolute positioning and CSS transforms. The implementation looks good and there are no issues with the code.


2-61: LGTM!

The imports in the code segment are well-organized and grouped based on their source and purpose. The naming of the imported entities is consistent and meaningful, making it easy to understand the dependencies of the component. There are no unused imports or missing dependencies.


Line range hint 212-389: LGTM!

The code segment makes appropriate use of hooks and effects to manage state and side effects in the component. The dependencies of the effects are correctly specified to avoid unnecessary re-runs. The functions for handling user actions and interactions are well-defined and have clear purposes. Overall, the code looks good and there are no major issues with the logic or syntax.


Line range hint 391-869: LGTM!

The main rendering logic of the component is well-structured and readable, despite its complexity. The conditional rendering of different screens and components based on various state variables is implemented correctly. The rendering of dialogs and notifications is also handled appropriately based on specific conditions. Overall, the rendering logic looks good and there are no major issues with the code.


Line range hint 874-887: LGTM!

The ProfileDialog component is conditionally rendered based on the showProfile state variable, and it is rendered with a semi-transparent background using appropriate CSS classes and absolute positioning. The props passed to the component, including withdraw, ethBalance, lordsBalance, ethContractAddress, and lordsContractAddress, seem relevant and necessary for its functionality. The implementation looks good and there are no issues with the code.

ui/src/app/lib/utils/processFutures.ts (13)

1-4: LGTM!

The imports are correctly added and seem necessary for the functionality in this file.


28-28: LGTM!

The addition of the xp property to the Beast interface is a good enhancement. It provides more information about the beast's experience points.


Line range hint 31-46: LGTM!

The addition of the xp property to the Encounter interface is a good enhancement. It provides more information about the encounter's experience points.


61-69: LGTM!

The TreeNode interface is well-structured and captures the necessary properties for representing a node in the decision tree of encounters.


71-77: LGTM!

The Step interface is well-structured and captures the necessary properties for representing a step in the encounter tree traversal.


79-117: LGTM!

The getOutcomesWithPath function is well-implemented and efficiently generates all possible outcomes from a given encounter tree. The recursive approach and handling of different encounter types are done correctly.


119-227: LGTM!

The recurseTree function is well-implemented and correctly processes encounters in the decision tree. It handles various scenarios such as adventurer's health reaching zero, level up, and different encounter types. The recursive approach and updating of the adventurer's state and encounter details at each node are done properly.


229-264: LGTM!

The getDecisionTree function is well-implemented and correctly initializes the encounter tree. It creates the root node with the adventurer's current state and the next encounter, and then calls the recurseTree function to recursively process the encounters and build the decision tree.


266-293: LGTM!

The addition of the xp property to the obstacleNode object in the processObstacleEncounter function is consistent with the changes made to the Encounter interface. It correctly provides the current experience points of the encounter.


295-357: LGTM!

The addition of the xp property to the returned Beast object in the processBeastEncounterCombat function is consistent with the changes made to the Beast interface. It correctly provides the current experience points of the beast encounter.


359-409: LGTM!

The addition of the xp property to the returned Beast object in the processBeastEncounterFlee function is consistent with the changes made to the Beast interface. It correctly provides the current experience points of the beast encounter.


411-451: LGTM!

The addition of the xp property to the returned Encounter object in the processDiscoveryEncounter function is consistent with the changes made to the Encounter interface. It correctly provides the current experience points of the discovery encounter.


15-15: Verify the impact of changing the id property type.

Changing the id property type from bigint to number in the Beast interface might have implications in other parts of the codebase where Beast is used.

Please ensure that this change is intentional and doesn't break any existing functionality.

Run the following script to verify the usage of the id property:

ui/src/app/lib/utils/syscalls.ts (1)

449-453: Verify the function signature change in the codebase.

The changes to the spawn function signature and logic look good. The function can now handle multiple revenue addresses by randomly selecting one from the provided array.

To ensure the changes are correctly propagated, run the following script to verify that all calls to spawn have been updated to pass an array of revenue addresses:

Verification successful

Changes to the spawn function have been implemented correctly.

The spawn function in the syscalls.ts file has been updated to accept an array of revenueAddresses and randomly select one address from the array. This change allows for multiple revenue addresses to be used, providing more flexibility and ensuring fair distribution among the provided addresses. The implementation matches the expectations outlined in the original review comment.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `spawn` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type typescript -A 5 $'spawn\('

Length of output: 72


Script:

#!/bin/bash
# Description: Find TypeScript files and search for `spawn` function usage

# Find TypeScript files and search for `spawn(` with context
fd -e ts -x rg -C 5 'spawn\(' {}

Length of output: 36


Script:

#!/bin/bash
# Description: Investigate the codebase for TypeScript files and 'spawn' occurrences

# Check for the existence of TypeScript files
echo "TypeScript files:"
fd -e ts -e tsx

# Search for any occurrences of "spawn" (case-insensitive) in all files
echo -e "\nOccurrences of 'spawn':"
rg -i spawn

# Look for the specific file we know contains the `spawn` function
echo -e "\nSearching for syscalls.ts file:"
fd syscalls.ts

# If the file is found, display its content
syscalls_file=$(fd syscalls.ts)
if [ -n "$syscalls_file" ]; then
    echo -e "\nContent of $syscalls_file:"
    cat "$syscalls_file"
fi

Length of output: 60131

@@ -0,0 +1 @@
NEXT_PUBLIC_NETWORK="mainnet"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't commit the .env file to version control.

It's generally considered a security risk to include the .env file in version control, as it often contains sensitive information like API keys or secrets.

Instead, add the .env file to your .gitignore to exclude it from version control, and provide a .env.example file with dummy values as a template for other developers to use.

Comment on lines +226 to +252

<td className="text-center">
{item.item === "Bronze Ring" && `No Special Effect`}
{item.item === "Silver Ring" && `+1 Luck | +20 Luck GR20`}
{item.item === "Gold Ring" && "3% Beast Gold"}
{item.item === "Platinum Ring" && "3% Name Match Dmg"}
{item.item === "Titanium Ring" && "3% Crit Dmg"}

{item.item === "Pendant" && (
<div className="flex flex-row items-center justify-center gap-2">
<p>3% Hide</p>
<EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Hide"} />
</div>
)}
{item.item === "Necklace" && (
<div className="flex flex-row items-center justify-center gap-2">
<p>3% Metal</p>
<EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Metal"} />
</div>
)}
{item.item === "Amulet" && (
<div className="flex flex-row items-center justify-center gap-2">
<p>3% Cloth</p>
<EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Cloth"} />
</div>
)}
</td>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved with a suggestion for improvement.

The changes correctly display the special effects for various items using conditional rendering based on the item name. The EfficacyDisplay component is used appropriately to visually represent the effect type.

However, to improve maintainability and reusability, consider extracting the repeated conditional rendering logic into a separate function. This will make the code more concise and easier to update in the future.

Here's an example of how you can extract the logic into a separate function:

const getItemEffect = (item: string) => {
  switch (item) {
    case "Bronze Ring":
      return "No Special Effect";
    case "Silver Ring":
      return "+1 Luck | +20 Luck GR20";
    case "Gold Ring":
      return "3% Beast Gold";
    case "Platinum Ring":
      return "3% Name Match Dmg";
    case "Titanium Ring":
      return "3% Crit Dmg";
    case "Pendant":
      return (
        <div className="flex flex-row items-center justify-center gap-2">
          <p>3% Hide</p>
          <EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Hide"} />
        </div>
      );
    case "Necklace":
      return (
        <div className="flex flex-row items-center justify-center gap-2">
          <p>3% Metal</p>
          <EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Metal"} />
        </div>
      );
    case "Amulet":
      return (
        <div className="flex flex-row items-center justify-center gap-2">
          <p>3% Cloth</p>
          <EfficacyDisplay size="w-5" className="h-5 sm:w-8" type={"Cloth"} />
        </div>
      );
    default:
      return null;
  }
};

Then, you can simplify the table cell rendering as follows:

<td className="text-center">{getItemEffect(item.item)}</td>

Comment on lines +222 to +233
<tr
className={
encounter.encounter === "Beast"
? "cursor-pointer hover:bg-terminal-green-50 hover:text-terminal-black"
: ""
}
onClick={() => {
if (encounter.encounter === "Beast") {
setSelectedBeastEncounter(steps[index]);
}
}}
>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a key property to the <tr> element.

The static analysis tool correctly suggests adding a key property to the <tr> element in the iterable. This helps React efficiently update the list when the order of items changes.

To fix this, add a unique key property to the <tr> element:

-<tr
+<tr key={index}
  className={
    encounter.encounter === "Beast"
      ? "cursor-pointer hover:bg-terminal-green-50 hover:text-terminal-black"
      : ""
  }
  onClick={() => {
    if (encounter.encounter === "Beast") {
      setSelectedBeastEncounter(steps[index]);
    }
  }}
>
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.

Suggested change
<tr
className={
encounter.encounter === "Beast"
? "cursor-pointer hover:bg-terminal-green-50 hover:text-terminal-black"
: ""
}
onClick={() => {
if (encounter.encounter === "Beast") {
setSelectedBeastEncounter(steps[index]);
}
}}
>
<tr key={index}
className={
encounter.encounter === "Beast"
? "cursor-pointer hover:bg-terminal-green-50 hover:text-terminal-black"
: ""
}
onClick={() => {
if (encounter.encounter === "Beast") {
setSelectedBeastEncounter(steps[index]);
}
}}
>
Tools
Biome

[error] 222-233: Missing key property for this element in iterable.

The order of the items may change, and having a key can help React identify which item was moved.
Check the React documentation.

(lint/correctness/useJsxKeyInIterable)

@starknetdev starknetdev merged commit 85182dc into main Sep 13, 2024
9 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants