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: update to starknet.js v6 #846

Merged
merged 6 commits into from
Jun 28, 2024
Merged

feat: update to starknet.js v6 #846

merged 6 commits into from
Jun 28, 2024

Conversation

irisdv
Copy link
Collaborator

@irisdv irisdv commented Jun 26, 2024

Summary by CodeRabbit

  • Dependency Updates

    • Updated starknet to version 6.9.0.
    • Updated starknetkit to version ^1.1.9.
  • Improvements

    • Enhanced type handling for contract call results.
    • Refined conditional checks in discount calculations.
    • Simplified provider configuration setup.
    • Improved transaction receipt handling.
  • Refactors

    • Renamed variables for clarity in multiple hooks and utility functions.

@irisdv irisdv added the 🚧 In progress do not merge Pull Request in progress, please do not merge label Jun 26, 2024
Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

The updates include version upgrades for starknet and starknetkit in package.json and several improvements for TypeScript type handling, such as casting and accessing properties using type-safe methods. Notable changes involve refining conditional checks, modifying imports, and restructuring data handling logic. These alterations enhance maintainability and type safety throughout the codebase, impacting components, hooks, context providers, and utility functions.

Changes

Files Change Summaries
package.json Update starknet to 6.9.0 and starknetkit to 1.1.9.
components/UI/searchBar.tsx Added Result import and updated type assertion for res in contract?.call.
components/discount/freeRenewalDiscount.tsx Refined conditional check for nested properties in mapping function.
components/identities/actions/clickable/clickablePersonhoodIcon.tsx Modified imports to TypedData from typedData and updated the sign function signature.
context/StarknetIdJsProvider.tsx Simplified Provider constructor configuration by removing rpc object wrapper.
hooks/naming.ts Cast data to CallResult and updated property access accordingly.
hooks/useAllowanceCheck.tsx Renamed erc20AllowanceData to erc20AllowanceRes and refactored condition check.
hooks/useBalances.tsx Renamed variable erc20BalanceData to erc20BalanceRes and updated usage.
hooks/useNeedAllowances.tsx Renamed erc20AllowanceData to erc20AllowanceRes and updated balance calculation logic.
hooks/useNotificationManager.ts Replaced provider.getTransactionReceipt with provider.waitForTransaction and handled new transaction receipt types.
types/frontTypes.d.ts Updated index signatures syntax and introduced CallResult type.
utils/altcoinService.ts Updated usage of priceData in getRenewalPriceETH to resolve type issue.
utils/cacheDomainData.ts Changed existingData type to a dictionary in storeDomainData and getDomainData.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

vercel bot commented Jun 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2024 8:13am
sepolia-app-starknet-id ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 28, 2024 8:13am

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6ec7e38 and 4ac4d20.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • package.json (1 hunks)
Files skipped from review due to trivial changes (1)
  • package.json

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4ac4d20 and 1d5b942.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • package.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package.json

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

Outside diff range and nitpick comments (4)
utils/altcoinService.ts (1)

Line range hint 155-158: Use modern JavaScript exponentiation operator.

Replace Math.pow with the exponentiation operator ** for better readability and performance.

- const strkConvertedBalance = (strkBalance * strkQuote) / BigInt(Math.pow(10, quoteData.decimals));
+ const strkConvertedBalance = (strkBalance * strkQuote) / BigInt(10 ** quoteData.decimals);
Tools
Biome

[error] 78-85: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)

components/identities/actions/clickable/clickablePersonhoodIcon.tsx (1)

Line range hint 93-93: Implement optional chaining for improved code safety.

Switching to optional chaining can prevent runtime errors when accessing properties on potentially null or undefined objects.

- return account?.signMessage(payload as TypedData) as Promise<
+ return account?.signMessage(payload as TypedData)? as Promise<
components/discount/freeRenewalDiscount.tsx (2)

Line range hint 242-242: Simplify conditional expression.

Directly assign the result without using a ternary operator for more concise code:

- setTermsBox(!termsBox)
+ setTermsBox(!termsBox)
Tools
Biome

[error] 288-289: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


Line range hint 442-442: Improve accessibility by adding alternative text to images.

It's crucial to provide a text alternative for images to support screen reader users:

- <img className={styles.image} src="/visuals/register.webp" />
+ <img className={styles.image} src="/visuals/register.webp" alt="Registration visual" />
Tools
Biome

[error] 288-289: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1d5b942 and 4abaebb.

Files selected for processing (12)
  • components/UI/searchBar.tsx (2 hunks)
  • components/discount/freeRenewalDiscount.tsx (1 hunks)
  • components/identities/actions/clickable/clickablePersonhoodIcon.tsx (2 hunks)
  • context/StarknetIdJsProvider.tsx (1 hunks)
  • hooks/naming.ts (1 hunks)
  • hooks/useAllowanceCheck.tsx (1 hunks)
  • hooks/useBalances.tsx (1 hunks)
  • hooks/useNeedAllowances.tsx (1 hunks)
  • hooks/useNotificationManager.ts (2 hunks)
  • types/frontTypes.d.ts (2 hunks)
  • utils/altcoinService.ts (1 hunks)
  • utils/cacheDomainData.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • hooks/useBalances.tsx
Additional context used
Biome
context/StarknetIdJsProvider.tsx

[error] 27-27: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

utils/altcoinService.ts

[error] 78-85: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 95-100: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 155-155: Use the '**' operator instead of 'Math.pow'.

Unsafe fix: Use the '**' operator instead of 'Math.pow'.

(lint/style/useExponentiationOperator)


[error] 158-158: Use the '**' operator instead of 'Math.pow'.

Unsafe fix: Use the '**' operator instead of 'Math.pow'.

(lint/style/useExponentiationOperator)

components/UI/searchBar.tsx

[error] 192-227: This else clause can be omitted because previous branches break early.

Unsafe fix: Omit the else clause.

(lint/style/noUselessElse)


[error] 199-227: This else clause can be omitted because previous branches break early.

(lint/style/noUselessElse)

components/identities/actions/clickable/clickablePersonhoodIcon.tsx

[error] 93-93: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 154-157: Enforce to have the onClick mouse event with the onKeyUp, the onKeyDown, or the onKeyPress keyboard event.

Actions triggered using mouse events should have corresponding keyboard events to account for keyboard-only navigation.

(lint/a11y/useKeyWithClickEvents)


[error] 181-181: Alternative text title element cannot be empty

For accessibility purposes, SVGs should have an alternative text, provided via title element. If the svg element has role="img", you should add the aria-label or aria-labelledby attribute.

(lint/a11y/noSvgWithoutTitle)


[error] 180-180: Provide an explicit type prop for the button element.

The default type of a button is submit, which causes the submission of a form when placed inside a form element. This is likely not the behaviour that you want inside a React application.
Allowed button types are: submit, button or reset

(lint/a11y/useButtonType)

components/discount/freeRenewalDiscount.tsx

[error] 242-242: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)


[error] 288-289: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 442-442: Provide a text alternative through the alt, aria-label or aria-labelledby attribute

Meaningful alternative text on elements helps users relying on screen readers to understand content's purpose within a page.

(lint/a11y/useAltText)

Additional comments not posted (8)
hooks/useAllowanceCheck.tsx (1)

27-32: Type casting and logic check adjustments in useAllowanceCheck function

The renaming of erc20AllowanceData to erc20AllowanceRes and the type casting to CallResult are appropriate given the context of handling the new starknet.js version. However, ensure that the property remaining is correctly defined within the CallResult type, as it is used to check the allowance status.

context/StarknetIdJsProvider.tsx (1)

32-32: Simplified Provider instantiation in StarknetIdJsProvider

The update to directly use nodeUrl in the Provider constructor simplifies the code and presumably aligns with the new API structure of starknet.js v6. This change should be tested to ensure that the provider is correctly instantiated and functional.

utils/cacheDomainData.ts (1)

55-55: Refactored data structure in storeDomainData and getDomainData functions

Changing existingData from an array to a dictionary mapping enhances data access performance. Ensure that all interactions with existingData are updated to work with the new structure, including checks and updates.

Also applies to: 66-66

hooks/useNeedAllowances.tsx (1)

70-74: Updated balance calculation in useNeedsAllowances

The conversion of erc20AllowanceData to erc20AllowanceRes and the subsequent use of fromUint256 for balance calculation align with the requirements for handling large number data types in blockchain contexts. Ensure that the fromUint256 function is correctly implemented and tested for accuracy.

hooks/useNotificationManager.ts (1)

7-10: Enhanced transaction receipt handling in useNotificationManager

The introduction of specific types for transaction receipt responses and the detailed handling of each possible outcome are excellent improvements. This ensures that users are accurately informed about the status of their transactions. Verify that all new methods (isRejected, isReverted, isError, isSuccess) are correctly implemented and that the match function properly handles each case.

Also applies to: 31-58

types/frontTypes.d.ts (1)

133-133: Approved type definition updates.

The changes to the index signature syntax and the addition of the CallResult type are appropriate and improve type safety and clarity in the codebase.

Also applies to: 179-181

components/identities/actions/clickable/clickablePersonhoodIcon.tsx (1)

16-16: Correct and secure handling of type imports and usage.

The update from typedData to TypedData is correct, reflecting the changes in the starknet.js library. The usage of TypedData in the signMessage function call is also appropriate, ensuring type safety.

Also applies to: 105-105

components/discount/freeRenewalDiscount.tsx (1)

288-289: Use optional chaining for safer property access.

The conditional access can be further improved by using optional chaining, which is safer and cleaner:

- needSubscription && needSubscription.needSubscription[domain]?.[currency]
+ needSubscription?.needSubscription[domain]?.[currency]
Tools
Biome

[error] 288-289: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

hooks/naming.ts Show resolved Hide resolved
utils/altcoinService.ts Show resolved Hide resolved
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4abaebb and dbbd085.

Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing (1)
  • package.json (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • package.json

Copy link
Contributor

@fricoben fricoben left a comment

Choose a reason for hiding this comment

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

lgtm

I tested most tx, everything seems to work well but the bugs are still here

@fricoben fricoben merged commit 1545c3f into testnet Jun 28, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔥 Ready for review This pull request needs a review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants