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

feat: babylon cosmos provider example #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ByteZhang1024
Copy link
Contributor

@ByteZhang1024 ByteZhang1024 commented Jan 15, 2025

Summary by CodeRabbit

Release Notes

  • Version Update

    • Incremented version to 2.2.7-alpha.3
  • New Features

    • Added Babylon chain support
    • Introduced new wallet connection functionalities for Bitcoin and Cosmos networks
    • Added Babylon-specific dApps (Osmosis and JunoSwap)
  • Dependencies

    • Added new blockchain and wallet-related libraries:
      • @cosmjs/stargate
      • @keystonehq/keystone-sdk
      • @tomo-inc/wallet-connect-sdk

Copy link

coderabbitai bot commented Jan 15, 2025

Walkthrough

This pull request introduces updates across multiple packages, focusing on adding support for the Babylon chain. The changes include version incrementation, new chain registration, dApp configuration, and a comprehensive wallet connection component for Bitcoin and Cosmos networks. New dependencies have been added to support these functionalities, and a new page has been created to showcase the Babylon DApp example.

Changes

File Change Summary
packages/core/src/versionInfo.ts Version updated from '2.2.7-alpha.2' to '2.2.7-alpha.3'
packages/example/chains.ts Added new Babylon chain entry with UUID, name, href, and icon
packages/example/components/chains/babylon/dapps.config.ts Introduced dapps constant with Osmosis and JunoSwap dApp configurations
packages/example/components/chains/babylon/example.tsx New React component for wallet connection with Bitcoin and Cosmos support
packages/example/components/chains/babylon/types.ts Added IProviderApi type and IProviderInfo interface
packages/example/package.json Added dependencies: @cosmjs/stargate, @keystonehq/keystone-sdk, @tomo-inc/wallet-connect-sdk
packages/example/pages/babylon/index.tsx New page component for Babylon DApp example
packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts Modified _base property initialization in ProviderAlph class

Sequence Diagram

sequenceDiagram
    participant User
    participant WalletConnect
    participant BitcoinProvider
    participant CosmosProvider
    
    User->>WalletConnect: Initiate Connection
    WalletConnect->>BitcoinProvider: Connect Bitcoin Wallet
    WalletConnect->>CosmosProvider: Connect Cosmos Wallet
    BitcoinProvider-->>User: Wallet Connected
    CosmosProvider-->>User: Wallet Connected
    User->>BitcoinProvider: Request Transaction
    User->>CosmosProvider: Request Transaction
Loading

Finishing Touches

  • 📝 Generate Docstrings (Beta)

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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 or 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: 10

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b4d54c and b370884.

⛔ Files ignored due to path filters (1)
  • packages/example/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • packages/core/src/versionInfo.ts (1 hunks)
  • packages/example/chains.ts (1 hunks)
  • packages/example/components/chains/babylon/dapps.config.ts (1 hunks)
  • packages/example/components/chains/babylon/example.tsx (1 hunks)
  • packages/example/components/chains/babylon/types.ts (1 hunks)
  • packages/example/package.json (2 hunks)
  • packages/example/pages/babylon/index.tsx (1 hunks)
  • packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/example/components/chains/babylon/example.tsx

[error] 53-53: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 409-409: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 411-411: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 473-473: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 475-476: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test_build_web
  • GitHub Check: lint (ubuntu-latest, 20)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (9)
packages/example/chains.ts (1)

70-75: Clean addition of Babylon chain!

The new chain entry follows the established pattern and uses consistent URL structure.

packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts (1)

38-39: Good version management approach!

Syncing version with base provider ensures consistency across the codebase.

Also applies to: 60-60

packages/core/src/versionInfo.ts (1)

2-2: Version bump looks good!

Appropriate increment for the new Babylon chain feature.

packages/example/components/chains/babylon/dapps.config.ts (1)

1-10: Verify dApp URLs accessibility

Let's ensure the dApp URLs are accessible and use HTTPS.

✅ Verification successful

URLs verified successfully

Both dApp URLs are secure (HTTPS) and accessible.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the dApp URLs are accessible and secure
for url in "https://app.osmosis.zone/" "https://junoswap.com/"; do
  echo "Checking $url"
  curl -sI "$url" | head -n 1
done

Length of output: 398

packages/example/package.json (3)

26-26: Looks good! @cosmjs/stargate addition

The version aligns well with your existing @cosmjs/amino dependency.


28-28: Check for newer versions of @keystonehq/keystone-sdk

Let's verify if version ^0.9.1 is the latest stable release.

✅ Verification successful

Package is using the latest version

The current version ^0.9.1 matches the latest stable release on npm.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check latest version and release info
curl -s https://registry.npmjs.org/@keystonehq/keystone-sdk | jq -r '.["dist-tags"].latest'

Length of output: 99


69-69: Verify stability of @tomo-inc/wallet-connect-sdk

The version ^0.3.10 suggests early development stage. Let's check:

  • Latest version
  • Weekly downloads (adoption)
  • Last publish date
packages/example/components/chains/babylon/types.ts (2)

1-1: Clean import statement!

Good job using a specific type import instead of importing the whole module.


1-9: Verify type usage across the codebase

Let's ensure these types are used consistently in related components.

✅ Verification successful

Types are correctly defined and used consistently

The IProviderApi and IProviderInfo types follow the standard pattern used across all chain implementations. The BBNProviderCosmos import is properly utilized in both babylon and cosmosBabylon chains.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of IProviderApi and IProviderInfo
echo "Searching for IProviderApi usage:"
rg "IProviderApi" -t ts -t tsx

echo -e "\nSearching for IProviderInfo usage:"
rg "IProviderInfo" -t ts -t tsx

Length of output: 280


Script:

#!/bin/bash
# Search with correct file patterns
echo "Searching for IProviderApi usage:"
rg "IProviderApi" --type-add 'ts:*.{ts,tsx}' -t ts

echo -e "\nSearching for IProviderInfo usage:"
rg "IProviderInfo" --type-add 'ts:*.{ts,tsx}' -t ts

# Search for related imports
echo -e "\nSearching for BBNProviderCosmos imports:"
rg "BBNProviderCosmos" --type-add 'ts:*.{ts,tsx}' -t ts

Length of output: 17430

Comment on lines +75 to +76
const providers = useTomoProviders();
console.log('providers', providers);
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Clean up debug console statements

The console.log statements used for debugging should be removed to tidy up the code.

-      console.log('providers', providers);
-      console.log('providerBitcoin', providerBitcoin);
-      console.log('providerCosmos', providerCosmos);

Also applies to: 80-81

Comment on lines +409 to +410
const network = await providerBitcoin?.getNetwork();

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Use Number.parseInt instead of parseInt

For consistency and to align with ES2015 standards, replace the global parseInt with Number.parseInt.

-    const amount = parseInt(fromData['amount'] as string);
-    const gasPrice = parseInt((fromData['gasPrice'] as string) ?? '20');
+    const amount = Number.parseInt(fromData['amount'] as string);
+    const gasPrice = Number.parseInt((fromData['gasPrice'] as string) ?? '20');

Repeat similar changes at other instances.

Also applies to: 411-411, 473-474, 475-476

🧰 Tools
🪛 Biome (1.9.4)

[error] 409-409: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

Comment on lines +102 to +104
if (!providerDetail) {
return Promise.reject('Wallet not found');
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Reject promises with Error objects

Rejecting promises with a string can lead to unhandled rejections without stack traces. Use an Error object instead for better error handling.

-    return Promise.reject('Wallet not found');
+    return Promise.reject(new Error('Wallet not found'));
📝 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
if (!providerDetail) {
return Promise.reject('Wallet not found');
}
if (!providerDetail) {
return Promise.reject(new Error('Wallet not found'));
}

}

const result = await tomoModal.open(providerDetail.inject as 'bitcoin' | 'cosmos');
console.log('xxxx', result);
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Remove unnecessary console.log statement

The console.log('xxxx', result); appears to be a leftover debug statement. Remove it to clean up the code.

-          console.log('xxxx', result);

Comment on lines +51 to +57
.reduce(
(acc, [k, v]) => ({
...acc,
[k]: v === Object(v) && !Array.isArray(v) ? removeNull(v) : v,
}),
{},
);
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Avoid using spread operator in reduce for better performance

Using the spread operator ...acc within a reducer can lead to O(n²) time complexity because it creates a new object on each iteration. Modify the accumulator directly to improve efficiency.

-        return Object.entries(obj)
-          .filter(([, v]) => v != null)
-          .reduce(
-            (acc, [k, v]) => ({
-              ...acc,
-              [k]: v === Object(v) && !Array.isArray(v) ? removeNull(v) : v,
-            }),
-            {},
-          );
+        const acc = {};
+        for (const [k, v] of Object.entries(obj)) {
+          if (v != null) {
+            acc[k] = v === Object(v) && !Array.isArray(v) ? removeNull(v) : v;
+          }
+        }
+        return acc;
📝 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
.reduce(
(acc, [k, v]) => ({
...acc,
[k]: v === Object(v) && !Array.isArray(v) ? removeNull(v) : v,
}),
{},
);
const acc = {};
for (const [k, v] of Object.entries(obj)) {
if (v != null) {
acc[k] = v === Object(v) && !Array.isArray(v) ? removeNull(v) : v;
}
}
return acc;
🧰 Tools
🪛 Biome (1.9.4)

[error] 53-53: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)

ssr: false,
});

export default function () {
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Name the default export function

Naming the default export function improves stack traces and debugging.

-export default function () {
+export default function BabylonPage() {
📝 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 default function () {
export default function BabylonPage() {

import dynamic from 'next/dynamic';
import PageLayout from '../../components/PageLayout';

// injected provider works only if nextjs ssr disabled
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Clarify the comment

Adjust the comment for clarity and proper capitalization.

-/* injected provider works only if nextjs ssr disabled */
+/* Injected provider works only if Next.js SSR is disabled */
📝 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
// injected provider works only if nextjs ssr disabled
/* Injected provider works only if Next.js SSR is disabled */

@@ -0,0 +1,10 @@
export const dapps = [
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add TypeScript interface for dApp configuration

Define an interface for better type safety and documentation.

+interface DApp {
+  name: string;
+  url: string;
+}
+
-export const dapps = [
+export const dapps: DApp[] = [
📝 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 const dapps = [
interface DApp {
name: string;
url: string;
}
export const dapps: DApp[] = [

@@ -0,0 +1,9 @@
import type { BBNProviderCosmos } from '@onekeyfe/onekey-cosmos-provider';

export type IProviderApi = BBNProviderCosmos
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Add JSDoc comment for the type alias

Add a brief description of what this provider API represents and its purpose.

+/** Babylon Cosmos Provider API type for handling wallet interactions */
 export type IProviderApi = BBNProviderCosmos
📝 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 type IProviderApi = BBNProviderCosmos
/** Babylon Cosmos Provider API type for handling wallet interactions */
export type IProviderApi = BBNProviderCosmos

Comment on lines +5 to +9
export interface IProviderInfo {
uuid: string;
name: string;
inject?: string; // window.ethereum
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Improve interface documentation and clarity

The interface needs proper documentation, and the inject property's purpose should be clearer.

+/**
+ * Provider information interface for Babylon chain integration
+ */
 export interface IProviderInfo {
+  /** Unique identifier for the provider */
   uuid: string;
+  /** Display name of the provider */
   name: string;
+  /** Optional injection path for the provider (e.g., window.ethereum) */
-  inject?: string; // window.ethereum
+  inject?: string;
 }
📝 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 interface IProviderInfo {
uuid: string;
name: string;
inject?: string; // window.ethereum
}
/**
* Provider information interface for Babylon chain integration
*/
export interface IProviderInfo {
/** Unique identifier for the provider */
uuid: string;
/** Display name of the provider */
name: string;
/** Optional injection path for the provider (e.g., window.ethereum) */
inject?: string;
}

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

♻️ Duplicate comments (3)
packages/example/components/chains/babylon/dapps.config.ts (1)

1-10: 🧹 Nitpick (assertive)

Add TypeScript interface for better type safety

Define an interface for the dApp configuration.

+interface DApp {
+  name: string;
+  url: string;
+}
+
-export const dapps = [
+export const dapps: DApp[] = [
packages/example/components/chains/babylon/types.ts (2)

3-3: 🧹 Nitpick (assertive)

Add JSDoc comment for the provider API type

Add a description of what this provider API represents.

+/** Babylon Cosmos Provider API type for handling wallet interactions */
 export type IProviderApi = BBNProviderCosmos

5-9: 🧹 Nitpick (assertive)

Document the provider info interface

Add JSDoc comments to explain the interface and its properties.

+/**
+ * Provider information interface for Babylon chain integration
+ */
 export interface IProviderInfo {
+  /** Unique identifier for the provider */
   uuid: string;
+  /** Display name of the provider */
   name: string;
+  /** Optional injection path for the provider (e.g., window.ethereum) */
   inject?: string;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b370884 and 28c9eec.

⛔ Files ignored due to path filters (1)
  • packages/example/yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (8)
  • packages/core/src/versionInfo.ts (1 hunks)
  • packages/example/chains.ts (1 hunks)
  • packages/example/components/chains/babylon/dapps.config.ts (1 hunks)
  • packages/example/components/chains/babylon/example.tsx (1 hunks)
  • packages/example/components/chains/babylon/types.ts (1 hunks)
  • packages/example/package.json (2 hunks)
  • packages/example/pages/babylon/index.tsx (1 hunks)
  • packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts (2 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
packages/example/components/chains/babylon/example.tsx

[error] 53-53: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


[error] 409-409: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 411-411: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 473-473: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)


[error] 475-476: Use Number.parseInt instead of the equivalent global.

ES2015 moved some globals into the Number namespace for consistency.
Safe fix: Use Number.parseInt instead.

(lint/style/useNumberNamespace)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: test_build_web
  • GitHub Check: lint (ubuntu-latest, 20)
🔇 Additional comments (13)
packages/example/components/chains/babylon/example.tsx (7)

53-55: Avoid using spread operator in reduce for better performance

Using the spread operator in a reduce function can hurt performance because it creates a new object on each iteration. Modify the accumulator directly to improve efficiency.

Apply this diff to optimize the code:

-        return Object.entries(obj)
-          .filter(([, v]) => v != null)
-          .reduce(
-            (acc, [k, v]) => ({
-              ...acc,
-              [k]: v === Object(v) && !Array.isArray(v) ? removeNull(v) : v,
-            }),
-            {},
-          );
+        const acc = {};
+        for (const [k, v] of Object.entries(obj)) {
+          if (v != null) {
+            acc[k] = v === Object(v) && !Array.isArray(v) ? removeNull(v) : v;
+          }
+        }
+        return acc;
🧰 Tools
🪛 Biome (1.9.4)

[error] 53-53: Avoid the use of spread (...) syntax on accumulators.

Spread syntax should be avoided on accumulators (like those in .reduce) because it causes a time complexity of O(n^2).
Consider methods such as .splice or .push instead.

(lint/performance/noAccumulatingSpread)


76-76: Remove unnecessary console.log statement

Delete the debug console.log statement to clean up the code.

Apply this diff:

-  console.log('providers', providers);

80-81: Remove unnecessary console.log statements

Delete these debug console.log statements to tidy up the code.

Apply this diff:

-  console.log('providerBitcoin', providerBitcoin);
-  console.log('providerCosmos', providerCosmos);

102-103: Reject promises with Error objects

Rejecting a promise with a string omits the stack trace. Use an Error object instead.

Apply this diff:

-            return Promise.reject('Wallet not found');
+            return Promise.reject(new Error('Wallet not found'));

107-107: Remove unnecessary console.log statement

Delete the debug console.log statement to clean up the code.

Apply this diff:

-          console.log('xxxx', result);

416-417: Use Number.parseInt instead of parseInt

Replace the global parseInt with Number.parseInt for consistency.

Apply this diff:

-    const amount = parseInt(fromData['amount'] as string);
-    const gasPrice = parseInt((fromData['gasPrice'] as string) ?? '20');
+    const amount = Number.parseInt(fromData['amount'] as string);
+    const gasPrice = Number.parseInt((fromData['gasPrice'] as string) ?? '20');

Also applies to: 468-469


468-469: Use Number.parseInt instead of parseInt

Replace the global parseInt with Number.parseInt for consistency.

Apply this diff:

-    const amount = parseInt(fromData['amount'] as string);
-    const gasPrice = parseInt((fromData['gasPrice'] as string) ?? '20');
+    const amount = Number.parseInt(fromData['amount'] as string);
+    const gasPrice = Number.parseInt((fromData['gasPrice'] as string) ?? '20');
packages/example/pages/babylon/index.tsx (2)

5-5: Clarify the comment

Adjust the comment for clarity and proper capitalization.

Apply this diff:

-// injected provider works only if nextjs ssr disabled
+// Injected provider works only if Next.js SSR is disabled

10-10: Name the default export function

Naming the default export function improves stack traces and debugging.

Apply this diff:

-export default function () {
+export default function BabylonPage() {
packages/example/chains.ts (1)

70-75: LGTM!

The new Babylon chain entry is added correctly.

packages/providers/onekey-alph-provider/src/OnekeyAlphProvider.ts (1)

38-39: Clean version management implementation!

Good job delegating version management to the base provider. The initialization looks solid.

Also applies to: 60-60

packages/core/src/versionInfo.ts (1)

2-2: Version bump looks good

Clean version increment following semantic versioning.

packages/example/package.json (1)

26-26: Check dependencies for security and compatibility.

The new dependencies align with the PR objectives for Babylon chain support. Let's verify their security and compatibility.

Also applies to: 28-28, 69-69

✅ Verification successful

Consider updating @cosmjs/stargate and @keystonehq/keystone-sdk

Your dependencies are stable and React-compatible, but two packages have newer versions:

  • @cosmjs/stargate: ^0.32.4 → 0.33.0
  • @keystonehq/keystone-sdk: ^0.9.1 → 0.9.2
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check dependencies for latest versions and security advisories

# Check latest versions
echo "Checking latest versions..."
for pkg in "@cosmjs/stargate" "@keystonehq/keystone-sdk" "@tomo-inc/wallet-connect-sdk"; do
  echo "Package: $pkg"
  npm view $pkg version
done

# Check for peer dependencies
echo -e "\nChecking peer dependencies..."
for pkg in "@cosmjs/stargate" "@keystonehq/keystone-sdk" "@tomo-inc/wallet-connect-sdk"; do
  echo "Package: $pkg"
  npm view $pkg peerDependencies
done

# Check for security advisories
echo -e "\nChecking security advisories..."
for pkg in "@cosmjs/stargate" "@keystonehq/keystone-sdk" "@tomo-inc/wallet-connect-sdk"; do
  echo "Package: $pkg"
  npm audit $pkg
done

Length of output: 3191


Script:

#!/bin/bash
# Check React version and search for potential security issues
echo "Checking React version..."
rg '"react":\s*"([^"]+)"' packages/example/package.json

echo -e "\nChecking for known vulnerabilities in GitHub Advisory Database..."
gh api /repos/cosmos/cosmjs/security-advisories --jq '.[].summary'
gh api /repos/KeystoneHQ/keystone-sdk/security-advisories --jq '.[].summary'

Length of output: 551

Comment on lines +1 to +4
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-return */
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Avoid extensive use of ESLint disable comments

Using multiple eslint-disable comments at the top may hide potential issues. Consider resolving the linting errors instead of disabling them.

@@ -23,7 +23,9 @@
"@codemirror/lang-json": "^6.0.1",
"@codemirror/lint": "^6.8.0",
"@cosmjs/amino": "^0.32.3",
"@cosmjs/stargate": "^0.32.4",
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick (assertive)

Verify @cosmjs version compatibility.

You have @cosmjs/amino at ^0.32.3 but @cosmjs/stargate at ^0.32.4. Consider aligning these versions.

-    "@cosmjs/amino": "^0.32.3",
+    "@cosmjs/amino": "^0.32.4",

Committable suggestion skipped: line range outside the PR's diff.

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