Skip to content

Conversation

kings177
Copy link
Contributor

@kings177 kings177 commented Aug 22, 2025

Summary by CodeRabbit

  • Chores
    • Analytics domains now adapt to mainnet or testnet across Allocator, Governance, Page, Portal, and Wallet, including rollup subdomains.
    • Replaced hard-coded analytics domain settings with environment-based configuration in app layouts.
    • No user-facing UI changes; layout structure remains the same.
    • No changes to public interfaces.

@Copilot Copilot AI review requested due to automatic review settings August 22, 2025 22:03
@kings177 kings177 requested a review from a team as a code owner August 22, 2025 22:03
Copy link
Contributor

coderabbitai bot commented Aug 22, 2025

Walkthrough

Adds environment-aware domain selection for Plausible analytics across five app layouts. Each layout imports env, derives isMainnet from NEXT_PUBLIC_TORUS_CHAIN_ENV, computes a comma-separated domains string per environment, and replaces hard-coded PlausibleProvider domain props with the computed domains. No exported/public signatures changed.

Changes

Cohort / File(s) Summary
Env-driven Plausible domains in app layouts
apps/torus-allocator/src/app/layout.tsx, apps/torus-governance/src/app/layout.tsx, apps/torus-page/src/app/layout.tsx, apps/torus-portal/src/app/(pages)/layout.tsx, apps/torus-wallet/src/app/layout.tsx
Import env, derive isMainnet from NEXT_PUBLIC_TORUS_CHAIN_ENV, compute per-app domains (mainnet vs testnet), and pass domain={domains} to PlausibleProvider instead of hard-coded strings.

Sequence Diagram(s)

sequenceDiagram
  participant AppLayout
  participant Env as Env (NEXT_PUBLIC_TORUS_CHAIN_ENV)
  participant Plausible as PlausibleProvider

  AppLayout->>Env: read chain env
  Env-->>AppLayout: "mainnet" or other
  AppLayout->>AppLayout: compute domains string (per app, env-based)
  AppLayout->>Plausible: initialize with domain={domains}
  Note over Plausible: Domains include app hostname and rollup hostname\ncomma-separated per environment
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement

Suggested reviewers

  • EdSDR

Poem

Hop hop! I tweak the winds of bytes,
Switching tracks for day and nights—
Mainnet carrots, testnet clover,
Analytics sniffed all over.
With whiskered wisdom, I align,
Domains in rows, so neat, so fine. 🥕✨

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.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch plausible-dynamic-domains

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 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.

@kings177 kings177 requested a review from EdSDR August 22, 2025 22:04
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes Plausible analytics tracking for testnet domains by making the domain configuration dynamic based on the chain environment. Instead of hardcoding mainnet domains, the applications now conditionally select appropriate domains for both mainnet and testnet environments.

  • Dynamic domain selection based on NEXT_PUBLIC_TORUS_CHAIN_ENV environment variable
  • Consistent pattern applied across all five Torus applications
  • Addition of env import where needed for environment variable access

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
apps/torus-wallet/src/app/layout.tsx Dynamic domain selection for wallet app analytics
apps/torus-portal/src/app/layout.tsx Dynamic domain selection for portal app analytics
apps/torus-page/src/app/layout.tsx Dynamic domain selection for page app analytics with env import
apps/torus-governance/src/app/layout.tsx Dynamic domain selection for governance app analytics
apps/torus-allocator/src/app/layout.tsx Dynamic domain selection for allocator app analytics with env import

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "wallet.torus.network,rollup.torus.network"
: "wallet.testnet.torus.network,testnet.rollup.torus.network";
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.

Suggested change
: "wallet.testnet.torus.network,testnet.rollup.torus.network";
const domains = getDomainsForEnv("wallet");

Copilot uses AI. Check for mistakes.

const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "torus.network,rollup.torus.network"
: "testnet.torus.network,testnet.rollup.torus.network";
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.

Copilot uses AI. Check for mistakes.

const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "dao.torus.network,rollup.torus.network"
: "dao.testnet.torus.network,testnet.rollup.torus.network";
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.

Suggested change
: "dao.testnet.torus.network,testnet.rollup.torus.network";
const domains = getDomainsForSubdomains(["dao", "rollup"]);

Copilot uses AI. Check for mistakes.

const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "allocator.torus.network,rollup.torus.network"
: "allocator.testnet.torus.network,testnet.rollup.torus.network";
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

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

The domain configuration logic is duplicated across all five layout files with only the subdomain prefix changing. Consider extracting this logic into a shared utility function that takes the subdomain prefix as a parameter to reduce code duplication.

Suggested change
: "allocator.testnet.torus.network,testnet.rollup.torus.network";
const domains = getDomainsForSubdomain("allocator");

Copilot uses AI. Check for mistakes.

Copy link

🚀 torus-cache Preview deployment will be available at: https://pr-342.torus-cache.torus.network

Copy link

🚀 torus-page Preview deployment will be available at: https://pr-342.torus-page.torus.network

Copy link

🚀 torus-allocator Preview deployment will be available at: https://pr-342.torus-allocator.torus.network

Copy link

🚀 torus-wallet Preview deployment will be available at: https://pr-342.torus-wallet.torus.network

Copy link

🚀 torus-portal Preview deployment will be available at: https://pr-342.torus-portal.torus.network

Copy link

🚀 torus-governance Preview deployment will be available at: https://pr-342.torus-governance.torus.network

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

🧹 Nitpick comments (5)
apps/torus-governance/src/app/layout.tsx (1)

39-43: Avoid duplication: centralize Plausible domains mapping across apps

Logic is correct. To prevent drift across five apps, consider a shared helper that derives the two-host list from chain env + app key. This keeps the mapping in one place.

Apply this minimal change here (using a shared helper):

-  const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
-  const domains = isMainnet
-    ? "dao.torus.network,rollup.torus.network"
-    : "dao.testnet.torus.network,testnet.rollup.torus.network";
+  const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "dao");

Helper (add once in a shared place; then import where needed):

// e.g. packages/shared-analytics/src/plausible.ts
export function getPlausibleDomains(
  chainEnv: string,
  app: "wallet" | "portal" | "allocator" | "dao" | "root",
): string {
  const isMainnet = chainEnv === "mainnet";
  const rollup = isMainnet ? "rollup.torus.network" : "testnet.rollup.torus.network";
  const base =
    app === "root"
      ? isMainnet
        ? "torus.network"
        : "testnet.torus.network"
      : isMainnet
        ? `${app}.torus.network`
        : `${app}.testnet.torus.network`;
  return `${base},${rollup}`;
}
apps/torus-portal/src/app/(pages)/layout.tsx (1)

38-42: Deduplicate with a helper for maintainability

Same suggestion as other apps: compute domains via a shared utility to avoid per-file string literals.

-  const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
-  const domains = isMainnet
-    ? "portal.torus.network,rollup.torus.network"
-    : "portal.testnet.torus.network,testnet.rollup.torus.network";
+  const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "portal");
apps/torus-page/src/app/layout.tsx (1)

35-39: Unify domain selection with a shared helper (apex-domain case)

This app uses the apex domain (torus.network). A shared helper can handle the “root” case to keep logic consistent across apps.

-  const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
-  const domains = isMainnet
-    ? "torus.network,rollup.torus.network"
-    : "testnet.torus.network,testnet.rollup.torus.network";
+  const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "root");

See proposed helper in the governance comment.

apps/torus-wallet/src/app/layout.tsx (1)

52-56: Consolidate domain mapping via shared helper

Keeps five files in sync and simplifies future changes.

-  const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
-  const domains = isMainnet
-    ? "wallet.torus.network,rollup.torus.network"
-    : "wallet.testnet.torus.network,testnet.rollup.torus.network";
+  const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "wallet");
apps/torus-allocator/src/app/layout.tsx (1)

32-36: Refactor suggestion: shared domain helper

Same reasoning as other apps; centralize to one utility.

-  const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
-  const domains = isMainnet
-    ? "allocator.torus.network,rollup.torus.network"
-    : "allocator.testnet.torus.network,testnet.rollup.torus.network";
+  const domains = getPlausibleDomains(env("NEXT_PUBLIC_TORUS_CHAIN_ENV"), "allocator");
📜 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 11131c2 and b7b7932.

📒 Files selected for processing (5)
  • apps/torus-allocator/src/app/layout.tsx (2 hunks)
  • apps/torus-governance/src/app/layout.tsx (1 hunks)
  • apps/torus-page/src/app/layout.tsx (2 hunks)
  • apps/torus-portal/src/app/(pages)/layout.tsx (1 hunks)
  • apps/torus-wallet/src/app/layout.tsx (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Follow the project's DOCUMENTATION_STYLE.md for all code documentation using JSDoc.

Files:

  • apps/torus-wallet/src/app/layout.tsx
  • apps/torus-governance/src/app/layout.tsx
  • apps/torus-allocator/src/app/layout.tsx
  • apps/torus-portal/src/app/(pages)/layout.tsx
  • apps/torus-page/src/app/layout.tsx
🧬 Code graph analysis (2)
apps/torus-governance/src/app/layout.tsx (2)
apps/torus-worker/src/index.ts (1)
  • env (19-23)
apps/torus-cache/src/env.ts (1)
  • env (5-18)
apps/torus-page/src/app/layout.tsx (1)
apps/torus-worker/src/workers/weight-aggregator.ts (1)
  • env (31-36)
⏰ 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). (4)
  • GitHub Check: torus-page-pr-activate / docker-build
  • GitHub Check: typecheck
  • GitHub Check: lint
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
apps/torus-governance/src/app/layout.tsx (2)

46-46: Plausible multi-domain config — LGTM

Passing a comma-separated data-domain is supported by Plausible. The change is correct.


39-43: Resolved: NEXT_PUBLIC_TORUS_CHAIN_ENV is declared in this app’s schema

I’ve verified that NEXT_PUBLIC_TORUS_CHAIN_ENV is indeed defined in apps/torus-governance/src/env.ts (line 44), so your build utility will recognize it and no runtime failures will occur.

apps/torus-portal/src/app/(pages)/layout.tsx (1)

45-45: LGTM on switching to dynamic domains

Using domain={domains} aligns with Plausible expectations.

apps/torus-page/src/app/layout.tsx (2)

12-12: Importing env here is correct

Env is used below to derive the domain list; the import looks good.


42-42: Dynamic Plausible domain — looks good

domain={domains} is the right prop wiring.

apps/torus-wallet/src/app/layout.tsx (2)

59-59: LGTM: provider now uses environment-aware domains

Correctly passes the computed multi-domain string.


52-56: Verified env schema and dynamic Plausible domains

All apps declare NEXT_PUBLIC_TORUS_CHAIN_ENV in their env.ts, and every PlausibleProvider uses the dynamic {domains} prop—no hardcoded domain literals remain.

• Env variable defined in:
– apps/torus-wallet/src/env.ts
– apps/torus-portal/src/env.ts
– apps/torus-governance/src/env.ts
– apps/torus-bridge/src/env.ts
– apps/torus-page/src/env.ts
– apps/torus-allocator/src/env.ts

• PlausibleProvider domain prop is always {domains} (across all five layout.tsx files); no static "domain=\"…\"" usages found.

apps/torus-allocator/src/app/layout.tsx (2)

10-10: Importing env alongside EnvScript — good catch

This is needed for the new domain logic.


39-39: LGTM on dynamic domain usage

domain={domains} is wired correctly.

Comment on lines +32 to +35
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "allocator.torus.network,rollup.torus.network"
: "allocator.testnet.torus.network,testnet.rollup.torus.network";
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be parameterized: we should be able to use other potential environments like "dev".

Suggested change
const isMainnet = env("NEXT_PUBLIC_TORUS_CHAIN_ENV") === "mainnet";
const domains = isMainnet
? "allocator.torus.network,rollup.torus.network"
: "allocator.testnet.torus.network,testnet.rollup.torus.network";
const chainEnv = env("NEXT_PUBLIC_TORUS_CHAIN_ENV")
const isMainnet = chainEnv === "mainnet";
const domains = isMainnet
? "allocator.torus.network,rollup.torus.network"
: "allocator.${chainEnv}.torus.network,testnet.${chainEnv}.torus.network";

Actually, there's another problem, which is that we are still not differentiating between chain environments and web app environments. mainnet vs testnet != production vs staging. But we need to change more stuff to fix that.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, this shit is fully-fledged code repetition instance.

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