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

Add denom prefix #182

Merged
merged 9 commits into from
Jan 8, 2025
Merged

Add denom prefix #182

merged 9 commits into from
Jan 8, 2025

Conversation

chalabi2
Copy link
Collaborator

@chalabi2 chalabi2 commented Jan 8, 2025

  • chore: add 'u' to subdenom programatically
  • fix: fix factory creation metadata issue
  • fix: revert metadata issues

This PR:

  • adds the denom prefix 'u' programtically.
  • fixes metadata issues
  • makes the denom creation simulation smoother

Summary by CodeRabbit

  • New Features

    • Modified denom creation process to automatically prefix subdenom with 'u'.
    • Updated form validation for subdenom input, broadening acceptable input range.
    • Enhanced user input experience by simplifying form input placeholder and removing helper text.
    • Improved handling of denom details by adjusting the construction of fullDenom and denomUnits.
  • Bug Fixes

    • Improved form submission button behavior by adding type="submit".
    • Streamlined test cases by removing unnecessary validation checks.

Copy link
Contributor

coderabbitai bot commented Jan 8, 2025

Walkthrough

The pull request introduces changes to the denom creation process across three components: ConfirmationForm.tsx, CreateDenom.tsx, and TokenDetailsForm.tsx. A new function, getDenomInfo, is added to ConfirmationForm.tsx to process subdenom, ensuring it starts with 'u'. In CreateDenom.tsx, the regex validation for subdenom is removed, enhancing input flexibility. The form submission logic is updated, including changes to placeholder text and validation triggers. TokenDetailsForm.tsx modifies how fullDenom and denom units are constructed, reflecting the new handling of subdenom.

Changes

File Change Summary
components/factory/forms/ConfirmationForm.tsx - Added getDenomInfo function for processing subdenom
- Updated createAsGroup and createAsUser to use prefixedSubdenom
- Changed symbol derivation to use formData.display
components/factory/forms/CreateDenom.tsx - Removed regex validation for subdenom
- Updated placeholder text from "utoken" to "token"
- Removed helper text
- Added type="submit" to submission button
- Modified form submission logic for asynchronous validation
components/factory/forms/TokenDetailsForm.tsx - Changed fullDenom construction to prefix subdenom with 'u'
- Updated denomUnits to use formData.display
- Modified useEffect dependencies to include formData.display
components/factory/forms/__tests__/CreateDenom.test.tsx - Changed placeholder text for subdenom input from 'utoken' to 'token'
- Removed tests related to validation and input handling

Possibly related PRs

Suggested labels

enhancement, bug

Suggested reviewers

  • chalabi2

Poem

🐰 A rabbit's tale of tokens bright,
Where 'u' now dances with delight,
Validation rules have softly swayed,
A denom's journey, freshly made,
With flexibility in sight! 🚀


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

@chalabi2
Copy link
Collaborator Author

chalabi2 commented Jan 8, 2025

fixes #179

@chalabi2 chalabi2 requested a review from fmorency January 8, 2025 00:03
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

🧹 Nitpick comments (1)
components/factory/forms/CreateDenom.tsx (1)

59-59: Add helper text about automatic prefix.

While removing the 'u' prefix from the placeholder aligns with the new design, users should be informed that a 'u' prefix will be automatically added to their input. Consider adding helper text to improve user experience.

 <TextInput
   label="Token Sub Denom"
   name="subdenom"
   placeholder="token"
+  helperText="A 'u' prefix will be automatically added to your token name"
   value={formData.subdenom}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 12555f6 and 944b872.

📒 Files selected for processing (2)
  • components/factory/forms/ConfirmationForm.tsx (2 hunks)
  • components/factory/forms/CreateDenom.tsx (2 hunks)
🧰 Additional context used
📓 Learnings (1)
components/factory/forms/CreateDenom.tsx (2)
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:106-120
Timestamp: 2024-11-12T13:03:18.927Z
Learning: In the file `components/factory/forms/CreateDenom.tsx`, the submit button is intentionally placed outside the `Form` component for stylistic reasons, as per the user's preference, even if it requires some workarounds.
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:20-31
Timestamp: 2024-11-12T13:03:18.927Z
Learning: Validation schemas that are specific to a single form and unlikely to be reused should remain within the form file.
🔇 Additional comments (3)
components/factory/forms/CreateDenom.tsx (2)

127-127: LGTM! Good accessibility improvement.

Adding type="submit" improves accessibility and follows HTML form best practices.


Line range hint 22-34: LGTM! Validation changes align with the new design.

The removal of the 'u' prefix validation while maintaining other important validations (length, profanity, simulation) aligns well with the new approach of handling the prefix programmatically.

components/factory/forms/ConfirmationForm.tsx (1)

Line range hint 55-70: Verify metadata structure for token creation

The metadata structure, particularly the denomUnits, needs verification to ensure it aligns with the new denom prefixing strategy.

Run this script to check existing token metadata patterns:

Also, consider adding validation to ensure the metadata structure matches the chain's requirements:

  1. Base denom should use the prefixed subdenom
  2. Display denom should use the correct symbol
  3. Exponents and aliases should be consistent

Also applies to: 119-134

✅ Verification successful

Metadata structure verification completed - Implementation is correct

The current metadata structure in ConfirmationForm.tsx follows the established pattern across the codebase, with proper denom prefixing, consistent exponents (0 and 6), and correct alias cross-referencing.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for token metadata patterns in the codebase

# Look for denomUnits patterns
rg -A 10 'denomUnits:.*\[' 

# Look for existing token creation patterns
ast-grep --pattern 'createDenom({ $$$, subdenom: $_, $$$})'

Length of output: 4995

components/factory/forms/ConfirmationForm.tsx Outdated Show resolved Hide resolved
components/factory/forms/ConfirmationForm.tsx Outdated 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: 1

🧹 Nitpick comments (1)
components/factory/forms/TokenDetailsForm.tsx (1)

81-81: Consider improving UI feedback

While the 'u' prefix is correctly displayed, consider adding helper text to explain the automatic prefix addition to users.

 <TextInput
   label="Subdenom"
   name="subdenom"
   disabled={true}
   value={`u${formData.subdenom}`}
+  helperText="The 'u' prefix is automatically added to your token's subdenom"
   aria-label="Token subdenom"
 />
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 944b872 and f346182.

📒 Files selected for processing (3)
  • components/factory/forms/ConfirmationForm.tsx (5 hunks)
  • components/factory/forms/CreateDenom.tsx (5 hunks)
  • components/factory/forms/TokenDetailsForm.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/factory/forms/ConfirmationForm.tsx
🧰 Additional context used
📓 Learnings (1)
components/factory/forms/CreateDenom.tsx (2)
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:20-31
Timestamp: 2024-11-12T13:03:18.927Z
Learning: Validation schemas that are specific to a single form and unlikely to be reused should remain within the form file.
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:106-120
Timestamp: 2024-11-12T13:03:18.927Z
Learning: In the file `components/factory/forms/CreateDenom.tsx`, the submit button is intentionally placed outside the `Form` component for stylistic reasons, as per the user's preference, even if it requires some workarounds.
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build
  • GitHub Check: build
🔇 Additional comments (5)
components/factory/forms/TokenDetailsForm.tsx (2)

46-47: LGTM: Denom prefix handling implemented correctly

The fullDenom construction now correctly includes the 'u' prefix for the subdenom, aligning with the PR objective.


52-52: Verify the impact of using display value in denomUnits

The change from using subdenom to display in denomUnits array might affect token metadata creation. Please ensure this aligns with the blockchain's token metadata requirements.

Also applies to: 56-56

✅ Verification successful

Using display in denomUnits is correct and consistent

The change from subdenom to display aligns with the token metadata patterns used throughout the codebase. All token implementations consistently use exponent 6 for the display/symbol denomination, while maintaining the full denom with exponent 0 as the base unit.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing token metadata creation patterns
rg -A 5 "denomUnits.*exponent.*6" 

Length of output: 35


Script:

#!/bin/bash
# Search for denomUnits patterns and token metadata
rg -U "denomUnits.*\[" -A 5
rg -U "interface.*Token" -A 10
rg -U "type.*Token" -A 10

Length of output: 4877

components/factory/forms/CreateDenom.tsx (3)

30-30: LGTM: Simulation now includes denom prefix

The simulateDenomCreation function now correctly includes the 'u' prefix when checking denom availability.


68-68: LGTM: UI improvements

Good improvements to the UI:

  • Simplified placeholder text
  • Added error clearing on change
  • Proper submit button type

Also applies to: 77-77, 137-137


53-54: Verify validation timing implications

Setting both validateOnChange and validateOnBlur to false means validation only occurs on submit. This might delay feedback to users about invalid inputs.

Consider enabling at least one of these for better user experience:

-validateOnChange={false}
-validateOnBlur={false}
+validateOnChange={false}
+validateOnBlur={true}

components/factory/forms/CreateDenom.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

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

Thanks!

This PR doesn't behave properly when the subdenom starts with an u, e.g., unicorn. We want uunicorn as the subdenom and not unicorn.

Copy link
Contributor

@fmorency fmorency left a comment

Choose a reason for hiding this comment

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

I fixed an alias issue and the tests. Lgtm!

@fmorency fmorency merged commit 8cdf6d2 into main Jan 8, 2025
6 checks passed
@fmorency fmorency deleted the chalabi/factory-denom branch January 8, 2025 20:35
@fmorency fmorency mentioned this pull request Jan 8, 2025
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

🔭 Outside diff range comments (2)
components/factory/forms/__tests__/CreateDenom.test.tsx (2)

Line range hint 35-41: Update test input to align with new prefix handling

The test is still manually including the 'u' prefix in the input value ('utest'), while according to the PR objectives, this prefix should be added programmatically. Update the test to use 'test' instead of 'utest' to verify the automatic prefix addition.

-    fireEvent.change(subdenomInput, { target: { value: 'utest' } });
+    fireEvent.change(subdenomInput, { target: { value: 'test' } });
     await waitFor(() => {
       expect(mockProps.dispatch).toHaveBeenCalledWith({
         type: 'UPDATE_FIELD',
         field: 'subdenom',
-        value: 'utest',
+        value: 'test',
       });
     });

Line range hint 49-55: Add test coverage for automatic prefix handling

The test suite is missing coverage for the new automatic 'u' prefix functionality. Add a test case to verify that the denom creation simulation receives the correct prefixed value.

Here's a suggested test case to add:

test('automatically adds u prefix during simulation', async () => {
  renderWithChainProvider(<CreateDenom {...mockProps} />);
  const subdenomInput = screen.getByPlaceholderText('token');
  fireEvent.change(subdenomInput, { target: { value: 'test' } });
  fireEvent.blur(subdenomInput);
  
  const simulateDenomCreation = require('@/utils/transactionUtils').useSimulateDenomCreation().simulateDenomCreation;
  await waitFor(() => {
    expect(simulateDenomCreation).toHaveBeenCalledWith(
      expect.objectContaining({
        subdenom: 'utest'
      })
    );
  });
});
🧹 Nitpick comments (2)
components/factory/forms/CreateDenom.tsx (2)

43-64: Optimize error handling reducer

Good improvement on error handling with proper TypeScript types! However, the spread operator in the reducer could cause performance issues with large error sets.

Consider this optimization:

-                const errors = err.inner.reduce(
-                  (acc: Record<string, string>, error) => ({
-                    ...acc,
-                    [error.path as string]: error.message,
-                  }),
-                  {}
-                );
+                const errors: Record<string, string> = {};
+                err.inner.forEach((error) => {
+                  if (error.path) {
+                    errors[error.path] = error.message;
+                  }
+                });
🧰 Tools
🪛 Biome (1.9.4)

[error] 51-51: 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)


80-80: Add helper text about 'u' prefix

Since the 'u' prefix is now added programmatically, consider adding helper text to inform users that their input will be prefixed with 'u'.

 <TextInput
   label="Token Sub Denom"
   name="subdenom"
   placeholder="token"
+  helperText="Will be prefixed with 'u' automatically"
   value={formData.subdenom}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ec5c6d3 and 2d5e171.

📒 Files selected for processing (3)
  • components/factory/forms/ConfirmationForm.tsx (5 hunks)
  • components/factory/forms/CreateDenom.tsx (5 hunks)
  • components/factory/forms/__tests__/CreateDenom.test.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/factory/forms/ConfirmationForm.tsx
🧰 Additional context used
📓 Learnings (1)
components/factory/forms/CreateDenom.tsx (2)
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:20-31
Timestamp: 2024-11-12T13:03:18.927Z
Learning: Validation schemas that are specific to a single form and unlikely to be reused should remain within the form file.
Learnt from: chalabi2
PR: liftedinit/manifest-app#9
File: components/factory/forms/CreateDenom.tsx:106-120
Timestamp: 2024-11-12T13:03:18.927Z
Learning: In the file `components/factory/forms/CreateDenom.tsx`, the submit button is intentionally placed outside the `Form` component for stylistic reasons, as per the user's preference, even if it requires some workarounds.
🪛 Biome (1.9.4)
components/factory/forms/CreateDenom.tsx

[error] 51-51: 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)

🔇 Additional comments (4)
components/factory/forms/CreateDenom.tsx (4)

65-66: Verify UX impact of delayed validation

Disabling validation on change and blur means users won't get immediate feedback. While this might reduce unnecessary simulations, it could impact user experience.

Consider enabling validation for basic rules (length, required) while keeping simulation validation on submit only.


89-89: LGTM!

Good practice to clear errors on input change to avoid showing stale error messages.


149-149: LGTM!

Adding type="submit" improves HTML semantics while maintaining the intentional button placement outside the Form component.


30-30: Verify prefix handling

While adding the 'u' prefix is correct, consider validating that the subdenom doesn't already start with 'u' to prevent potential double prefixing.

✅ Verification successful

Prefix handling is correctly implemented

The current implementation follows the codebase's consistent pattern where subdenom is stored without prefix in formData and the 'u' prefix is added only when needed. The validation logic and related components already handle prefix management appropriately.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any existing uses of the subdenom to ensure consistent prefix handling
rg -l "formData\.subdenom" | xargs rg "u.*formData\.subdenom"

Length of output: 723


Script:

#!/bin/bash
# Check getDenomInfo implementation and validation rules
ast-grep --pattern 'function getDenomInfo($_) { $$$ }'
rg -A 5 "subdenom.*validation|validation.*subdenom"

Length of output: 717


Script:

#!/bin/bash
# Search for TokenDetailsSchema implementation and related validation
ast-grep --pattern 'const TokenDetailsSchema = $_'
rg -A 10 "TokenDetailsSchema.*="

Length of output: 5779

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.

2 participants