-
Notifications
You must be signed in to change notification settings - Fork 18
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
prevent duplicate tokens being added in adminJS #1851
Conversation
WalkthroughThe changes in this pull request focus on the Changes
Possibly related PRs
Suggested reviewers
Poem
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: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (1)
- src/server/adminJs/tabs/tokenTab.ts (1 hunks)
🔇 Additional comments (3)
src/server/adminJs/tabs/tokenTab.ts (3)
133-142
: Validation for required fields is appropriateThe code correctly checks that all required fields (
address
,decimals
,name
,networkId
, andsymbol
) are provided before proceeding, which helps prevent incomplete data from being processed.
143-149
: Duplicate address check ensures uniquenessThe query effectively checks for an existing token with the same address and network ID, using case-insensitive comparison to prevent duplicate entries.
150-156
: Duplicate symbol check ensures uniquenessThe query appropriately checks for an existing token with the same symbol and network ID, ensuring that token symbols remain unique within the network.
if (duplicateSymbol || duplicateAddress) { | ||
message = `Token ${ | ||
duplicateAddress ? 'address' : 'symbol' | ||
} already exists!`; | ||
type = 'danger'; | ||
return { | ||
record: {}, | ||
notice: { | ||
message, | ||
type, | ||
}, | ||
}; | ||
} |
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.
Improve error messaging when both address and symbol already exist
Currently, if both duplicateAddress
and duplicateSymbol
are true, the error message will only mention the address due to the conditional operator. This could confuse users if both the address and symbol are duplicates.
Consider updating the error message to inform the user when both the address and symbol already exist. Here's a suggested modification:
if (duplicateSymbol || duplicateAddress) {
- message = `Token ${
- duplicateAddress ? 'address' : 'symbol'
- } already exists!`;
+ if (duplicateAddress && duplicateSymbol) {
+ message = 'Token address and symbol already exist!';
+ } else if (duplicateAddress) {
+ message = 'Token address already exists!';
+ } else if (duplicateSymbol) {
+ message = 'Token symbol already exists!';
+ }
type = 'danger';
return {
record: {},
notice: {
message,
type,
},
};
}
This change provides clearer feedback to the user, specifying exactly which fields are causing the duplication issue.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if (duplicateSymbol || duplicateAddress) { | |
message = `Token ${ | |
duplicateAddress ? 'address' : 'symbol' | |
} already exists!`; | |
type = 'danger'; | |
return { | |
record: {}, | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} | |
if (duplicateSymbol || duplicateAddress) { | |
if (duplicateAddress && duplicateSymbol) { | |
message = 'Token address and symbol already exist!'; | |
} else if (duplicateAddress) { | |
message = 'Token address already exists!'; | |
} else if (duplicateSymbol) { | |
message = 'Token symbol already exists!'; | |
} | |
type = 'danger'; | |
return { | |
record: {}, | |
notice: { | |
message, | |
type, | |
}, | |
}; | |
} |
#1777
Summary by CodeRabbit
New Features
Bug Fixes