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: tranfer token ownership #152

Merged
merged 6 commits into from
Dec 12, 2024
Merged

Conversation

fmorency
Copy link
Contributor

@fmorency fmorency commented Dec 11, 2024

This PR allows one to transfer ownership of a token created via the Token Factory module to a new owner. The Factory page now only displays tokens owned by the current user.

manifestjs was bumped to 0.0.1-rc.1 to be able to query tokens by owner (admin).

Fixes #135
Relates #137

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a TransferModal for token transfers, allowing users to initiate ownership changes directly.
    • Added a transfer action button in the token row, enabling quick access to transfer functionality.
  • Improvements

    • Updated the MyDenoms component to manage transfer modal visibility and state.
    • Enhanced the useQueries hook to include new functionality for fetching authority metadata.
  • Dependency Updates

    • Upgraded various dependencies, including React and related type definitions, to improve performance and compatibility.

@fmorency fmorency requested a review from chalabi2 December 11, 2024 18:53
@fmorency fmorency self-assigned this Dec 11, 2024
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Warning

Rate limit exceeded

@fmorency has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 24 minutes and 5 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3586c87 and 6de67b0.

📒 Files selected for processing (1)
  • components/factory/modals/TransferModal.tsx (1 hunks)

Walkthrough

The pull request introduces enhancements to the token management functionality within the application. Key changes include the addition of a TransferModal for transferring token ownership, modifications to the MyDenoms component to incorporate this modal, and updates to related hooks and types. The changes also involve renaming existing hooks for clarity and adjusting the package.json dependencies to reflect updated versions. Overall, these modifications aim to improve the user experience and functionality related to token transfers.

Changes

File Path Change Summary
components/factory/components/MyDenoms.tsx - Added TransferModal integration with state management for visibility.
- Updated handleDenomSelect and added handleTransferModal for transfer actions.
- Modified TokenRow to include an onTransfer prop and a button for token transfer.
components/factory/modals/TransferModal.tsx - Introduced a new modal component for transferring token ownership with form management and validation logic.
components/factory/modals/index.ts - Added export for TransferModal to the module's public API.
helpers/formReducer.tsx - Added new type TransferTokenFormData for managing transfer form data.
hooks/useOsmosisRpcQueryClient.ts - Introduced a custom hook for managing RPC query client state for the Osmosis protocol.
hooks/useQueries.ts - Renamed useTokenFactoryDenoms to useTokenFactoryDenomsFromAdmin and added useDenomAuthorityMetadata hook.
package.json - Updated dependency versions for @liftedinit/manifestjs, react, react-dom, and their type declarations.
pages/factory/index.tsx - Updated import for useTokenFactoryDenoms to the new hook name and adjusted data handling accordingly.

Assessment against linked issues

Objective Addressed Explanation
Add token factory ownership transfer (#135)

Possibly related PRs

Suggested labels

enhancement, UX

Suggested reviewers

  • chalabi2

Poem

In the garden of tokens, we hop and play,
A modal for transfers, brightens the day.
With each little click, ownership's clear,
A hop, skip, and jump, the tokens draw near!
So let’s celebrate changes, both big and small,
For in our token world, there's room for us all! 🐇✨


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>, 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. (Experiment)
  • @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

codecov bot commented Dec 11, 2024

Codecov Report

Attention: Patch coverage is 71.94245% with 78 lines in your changes missing coverage. Please review.

Project coverage is 57.39%. Comparing base (88e8e7b) to head (6de67b0).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
components/factory/modals/TransferModal.tsx 77.29% 42 Missing ⚠️
components/factory/components/MyDenoms.tsx 52.27% 21 Missing ⚠️
hooks/useQueries.ts 60.00% 12 Missing ⚠️
hooks/useOsmosisRpcQueryClient.ts 83.33% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #152      +/-   ##
==========================================
+ Coverage   57.01%   57.39%   +0.38%     
==========================================
  Files         145      147       +2     
  Lines       14436    14706     +270     
==========================================
+ Hits         8230     8440     +210     
- Misses       6206     6266      +60     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 (13)
components/factory/modals/TransferModal.tsx (5)

107-122: Consider extracting inline styles to a CSS class or styled component

The inline styles applied to the <dialog> component make the code less maintainable and harder to read. Extracting these styles into a CSS class or using a styled component can improve readability and facilitate reusability.


128-129: Remove redundant Formik validation props

The props validateOnChange and validateOnBlur are true by default in Formik. Explicitly setting them is unnecessary unless you intend to override default behavior.

Apply this diff to simplify the code:

            initialValues={formData}
            validationSchema={TokenOwnershipSchema}
            onSubmit={(values, { resetForm }) => handleTransfer(values, resetForm)}
-           validateOnChange={true}
-           validateOnBlur={true}

137-137: Simplify the onClick handler for the close button

You can pass resetForm directly to handleCloseModal without wrapping it in an additional arrow function, simplifying the code.

Apply this diff to streamline the function call:

- onClick={() => handleCloseModal(() => resetForm())}
+ onClick={() => handleCloseModal(resetForm)}

36-44: Add unit tests for the Escape key handling in useEffect

The useEffect hook manages the modal's visibility based on the Escape key press. Consider adding unit tests to ensure this behavior functions as expected across different scenarios.

Would you like help in creating these unit tests?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 36-38: components/factory/modals/TransferModal.tsx#L36-L38
Added lines #L36 - L38 were not covered by tests


47-50: Ensure handleCloseModal properly resets the form

While the handleCloseModal function closes the modal and optionally resets the form, adding tests can verify that the form state is correctly managed when the modal is closed in various ways.

Would you like assistance in writing tests for this functionality?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 47-48: components/factory/modals/TransferModal.tsx#L47-L48
Added lines #L47 - L48 were not covered by tests

hooks/useOsmosisRpcQueryClient.ts (1)

12-14: Add unit tests for useOsmosisRpcQueryClient

Adding unit tests for this hook will help ensure it behaves correctly when selectedEndpoint?.rpc is undefined, null, or an invalid URL, enhancing the robustness of the application.

Would you like assistance in writing these unit tests?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 12-14: hooks/useOsmosisRpcQueryClient.ts#L12-L14
Added lines #L12 - L14 were not covered by tests

components/factory/components/MyDenoms.tsx (2)

75-86: Add test coverage for transfer functionality.

The new transfer-related code paths are not covered by tests. This includes:

  • Modal type handling
  • Transfer action handling
  • Transfer modal state management

Would you like me to help generate test cases for these scenarios:

  1. Transfer modal opening/closing
  2. Transfer action handling
  3. Router query updates
  4. Modal state management

Also applies to: 122-129

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 75-75: components/factory/components/MyDenoms.tsx#L75
Added line #L75 was not covered by tests


[warning] 78-80: components/factory/components/MyDenoms.tsx#L78-L80
Added lines #L78 - L80 were not covered by tests


[warning] 84-86: components/factory/components/MyDenoms.tsx#L84-L86
Added lines #L84 - L86 were not covered by tests


397-415: Consider consolidating modal state management.

The TransferModal implementation follows the same pattern as other modals but introduces duplicate state management logic. Consider extracting common modal behavior into a custom hook.

Example implementation:

const useModalState = (modalType: string, onSuccess?: () => void) => {
  const [isOpen, setIsOpen] = useState(false);
  
  const handleClose = () => {
    setIsOpen(false);
    handleCloseModal();
  };
  
  const handleSuccess = () => {
    onSuccess?.();
    handleUpdateModalClose();
  };
  
  return { isOpen, setIsOpen, handleClose, handleSuccess };
};
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 400-403: components/factory/components/MyDenoms.tsx#L400-L403
Added lines #L400 - L403 were not covered by tests


[warning] 407-408: components/factory/components/MyDenoms.tsx#L407-L408
Added lines #L407 - L408 were not covered by tests

hooks/useQueries.ts (3)

Line range hint 583-613: LGTM! The rename improves clarity and the refetch configuration is appropriate.

The function rename from useTokenFactoryDenoms to useTokenFactoryDenomsFromAdmin better reflects its purpose, and the frequent refetching configuration is appropriate for tracking ownership changes.

Consider adding unit tests to cover this hook, as indicated by the code coverage report.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 593-594: hooks/useQueries.ts#L593-L594
Added lines #L593 - L594 were not covered by tests


615-645: LGTM! Well-structured hook with proper error handling.

The implementation is solid with:

  • Well-justified use of RPC client (as commented)
  • Comprehensive error handling
  • Consistent refetch configuration with useTokenFactoryDenomsFromAdmin

Consider adding unit tests to cover this hook, as indicated by the code coverage report. I can help generate test cases if needed.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 619-627: hooks/useQueries.ts#L619-L627
Added lines #L619 - L627 were not covered by tests


Line range hint 583-645: Offer assistance with test coverage

Both new hooks are critical for token ownership transfer functionality but lack test coverage. Would you like me to help generate comprehensive test cases for:

  1. useTokenFactoryDenomsFromAdmin
  2. useDenomAuthorityMetadata

The test suite should cover:

  • Successful queries
  • Error handling scenarios
  • Refetch behavior
🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 619-627: hooks/useQueries.ts#L619-L627
Added lines #L619 - L627 were not covered by tests

pages/factory/index.tsx (2)

Line range hint 39-63: Consider extracting token processing logic

While the implementation is correct, the data processing logic could be more maintainable by extracting it into a separate utility function.

Consider this refactor:

+ const processTokenData = (
+   denom: string,
+   metadatas: MetadataSDKType[],
+   balances: Balance[],
+   totalSupply: Supply[]
+ ): ExtendedMetadataSDKType | null => {
+   const metadata = metadatas.find(meta => meta.base === denom);
+   const balance = balances.find(bal => bal.denom === denom);
+   const supply = totalSupply.find(supply => supply.denom === denom);
+   return metadata
+     ? {
+         ...metadata,
+         balance: balance?.amount || '0',
+         totalSupply: supply?.amount || '0',
+       }
+     : null;
+ };

  const combinedData = useMemo(() => {
    if (denoms?.denoms && metadatas?.metadatas && balances && totalSupply) {
      const otherTokens = denoms.denoms
        .filter(denom => denom !== 'umfx')
-       .map((denom: string) => {
-         const metadata = metadatas.metadatas.find(meta => meta.base === denom);
-         const balance = balances.find(bal => bal.denom === denom);
-         const supply = totalSupply.find(supply => supply.denom === denom);
-         return metadata
-           ? {
-               ...metadata,
-               balance: balance?.amount || '0',
-               totalSupply: supply?.amount || '0',
-             }
-           : null;
-       })
+       .map((denom: string) => processTokenData(denom, metadatas.metadatas, balances, totalSupply))
        .filter((meta): meta is ExtendedMetadataSDKType => meta !== null);

      return [...otherTokens];
    }
    return [];
  }, [denoms, metadatas, balances, totalSupply]);

Line range hint 82-89: Update placeholder SEO metadata URLs

The SEO metadata contains placeholder URLs that should be updated with actual production URLs.

Consider updating these placeholders:

- <meta property="og:url" content="https://" />
- <meta property="og:image" content="https://" />
+ <meta property="og:url" content="https://your-production-url.com/factory" />
+ <meta property="og:image" content="https://your-production-url.com/og-image.png" />
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 88e8e7b and 57e70c4.

⛔ Files ignored due to path filters (1)
  • bun.lockb is excluded by !**/bun.lockb
📒 Files selected for processing (8)
  • components/factory/components/MyDenoms.tsx (10 hunks)
  • components/factory/modals/TransferModal.tsx (1 hunks)
  • components/factory/modals/index.ts (1 hunks)
  • helpers/formReducer.tsx (1 hunks)
  • hooks/useOsmosisRpcQueryClient.ts (1 hunks)
  • hooks/useQueries.ts (4 hunks)
  • package.json (1 hunks)
  • pages/factory/index.tsx (2 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
hooks/useOsmosisRpcQueryClient.ts

[warning] 12-14: hooks/useOsmosisRpcQueryClient.ts#L12-L14
Added lines #L12 - L14 were not covered by tests

components/factory/modals/TransferModal.tsx

[warning] 36-38: components/factory/modals/TransferModal.tsx#L36-L38
Added lines #L36 - L38 were not covered by tests


[warning] 47-48: components/factory/modals/TransferModal.tsx#L47-L48
Added lines #L47 - L48 were not covered by tests


[warning] 63-98: components/factory/modals/TransferModal.tsx#L63-L98
Added lines #L63 - L98 were not covered by tests


[warning] 221-221: components/factory/modals/TransferModal.tsx#L221
Added line #L221 was not covered by tests

hooks/useQueries.ts

[warning] 583-583: hooks/useQueries.ts#L583
Added line #L583 was not covered by tests


[warning] 593-594: hooks/useQueries.ts#L593-L594
Added lines #L593 - L594 were not covered by tests


[warning] 619-627: hooks/useQueries.ts#L619-L627
Added lines #L619 - L627 were not covered by tests

components/factory/components/MyDenoms.tsx

[warning] 75-75: components/factory/components/MyDenoms.tsx#L75
Added line #L75 was not covered by tests


[warning] 78-80: components/factory/components/MyDenoms.tsx#L78-L80
Added lines #L78 - L80 were not covered by tests


[warning] 84-86: components/factory/components/MyDenoms.tsx#L84-L86
Added lines #L84 - L86 were not covered by tests


[warning] 101-101: components/factory/components/MyDenoms.tsx#L101
Added line #L101 was not covered by tests


[warning] 108-108: components/factory/components/MyDenoms.tsx#L108
Added line #L108 was not covered by tests


[warning] 122-127: components/factory/components/MyDenoms.tsx#L122-L127
Added lines #L122 - L127 were not covered by tests


[warning] 400-403: components/factory/components/MyDenoms.tsx#L400-L403
Added lines #L400 - L403 were not covered by tests


[warning] 407-408: components/factory/components/MyDenoms.tsx#L407-L408
Added lines #L407 - L408 were not covered by tests

🔇 Additional comments (8)
components/factory/modals/index.ts (1)

5-5: Export statement for TransferModal is correctly added

The export statement for TransferModal is properly added and follows the existing naming conventions and structure.

hooks/useOsmosisRpcQueryClient.ts (1)

12-14: ⚠️ Potential issue

Handle potential issues with empty rpcEndpoint

The rpcEndpoint defaults to an empty string if selectedEndpoint?.rpc is undefined. Verify that createRpcQueryClient can handle an empty string without throwing an error.

Apply this diff to prevent potential issues:

        queryFn: () =>
          createRpcQueryClient({
-           rpcEndpoint: selectedEndpoint?.rpc || '',
+           rpcEndpoint: selectedEndpoint?.rpc ?? '',
          }),

This change ensures that undefined is passed instead of an empty string when the rpcEndpoint is not available.

Likely invalid or redundant comment.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 12-14: hooks/useOsmosisRpcQueryClient.ts#L12-L14
Added lines #L12 - L14 were not covered by tests

package.json (1)

42-42: Verify compatibility with updated dependency versions

Several dependencies have been updated:

  • @liftedinit/manifestjs to 0.0.1-rc.1
  • react and react-dom to 18.3.1
  • @types/react and @types/react-dom to match React version

Ensure that these updates are compatible with your application and that all components function as expected. Pay special attention to any breaking changes or deprecated features in the new versions.

Also applies to: 66-67, 70-71

helpers/formReducer.tsx (1)

381-385: LGTM! Clean type definition.

The TransferTokenFormData type is well-structured with appropriate field types.

components/factory/components/MyDenoms.tsx (1)

491-498: LGTM! Clean implementation of transfer button.

The transfer button implementation:

  • Correctly disables for 'umfx' tokens
  • Follows consistent styling with other action buttons
  • Properly handles event propagation
pages/factory/index.tsx (3)

20-22: LGTM! Well-structured hook implementation

The hook usage is well-implemented with proper error handling and null safety for the address parameter.


1-1: Verify the hook rename impact across the codebase

The hook rename from useTokenFactoryDenoms to useTokenFactoryDenomsFromAdmin better reflects its purpose for token ownership management. However, we should ensure all usages are updated.

Also applies to: 5-5


20-22: Verify token ownership filtering

The implementation aligns with the PR objectives to show only user-owned tokens. Let's verify the filtering logic in the related hooks.

Also applies to: 39-63

✅ Verification successful

Let me gather more information about the token factory queries and filtering logic.


Token ownership filtering is correctly implemented

The verification confirms that the token ownership filtering is properly implemented through the denomsFromAdmin query. The query specifically filters tokens by the admin address parameter, ensuring only tokens owned by the user are returned. The implementation in useTokenFactoryDenomsFromAdmin hook correctly passes the user's address and handles the data fetching with appropriate loading states.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the implementation of useTokenFactoryDenomsFromAdmin
rg -A 10 "useTokenFactoryDenomsFromAdmin.*=.*" 

# Check for any ownership-related queries
ast-grep --pattern 'query.*owner.*'

Length of output: 684


Script:

#!/bin/bash
# Check the complete implementation of the token factory query
rg -A 15 "denomsFromAdmin" 

# Check the component implementation to understand how the data is filtered
rg -A 20 "const.*denoms.*useTokenFactoryDenomsFromAdmin" 

Length of output: 2087

Comment on lines 63 to 98
const handleTransfer = async (values: FormikValues, resetForm: () => void) => {
setIsSigning(true);
try {
const msg = changeAdmin({
sender: address,
denom: denom?.base ?? '',
newAdmin: values.newAdmin,
});

const fee = await estimateFee(address, [msg]);

await tx([msg], {
fee,
onSuccess: () => {
onSuccess();
handleCloseModal(resetForm);
},
});
} catch (error) {
console.error('Error during transaction setup:', error);
let errorMessage = 'An unknown error occurred while adding the endpoint.';

if (error instanceof Error) {
if (error.message.includes('unauthorized account')) {
errorMessage = 'Unauthorized account. Please check your account and try again.';
}
}

setToastMessage({
type: 'alert-error',
title: 'Error transferring ownership',
description: errorMessage,
bgColor: '#e74c3c',
});
throw error;
} finally {
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add unit tests for the handleTransfer function

The handleTransfer function involves critical logic for transaction handling and error management. Adding unit tests will enhance reliability and ensure that any future changes do not break existing functionality.

Would you like assistance in writing unit tests for this function?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 63-98: components/factory/modals/TransferModal.tsx#L63-L98
Added lines #L63 - L98 were not covered by tests

components/factory/modals/TransferModal.tsx Outdated Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Félix C. Morency <[email protected]>
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 (2)
components/factory/components/MyDenoms.tsx (2)

38-38: Consider Using a Dedicated Type or Enum for Modal Types

To enhance maintainability and reduce repetition, consider defining a dedicated type or enum for modalType. This approach centralizes the modal types, making it easier to manage and less error-prone when adding or modifying modal actions.

For example:

type ModalType = 'mint' | 'burn' | 'multimint' | 'multiburn' | 'update' | 'info' | 'transfer' | null;

const [modalType, setModalType] = useState<ModalType>(null);

This way, you can reuse ModalType throughout your codebase, ensuring consistency and simplifying future updates.


Line range hint 38-413: Add Unit Tests for New Transfer Functionality

The new transfer functionality, including state variables and handlers, is not covered by unit tests. To ensure reliability and prevent regressions, please add tests covering these additions.

Would you like assistance in generating unit tests for the transfer functionality or creating a GitHub issue to track this task?

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 399-402: components/factory/components/MyDenoms.tsx#L399-L402
Added lines #L399 - L402 were not covered by tests


[warning] 406-407: components/factory/components/MyDenoms.tsx#L406-L407
Added lines #L406 - L407 were not covered by tests

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 57e70c4 and 3586c87.

📒 Files selected for processing (1)
  • components/factory/components/MyDenoms.tsx (9 hunks)
🧰 Additional context used
🪛 GitHub Check: codecov/patch
components/factory/components/MyDenoms.tsx

[warning] 74-74: components/factory/components/MyDenoms.tsx#L74
Added line #L74 was not covered by tests


[warning] 77-79: components/factory/components/MyDenoms.tsx#L77-L79
Added lines #L77 - L79 were not covered by tests


[warning] 83-85: components/factory/components/MyDenoms.tsx#L83-L85
Added lines #L83 - L85 were not covered by tests


[warning] 100-100: components/factory/components/MyDenoms.tsx#L100
Added line #L100 was not covered by tests


[warning] 107-107: components/factory/components/MyDenoms.tsx#L107
Added line #L107 was not covered by tests


[warning] 121-126: components/factory/components/MyDenoms.tsx#L121-L126
Added lines #L121 - L126 were not covered by tests


[warning] 399-402: components/factory/components/MyDenoms.tsx#L399-L402
Added lines #L399 - L402 were not covered by tests


[warning] 406-407: components/factory/components/MyDenoms.tsx#L406-L407
Added lines #L406 - L407 were not covered by tests

🔇 Additional comments (6)
components/factory/components/MyDenoms.tsx (6)

100-100: Reassess Closing Transfer Modal in handleCloseModal

In handleCloseModal, you're setting setOpenTransferDenomModal(false);. Since this function is intended to close modals, this line is appropriate. Just ensure consistency with other modal close handlers.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 100-100: components/factory/components/MyDenoms.tsx#L100
Added line #L100 was not covered by tests


267-267: Pass Event Handler Correctly to TokenRow Component

The onTransfer prop is being passed correctly to the TokenRow component. Ensure that the handleTransferModal function properly handles the event.


Line range hint 424-438: Ensure Props and Handlers in TokenRow Are Consistent

The TokenRow component's props have been extended to include onTransfer, and the types align correctly. This addition is implemented properly.


396-414: Review TransferModal Integration

The TransferModal component is integrated correctly with the necessary props. Ensure that all callback functions and state variables (modalId, openTransferDenomModal, setOpenTransferDenomModal, onSuccess, etc.) are functioning as intended.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 399-402: components/factory/components/MyDenoms.tsx#L399-L402
Added lines #L399 - L402 were not covered by tests


[warning] 406-407: components/factory/components/MyDenoms.tsx#L406-L407
Added lines #L406 - L407 were not covered by tests


74-85: ⚠️ Potential issue

Ensure Transfer Modal Opens When Action Is 'transfer'

In the useEffect hook, when the action is 'transfer', the TransferModal does not open because setOpenTransferDenomModal(true) is not called. This prevents users from accessing the transfer functionality via URL parameters.

Apply this diff to open the TransferModal when the action is 'transfer':

if (
  action === 'mint' ||
  action === 'burn' ||
  action === 'multimint' ||
  action === 'multiburn' ||
  action === 'update' ||
+ action === 'transfer' ||
  action === 'info'
) {
  setModalType(
    action as 'mint' | 'burn' | 'multimint' | 'multiburn' | 'update' | 'info' | 'transfer'
  );
  if (action === 'update') {
    setOpenUpdateDenomMetadataModal(true);
  }
+ if (action === 'transfer') {
+   setOpenTransferDenomModal(true);
+ }
}

Likely invalid or redundant comment.

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 74-74: components/factory/components/MyDenoms.tsx#L74
Added line #L74 was not covered by tests


[warning] 77-79: components/factory/components/MyDenoms.tsx#L77-L79
Added lines #L77 - L79 were not covered by tests


[warning] 83-85: components/factory/components/MyDenoms.tsx#L83-L85
Added lines #L83 - L85 were not covered by tests


490-497: Verify the Condition for Disabling the Transfer Button

The condition denom.base.includes('umfx') is used to disable the Transfer button. Verify that this condition correctly reflects when the transfer action should be disabled.

Run the following script to check all instances where denom.base includes 'umfx' and confirm that these are the tokens for which transfer should be disabled:

✅ Verification successful

Let me gather more context about the token functionality by checking the related code.


Based on the search results, I can now provide a definitive response about the condition for disabling the transfer button.

The umfx Token Disable Condition is Correct

The condition denom.base.includes('umfx') correctly identifies the native Manifest Chain token that should have transfer disabled. This is verified by:

  • It's consistently used across multiple components to disable actions for the native token
  • The token is defined as the native/core token in constants with base denom 'umfx'
  • The same check is used to disable burn, mint and other token operations
  • The token appears in configurations as the fee token and native denomination
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: List all denom bases that include 'umfx'

rg "denom\.base.*includes\('umfx'\)" -A 5

# Verify denom bases in the codebase
rg "base:.*'umfx'"

Length of output: 3690


Script:

#!/bin/bash
# Check for token-related functionality and permissions
ast-grep --pattern 'function $FUNC($$$) {
  $$$
  denom.base$$$
  $$$
}'

# Check for any comments or documentation about umfx tokens
rg -i "umfx" -B 2 -A 2

# Check for any token type definitions or interfaces
ast-grep --pattern 'interface $_ {
  base: $_
  $$$
}'

Length of output: 76554

Comment on lines +406 to +409
onSuccess={() => {
refetchDenoms();
handleUpdateModalClose();
}}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Use handleCloseModal Instead of handleUpdateModalClose

In the onSuccess callback of the TransferModal, you're calling handleUpdateModalClose(), which is specific to the update modal. To properly close the transfer modal and reset relevant states, you should use handleCloseModal().

Apply this diff to correct the function call:

onSuccess={() => {
  refetchDenoms();
- handleUpdateModalClose();
+ handleCloseModal();
}}

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

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 406-407: components/factory/components/MyDenoms.tsx#L406-L407
Added lines #L406 - L407 were not covered by tests

router.push('/factory', undefined, { shallow: true });
};

const handleUpdateModalClose = () => {
setSelectedDenom(null);
setOpenUpdateDenomMetadataModal(false);
setOpenTransferDenomModal(false);
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Avoid Closing Transfer Modal in handleUpdateModalClose

The handleUpdateModalClose function is specific to the update modal. Setting setOpenTransferDenomModal(false); here could lead to unintended side effects, such as closing the transfer modal when only the update modal should be affected.

Apply this diff to remove the unintended closure:

const handleUpdateModalClose = () => {
  setSelectedDenom(null);
  setOpenUpdateDenomMetadataModal(false);
- setOpenTransferDenomModal(false);
  setModalType(null);
  router.push('/factory', undefined, { shallow: true });
};

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

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 107-107: components/factory/components/MyDenoms.tsx#L107
Added line #L107 was not covered by tests

Copy link
Collaborator

@chalabi2 chalabi2 left a comment

Choose a reason for hiding this comment

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

lgtm! full blown web dev 🦐

@fmorency fmorency merged commit 0b5f1a9 into liftedinit:main Dec 12, 2024
4 checks passed
@fmorency fmorency deleted the token-transfer branch December 12, 2024 14:54
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.

Add token factory ownership transfer
2 participants