External Call Template#1077
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughAdds an EVM init template variant FeatureExternalCalls, wires it into CLI prompts and template resolution, passes an extra viem dependency into template rendering for that flow, and introduces a TypeScript template demonstrating external RPC calls via an Effect (handlers, schema, config, tests, docs). Changes
Sequence Diagram(s)sequenceDiagram
participant Handler as Handler\n(UniswapV3Factory.PoolCreated)
participant EffectAPI as Effect API\n(createEffect / context.effect)
participant ViemClient as Viem Client(s)\n(per-chain)
participant RPC as RPC Provider
participant DB as Persistence
Handler->>EffectAPI: context.effect("fetchTokenDetails",{token, chainId})
EffectAPI->>ViemClient: select client by chainId -> readContract(decimals)
ViemClient->>RPC: JSON-RPC request
RPC-->>ViemClient: decimals (or error)
ViemClient-->>EffectAPI: {decimal} (or fallback 18)
EffectAPI-->>Handler: effect result {decimal}
Handler->>DB: assemble entity and persist UniswapV3Factory_PoolCreated
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
packages/cli/templates/static/external_calls_template/shared/.gitignore (1)
1-18: Deduplicate repeated ignore patterns.
*.objand*.annotare listed twice. Removing duplicates keeps the template cleaner without changing behavior.Proposed cleanup
*.exe *.obj *.out *.compile *.native *.byte *.cmo *.annot *.cmi *.cmx *.cmt *.cmti *.cma *.a *.cmxa -*.obj *~ -*.annot *.cmj *.bak🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/templates/static/external_calls_template/shared/.gitignore` around lines 1 - 18, The .gitignore template contains duplicate ignore patterns (*.obj and *.annot); remove the repeated entries so each glob appears only once (keep a single occurrence of *.obj and a single occurrence of *.annot), preserving the existing order of the other entries and leaving all other patterns unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cli/templates/static/external_calls_template/shared/.env.example`:
- Line 4: The .env.example currently ends with the ENVIO_ETHEREUM_MAINNET_RPC
entry without a trailing newline which triggers dotenv-linter; open the
.env.example containing the
ENVIO_ETHEREUM_MAINNET_RPC=<YOUR-ETHEREUM-MAINNET-RPC-URL> line and add a single
blank newline at EOF so the file ends with a trailing newline.
In
`@packages/cli/templates/static/external_calls_template/typescript/src/handlers/UniswapV3Factory.ts`:
- Around line 7-16: The module currently uses non-null assertions on
process.env.ENVIO_ETHEREUM_MAINNET_RPC and process.env.ENVIO_ARBITRUM_RPC when
building CHAIN_CLIENTS at module load (via createPublicClient + http), which can
instantiate clients with undefined URLs; change this to lazily or conditionally
create clients instead: either convert CHAIN_CLIENTS into a factory function
(e.g., getChainClients()) or make its values optional (Record<number,
ReturnType<typeof createPublicClient> | undefined>) and only call
http/createPublicClient when the corresponding env var exists, using optional
chaining or explicit checks for process.env.ENVIO_ETHEREUM_MAINNET_RPC and
process.env.ENVIO_ARBITRUM_RPC before calling http/createPublicClient to avoid
non-null assertions and preserve the runtime graceful fallback in the effect
handler.
---
Nitpick comments:
In `@packages/cli/templates/static/external_calls_template/shared/.gitignore`:
- Around line 1-18: The .gitignore template contains duplicate ignore patterns
(*.obj and *.annot); remove the repeated entries so each glob appears only once
(keep a single occurrence of *.obj and a single occurrence of *.annot),
preserving the existing order of the other entries and leaving all other
patterns unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 7bd6f49d-65a3-482b-93a8-15ab9f712270
📒 Files selected for processing (14)
packages/cli/src/cli_args/init_config.rspackages/cli/src/cli_args/interactive_init/mod.rspackages/cli/src/executor/init.rspackages/cli/src/hbs_templating/init_templates.rspackages/cli/src/template_dirs.rspackages/cli/templates/dynamic/init_templates/shared/package.json.hbspackages/cli/templates/static/external_calls_template/shared/.env.examplepackages/cli/templates/static/external_calls_template/shared/.gitignorepackages/cli/templates/static/external_calls_template/shared/README.mdpackages/cli/templates/static/external_calls_template/shared/schema.graphqlpackages/cli/templates/static/external_calls_template/typescript/config.yamlpackages/cli/templates/static/external_calls_template/typescript/src/handlers/UniswapV3Factory.tspackages/cli/templates/static/external_calls_template/typescript/src/indexer.test.tspackages/cli/templates/static/external_calls_template/typescript/tsconfig.json
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/cli/templates/static/external_calls_template/typescript/src/indexer.test.ts (1)
102-102: Strengthen the ID test assertion to avoid false positives.
toBeDefined()is fairly loose for an identity-format test. Consider asserting the fetched entityidequals1_${pool}(or matching the full expected object) so the test fails on subtle retrieval behavior changes.Proposed test-tightening diff
- expect(await indexer.UniswapV3Factory_PoolCreated.get(`1_${pool}`)).toBeDefined(); + const entityId = `1_${pool}`; + await expect(indexer.UniswapV3Factory_PoolCreated.get(entityId)).resolves.toMatchObject({ + id: entityId, + pool, + token0, + token1, + });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/cli/templates/static/external_calls_template/typescript/src/indexer.test.ts` at line 102, The test currently uses a loose assertion expect(await indexer.UniswapV3Factory_PoolCreated.get(`1_${pool}`)).toBeDefined(); — change it to assert the returned entity's id exactly equals the expected id (e.g., fetch via indexer.UniswapV3Factory_PoolCreated.get(`1_${pool}`) and expect(entity.id).toBe(`1_${pool}`)) or assert full object equality against the expected object to prevent false positives; target the indexer.UniswapV3Factory_PoolCreated.get call and the pool variable when making this change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@packages/cli/templates/static/external_calls_template/typescript/src/indexer.test.ts`:
- Line 102: The test currently uses a loose assertion expect(await
indexer.UniswapV3Factory_PoolCreated.get(`1_${pool}`)).toBeDefined(); — change
it to assert the returned entity's id exactly equals the expected id (e.g.,
fetch via indexer.UniswapV3Factory_PoolCreated.get(`1_${pool}`) and
expect(entity.id).toBe(`1_${pool}`)) or assert full object equality against the
expected object to prevent false positives; target the
indexer.UniswapV3Factory_PoolCreated.get call and the pool variable when making
this change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 1bf6e39e-b10c-409e-a92f-c89fe4019c8f
📒 Files selected for processing (1)
packages/cli/templates/static/external_calls_template/typescript/src/indexer.test.ts
DZakh
left a comment
There was a problem hiding this comment.
Whoa, really nice. I didn't expect to see tests using Simulate, which has not even released. Really nice job!
A template for external calls was added to the CLI. Old PR: #826. All the suggestions from that PR are included in this PR.
Summary by CodeRabbit
New Features
Documentation
Tests