Skip to content

Commit

Permalink
fix: remove typechecks which are already defined and handle singular/…
Browse files Browse the repository at this point in the history
…plural Id's alert msg

Simplify code by removing redundant typeof check, Update alert message to handle singular and plural
cases appropriately.
  • Loading branch information
tanyas-codes committed Feb 19, 2024
1 parent 181fa86 commit 5e4dbe7
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions apps/dashboard/src/components/add-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,28 +73,31 @@ export default function AddMemberModal({
}
if (group.type === "on-chain" && group.members) {
const existingMembers = new Set(
group.members.map((memberId) =>
typeof memberId === "string" ? BigInt(memberId) : memberId
)
group.members.map((memberId) => BigInt(memberId))
)

const conflictingMembers = []

for (const memberId of memberIds) {
const parsedMemberId =
typeof memberId === "string" ? BigInt(memberId) : memberId
const parsedMemberId = BigInt(memberId)

if (existingMembers.has(parsedMemberId)) {
conflictingMembers.push(parsedMemberId)
}
}

if (conflictingMembers.length > 0) {
alert(
`Member IDs ${conflictingMembers.join(
", "
)} already exist in the group.`
)
if (conflictingMembers.length === 1) {
alert(
`Member ID ${conflictingMembers[0]} already exists in the group.`
)
} else {
alert(
`Member IDs ${conflictingMembers.join(
", "
)} already exist in the group.`
)
}
return
}
}
Expand Down

0 comments on commit 5e4dbe7

Please sign in to comment.