Skip to content

Conversation

@epsjunior
Copy link
Contributor

@epsjunior epsjunior commented Aug 29, 2025

What

  • Connect MetaMask inside setCurrentAccount to cover the “deleted network” edge case.
  • The connect method also creates the Genlayer network if missing, switches to it, and installs the Genlayer wallet when needed.
  • Update .env.example to document network-related configuration.

Why

  • Ensure MetaMask stays connected even if the user manually deletes the network and the UI connect button doesn’t reappear.
  • Clarify required env configuration for smoother setup.

Testing done

  • Manually removed the Genlayer network in MetaMask; selecting a MetaMask account auto-connected and switched network.
  • Switched MetaMask accounts and verified reconnection and network switching.
  • Verified local account flow unaffected.

Decisions made

  • Triggering connect in setCurrentAccount instead of relying solely on the UI button, because the button only shows when no MetaMask account was previously connected; connecting on selection covers the edge case after a user removes the network.
  • Known limitation: studionet and localnet currently share the same chainId, so genlayer-js cannot distinguish them when using a MetaMask account. This will be addressed separately when studionet and localnet have distinct chainIds.

Reviewing tips

  • Focus on the small change in setCurrentAccount and its inline comment rationale.
  • Ensure .env.example aligns with current env usage (e.g., network configuration).

User facing release notes

  • MetaMask accounts now automatically connect and switch to the Genlayer network on selection, even if the user previously removed the network, reducing friction and avoiding broken states.
  • Note: studionet and localnet currently share a chainId, which may affect MetaMask behavior. A future update will assign distinct chainIds.

Summary by CodeRabbit

  • New Features

    • Automatically connects to the configured network when selecting MetaMask, streamlining onboarding.
  • Bug Fixes

    • Fixed an issue where switching networks could hide the MetaMask connect option.
  • Documentation

    • Updated example environment configuration to include a VITE_NETWORK entry with default "localnet".

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 29, 2025

Walkthrough

Adds VITE_NETWORK to .env.example and updates the accounts store so that selecting MetaMask triggers a Genlayer client connect to the configured network before updating the selected account.

Changes

Cohort / File(s) Summary
Environment configuration
\.env.example
Added VITE_NETWORK='localnet' after VITE_MAX_ROTATIONS=3.
Accounts store update
frontend/src/stores/accounts.ts
When setCurrentAccount receives metamask, calls useGenlayer() and invokes genlayer.client?.value?.connect(import.meta.env.VITE_NETWORK) prior to setting selectedAccount. Added useGenlayer import; preserved public signatures.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as UI
    participant Store as AccountsStore
    participant Hook as useGenlayer()
    participant Client as GenlayerClient
    participant Wallet as MetaMask/Provider

    User->>UI: Select MetaMask account
    UI->>Store: setCurrentAccount('metamask')
    Store->>Hook: useGenlayer()
    Store->>Client: connect(import.meta.env.VITE_NETWORK)
    Note right of Client: Automatic connect on MetaMask selection
    Client->>Wallet: Establish provider connection
    Wallet-->>Client: Connected / Failed
    Store->>Store: Update selectedAccount
    Store-->>UI: State updated
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • cristiam86

Poem

I twitched my whiskers at a net so bright,
Set VITE_NETWORK and hopped into the light.
MetaMask chosen, Genlayer makes the link,
A gentle connect—no more need to think.
Burrow, build, and then commit—what a sight! 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5c5e161 and 7becdc0.

📒 Files selected for processing (1)
  • frontend/src/stores/accounts.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/stores/accounts.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: backend-unit-tests
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dxp-588-use-genlayerjs-connect-method-in-the-studio

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

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: 1

🧹 Nitpick comments (3)
.env.example (1)

105-105: Fix dotenv spacing to satisfy linter

dotenv-linter flags spaces around '='. Align with the rest of the tooling by removing spaces.

-VITE_NETWORK = 'localnet'
+VITE_NETWORK='localnet'

Please confirm accepted values for VITE_NETWORK (e.g., 'localnet', 'studionet') and consider adding a one-line comment right above this line documenting them for users.

frontend/src/stores/accounts.ts (2)

165-171: Harden connect call: default network + user-facing error handling

If VITE_NETWORK is missing or connect throws (user rejects, pending request, unknown chain), the current code silently fails. Add a safe default and notify on error.

-    if (account?.type === 'metamask') {
-      const genlayer = useGenlayer();
-      genlayer.client?.value?.connect(import.meta.env.VITE_NETWORK);
-    }
+    if (account?.type === 'metamask') {
+      const genlayer = useGenlayer();
+      const targetNetwork =
+        (import.meta.env.VITE_NETWORK as string) || 'localnet';
+      // Fire-and-forget but surface failures to the user
+      genlayer.client?.value
+        ?.connect(targetNetwork)
+        .catch((err: unknown) =>
+          notify({
+            title: 'Failed to connect Genlayer network',
+            text:
+              (err as any)?.message ??
+              'Please try again or check your MetaMask network configuration.',
+            type: 'error',
+          }),
+        );
+    }

165-171: Potential chain/config mismatch between client and requested network

useGenlayer initializes the client with chain: localnet regardless of VITE_NETWORK. If VITE_NETWORK='studionet', you’ll connect MetaMask to studionet but keep a client configured for localnet (and possibly a local RPC URL). This can cause confusing behavior.

Consider making useGenlayer select chain and endpoint from VITE_NETWORK (and corresponding URLs), e.g.:

// In frontend/src/hooks/useGenlayer.ts (illustrative)
const NETWORK = (import.meta.env.VITE_NETWORK as 'localnet' | 'studionet') || 'localnet';
const CHAIN = NETWORK === 'studionet' ? studionet : localnet;
const ENDPOINT =
  NETWORK === 'studionet'
    ? import.meta.env.VITE_JSON_RPC_SERVER_URL_STUDIONET
    : import.meta.env.VITE_JSON_RPC_SERVER_URL;

client.value = createClient({
  chain: CHAIN,
  endpoint: ENDPOINT,
  account: clientAccount,
});

Also document the extra endpoint variable(s) in .env.example if you adopt this.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 5eb1622 and 5c5e161.

📒 Files selected for processing (2)
  • .env.example (1 hunks)
  • frontend/src/stores/accounts.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/src/stores/accounts.ts (1)
frontend/src/hooks/useGenlayer.ts (1)
  • useGenlayer (12-41)
🪛 GitHub Actions: pre-commit
frontend/src/stores/accounts.ts

[error] 1-1: Prettier formatting failed for file 'frontend/src/stores/accounts.ts'. Run 'prettier --write' to fix code style issues.

🪛 dotenv-linter (3.3.0)
.env.example

[warning] 105-105: [SpaceCharacter] The line has spaces around equal sign

(SpaceCharacter)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Load Tests / load-test
  • GitHub Check: test
  • GitHub Check: backend-unit-tests

@sonarqubecloud
Copy link

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.

2 participants