-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix: autoconnect & argent mobile connection #856
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
Warning Rate limit exceeded@irisdv has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 0 minutes and 36 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. WalkthroughThe changes primarily focus on improving the Changes
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (1)
package-lock.json
is excluded by!**/package-lock.json
Files selected for processing (3)
- components/UI/navbar.tsx (1 hunks)
- components/UI/walletConnect.tsx (3 hunks)
- utils/connectorWrapper.ts (2 hunks)
Additional context used
Biome
utils/connectorWrapper.ts
[error] 94-94: Invalid
typeof
comparison value: this expression is not a string literalnot a string literal
Unsafe fix: Compare the result oftypeof
with a valid type name(lint/suspicious/useValidTypeof)
Additional comments not posted (4)
components/UI/walletConnect.tsx (3)
1-1
: Review of imports and state initialization:
- The imports for
useEffect
anduseState
are correctly added as these hooks are used in the component.- The import of
isInArgentMobileAppBrowser
is appropriate as it's used within theuseEffect
hook to set theisArgentMobile
state.- The state
isArgentMobile
is correctly initialized tofalse
, which is a safe default value.Everything looks good here.
Also applies to: 11-11, 29-29
36-39
: Review of useEffect hook for settingisArgentMobile
:
- The hook correctly checks for the
window
object before callingisInArgentMobileAppBrowser
, which ensures it only runs in a browser environment.- The empty dependency array (
[]
) ensures that this effect runs only once after the initial render, which is appropriate for setting the initial state based on the browser type.This implementation is correct and efficient.
40-44
: Review of modifications tofilterConnectors
function:
- The function now filters connectors to only include those with
id
equal to "argentMobile" ifisArgentMobile
istrue
. This is a straightforward and efficient way to filter based on the state.- The function falls back to the previous behavior if
isArgentMobile
isfalse
, which maintains backward compatibility.The changes are logical and well-implemented.
components/UI/navbar.tsx (1)
86-86
: Review ofuseEffect
dependency modification:
- The change to include only
connectors
in the dependency array of theuseEffect
hook that handles autoconnect is appropriate. This ensures that the hook only re-runs whenconnectors
changes, which is likely the intended behavior to re-establish connections when available connectors change.This change is a good practice for optimizing component re-renders.
utils/connectorWrapper.ts
Outdated
export const isInArgentMobileAppBrowser = (): boolean => { | ||
if (typeof window === undefined || !window?.starknet_argentX) { | ||
return false; | ||
} | ||
|
||
const starknetMobile = | ||
window?.starknet_argentX as unknown as StarknetWindowObject & { | ||
isInAppBrowser: boolean; | ||
}; | ||
|
||
return starknetMobile?.isInAppBrowser; | ||
}; |
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.
Issue with typeof
comparison in isInArgentMobileAppBrowser
:
- The static analysis tool flagged an issue with the
typeof
comparison on line 94. The correct usage should compare against a string literal. The current implementation might lead to unexpected behavior.
Here's a proposed fix:
- if (typeof window === undefined || !window?.starknet_argentX) {
+ if (typeof window === "undefined" || !window?.starknet_argentX) {
return false;
}
This change ensures that the comparison checks if window
is undefined correctly.
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.
export const isInArgentMobileAppBrowser = (): boolean => { | |
if (typeof window === undefined || !window?.starknet_argentX) { | |
return false; | |
} | |
const starknetMobile = | |
window?.starknet_argentX as unknown as StarknetWindowObject & { | |
isInAppBrowser: boolean; | |
}; | |
return starknetMobile?.isInAppBrowser; | |
}; | |
export const isInArgentMobileAppBrowser = (): boolean => { | |
if (typeof window === "undefined" || !window?.starknet_argentX) { | |
return false; | |
} | |
const starknetMobile = | |
window?.starknet_argentX as unknown as StarknetWindowObject & { | |
isInAppBrowser: boolean; | |
}; | |
return starknetMobile?.isInAppBrowser; | |
}; |
Tools
Biome
[error] 94-94: Invalid
typeof
comparison value: this expression is not a string literalnot a string literal
Unsafe fix: Compare the result oftypeof
with a valid type name(lint/suspicious/useValidTypeof)
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
Outside diff range, codebase verification and nitpick comments (2)
components/UI/navbar.tsx (2)
Line range hint
89-91
: Simplify theisConnected
state update.The
useEffect
for updatingisConnected
based onaddress
is straightforward. Consider simplifying the ternary operation for clarity.- address ? setIsConnected(true) : setIsConnected(false); + setIsConnected(!!address);Tools
Biome
[error] 83-83: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Line range hint
93-102
: Check network conditions for potential simplification.The network check logic in
useEffect
is complex. Consider simplifying the condition to improve readability and possibly performance.- const isWrongNetwork = - (chainId === bigintToStringHex(sepolia.id) && network === "mainnet") || - (chainId === bigintToStringHex(mainnet.id) && network === "testnet"); + const expectedChainId = network === "mainnet" ? mainnet.id : sepolia.id; + const isWrongNetwork = chainId !== bigintToStringHex(expectedChainId);Tools
Biome
[error] 83-83: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- components/UI/navbar.tsx (1 hunks)
Additional context used
Biome
components/UI/navbar.tsx
[error] 83-83: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Additional comments not posted (1)
components/UI/navbar.tsx (1)
Line range hint
104-106
: Approve the update tolastConnector
.The
useEffect
for updatinglastConnector
is appropriately usingisConnected
as a dependency, ensuring it updates only when necessary.Tools
Biome
[error] 83-83: Change to an optional chain.
Unsafe fix: Change to an optional chain.
(lint/complexity/useOptionalChain)
Summary by CodeRabbit
New Features
Bug Fixes
Navbar
component to ensure state updates run correctly and efficiently.