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

Spaceward: use MsgNewAction for creating new Actions #385

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

Pitasi
Copy link
Contributor

@Pitasi Pitasi commented Jun 10, 2024

Bump wardenjs to use BigInts instead of Longs (see #384), and use a new hook called useNewAction() to create and broadcast transactions with a MsgNewAction message.

This affects: MsgUpdateSpace, MsgAddSpaceOwner, MsgRemoveSpaceOwner, MsgUpdateKey (unused in Spaceward), MsgNewKeyRequest, MsgNewSignatureRequest.

I think I fixed all usages.

I had to switch back from Amino to Protobuf message encoding, unfortunately, because I couldn't get Keplr/wardenjs to play well with the fact that MsgNewAction has a Any field. I'm in contact with the Telescope team to figure this out.

Summary by CodeRabbit

  • New Features

    • Introduced useNewAction for creating new actions and transactions.
    • Added functionality for packing data into Google Protocol Buffers Any messages.
    • Implemented query key hashing for stability.
  • Refactor

    • Replaced Long with BigInt for handling numeric values across multiple components.
    • Updated key request and signature request functionalities to use useNewAction.
  • Chores

    • Removed dependency on "long": "^5.2.3".
    • Removed 'plugin:storybook/recommended' from ESLint configuration.

@Pitasi Pitasi added the blocked label Jun 10, 2024
Copy link
Contributor

coderabbitai bot commented Jun 10, 2024

Warning

Review failed

The pull request is closed.

Walkthrough

Walkthrough

The overall changes involve removing the Long library and replacing its usage with BigInt across multiple files, updating ESLint and package dependencies, and introducing new hooks and utility functions. These updates enhance type consistency, simplify numeric handling, and refine action handling mechanisms within the codebase.

Changes

File(s) Change Summary
.eslintrc.cjs, package.json, pnpm-lock.yaml Removed storybook linting rules and long package dependency.
src/App.tsx Added hashQueryKey import and updated QueryClient options.
src/components/SendEth.tsx, src/features/assets/Assets.tsx, src/features/home/TotalAssetValue.tsx, src/features/keys/Keys.tsx, src/features/keys/NewKeyButton.tsx, src/features/metamask/AddToMetaMaskButton.tsx, src/features/metamask/MetaMaskRequests.tsx, src/features/spaces/SpaceSelector.tsx, src/features/walletconnect/WalletConnect.tsx, src/hooks/useEthereumTx.tsx Replaced Long with BigInt for numeric handling.
src/features/owners/AddSpaceOwnerForm.tsx, src/features/keys/NewKeyButton.tsx, src/hooks/useRequestKey.ts, src/hooks/useRequestSignature.ts, src/pages/Intents.tsx, src/pages/Owners.tsx Updated action handling to use new useNewAction hook and refactored related logic.
src/hooks/useAction.ts, src/hooks/useModuleAccount.ts Introduced new hooks for action creation and module account fetching.
src/hooks/useClient.ts Renamed getOfflineSigner to getOfflineSignerDirect and added TypeScript comment.
src/utils/any.ts, src/utils/queryKeyHash.ts Added new utility functions for packing data into Any messages and hashing query keys.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant App
    participant QueryClient
    participant ActionHandler
    participant BigIntUtil

    User->>App: Interact with UI
    App->>QueryClient: Initialize with hashQueryKey
    App->>ActionHandler: Trigger action
    ActionHandler->>BigIntUtil: Convert ID using BigInt
    BigIntUtil-->>ActionHandler: Return BigInt ID
    ActionHandler-->>App: Return action result
    App-->>User: Display result
Loading

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

Hey @Pitasi and thank you for opening this pull request! 👋🏼

It looks like you forgot to add a changelog entry for your changes. Make sure to add a changelog entry in the 'CHANGELOG.md' file.

Base automatically changed from wardenjs-use-bigint to main June 10, 2024 15:10
@Pitasi Pitasi force-pushed the spaceward-new-action branch from 40ab076 to 4b952e8 Compare June 10, 2024 15:11
@Pitasi Pitasi removed the blocked label Jun 10, 2024
@Pitasi Pitasi requested a review from jjheywood June 10, 2024 15:11
jjheywood
jjheywood previously approved these changes Jun 10, 2024
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: 6

Outside diff range and nitpick comments (5)
spaceward/src/utils/any.ts (1)

4-15: Well implemented utility functions for handling Protocol Buffers Any messages.

Consider adding detailed documentation for the Msg interface and packAny function to improve code readability and maintainability.

spaceward/src/hooks/useModuleAccount.ts (1)

4-14: Well implemented hook for retrieving module accounts.

Consider adding error handling for cases where the cosmos.auth.v1beta1.useModuleAccounts call fails or returns unexpected results.

spaceward/src/hooks/useEthereumTx.tsx (1)

17-17: The update to use bigint in signEthereumTx is correctly implemented.

Consider adding more detailed logging for debugging purposes, especially when the ethereumAnalyzerContract is missing.

spaceward/src/hooks/useAction.ts (1)

9-30: Well implemented useNewAction hook for creating new actions.

Consider adding unit tests for the useNewAction function to ensure its functionality and handle edge cases.

spaceward/src/hooks/useClient.ts (1)

Line range hint 57-119: Review the use of @ts-ignore to suppress TypeScript errors. It's generally better to handle the types explicitly unless there's a compelling reason to suppress the errors.

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 10dbac7 and 4b952e8.

Files selected for processing (25)
  • spaceward/.eslintrc.cjs (1 hunks)
  • spaceward/package.json (1 hunks)
  • spaceward/pnpm-lock.yaml (2 hunks)
  • spaceward/src/App.tsx (1 hunks)
  • spaceward/src/components/SendEth.tsx (2 hunks)
  • spaceward/src/features/assets/Assets.tsx (7 hunks)
  • spaceward/src/features/home/HomeAssets.tsx (5 hunks)
  • spaceward/src/features/home/TotalAssetValue.tsx (2 hunks)
  • spaceward/src/features/keys/Keys.tsx (3 hunks)
  • spaceward/src/features/keys/NewKeyButton.tsx (3 hunks)
  • spaceward/src/features/metamask/AddToMetaMaskButton.tsx (2 hunks)
  • spaceward/src/features/metamask/MetaMaskRequests.tsx (6 hunks)
  • spaceward/src/features/owners/AddSpaceOwnerForm.tsx (3 hunks)
  • spaceward/src/features/spaces/SpaceSelector.tsx (5 hunks)
  • spaceward/src/features/walletconnect/WalletConnect.tsx (3 hunks)
  • spaceward/src/hooks/useAction.ts (1 hunks)
  • spaceward/src/hooks/useClient.ts (2 hunks)
  • spaceward/src/hooks/useEthereumTx.tsx (2 hunks)
  • spaceward/src/hooks/useModuleAccount.ts (1 hunks)
  • spaceward/src/hooks/useRequestKey.ts (4 hunks)
  • spaceward/src/hooks/useRequestSignature.ts (5 hunks)
  • spaceward/src/pages/Intents.tsx (4 hunks)
  • spaceward/src/pages/Owners.tsx (2 hunks)
  • spaceward/src/utils/any.ts (1 hunks)
  • spaceward/src/utils/queryKeyHash.ts (1 hunks)
Files not summarized due to errors (1)
  • spaceward/src/features/walletconnect/WalletConnect.tsx: Error: Server error. Please try again later.
Files skipped from review due to trivial changes (3)
  • spaceward/.eslintrc.cjs
  • spaceward/package.json
  • spaceward/pnpm-lock.yaml
Additional comments not posted (35)
spaceward/src/hooks/useEthereumTx.tsx (1)

8-8: The update to use bigint in signRaw is correctly implemented.

spaceward/src/features/owners/AddSpaceOwnerForm.tsx (3)

6-7: Introduced useNewAction and warden imports to support the new action creation mechanism.

Also applies to: 9-9


11-12: Refactored to use useNewAction for creating new space owners, aligning with the new action-based architecture.


71-71: The button's onClick handler correctly resets the newOwner state after attempting to add an owner.

spaceward/src/utils/queryKeyHash.ts (5)

1-9: Introduced types and the hashQueryKey function for handling and hashing query keys.


12-26: The stableValueHash function uses a custom serializer for JSON.stringify to handle bigint and plain objects, ensuring consistent hashing.


28-38: Added utility functions isBigInt and ensureQueryKeyArray to support the hashing process.


40-67: Implemented isPlainObject to check for plain JavaScript objects, useful for serialization and hashing.


69-72: The hasObjectPrototype function assists in determining if an object is a plain JavaScript object, supporting the isPlainObject checks.

spaceward/src/features/metamask/AddToMetaMaskButton.tsx (1)

14-14: Updated the keyId parameter to use bigint, aligning with the new type standards in the project.

spaceward/src/pages/Owners.tsx (2)

8-9: Introduced useNewAction and related imports to manage space owner actions, aligning with the new action-based architecture.

Also applies to: 11-11


71-71: The button's onClick handler correctly triggers the removeOwner function. The AddSpaceOwnerForm is correctly integrated with the spaceId.

Also applies to: 79-79

spaceward/src/features/home/TotalAssetValue.tsx (1)

39-42: Ensure that the BigInt conversion is safe and won't cause runtime errors when spaceId is an empty string.

#!/bin/bash
# Description: Verify that `spaceId` is always a valid number before conversion to `BigInt`.

# Test: Search for any assignments to `spaceId` that might not ensure a valid number.
ast-grep --lang javascript --pattern $'const { spaceId } = useSpaceId(); $$$'
spaceward/src/features/keys/NewKeyButton.tsx (2)

117-120: LGTM! The conversion to BigInt in the onClick handler is correctly implemented.


33-33: Ensure that the useQueryHooks is properly implemented and tested, especially the warden.warden.v1beta2.useKeychains method.

#!/bin/bash
# Description: Verify the implementation of `useQueryHooks` and its methods.

# Test: Search for the implementation of `useQueryHooks`.
ast-grep --lang javascript --pattern $'export function useQueryHooks() { $$$ }'

Also applies to: 43-44

spaceward/src/hooks/useRequestKey.ts (1)

9-11: Ensure that the new useNewAction hook is robustly implemented and tested, especially in handling errors and edge cases.

#!/bin/bash
# Description: Verify the implementation of `useNewAction` and its error handling.

# Test: Search for the implementation of `useNewAction`.
ast-grep --lang javascript --pattern $'export function useNewAction() { $$$ }'

Also applies to: 26-53, 60-120

spaceward/src/features/spaces/SpaceSelector.tsx (1)

46-47: Ensure correct usage of BigInt for IDs.

The conversion of signIntentId and adminIntentId to BigInt aligns with the PR's objective to handle large integers more efficiently. This change is crucial for maintaining data integrity and avoiding potential overflow issues with large numbers.

spaceward/src/features/keys/Keys.tsx (1)

29-35: Updated parameter types to BigInt.

The update from Long to BigInt for spaceId and limit in the useKeysBySpaceId function is a positive change. It ensures that the application can handle larger numbers, which is essential for scalability and robustness.

spaceward/src/components/SendEth.tsx (1)

53-53: Conversion to BigInt for key ID.

The change to use BigInt for the id parameter in the useKeyById function is consistent with the overall PR goal of replacing Long with BigInt. This ensures that the application can handle larger integers effectively, which is particularly important for cryptographic operations and identifiers.

spaceward/src/hooks/useRequestSignature.ts (2)

39-51: Refactored to use useNewAction for creating new signature requests.

The refactoring to use the useNewAction hook for creating new signature requests simplifies the code and aligns with the PR's objectives to enhance modularity. This change also potentially improves the maintainability of the code by centralizing the action creation logic.


Line range hint 58-74: Handling of empty arrays and use of BigInt.

The handling of potentially empty arrays by converting them to undefined is a clever workaround for issues with generated code not handling empty arrays correctly. Additionally, the consistent use of BigInt for keyId ensures that the application can handle larger integers, aligning with the PR's goals.

spaceward/src/App.tsx (2)

60-60: Good integration of hashQueryKey into the query client configuration. This should enhance the cache management by providing a consistent hashing mechanism for query keys.


54-54: Ensure that the hashQueryKey function is correctly implemented and tested since it's now a crucial part of the query configuration.

#!/bin/bash
# Description: Verify the implementation and test coverage for `hashQueryKey`.

# Test: Search for the function implementation and tests. Expect: Implementation and tests exist.
rg --type typescript $'hashQueryKey'
spaceward/src/features/home/HomeAssets.tsx (3)

29-35: Using BigInt for spaceId and limit in the query setup is a good practice for handling large numbers, ensuring the application can scale without issues related to number size.


69-69: Correctly updated the key attribute to use toString() on BigInt. This ensures that React can handle the key as a string, which is necessary for keys in lists.


101-101: Updating the keyId parameter to bigint aligns with the changes in the rest of the application to handle large numbers. Ensure all usages of Address are updated accordingly.

#!/bin/bash
# Description: Verify all usages of `Address` component have updated `keyId` parameter.

# Test: Search for `Address` component usage. Expect: All usages have `keyId` as `bigint`.
rg --type typescript $'Address'
spaceward/src/features/assets/Assets.tsx (3)

42-48: Using BigInt for spaceId and limit in the query setup is consistent with the changes across the application to handle large numbers effectively.


78-78: Properly updated the key attribute to use toString() on BigInt, ensuring React can handle the key as a string. This is important for list rendering.


120-120: The update of the keyId parameter to bigint is necessary for consistency with the rest of the application's handling of large numbers.

spaceward/src/features/metamask/MetaMaskRequests.tsx (4)

Line range hint 23-34: Introduction of the SignTransactionParams interface helps in defining a clear contract for transaction parameters, which is crucial for maintaining type safety and clarity in function calls.


95-95: Correctly handling keyId as BigInt in the handleApproveRequest function ensures that large numbers are managed properly throughout the application.


130-130: Proper handling of transaction parameters using the SignTransactionParams type in the eth_signTransaction case ensures type safety and clarity.


157-157: Ensuring that the typed message parameters are handled correctly in the eth_signTypedData_v4 case is crucial for the integrity of the signing process.

spaceward/src/pages/Intents.tsx (2)

15-16: Imported useNewAction and warden for new action creation and handling.

This aligns with the PR's objective to utilize MsgNewAction for creating new actions, enhancing the modularity and maintainability of the code.


131-132: Introduced MsgUpdateSpace from warden.warden.v1beta2.

This change is necessary for the new action creation process and ensures that the correct message type is used.

@Pitasi
Copy link
Contributor Author

Pitasi commented Jun 10, 2024

sorry @jjheywood, had to fix some conflicts and dismissed your approval

@Pitasi Pitasi requested a review from jjheywood June 10, 2024 15:42
@Pitasi Pitasi merged commit 333d497 into main Jun 10, 2024
5 checks passed
@Pitasi Pitasi deleted the spaceward-new-action branch June 10, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants