-
Notifications
You must be signed in to change notification settings - Fork 119
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
fix: boost token #885
Conversation
@Abeeujah is attempting to deploy a commit to the LFG Labs Team on Vercel. A member of the Team first needs to authorize it. |
Caution Review failedThe pull request is closed. WalkthroughThe pull request modifies the Changes
Assessment against linked issues
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 improvementThe 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 displayWhile the dropdown options now correctly use token addresses as values, there are a couple of areas that need attention to fully implement this change:
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.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:
- The correct token decimals are set based on the selected token.
- The
token
property inboostInput
remains a token name for consistency.- The dropdown correctly displays the selected token based on its address.
Also applies to: 141-150
Line range hint
1-180
: General suggestions for improvementThe component looks well-structured and the changes address the main issue. Here are some suggestions for further improvement:
Consider using TypeScript's
as const
assertion forTOKEN_ADDRESS_MAP
andTOKEN_DECIMAL_MAP
to improve type inference and catch potential errors at compile-time.The
any
type insetBoostInput
could be replaced with a more specific type to improve type safety.Consider extracting the boost-related form fields into a separate component to improve code organization and reusability.
Add prop-types or TypeScript interface for the component props to improve documentation and type checking.
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
📒 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 toTOKEN_ADDRESS_MAP
The explicit type annotation
Record<string, Record<string, string>>
forTOKEN_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:
- Improved static type checking, reducing potential type-related errors.
- Enhanced developer experience with better IDE support and auto-completion.
- Clear documentation of the expected structure of the
TOKEN_ADDRESS_MAP
.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm!
Bugfix
Please add the labels corresponding to the type of changes your PR introduces:
Resolves: #882
Context
Summary by CodeRabbit
New Features
amount
,num_of_winners
,token_decimals
) to boost input handling for improved data processing.Bug Fixes
RewardDetailsForm
component.Documentation
TOKEN_ADDRESS_MAP
constant for better clarity on its structure.