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

Change address of dashboard when changing wallets #941

Open
wants to merge 11 commits into
base: testnet
Choose a base branch
from

Conversation

caxtonacollins
Copy link

@caxtonacollins caxtonacollins commented Nov 9, 2024

Change.adress.of.dashboard.when.changing.wallets.mp4

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced user data handling with improved error logging and notifications.
    • Optimized address formatting in the ProfileCard component.
  • Bug Fixes

    • Improved error handling in data fetching functions for better user feedback.
  • Style

    • Standardized use of single quotes across various components for consistency.
    • Reformatted import statements and JSX structures for improved readability.
  • Chores

    • Minor adjustments in tsconfig.json for JSON formatting compliance.

Copy link

vercel bot commented Nov 9, 2024

@caxtonacollins is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Nov 9, 2024

Walkthrough

The pull request introduces several modifications across multiple components, primarily focusing on user data handling, fetching logic, and UI rendering. A new fetchPortfolioData function is added to centralize user data fetching with improved error handling. The Providers component undergoes formatting changes for consistency in string literals. Additionally, various components, including Navbar, ProfileCard, and WalletButton, have been updated for consistent use of single quotes. Overall, the changes enhance code readability and maintainability while preserving existing functionality.

Changes

File Change Summary
app/[addressOrDomain]/page.tsx Added fetchPortfolioData function for user data fetching; enhanced error handling in fetching functions; adjusted rendering logic for PortfolioSummary to manage loading states; minor formatting changes (single quotes, indentation). Updated method signatures for fetchPortfolioProtocols and fetchPortfolioAssets.
app/provider.tsx Converted double quotes to single quotes for string literals; minor adjustments in Providers function for string formatting.
components/UI/navbar.tsx Reformatted import statements and JSX structure to use single quotes consistently; no changes to functionality or logic.
components/UI/profileCard/profileCard.tsx Introduced useAccount and useStarkProfile hooks; optimized formattedAddress computation using useMemo; updated fetchTotalBalance to conditionally execute based on address; improved error handling; consistent use of single quotes for JSX attributes.
components/navbar/walletButton.tsx Reformatted isWebWallet declaration and JSX structure to use single quotes; no changes to functionality or logic.
tsconfig.json Added a trailing comma in the include array; no other changes to configuration options.

Possibly related PRs

  • update provider.tsx #944: The changes in app/provider.tsx involve modifications to the availableConnectors array and the introduction of a new function, which may relate to user data handling and wallet connections, similar to the updates in the Page component's fetching logic in the main PR.

Suggested reviewers

  • fricoben

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

app/provider.tsx

Oops! Something went wrong! :(

ESLint: 9.14.0

ESLint couldn't find an eslint.config.(js|mjs|cjs) file.

From ESLint v9.0.0, the default configuration file is now eslint.config.js.
If you are using a .eslintrc.* file, please follow the migration guide
to update your configuration file to the new format:

https://eslint.org/docs/latest/use/configure/migration-guide

If you still have problems after following the migration guide, please stop by
https://eslint.org/chat/help to chat with the team.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 85d221f and c31ed2a.

📒 Files selected for processing (2)
  • app/provider.tsx (2 hunks)
  • components/UI/profileCard/profileCard.tsx (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • app/provider.tsx
  • components/UI/profileCard/profileCard.tsx

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.

@caxtonacollins
Copy link
Author

@kfastov please review

Copy link
Contributor

@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 (12)
context/WalletProvider.tsx (1)

1-11: LGTM! Consider adding JSDoc comments for better documentation.

The type definitions and imports are well-structured. The WalletContextType interface clearly defines the contract for the wallet context.

Consider adding JSDoc comments to document the purpose of each property:

+/**
+ * Type definition for the Wallet context
+ */
 type WalletContextType = {
+  /** Current wallet address, null when no wallet is connected */
   newAddress: string | null;
+  /** Updates the current wallet address */
   setNewAddress: (account: string | null) => void;
+  /** Current URL parameters for the wallet route */
   newURLParams: string;
+  /** Updates the URL parameters for the wallet route */
   setNewURLParams: (account: string) => void;
 };
app/provider.tsx (4)

39-59: Consider extracting wallet configuration to a separate config file.

The wallet connectors configuration, especially the ArgentMobile settings, contains hardcoded values. Consider:

  1. Moving these configurations to a separate config file
  2. Using environment variables for dynamic values
+ // config/wallet.ts
+ export const walletConfig = {
+   dappName: process.env.NEXT_PUBLIC_DAPP_NAME || 'Starknet Quest',
+   dappIcon: process.env.NEXT_PUBLIC_DAPP_ICON || 'https://starknet.quest/visuals/starknetquestLogo.svg',
+ };

90-96: Consider using MUI's breakpoints for responsive design.

The media query breakpoint is hardcoded. Consider using MUI's breakpoint system for consistency:

- ['@media (min-width:768px)']: {
+ [theme.breakpoints.up('md')]: {

111-113: Apply the same breakpoint suggestion here.

For consistency, update this media query as well:

- ['@media (min-width:768px)']: {
+ [theme.breakpoints.up('md')]: {

⚠️ Privacy implications need to be addressed for session recording

Based on the codebase analysis:

  1. No privacy policy or cookie consent implementation was found despite the use of session recording
  2. PostHog is configured with cross-origin iframe recording enabled
  3. No user notification or consent mechanism for session recording was detected

Required actions:

  • Implement a cookie consent mechanism before initializing PostHog
  • Add a privacy policy addressing session recording practices
  • Consider disabling recordCrossOriginIframes unless specifically required for functionality
  • Add user notification about session recording
🔗 Analysis chain

Line range hint 26-35: Verify privacy implications of cross-origin iframe recording.

The PostHog configuration enables recording of cross-origin iframes. Please ensure:

  1. This aligns with your privacy policy
  2. Sensitive user data is not inadvertently captured
  3. Users are properly informed about the recording
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for privacy policy and cookie consent implementations
echo "Searching for privacy policy and cookie consent..."
rg -i "privacy|cookie|consent" --type html --type tsx --type ts

Length of output: 204


Script:

#!/bin/bash
# Check for privacy policy and cookie consent with correct file extensions
echo "Searching for privacy policy and cookie consent..."
rg -i "privacy|cookie|consent" -t ts -t js -t jsx -t tsx

# Check for PostHog configuration and usage
echo -e "\nSearching for PostHog configuration and usage..."
rg -i "posthog" -t ts -t js -t jsx -t tsx -A 3

# Check for any session recording related code
echo -e "\nSearching for session recording related code..."
rg -i "session.*record|record.*session" -t ts -t js -t jsx -t tsx

Length of output: 592


Script:

#!/bin/bash
# Search using ripgrep without file type specifications
echo "Searching for privacy and cookie consent..."
rg -i "privacy|cookie|consent"

echo -e "\nSearching for PostHog configuration..."
rg -i "posthog" -A 3

echo -e "\nSearching for session recording..."
rg -i "session.*record|record.*session"

# Also check for any configuration files
echo -e "\nChecking configuration files..."
fd -e json -e yaml -e yml -e config

Length of output: 5110

components/UI/profileCard/profileCard.tsx (2)

53-59: Consider adding input validation

The address formatting logic is well-memoized, but consider adding validation for the identity.owner string.

  const formattedAddress = useMemo(
    () =>
+     !identity.owner ? undefined :
      (identity.owner.startsWith("0x")
        ? identity.owner
        : `0x${identity.owner}`) as Address,
    [identity.owner]
  );

74-84: Improve error handling specificity

The error logging could be more specific about the type of error encountered to aid debugging.

-          console.error(
-            `Attempt ${attempts} - Error fetching total balance:`,
-            err
-          );
+          console.error(
+            `Attempt ${attempts} - Error fetching total balance for address ${formattedAddress}:`,
+            err instanceof Error ? err.message : err
+          );
components/UI/navbar.tsx (1)

314-321: Consider moving social media URLs to constants.

While the social media links are properly formatted with security attributes, consider moving the URLs to a constants file for better maintainability.

Example implementation:

// constants/social-media.ts
export const SOCIAL_MEDIA = {
  TWITTER: 'https://twitter.com/starknet_quest',
  DISCORD: 'https://discord.gg/byEGk6w6T6'
} as const;

Then update the links:

- href='https://twitter.com/starknet_quest'
+ href={SOCIAL_MEDIA.TWITTER}

Also applies to: 326-333

app/[addressOrDomain]/page.tsx (4)

Line range hint 208-322: Consider optimizing parallel promise execution and error handling.

The portfolio calculation logic has several areas for improvement:

  1. The parallel promise execution could be optimized by using Promise.allSettled instead of Promise.all to handle failed calculations gracefully.
  2. Magic numbers (like 4 for max assets) should be extracted as constants.

Consider applying these changes:

+ const MAX_DISPLAYED_ASSETS = 4;
+ const ASSET_COLORS = ["#1E2097", "#637DEB", "#2775CA", "#5CE3FE", "#F4FAFF"];

- const results = (await Promise.all([...balancePromises, ...userTokenPromises])).filter(Boolean);
+ const results = (await Promise.allSettled([...balancePromises, ...userTokenPromises]))
+   .filter((result) => result.status === 'fulfilled')
+   .map((result) => (result as PromiseFulfilledResult<any>).value)
+   .filter(Boolean);

- if (sortedAssets.length > 4) {
+ if (sortedAssets.length > MAX_DISPLAYED_ASSETS) {

553-591: Improve error handling and consider splitting responsibilities.

The fetchPortfolioData function handles multiple concerns and could benefit from:

  1. More specific error type handling beyond just AbortError
  2. Separation of data fetching and processing responsibilities

Consider splitting the function:

+ const fetchRawPortfolioData = async (
+   addr: string,
+   abortController: AbortController
+ ) => {
+   const normalizedAddr = addr.toLowerCase();
+   return Promise.all([
+     fetchDapps({ signal: abortController.signal }),
+     fetchTokens({ signal: abortController.signal }),
+     fetchUserTokens(normalizedAddr, { signal: abortController.signal }),
+     fetchUserDapps(normalizedAddr, { signal: abortController.signal }),
+   ]);
+ };

const fetchPortfolioData = useCallback(
  async (addr: string, abortController: AbortController) => {
    setLoadingProtocols(true);
    try {
-     const normalizedAddr = addr.toLowerCase();
-     const [dappsData, tokensData, userTokensData, userDappsData] =
-       await Promise.all([...]);
+     const [dappsData, tokensData, userTokensData, userDappsData] =
+       await fetchRawPortfolioData(addr, abortController);

726-727: Extract UI strings to constants for better maintainability.

Consider moving hardcoded strings to a constants file for better maintainability and internationalization support.

+ const UI_STRINGS = {
+   ERROR_PROFILE_NOT_FOUND: 'Profile or Page not found',
+   ERROR_GO_BACK: 'Go back to quests',
+   NO_QUESTS_MESSAGE: 'User has not completed any quests at the moment',
+ };

- errorMessage='Profile or Page not found'
- buttonText='Go back to quests'
+ errorMessage={UI_STRINGS.ERROR_PROFILE_NOT_FOUND}
+ buttonText={UI_STRINGS.ERROR_GO_BACK}

Also applies to: 840-843


791-795: Enhance accessibility attributes for tab navigation.

The tab implementation could benefit from additional ARIA attributes for better screen reader support.

 <Tabs
   style={{
     borderBottom: "0.5px solid rgba(224, 224, 224, 0.3)",
   }}
   className='pb-6'
   value={tabIndex}
   onChange={handleChangeTab}
-  aria-label='quests and collectons tabs'
+  aria-label='Quest completion status'
+  role="navigation"
   indicatorColor='secondary'
 >
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 706b4b3 and 764ce9d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (7)
  • app/[addressOrDomain]/page.tsx (14 hunks)
  • app/provider.tsx (4 hunks)
  • components/UI/navbar.tsx (10 hunks)
  • components/UI/profileCard/profileCard.tsx (9 hunks)
  • components/navbar/walletButton.tsx (4 hunks)
  • context/WalletProvider.tsx (1 hunks)
  • tsconfig.json (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • components/navbar/walletButton.tsx
  • tsconfig.json
🔇 Additional comments (10)
context/WalletProvider.tsx (2)

49-55: LGTM! Well-implemented context consumer hook.

The useWallet hook follows React best practices with proper error handling for usage outside the provider context.


1-55: Consider additional architectural improvements.

A few architectural considerations for the wallet management implementation:

  1. State Persistence: Consider persisting the wallet state in localStorage to handle page refreshes
  2. SEO Impact: The dynamic URL updates might affect SEO. Consider implementing proper meta tags and Next.js static paths
  3. Integration: This component might benefit from integration with a wallet connection library (e.g., Web3Modal, RainbowKit)

Let's check if there are any wallet connection libraries already in use:

app/provider.tsx (2)

1-23: LGTM! Import statements are well-organized.

The imports are logically grouped and the addition of WalletProvider aligns with the PR's objective of handling wallet changes.


136-138: LGTM! Provider hierarchy is well-structured.

The placement of WalletProvider wrapping QuestsContextProvider ensures wallet state is available to quest-related components, which aligns with the PR's objective of handling wallet changes.

components/UI/profileCard/profileCard.tsx (3)

27-27: LGTM: Clean wallet integration

The integration of the WalletProvider context through the useWallet hook is well-implemented and follows React best practices.

Also applies to: 51-52


136-144: LGTM: Improved accessibility and consistent styling

The UI changes improve accessibility with proper alt texts and maintain consistent styling conventions.

Also applies to: 160-160, 169-179, 190-203, 213-228


97-100: Verify wallet address dependency

The effect now depends on newAddress but ensure this doesn't cause unnecessary refetches when the address hasn't actually changed.

✅ Verification successful

After analyzing the code, I can now generate the final response:

Effect dependency on newAddress is correctly implemented

The newAddress dependency in the effect is properly used as it:

  • Only triggers fetchTotalBalance when there's a new address value
  • Is used alongside formattedAddress which is required for the balance calculation
  • Serves as a proper guard to prevent unnecessary API calls
  • Is consistently used in the component for display purposes as well

The implementation ensures the balance is only fetched when there's an actual address change, avoiding unnecessary refetches.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for other uses of newAddress to ensure consistent behavior
rg "newAddress" --type ts --type tsx

Length of output: 64


Script:

#!/bin/bash
# Search for newAddress usage with proper file type patterns
rg "newAddress" -t typescript -t tsx

# Also check the specific file content to understand the context
cat "components/UI/profileCard/profileCard.tsx"

Length of output: 8739

components/UI/navbar.tsx (3)

34-34: LGTM: Wallet context integration looks good!

The addition of the useWallet hook and its destructured methods aligns well with the PR objective of managing wallet address changes.

Also applies to: 52-52


186-189: LGTM: UI formatting changes are consistent.

The formatting changes to div elements, Link components, and icon properties maintain consistent styling without affecting functionality.

Also applies to: 196-199, 233-235, 239-240


34-34: Verify wallet address updates across different scenarios.

While the implementation looks correct, please ensure testing covers:

  1. Wallet disconnection/reconnection
  2. Network changes
  3. Multiple wallet switches in succession

Also applies to: 52-52, 156-157

✅ Verification successful

Wallet address updates implementation is properly structured and contained

The implementation is well-organized with proper state management through the WalletContext:

  • Address updates are centralized in the WalletProvider context
  • Only two components consume the wallet context: navbar (for updates) and profileCard (for display)
  • State updates are properly handled with both address and URL params being updated together
  • The implementation includes proper mounting checks and router integration

The current implementation already covers the scenarios mentioned in the review:

  1. Wallet disconnection/reconnection (handled via setNewAddress null/address states)
  2. Network changes (managed through the context)
  3. Multiple wallet switches (handled via state updates in navbar)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for other components that might be affected by wallet address changes
echo "Searching for components using address-dependent routes..."
rg -l "/${address}" --type tsx

echo "Checking for other wallet address dependencies..."
ast-grep --pattern 'useWallet()' --lang tsx

Length of output: 499


Script:

#!/bin/bash
# Let's check the actual usage patterns and dependencies more thoroughly

# Check how wallet address is used in components
echo "Checking wallet address usage patterns..."
rg -A 5 "newAddress" --type ts --type tsx

# Check for route definitions that might depend on wallet addresses
echo "\nChecking route definitions..."
rg -A 3 "path.*:.*address" --type ts --type tsx

# Look for wallet-related state updates
echo "\nChecking wallet state updates..."
rg -A 3 "setNewAddress|setNewURLParams" --type ts --type tsx

# Check the wallet context implementation
echo "\nChecking WalletProvider implementation..."
cat "@context/WalletProvider.tsx" 2>/dev/null || echo "WalletProvider.tsx not found in expected location"

Length of output: 723


Script:

#!/bin/bash
# Let's try with correct file extensions and without type specifications

# Check how wallet address is used in components
echo "Checking wallet address usage patterns..."
rg -A 5 "newAddress"

# Check for route definitions that might depend on wallet addresses
echo "\nChecking route definitions..."
rg -A 3 "path.*:.*address"

# Look for wallet-related state updates
echo "\nChecking wallet state updates..."
rg -A 3 "setNewAddress|setNewURLParams"

# Find and check the wallet provider implementation
echo "\nLocating WalletProvider file..."
fd -e tsx -e ts "WalletProvider"

Length of output: 4767

Comment on lines 28 to 38
useEffect(() => {
if (isMounted && newURLParams) {
const updateUrl = (newURLParams: string) => {
// Replace everything after the base URL with the new address
const newUrl = `/${newURLParams}`;
router.replace(newUrl);
};

updateUrl(newURLParams);
}
}, [isMounted, newURLParams, newAddress]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Optimize useEffect implementation and add error handling.

The URL update effect has several potential improvements:

  1. newAddress is in the dependency array but not used in the effect
  2. updateUrl function is recreated on every render
  3. No error handling for URL updates

Consider this improved implementation:

+ const updateUrl = React.useCallback((newURLParams: string) => {
+   try {
+     const newUrl = `/${newURLParams}`;
+     router.replace(newUrl);
+   } catch (error) {
+     console.error('Failed to update URL:', error);
+   }
+ }, [router]);

 useEffect(() => {
   if (isMounted && newURLParams) {
-    const updateUrl = (newURLParams: string) => {
-      const newUrl = `/${newURLParams}`;
-      router.replace(newUrl);
-    };
     updateUrl(newURLParams);
   }
- }, [isMounted, newURLParams, newAddress]);
+ }, [isMounted, newURLParams, updateUrl]);
📝 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
useEffect(() => {
if (isMounted && newURLParams) {
const updateUrl = (newURLParams: string) => {
// Replace everything after the base URL with the new address
const newUrl = `/${newURLParams}`;
router.replace(newUrl);
};
updateUrl(newURLParams);
}
}, [isMounted, newURLParams, newAddress]);
const updateUrl = React.useCallback((newURLParams: string) => {
try {
const newUrl = `/${newURLParams}`;
router.replace(newUrl);
} catch (error) {
console.error('Failed to update URL:', error);
}
}, [router]);
useEffect(() => {
if (isMounted && newURLParams) {
updateUrl(newURLParams);
}
}, [isMounted, newURLParams, updateUrl]);

components/UI/profileCard/profileCard.tsx Outdated Show resolved Hide resolved
Comment on lines 156 to 157
setNewAddress(domainOrAddressMinified);
if (address) setNewURLParams(address);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider separating state updates from text generation.

The topButtonText function now has side effects (state updates) which doesn't align with its naming convention. Consider:

  1. Renaming the function to better reflect its behavior, or
  2. Moving the state updates to a more appropriate location (e.g., useEffect or click handler)

Here's a suggested refactor:

- function topButtonText(): string | undefined {
-   setNewAddress(domainOrAddressMinified);
-   if (address) setNewURLParams(address);
-   const textToReturn = isConnected ? domainOrAddressMinified : "connect";
-   return textToReturn;
- }

+ useEffect(() => {
+   if (domainOrAddressMinified) {
+     setNewAddress(domainOrAddressMinified);
+   }
+   if (address) {
+     setNewURLParams(address);
+   }
+ }, [domainOrAddressMinified, address]);
+
+ function topButtonText(): string {
+   return isConnected ? domainOrAddressMinified : "connect";
+ }
📝 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
setNewAddress(domainOrAddressMinified);
if (address) setNewURLParams(address);
useEffect(() => {
if (domainOrAddressMinified) {
setNewAddress(domainOrAddressMinified);
}
if (address) {
setNewURLParams(address);
}
}, [domainOrAddressMinified, address]);
function topButtonText(): string {
return isConnected ? domainOrAddressMinified : "connect";
}

@kfastov
Copy link
Contributor

kfastov commented Nov 10, 2024

@caxtonacollins Sorry, was busy on HH, will review today

Copy link

vercel bot commented Nov 10, 2024

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

Name Status Preview Comments Updated (UTC)
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 11, 2024 5:35am

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

You got the overall idea, I propose you something way easier using starknet-react features

app/provider.tsx Outdated
@@ -130,7 +133,9 @@ export function Providers({ children }: { children: React.ReactNode }) {
<NotificationProvider>
<ThemeProvider theme={theme}>
<PostHogProvider client={posthog}>
<QuestsContextProvider>{children}</QuestsContextProvider>
<WalletProvider>
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think you need a walletProvider here to do the job, it adds unnecessary complexity.

What I would do instead is to use starknet react useAccount() hook to change URL based on the address you can get from it, you can do that directly on the [addressOrDomain]/page.tsx file.

Here is an example of what i would look like.

export default function Page({ params }: AddressOrDomainProps) {
  // ... existing state declarations ...
  const [connectedAddress, setConnectedAddress] = useState<string | undefined>(); // address set as connected
  const { address } = useAccount(); // current address connected
  
  // Add this useEffect to handle address changes and URL updates
  useEffect(() => {    
    // Skip if the address hasn't changed or isn't defined
    if (!address || address === connectedAddress) return;
    
    // Update connected address state
    setConnectedAddress(address);
    
    // If we're not on the current user's profile, don't redirect
    if (address && addressOrDomain !== address && addressOrDomain !== undefined) {
      return;
    }
    
    // Redirect to the new address profile
    if (address) {
      router.push(`/${address}`);
    }
  }, [address, addressOrDomain, connectedAddress, router]);

  // ... rest of the component ...
}

I might have done some mistake here so I'll let you test and adapt but that solution would be way easier than adding a provider (starknet-react is your provider here)

@fricoben fricoben added the ❌ Change request Change requested from reviewer label Nov 10, 2024
Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (4)
app/[addressOrDomain]/page.tsx (4)

100-110: Add error handling for router navigation.

The URL update logic should include error handling for the router.replace call to gracefully handle navigation failures.

 const updateUrl = (address: string) => {
-  const newUrl = `/${address}`;
-  router.replace(newUrl);
+  const newUrl = `/${address}`;
+  router.replace(newUrl).catch((error) => {
+    console.error('Failed to update URL:', error);
+    showNotification('Failed to update profile URL', 'error');
+  });
 };

Line range hint 221-373: Optimize promise handling and improve error messages.

The portfolio calculation logic could be optimized in several ways:

  1. Use Promise.allSettled instead of Promise.all to handle partial failures
  2. Add more specific error messages for better debugging
 const results = (
-  await Promise.all([...balancePromises, ...userTokenPromises])
+  await Promise.allSettled([...balancePromises, ...userTokenPromises])
 ).filter(Boolean);

-results.forEach((result) => {
+results.forEach((promiseResult) => {
+  if (promiseResult.status === 'rejected') {
+    console.error('Failed to calculate token value:', promiseResult.reason);
+    return;
+  }
+  const result = promiseResult.value;
   if (!result) return;
   // ... rest of the code
 });

566-604: Enhance data fetching reliability.

The portfolio data fetching could be more resilient by:

  1. Adding retry logic for transient failures
  2. Implementing request timeout
 const fetchPortfolioData = useCallback(
   async (addr: string, abortController: AbortController) => {
     setLoadingProtocols(true);
+    const timeout = setTimeout(() => abortController.abort(), 30000); // 30s timeout
     try {
       // ... existing code
     } catch (error) {
       console.log("Error while fetching address portfolio", error);
-      if (error instanceof Error && error.name === "AbortError") {
+      if (error instanceof Error && (error.name === "AbortError" || error.name === "TimeoutError")) {
         // Do not show notification for AbortError
         return;
       }
       showNotification("Error while fetching address portfolio", "error");
     } finally {
+      clearTimeout(timeout);
       setLoadingProtocols(false);
     }
   },
   [fetchPortfolioProtocols, fetchPortfolioAssets]
 );

739-740: Improve consistency and maintainability of UI strings.

Consider moving hardcoded strings to constants and maintaining consistent quote usage throughout the component.

+const UI_STRINGS = {
+  ERROR_MESSAGE: 'Profile or Page not found',
+  ERROR_BUTTON: 'Go back to quests',
+  ARIA_LABEL: 'quests and collectons tabs',
+};

-errorMessage='Profile or Page not found'
-buttonText='Go back to quests'
+errorMessage={UI_STRINGS.ERROR_MESSAGE}
+buttonText={UI_STRINGS.ERROR_BUTTON}

-className='pb-6'
-aria-label='quests and collectons tabs'
+className="pb-6"
+aria-label={UI_STRINGS.ARIA_LABEL}

Also applies to: 804-808

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 764ce9d and 1b6f0e0.

📒 Files selected for processing (4)
  • app/[addressOrDomain]/page.tsx (16 hunks)
  • app/provider.tsx (4 hunks)
  • components/UI/navbar.tsx (7 hunks)
  • components/UI/profileCard/profileCard.tsx (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • app/provider.tsx
  • components/UI/navbar.tsx
  • components/UI/profileCard/profileCard.tsx

@caxtonacollins
Copy link
Author

@fricoben please review

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

Need to fix conflcits and we're good

@fricoben
Copy link
Contributor

@caxtonacollins waiting for your conflicts fix

@caxtonacollins
Copy link
Author

@fricoben please review, conflicts resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
❌ Change request Change requested from reviewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants