Skip to content

feat: add react hook to use predeployed accounts #419

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

Merged
merged 1 commit into from
Mar 14, 2025

Conversation

MartianGreed
Copy link
Collaborator

@MartianGreed MartianGreed commented Mar 14, 2025

Closes #

Introduced changes

Checklist

  • Linked relevant issue
  • Updated relevant documentation
  • Added relevant tests
  • Add a dedicated CI job for new examples
  • Performed self-review of the code

Summary by CodeRabbit

  • New Features

    • Added a React hook for retrieving predeployed accounts, enhancing how account data is accessed.
    • Improved React integration with updated exports for better compatibility.
  • Refactor

    • Streamlined several components to replace manual state handling with the new hook, simplifying account management.
  • Chore

    • Optimized dependency management and build configurations, including adjustments to development dependency categorization and ignore settings.

Copy link

coderabbitai bot commented Mar 14, 2025

Walkthrough

This pull request introduces a new React hook, usePredeployedAccounts, within the @dojoengine/predeployed-connector package. It refactors multiple StarknetProvider components in various examples to remove manual state management in favor of the hook. Additionally, the changes update several package.json files to re-categorize the vite-plugin-top-level-await dependency by moving it from dependencies to devDependencies, add a new ignore pattern in .gitignore, and amend build/export configurations, including a new entry point in the tsup configuration.

Changes

File(s) Change Summary
.changeset/clean-tables-turn.md, packages/predeployed-connector/package.json, packages/predeployed-connector/src/react/index.ts, packages/predeployed-connector/tsup.config.ts Added a new patch entry; introduced the usePredeployedAccounts hook and updated exports, devDependencies, peerDependencies, and build entries for React integration.
.gitignore Added an ignore rule for files matching **/**/vite.config.ts.timestamp-*.
examples/.../starknet-provider.tsx (multiple files) Refactored StarknetProvider components to utilize the usePredeployedAccounts hook, eliminating manual state and promise handling.
examples/.../package.json (multiple files) Moved vite-plugin-top-level-await from dependencies to devDependencies across several example projects.

Sequence Diagram(s)

sequenceDiagram
    participant Component as StarknetProvider
    participant Hook as usePredeployedAccounts
    participant Fetcher as predeployedAccounts
    participant Config as StarknetConfig

    Component->>Hook: Call usePredeployedAccounts(options)
    Hook->>Fetcher: Request predeployed accounts with options
    Fetcher-->>Hook: Return connectors data (with retry logic)
    Hook-->>Component: Provide connectors array
    Component->>Config: Pass connectors to StarknetConfig
Loading

Possibly related PRs

Poem

I'm a rabbit coding through the night,
With hooks that make my code so light.
No more tangled states in sight,
Predeployed accounts now fetched just right.
Hop on, let configs dance in delight—
Celebrating changes with a bunny byte!
🐇🌟


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

Copy link

@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 (8)
examples/example-vite-react-sdk/package.json (1)

48-49: Version Consistency Check for “vite-plugin-top-level-await”
In this file, "vite-plugin-top-level-await" is added to devDependencies with version "^1.5.0", which differs from the "^1.4.4" used in the other examples. If this version bump is intentional (perhaps due to new features or improved compatibility in the React SDK), please ensure that it is documented and that all related tooling supports it. Otherwise, consider aligning the version across examples for consistency.

packages/predeployed-connector/src/react/index.ts (3)

23-28: Add retries to the dependency array to prevent stale value issues.

The useEffect hook uses the retries variable inside its callback function, but retries is not included in the dependency array. This could lead to stale values being used and potentially cause unexpected behavior.

- }, [connectors, options]);
+ }, [connectors, options, retries]);

However, adding retries to the dependency array could lead to an infinite loop, since you're incrementing it inside the effect. Consider refactoring to use the functional update form of setRetries:

- setRetries(retries + 1);
+ setRetries(prev => prev + 1);

This way, you wouldn't need to include retries in the dependency array at all:

- }, [connectors, options]);
+ }, [connectors, options]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)


23-28: Consider enhancing error handling for failed account fetching.

The current implementation only retries up to 5 times without providing feedback if all attempts fail. Consider adding explicit error handling to inform users when account fetching fails completely.

- predeployedAccounts(options).then(setConnectors);
+ predeployedAccounts(options)
+   .then(setConnectors)
+   .catch(error => {
+     console.error("Failed to fetch predeployed accounts:", error);
+     // Optionally add a state variable to track and expose the error
+   });
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)


23-28: Optimize dependency handling for the options object.

Including the options object in the dependency array might cause unnecessary effect runs if the object is recreated on each render, even if its contents haven't changed.

Consider either:

  1. Memoizing the options object using useMemo
  2. Extracting primitive values from options and using those in the dependency array
  3. Using the useDeepCompareEffect from a library like use-deep-compare-effect
- useEffect(() => {
+ // Example using primitive values
+ const { rpc, id, name } = options;
+ useEffect(() => {
    if (connectors.length === 0 && retries < 5) {
        setRetries(prev => prev + 1);
        predeployedAccounts(options).then(setConnectors);
    }
- }, [connectors, options]);
+ }, [connectors, rpc, id, name]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)

examples/example-vite-kitchen-sink/src/components/starknet-provider.tsx (2)

9-16: Ensure consistent RPC URL sources.

The component uses two different sources for RPC URLs:

  • dojoConfig.rpcUrl for the predeployed accounts hook
  • getRpcUrl() for the JSON RPC provider

This inconsistency could lead to problems if these sources return different values.

Consider using the same source for both:

const { connectors } = usePredeployedAccounts({
    rpc: dojoConfig.rpcUrl as string,
    id: "katana",
    name: "Katana",
});
const provider = jsonRpcProvider({
-    rpc: () => ({ nodeUrl: getRpcUrl() }),
+    rpc: () => ({ nodeUrl: dojoConfig.rpcUrl as string }),
});

Or alternatively:

+ const rpcUrl = getRpcUrl();
const { connectors } = usePredeployedAccounts({
-    rpc: dojoConfig.rpcUrl as string,
+    rpc: rpcUrl,
    id: "katana",
    name: "Katana",
});
const provider = jsonRpcProvider({
-    rpc: () => ({ nodeUrl: getRpcUrl() }),
+    rpc: () => ({ nodeUrl: rpcUrl }),
});

22-22: Simplify array usage by removing unnecessary spread operator.

The spread operator in [...connectors] is unnecessary since connectors is already an array that can be directly passed to the connectors prop.

- connectors={[...connectors]}
+ connectors={connectors}
examples/example-predeployed-connector/src/starknet-provider.tsx (1)

1-1: Use import type for type-only imports.

Since PropsWithChildren is only used as a type and not as a value, it's better to use import type to ensure it gets removed during compilation.

- import { type PropsWithChildren } from "react";
+ import type { PropsWithChildren } from "react";
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

examples/example-vite-react-sql/src/components/starknet-provider.tsx (1)

1-1: Use import type for type-only imports

Consider using the import type syntax for the PropsWithChildren import since it's only used as a type annotation.

-import { type PropsWithChildren } from "react";
+import type { PropsWithChildren } from "react";
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 09c2599 and 19d964f.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/clean-tables-turn.md (1 hunks)
  • .gitignore (1 hunks)
  • examples/example-predeployed-connector/src/starknet-provider.tsx (1 hunks)
  • examples/example-vite-kitchen-sink/src/components/starknet-provider.tsx (2 hunks)
  • examples/example-vite-react-app-recs/package.json (1 hunks)
  • examples/example-vite-react-phaser-recs/package.json (1 hunks)
  • examples/example-vite-react-sdk/package.json (1 hunks)
  • examples/example-vite-react-sdk/src/starknet-provider.tsx (2 hunks)
  • examples/example-vite-react-sql/src/components/starknet-provider.tsx (1 hunks)
  • examples/example-vite-react-threejs-recs/package.json (1 hunks)
  • examples/example-vite-svelte-recs/package.json (1 hunks)
  • examples/example-vue-app-recs/package.json (1 hunks)
  • packages/predeployed-connector/package.json (2 hunks)
  • packages/predeployed-connector/src/react/index.ts (1 hunks)
  • packages/predeployed-connector/tsup.config.ts (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
examples/example-vite-react-sql/src/components/starknet-provider.tsx

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

examples/example-predeployed-connector/src/starknet-provider.tsx

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

packages/predeployed-connector/src/react/index.ts

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: check
  • GitHub Check: build
🔇 Additional comments (15)
examples/example-vite-react-threejs-recs/package.json (1)

81-82: Correct categorization of vite-plugin-top-level-await as a dev dependency

Moving vite-plugin-top-level-await from dependencies to devDependencies is appropriate since it's a build-time plugin that isn't needed at runtime. This follows the best practice of only including runtime dependencies in the dependencies section.

.changeset/clean-tables-turn.md (1)

1-5: Properly documented new React hook for predeployed accounts

The changeset correctly indicates this is a patch release for the predeployed-connector package. The feature description is clear and concise.

.gitignore (1)

10-10: Good addition to gitignore for Vite timestamp files

Adding this pattern will help keep the repository clean by ignoring Vite's temporary timestamp files. The double asterisk pattern properly covers timestamp files in any subdirectory.

packages/predeployed-connector/tsup.config.ts (1)

7-10: Correctly configured entry points including new React integration

The configuration now properly exposes the React hook as a separate entry point, which is good for tree-shaking and allows consumers to import only what they need. This matches the feature described in the changeset.

examples/example-vue-app-recs/package.json (1)

32-33: Relocate “vite-plugin-top-level-await” to DevDependencies
The dependency "vite-plugin-top-level-await": "^1.4.4" is now placed in the devDependencies section, which is appropriate since it is used only during development/build time. Ensure that no production code relies on it at runtime.

examples/example-vite-svelte-recs/package.json (1)

19-20: Ensure Consistency in Dependency Placement
The plugin "vite-plugin-top-level-await": "^1.4.4" has been correctly moved to devDependencies along with "vite": "^5.4.1". Confirm that this re-categorization does not affect build or runtime behavior in this Svelte example.

examples/example-vite-react-phaser-recs/package.json (1)

58-59: Validate Updated DevDependencies for React-Phaser Example
The changes update "vite": "^6.0.11" and relocate "vite-plugin-top-level-await": "^1.4.4" to the devDependencies section. This is consistent with similar examples. Please verify that the tooling and build scripts (e.g., for TypeScript and ESLint) are compatible with these updated versions.

examples/example-vite-react-app-recs/package.json (1)

45-46: Confirm Dependency Relocation for React App Example
The removal of "vite-plugin-top-level-await" from the runtime dependencies and its re-addition in devDependencies with version "^1.4.4" is correctly implemented. It would be good to double-check that this change does not introduce any runtime issues in this React example.

packages/predeployed-connector/package.json (1)

67-68: LGTM! Dependencies have been properly configured.

The package correctly sets React and React DOM as peer dependencies while including their types as dev dependencies. This is the recommended approach for packages that provide React components or hooks.

examples/example-predeployed-connector/src/starknet-provider.tsx (1)

8-12: Good implementation of the predeployed accounts hook.

The component now uses the usePredeployedAccounts hook which simplifies the code by removing manual state management and retries logic. This is a clean implementation that follows good React practices.

examples/example-vite-react-sdk/src/starknet-provider.tsx (3)

3-5: Good refactoring with improved imports

The changes to the import statements appropriately integrate the new usePredeployedAccounts hook while maintaining a clean import structure.


8-12: Clean implementation of the new hook

The implementation of the usePredeployedAccounts hook is well-structured with clear parameters. This approach simplifies the component by abstracting away the complexity of managing predeployed accounts.


22-22: Simplified connector management

Using the connectors directly from the hook return value eliminates the need for manual state management, making the code more maintainable and less error-prone.

examples/example-vite-react-sql/src/components/starknet-provider.tsx (2)

5-5: Good addition of the new hook import

The import of usePredeployedAccounts is correctly placed and follows the component's import organization pattern.


8-12: Clean implementation of the hook with consistent configuration

The implementation of usePredeployedAccounts with configuration parameters is well-structured and consistent with other examples in the codebase. This refactoring removes the need for manual state management with useState and useEffect, resulting in cleaner, more maintainable code.

Comment on lines +24 to +27
"./react": {
"import": "./dist/src/react.js",
"types": "./dist/src/react.d.ts"
},
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Verify the export path for the React module.

The export path for the React module points to ./dist/src/react.js and ./dist/src/react.d.ts, but based on the file structure, the actual files might be at ./dist/src/react/index.js and ./dist/src/react/index.d.ts.

If the paths don't match, update the package.json exports accordingly:

"./react": {
-    "import": "./dist/src/react.js",
-    "types": "./dist/src/react.d.ts"
+    "import": "./dist/src/react/index.js",
+    "types": "./dist/src/react/index.d.ts"
}

🏁 Script executed:

#!/bin/bash
# Check the actual build output path for the React module
ls -la ./packages/predeployed-connector/dist/src/ | grep -E "react|react.js|react.d.ts"
ls -la ./packages/predeployed-connector/dist/src/react/ 2>/dev/null | grep -E "index|index.js|index.d.ts"

# Verify build configuration
grep -r "src/react" ./packages/predeployed-connector/tsup.config.ts

Length of output: 386


Action Required: Update Export Paths for React Module

It appears that the build output no longer contains the "src" folder under ./dist, so the paths in the package.json export should be updated to point to ./dist/react/index.js and ./dist/react/index.d.ts instead of the current paths. Based on the output from running the verification scripts:

  • The directory ./packages/predeployed-connector/dist/src/ doesn’t exist.
  • The tsup configuration maps "src/react" to "src/react/index.ts", implying that the built files should be located at ./dist/react/index.js and ./dist/react/index.d.ts.

Please update the export snippet in packages/predeployed-connector/package.json as follows:

"./react": {
-    "import": "./dist/src/react.js",
-    "types": "./dist/src/react.d.ts"
+    "import": "./dist/react/index.js",
+    "types": "./dist/react/index.d.ts"
}
📝 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
"./react": {
"import": "./dist/src/react.js",
"types": "./dist/src/react.d.ts"
},
"./react": {
- "import": "./dist/src/react.js",
- "types": "./dist/src/react.d.ts"
+ "import": "./dist/react/index.js",
+ "types": "./dist/react/index.d.ts"
},

@MartianGreed MartianGreed force-pushed the fix/example-predeployed branch from 19d964f to 612da82 Compare March 14, 2025 09:59
Copy link

@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

♻️ Duplicate comments (1)
packages/predeployed-connector/package.json (1)

24-27: ⚠️ Potential issue

Update export paths for the React module.

The export paths for the React module need to be updated based on the actual build output structure.

"./react": {
-    "import": "./dist/src/react.js",
-    "types": "./dist/src/react.d.ts"
+    "import": "./dist/react/index.js",
+    "types": "./dist/react/index.d.ts"
}
🧹 Nitpick comments (2)
examples/example-vite-react-sql/src/components/starknet-provider.tsx (1)

1-1: Consider using import type for type-only imports.

The PropsWithChildren import is only used as a type. Using import type ensures it's removed during compilation and avoids loading unnecessary modules.

-import { type PropsWithChildren } from "react";
+import type { PropsWithChildren } from "react";
🧰 Tools
🪛 Biome (1.9.4)

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

packages/predeployed-connector/src/react/index.ts (1)

23-28: Improve error handling in the account fetching logic.

The current implementation only has a retry mechanism but lacks proper error handling. If predeployedAccounts fails, there's no feedback to the user.

    useEffect(() => {
        if (connectors.length === 0 && retries < 5) {
            setRetries(retries + 1);
-            predeployedAccounts(options).then(setConnectors);
+            predeployedAccounts(options)
+                .then(setConnectors)
+                .catch(error => {
+                    console.error("Failed to fetch predeployed accounts:", error);
+                    // Optionally set some error state here to show to the user
+                });
        }
    }, [connectors, options, retries]);
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 19d964f and 612da82.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .changeset/clean-tables-turn.md (1 hunks)
  • .gitignore (1 hunks)
  • examples/example-predeployed-connector/src/starknet-provider.tsx (1 hunks)
  • examples/example-vite-kitchen-sink/src/components/starknet-provider.tsx (2 hunks)
  • examples/example-vite-react-app-recs/package.json (1 hunks)
  • examples/example-vite-react-phaser-recs/package.json (1 hunks)
  • examples/example-vite-react-sdk/package.json (1 hunks)
  • examples/example-vite-react-sdk/src/starknet-provider.tsx (2 hunks)
  • examples/example-vite-react-sql/src/components/starknet-provider.tsx (1 hunks)
  • examples/example-vite-react-threejs-recs/package.json (1 hunks)
  • examples/example-vite-svelte-recs/package.json (1 hunks)
  • examples/example-vue-app-recs/package.json (1 hunks)
  • packages/predeployed-connector/package.json (2 hunks)
  • packages/predeployed-connector/src/react/index.ts (1 hunks)
  • packages/predeployed-connector/tsup.config.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (11)
  • .changeset/clean-tables-turn.md
  • .gitignore
  • packages/predeployed-connector/tsup.config.ts
  • examples/example-vite-svelte-recs/package.json
  • examples/example-vite-react-phaser-recs/package.json
  • examples/example-vite-react-sdk/package.json
  • examples/example-vue-app-recs/package.json
  • examples/example-vite-react-threejs-recs/package.json
  • examples/example-vite-react-sdk/src/starknet-provider.tsx
  • examples/example-vite-kitchen-sink/src/components/starknet-provider.tsx
  • examples/example-vite-react-app-recs/package.json
🧰 Additional context used
🪛 Biome (1.9.4)
examples/example-vite-react-sql/src/components/starknet-provider.tsx

[error] 1-1: All these imports are only used as types.

Importing the types with import type ensures that they are removed by the compilers and avoids loading unnecessary modules.
Safe fix: Use import type.

(lint/style/useImportType)

packages/predeployed-connector/src/react/index.ts

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: check
🔇 Additional comments (3)
examples/example-vite-react-sql/src/components/starknet-provider.tsx (1)

5-5: LGTM - Great refactoring with the new hook!

Using the usePredeployedAccounts hook simplifies the component by removing manual state management for predeployed accounts. This abstraction improves readability and maintainability.

Also applies to: 8-12

packages/predeployed-connector/package.json (1)

33-34: LGTM - Good practice adding React as peer dependency.

Adding React and React DOM as peer dependencies with their corresponding type definitions ensures proper compatibility and prevents duplicate React instances.

Also applies to: 45-46

examples/example-predeployed-connector/src/starknet-provider.tsx (1)

1-1: LGTM - Consistent implementation of the new hook.

The refactoring to use usePredeployedAccounts hook is consistent with other components and removes manual state management, making the code cleaner and more maintainable.

Also applies to: 5-5, 8-12

Comment on lines +15 to +31
export function usePredeployedAccounts(
options: PredeployedAccountsConnectorOptions
) {
const [retries, setRetries] = useState<number>(0);
const [connectors, setConnectors] = useState<
PredeployedAccountsConnector[]
>([]);

useEffect(() => {
if (connectors.length === 0 && retries < 5) {
setRetries(retries + 1);
predeployedAccounts(options).then(setConnectors);
}
}, [connectors, options]);

return { connectors };
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing dependency in useEffect dependency array.

The retries state variable is used inside the useEffect callback but is missing from the dependency array, which could lead to stale closures and unexpected behavior.

    useEffect(() => {
        if (connectors.length === 0 && retries < 5) {
            setRetries(retries + 1);
            predeployedAccounts(options).then(setConnectors);
        }
-    }, [connectors, options]);
+    }, [connectors, options, retries]);
📝 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
export function usePredeployedAccounts(
options: PredeployedAccountsConnectorOptions
) {
const [retries, setRetries] = useState<number>(0);
const [connectors, setConnectors] = useState<
PredeployedAccountsConnector[]
>([]);
useEffect(() => {
if (connectors.length === 0 && retries < 5) {
setRetries(retries + 1);
predeployedAccounts(options).then(setConnectors);
}
}, [connectors, options]);
return { connectors };
}
export function usePredeployedAccounts(
options: PredeployedAccountsConnectorOptions
) {
const [retries, setRetries] = useState<number>(0);
const [connectors, setConnectors] = useState<
PredeployedAccountsConnector[]
>([]);
useEffect(() => {
if (connectors.length === 0 && retries < 5) {
setRetries(retries + 1);
predeployedAccounts(options).then(setConnectors);
}
}, [connectors, options, retries]);
return { connectors };
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 23-23: This hook does not specify all of its dependencies: retries

This dependency is not specified in the hook dependency list.

This dependency is not specified in the hook dependency list.

(lint/correctness/useExhaustiveDependencies)

@MartianGreed MartianGreed merged commit 94d33f5 into main Mar 14, 2025
5 of 6 checks passed
@MartianGreed MartianGreed deleted the fix/example-predeployed branch March 14, 2025 10:12
@coderabbitai coderabbitai bot mentioned this pull request Jun 19, 2025
5 tasks
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.

1 participant