Skip to content

Commit

Permalink
Merge pull request #21 from decentraland/fix/contract-duplicates
Browse files Browse the repository at this point in the history
fix: Contract duplicates
  • Loading branch information
LautaroPetaccio authored Aug 5, 2024
2 parents 96b5d10 + 8c6fe5d commit 00c376f
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,18 @@ const UpdateThirdPartyForm = ({ thirdParty, canUpdate, isUpdating, isThirdPartyV
control={control}
rules={{
validate: (contracts: LinkedContract[]) => {
for (const contract of contracts) {
if (contracts.some(c => c.address === contract.address && c.network === contract.network)) {
return 'There are duplicated contracts in the list'
}
const hasDuplicated = contracts.reduce((acc, contract, index, contracts) => {
return (
acc ||
contracts.some(
(anotherContract, anotherIndex) =>
anotherContract.address === contract.address && anotherContract.network === contract.network && index !== anotherIndex
)
)
}, false)

if (hasDuplicated) {
return 'There are duplicated contracts in the list'
}
}
}}
Expand Down

0 comments on commit 00c376f

Please sign in to comment.