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

fix: boost token #885

Merged
merged 3 commits into from
Oct 17, 2024
Merged

fix: boost token #885

merged 3 commits into from
Oct 17, 2024

Conversation

ooochoche
Copy link

@ooochoche ooochoche commented Oct 16, 2024

Bugfix

Please add the labels corresponding to the type of changes your PR introduces:

  • Bugfix

Resolves: #882

Context

  • The token address is sent instead of the token name
  • The token type changes successfully instead of reverting back to "USDC"

Summary by CodeRabbit

  • New Features

    • Enhanced dropdown for selecting boost tokens to display the correct token address based on the selected network.
    • Added new properties (amount, num_of_winners, token_decimals) to boost input handling for improved data processing.
  • Bug Fixes

    • Corrected the value mapping for dropdown options in the RewardDetailsForm component.
    • Refined error handling to ensure consistent number conversion for boost input values.
  • Documentation

    • Improved type annotation for the TOKEN_ADDRESS_MAP constant for better clarity on its structure.

Copy link

vercel bot commented Oct 16, 2024

@Abeeujah is attempting to deploy a commit to the LFG Labs Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request modifies the RewardDetailsForm component to improve the handling of token values in the dropdown for selecting boost tokens. The value assigned to the dropdown options is changed to reference the correct token address based on the selected network. Additionally, the TOKEN_ADDRESS_MAP constant is updated to include an explicit type annotation, enhancing clarity regarding its structure. No other changes to the component's logic or exported entities are made.

Changes

File Path Change Summary
components/admin/formSteps/RewardDetailsForm.tsx Updated dropdown value assignment to use TOKEN_ADDRESS_MAP[network][eachItem] for correct token address. Updated handleBoostTokenChange function to retrieve tokenAddress and tokenName correctly. Modified useCallback dependency to include network.
constants/common.ts Added explicit type annotation to TOKEN_ADDRESS_MAP, changing it to Record<string, Record<string, string>>.
app/admin/quests/dashboard/[questId]/page.tsx Updated boostInput state to include amount, num_of_winners, and token_decimals. Refined error handling in handleUpdateBoost and adjusted handleCreateBoost to incorporate new properties.

Assessment against linked issues

Objective Addressed Explanation
Update dropdown to use token address instead of name (#[882])
Ensure correct token address is sent to API (#[882]) The implementation does not address API request changes.
Fix issue of always showing "USDC" in dropdown (#[882]) It is unclear if the dropdown now reflects the selected token correctly.

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 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
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 and nitpick comments (4)
constants/common.ts (1)

Line range hint 35-46: Overall impact is positive with room for minor improvement

The addition of the type annotation to TOKEN_ADDRESS_MAP is a positive change that enhances type safety and code readability without affecting runtime behavior. This aligns well with the PR's objective of improving token handling, albeit indirectly.

To further improve the code, consider the following suggestion:

Consider creating a custom type for the token map structure. This would make the code even more self-documenting and reusable. For example:

type NetworkTokenMap = Record<string, string>;
type TokenAddressMap = Record<string, NetworkTokenMap>;

export const TOKEN_ADDRESS_MAP: TokenAddressMap = {
  // ... (existing content)
};

This approach would allow you to reuse these types if needed elsewhere in the codebase.

components/admin/formSteps/RewardDetailsForm.tsx (3)

145-147: Approved: Token address is now correctly used as the dropdown value.

This change successfully addresses the issue of sending the token address instead of the token name to the API. It aligns with the PR objectives and should resolve the problem described in issue #882.

Consider adding a fallback or error handling in case TOKEN_ADDRESS_MAP[network][eachItem] is undefined:

value: TOKEN_ADDRESS_MAP[network][eachItem] || eachItem,

This ensures that even if a token address is not found for the current network, the dropdown will still have a valid value (the token name), preventing potential runtime errors.


Line range hint 52-66: Ensure consistency between token selection and token name display

While the dropdown options now correctly use token addresses as values, there are a couple of areas that need attention to fully implement this change:

  1. In the handleBoostTokenChange function:

    • The token_decimals lookup should use the token address, not the token name.
    • The token property should be set to the token name for consistency with the rest of the component.
  2. The dropdown's value prop should use the token address, not the token name.

Here are the suggested changes:

const handleBoostTokenChange = useCallback(
  (event: SelectChangeEvent) => {
    const tokenAddress = event.target.value;
    const tokenName = Object.keys(TOKEN_ADDRESS_MAP[network]).find(
      (key) => TOKEN_ADDRESS_MAP[network][key] === tokenAddress
    ) || '';
    setBoostInput((prev: any) => ({
      ...prev,
      token: tokenName,
      token_decimals: TOKEN_DECIMAL_MAP[tokenName as keyof typeof TOKEN_DECIMAL_MAP],
    }));
  },
  [setBoostInput, network]
);

// In the Dropdown component
<Dropdown
  value={boostInput?.token ? TOKEN_ADDRESS_MAP[network][boostInput.token] : ""}
  // ... other props
/>

These changes ensure that:

  1. The correct token decimals are set based on the selected token.
  2. The token property in boostInput remains a token name for consistency.
  3. The dropdown correctly displays the selected token based on its address.

Also applies to: 141-150


Line range hint 1-180: General suggestions for improvement

The component looks well-structured and the changes address the main issue. Here are some suggestions for further improvement:

  1. Consider using TypeScript's as const assertion for TOKEN_ADDRESS_MAP and TOKEN_DECIMAL_MAP to improve type inference and catch potential errors at compile-time.

  2. The any type in setBoostInput could be replaced with a more specific type to improve type safety.

  3. Consider extracting the boost-related form fields into a separate component to improve code organization and reusability.

  4. Add prop-types or TypeScript interface for the component props to improve documentation and type checking.

  5. Consider using a form library like Formik or react-hook-form to manage form state and validation more efficiently.

These suggestions are not critical for the current PR but could be considered for future improvements to enhance the overall code quality and maintainability of the component.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 420026d and c98d2c9.

📒 Files selected for processing (2)
  • components/admin/formSteps/RewardDetailsForm.tsx (1 hunks)
  • constants/common.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (1)
constants/common.ts (1)

Line range hint 35-46: Excellent addition of type annotation to TOKEN_ADDRESS_MAP

The explicit type annotation Record<string, Record<string, string>> for TOKEN_ADDRESS_MAP is a great improvement. It enhances code readability, provides better type checking, and aligns with TypeScript best practices for complex object structures.

This change offers the following benefits:

  1. Improved static type checking, reducing potential type-related errors.
  2. Enhanced developer experience with better IDE support and auto-completion.
  3. Clear documentation of the expected structure of the TOKEN_ADDRESS_MAP.

Copy link

vercel bot commented Oct 16, 2024

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

Name Status Preview Comments Updated (UTC)
sepolia-starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2024 9:34am
starknet-quest ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 17, 2024 9:34am

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

It looks good, but it doesn't save the selected option. When creating the quest I got an error in the request: Token decimals missing. When editing the quest after reloading, when I tried again adding the boost, there were just no requests.

Copy link
Collaborator

@Marchand-Nicolas Marchand-Nicolas left a comment

Choose a reason for hiding this comment

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

Lgtm!

@Marchand-Nicolas Marchand-Nicolas merged commit ca3ee66 into lfglabs-dev:testnet Oct 17, 2024
1 of 3 checks passed
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.

Fix boost token
3 participants