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

Testnets #134

Merged
merged 2 commits into from
Nov 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/data/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ const sanitize = (res: MeQuery[]) => {
if (claimer.claimer?.currentRequest && claimer.claimer?.registration) {
if (claimer.claimer?.currentRequest.index <= -100) {
claimer.claimer.currentRequest = null;
} else {
} else if (res.filter((cl) => cl.claimer?.registration).length > 1) {
claimer.claimer.registration = null;
} else {
claimer.claimer.currentRequest = null;
}
Comment on lines +13 to 17
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Improve type safety and efficiency of the registration check

The current implementation could be more robust and efficient.

Consider these improvements:

-      } else if (res.filter((cl) => cl.claimer?.registration).length > 1) {
+      } else if (res.some((cl, index) => 
+        cl.claimer?.registration && 
+        res.some((other, otherIndex) => 
+          index !== otherIndex && other.claimer?.registration
+        )
+      )) {
         claimer.claimer.registration = null;
       } else {
         claimer.claimer.currentRequest = null;

This version:

  1. Stops at the first duplicate found (more efficient)
  2. More clearly expresses the intent to find duplicates
📝 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.

Suggested change
} else if (res.filter((cl) => cl.claimer?.registration).length > 1) {
claimer.claimer.registration = null;
} else {
claimer.claimer.currentRequest = null;
}
} else if (res.some((cl, index) =>
cl.claimer?.registration &&
res.some((other, otherIndex) =>
index !== otherIndex && other.claimer?.registration
)
)) {
claimer.claimer.registration = null;
} else {
claimer.claimer.currentRequest = null;
}

}
});
Expand Down
Loading