-
Notifications
You must be signed in to change notification settings - Fork 37
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
🏆 feat/trophy page #1987
🏆 feat/trophy page #1987
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
You are out of MentatBot reviews. Your usage will refresh November 11 at 08:00 AM. |
@bal7hazar is attempting to deploy a commit to the Loot Bibliotheca Team on Vercel. A member of the Team first needs to authorize it. |
WalkthroughThe pull request includes updates to several files within the Changes
Possibly related PRs
Suggested reviewers
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.
need to test in next branch live but looks good
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: 2
🧹 Outside diff range and nitpick comments (4)
client/src/hooks/context/accountStore.tsx (1)
1-1
: LGTM! Consider adding JSDoc comments.The addition of the
ControllerConnector
type and related interface properties is well-structured. The nullable type for the connector property is appropriate for state management.Consider adding JSDoc comments to document the purpose of these new properties:
interface AccountState { account: Account | AccountInterface | null; setAccount: (account: Account | AccountInterface) => void; + /** Controller connector instance for managing trophy-related functionality */ connector: ControllerConnector | null; + /** Sets the controller connector instance */ setConnector: (connector: ControllerConnector) => void; }Also applies to: 8-9
client/src/hooks/context/starknet-provider.tsx (1)
9-10
: Add documentation for configuration constants.The purpose and significance of these configuration values should be documented. Consider moving these values to a centralized configuration file for easier maintenance and version control.
+// Unique identifier for the current version/release of the application const slot: string = "eternum-rc1-1"; +// Application namespace for controller connector isolation const namespace: string = "eternum";client/src/ui/config.tsx (2)
Line range hint
5-23
: Replace deprecated battery API with more reliable device detection.The current implementation has several concerns:
navigator.getBattery()
is deprecated and not widely supported across browsers- Battery charging state is not a reliable indicator for device type
- The function name suggests laptop detection but it's actually used for graphics settings
Consider using more reliable methods such as:
const checkDeviceCapabilities = () => { // Check GPU capabilities const canvas = document.createElement('canvas'); const gl = canvas.getContext('webgl'); if (!gl) return true; // Return true for low graphics if WebGL not supported const debugInfo = gl.getExtension('WEBGL_debug_renderer_info'); if (!debugInfo) return true; const renderer = gl.getParameter(debugInfo.UNMASKED_RENDERER_WEBGL); // Check if integrated GPU (common in laptops) or mobile GPU const isLowPower = /(Intel|AMD|Mobile|Iris|HD Graphics)/i.test(renderer); localStorage.setItem("LOW_GRAPHICS_FLAG", isLowPower.toString()); localStorage.setItem("INITIAL_LAPTOP_CHECK", "true"); return isLowPower; };
Line range hint
25-28
: Improve device detection implementation.
- Awaiting at module level can block module initialization
- User Agent string detection is not recommended for device detection
Consider this alternative approach:
export const getDeviceCapabilities = () => { // Use feature detection instead of UA strings const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || matchMedia('(pointer:coarse)').matches; return { isMobile, isLowGraphics: checkDeviceCapabilities() }; }; // Then use it in your components const { isMobile, isLowGraphics } = getDeviceCapabilities();
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (2)
client/public/images/buildings/thumb/trophy.png
is excluded by!**/*.png
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (6)
client/package.json
(1 hunks)client/src/hooks/context/DojoContext.tsx
(2 hunks)client/src/hooks/context/accountStore.tsx
(1 hunks)client/src/hooks/context/starknet-provider.tsx
(1 hunks)client/src/ui/config.tsx
(1 hunks)client/src/ui/modules/navigation/SecondaryMenuItems.tsx
(3 hunks)
🔇 Additional comments (8)
client/src/hooks/context/accountStore.tsx (1)
15-16
: Verify connector cleanup on account changes.
The implementation looks good, but we should ensure the connector is properly cleaned up when the account changes to prevent memory leaks or stale connections.
Let's verify if there's any cleanup logic elsewhere in the codebase:
✅ Verification successful
Connector cleanup is properly handled through Starknet React hooks
The connector cleanup is handled automatically through the Starknet React hooks integration:
- The connector state in
accountStore
is managed throughuseAccount
hook inDojoContext.tsx
:
const { account: controllerAccount, connector, isConnected } = useAccount();
useEffect(() => {
if (connector) {
useAccountStore.getState().setConnector(connector as ControllerConnector);
}
}, [controllerAccount, isConnected, connector]);
- The
useAccount
hook from@starknet-react/core
handles the lifecycle of the connector, including cleanup when the account changes or disconnects. TheStarknetConfig
provider in the app properly configures this behavior.
No additional cleanup is needed in the accountStore
as the connector state is managed by the framework's hooks.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Search for connector cleanup logic in account-related files
rg -l 'setConnector.*null|cleanup.*connector' --type tsx --type ts
# Search for useEffect hooks that might handle connector cleanup
ast-grep --pattern 'useEffect(() => {
$$$
setConnector($$$)
$$$
})'
Length of output: 172
Script:
#!/bin/bash
# Search for connector cleanup logic in account-related files with correct file extensions
rg -l 'setConnector.*null|cleanup.*connector' -g '*.tsx' -g '*.ts'
# Search for useEffect hooks that might handle connector cleanup
rg -A 5 'useEffect.*setConnector' -g '*.tsx' -g '*.ts'
# Look for account change handlers that might cleanup connector
rg -A 5 'account.*change|onAccountChange' -g '*.tsx' -g '*.ts'
# Search for connector cleanup in disconnect handlers
rg -A 5 'disconnect.*connector|cleanup.*connector' -g '*.tsx' -g '*.ts'
Length of output: 264
Script:
#!/bin/bash
# Let's look at the entire accountStore implementation to understand the connector usage
fd "accountStore.tsx" --type f --exec cat {}
# Search for files that import and use the connector
rg "import.*accountStore" -g '*.tsx' -g '*.ts' -A 3
# Look for wallet connection/disconnection handling
rg "connect|disconnect" -g '*.tsx' -g '*.ts' -A 5
Length of output: 21852
client/src/hooks/context/starknet-provider.tsx (1)
14-15
: LGTM! Verify integration with account management.
The configuration updates look correct. Since this is part of a larger account management feature, ensure that these changes are properly integrated with the account store and controller context.
Let's verify the integration with related components:
✅ Verification successful
Integration with account management verified
The changes are properly integrated with the account management system:
ControllerConnector
is correctly imported and used inaccountStore.tsx
with proper state management- The connector is properly integrated in
DojoContext.tsx
with account state synchronization - The account store maintains the connector state and provides setter methods
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Verify the integration between ControllerConnector and account management
# Check for related account management implementations
echo "Checking account management integration..."
rg -l "ControllerConnector" --type tsx
# Verify consistent namespace usage
echo "\nVerifying namespace consistency..."
rg "eternum-rc1-1|eternum" --type tsx
Length of output: 312
Script:
#!/bin/bash
# Let's try without file type restriction since tsx extension might not be recognized
echo "Checking ControllerConnector usage..."
rg -l "ControllerConnector"
echo -e "\nChecking namespace and slot references..."
rg "namespace.*slot|slot.*namespace"
echo -e "\nChecking account management related code..."
rg -l "account.*management|AccountManagement|AccountStore"
Length of output: 926
Script:
#!/bin/bash
# Let's examine the integration points more closely
# Check the implementation in accountStore.tsx
echo "Checking accountStore.tsx implementation..."
rg -A 5 "ControllerConnector" client/src/hooks/context/accountStore.tsx
# Check how namespace and slot are used in starknet-provider
echo -e "\nChecking starknet-provider implementation..."
rg -A 10 "namespace.*slot|slot.*namespace" client/src/hooks/context/starknet-provider.tsx
# Check DojoContext integration
echo -e "\nChecking DojoContext integration..."
rg -A 5 "ControllerConnector" client/src/hooks/context/DojoContext.tsx
Length of output: 1569
client/package.json (1)
20-21
: Verify the minimum required versions for cartridge packages.
The update of both @cartridge/connector
and @cartridge/controller
from alpha.4 to alpha.6 appears to support the account management changes. However, since these are alpha versions:
- Please verify if alpha.6 is the minimum required version or if alpha.4 would still work
- Consider documenting the reason for these version updates in the PR description
- Be cautious of potential breaking changes in these alpha releases
Let's verify the minimum required versions:
✅ Verification successful
Based on the package.json files found, I can now generate a final response:
Version updates are required for trophy page implementation
The version updates to alpha.6 are necessary as evidenced by:
- The client package requires these specific versions for new account management features
- The landing package is already using alpha.5, indicating a progressive upgrade path
- These packages are core dependencies for the client's functionality, used alongside other Dojo-related packages
The synchronized update of both packages to the same version is the correct approach since they are tightly coupled components of the Cartridge framework.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check if there are any breaking changes between alpha.4 and alpha.6
# Look for import statements and usage patterns of these packages
echo "Searching for @cartridge/* package usage patterns..."
rg --type typescript "@cartridge/(connector|controller)" -A 5
# Check the changelog or release notes in package.json
echo "Checking for potential breaking changes in package.json..."
rg "\"@cartridge/(connector|controller)\"" package.json
Length of output: 396
Script:
#!/bin/bash
# Search for TypeScript/JavaScript files using cartridge packages
echo "Searching for cartridge package imports..."
rg -t js -t jsx -t ts -t tsx "@cartridge/(connector|controller)" -A 5
# Look for package.json files and their content
echo "Checking package.json files..."
fd package.json --exec cat {}
# Look for any migration guides or documentation
echo "Checking for documentation..."
fd -e md -e txt | xargs rg -l "cartridge|migration|upgrade"
Length of output: 10656
client/src/ui/config.tsx (1)
72-72
: LGTM! Trophy thumbnail addition is well-implemented.
The new trophy thumbnail path follows the established pattern and aligns with the PR's objective of adding a trophy page.
client/src/ui/modules/navigation/SecondaryMenuItems.tsx (2)
1-1
: LGTM!
The import is correctly placed and necessary for the new trophy feature implementation.
36-39
: Remove console.log statements
These debug statements should not be committed to production code.
client/src/hooks/context/DojoContext.tsx (2)
4-4
: LGTM: Import aligns with connector integration.
The import of ControllerConnector
is necessary for the enhanced account management functionality.
68-76
: Verify connector state management across the application.
The addition of connector state management might affect other components that rely on the account store.
Let's verify the connector usage and cleanup:
✅ Verification successful
Connector state management is properly implemented
Based on the verification results:
- The connector state is cleanly managed in a centralized store (accountStore.tsx)
- Usage is limited to DojoContext (for setting) and SecondaryMenuItems (for reading)
- No cleanup is needed as the store handles state persistence
- The implementation follows proper patterns with typed interfaces
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check for connector usage in components and potential memory leaks
echo "Searching for connector usage in components..."
rg -l "useAccountStore.*connector" --type tsx
echo "Checking for proper cleanup in components using connector..."
rg -A 5 "useEffect.*connector" --type tsx
Length of output: 381
Script:
#!/bin/bash
# Search for connector usage in components with correct file extension
echo "Searching for connector usage in components..."
rg -l "useAccountStore.*connector" --type ts --type tsx --type jsx --type js
echo "Checking for proper cleanup in components using connector..."
rg -A 5 "useEffect.*connector" --type ts --type tsx --type jsx --type js
# Search for connector-related state management
echo "Searching for connector state management..."
rg "setConnector|getConnector" --type ts --type tsx --type jsx --type js
# Look for account store implementation
echo "Looking for account store implementation..."
fd "AccountStore" --type f --exec cat {}
Length of output: 783
Script:
#!/bin/bash
# Search for files and patterns without relying on file extensions
echo "Searching for connector usage..."
rg -l "useAccountStore.*connector"
echo "Checking for connector-related effects..."
rg -A 5 "useEffect.*connector"
echo "Searching for connector state management..."
rg "setConnector|getConnector"
echo "Looking for account store files..."
fd "AccountStore"
Length of output: 876
Script:
#!/bin/bash
# Let's examine the specific files we found
echo "Content of SecondaryMenuItems.tsx..."
cat client/src/ui/modules/navigation/SecondaryMenuItems.tsx
echo -e "\nContent of accountStore.tsx..."
cat client/src/hooks/context/accountStore.tsx
echo -e "\nChecking for cleanup patterns..."
rg -B 5 -A 5 "useEffect.*connector.*return"
Length of output: 5538
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: 2
🧹 Outside diff range and nitpick comments (2)
client/src/hooks/context/starknet-provider.tsx (2)
4-4
: Consider moving configuration constants to a dedicated config file.These configuration constants (
slot
,namespace
,colorMode
) would be better placed in a dedicated configuration file. This would:
- Centralize configuration management
- Make it easier to update values across environments
- Improve maintainability
Also applies to: 10-12
14-21
: Maintain consistent ordering of properties.Consider ordering the ControllerConnector properties to match the order of their constant declarations above for better code readability:
const controller = new ControllerConnector({ rpc: import.meta.env.VITE_PUBLIC_NODE_URL, - namespace, - slot, policies, theme, + slot, + namespace, colorMode, });
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
⛔ Files ignored due to path filters (1)
pnpm-lock.yaml
is excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
client/package.json
(1 hunks)client/src/hooks/context/DojoContext.tsx
(3 hunks)client/src/hooks/context/starknet-provider.tsx
(1 hunks)client/src/ui/modules/navigation/SecondaryMenuItems.tsx
(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- client/package.json
- client/src/ui/modules/navigation/SecondaryMenuItems.tsx
🔇 Additional comments (2)
client/src/hooks/context/DojoContext.tsx (2)
4-4
: LGTM: Import addition is appropriate.
The ControllerConnector import is correctly added and properly used for type casting in the connector management.
158-158
:
Avoid hardcoding environment flags.
The isDev
flag is hardcoded to false
, which could make local development difficult. Consider deriving this value from environment variables or build configuration.
Consider using environment variables:
- const isDev = false;
+ const isDev = import.meta.env.MODE === 'development' || import.meta.env.VITE_ENV === 'development';
Let's check if there are any environment-related configurations:
const controller = new ControllerConnector({ | ||
rpc: import.meta.env.VITE_PUBLIC_NODE_URL, | ||
namespace, | ||
slot, | ||
policies, | ||
theme, | ||
colorMode, | ||
}); |
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 environment variable validation.
Consider adding validation for the VITE_PUBLIC_NODE_URL
environment variable to prevent runtime errors:
+if (!import.meta.env.VITE_PUBLIC_NODE_URL) {
+ throw new Error('VITE_PUBLIC_NODE_URL environment variable is not set');
+}
const controller = new ControllerConnector({
rpc: import.meta.env.VITE_PUBLIC_NODE_URL,
namespace,
slot,
policies,
theme,
colorMode,
});
📝 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 controller = new ControllerConnector({ | |
rpc: import.meta.env.VITE_PUBLIC_NODE_URL, | |
namespace, | |
slot, | |
policies, | |
theme, | |
colorMode, | |
}); | |
if (!import.meta.env.VITE_PUBLIC_NODE_URL) { | |
throw new Error('VITE_PUBLIC_NODE_URL environment variable is not set'); | |
} | |
const controller = new ControllerConnector({ | |
rpc: import.meta.env.VITE_PUBLIC_NODE_URL, | |
namespace, | |
slot, | |
policies, | |
theme, | |
colorMode, | |
}); |
const { account, connector, isConnected } = useAccount(); | ||
|
||
useEffect(() => { | ||
if (controllerAccount) { | ||
useAccountStore.getState().setAccount(controllerAccount); | ||
if (account) { | ||
useAccountStore.getState().setAccount(account); | ||
} | ||
}, [controllerAccount, isConnected]); | ||
return controllerAccount; | ||
}, [account, isConnected]); | ||
|
||
useEffect(() => { | ||
if (connector) { | ||
useAccountStore.getState().setConnector(connector as ControllerConnector); | ||
} | ||
}, [connector, isConnected]); | ||
|
||
return account; |
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
Improve error handling in useControllerAccount effects.
While the separation of concerns between account and connector effects is a good improvement, the implementation could still benefit from proper error handling and cleanup functions as suggested in the previous review.
Consider adding error handling and cleanup:
useEffect(() => {
if (account) {
+ try {
useAccountStore.getState().setAccount(account);
+ } catch (error) {
+ console.error('Failed to set account:', error);
+ }
}
+ return () => {
+ // Cleanup when component unmounts or account changes
+ };
}, [account, isConnected]);
useEffect(() => {
if (connector) {
+ try {
useAccountStore.getState().setConnector(connector as ControllerConnector);
+ } catch (error) {
+ console.error('Failed to set connector:', error);
+ }
}
+ return () => {
+ // Cleanup when component unmounts or connector changes
+ };
}, [connector, isConnected]);
Committable suggestion skipped: line range outside the PR's diff.
Summary by CodeRabbit
Release Notes
New Features
Improvements
Bug Fixes
These updates improve user experience and enhance the overall functionality of the application.