Skip to content

Commit

Permalink
Merge pull request #394 from tanyas-codes/bug/onchain-id-checks
Browse files Browse the repository at this point in the history
fix: prevent manual addition of duplicate member IDs in on-chain groups
  • Loading branch information
vplasencia authored Feb 19, 2024
2 parents eeec708 + 5e4dbe7 commit ee2e151
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/dashboard/src/components/add-member-modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,36 @@ export default function AddMemberModal({
alert("Please ensure there are no repeated member IDs!")
return
}
if (group.type === "on-chain" && group.members) {
const existingMembers = new Set(
group.members.map((memberId) => BigInt(memberId))
)

const conflictingMembers = []

for (const memberId of memberIds) {
const parsedMemberId = BigInt(memberId)

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

if (conflictingMembers.length > 0) {
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
}
}

const confirmMessage = `
Are you sure you want to add the following members?
Expand Down

0 comments on commit ee2e151

Please sign in to comment.