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

fix: unique addresses validation #1222

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/back/routes/proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ import {
isValidUpdateProposalStatus,
} from '../../entities/Proposal/utils'
import { SNAPSHOT_DURATION } from '../../entities/Snapshot/constants'
import { validateUniqueAddresses } from '../../entities/Transparency/utils'
import UpdateModel from '../../entities/Updates/model'
import BidService from '../../services/BidService'
import { DiscourseService } from '../../services/DiscourseService'
Expand All @@ -83,7 +84,7 @@ import { ProposalInCreation, ProposalService } from '../../services/ProposalServ
import { getProfile } from '../../utils/Catalyst'
import Time from '../../utils/date/Time'
import { ErrorCategory } from '../../utils/errorCategories'
import { validateAddress, validateProposalId, validateUniqueAddresses } from '../utils/validations'
import { validateAddress, validateProposalId } from '../utils/validations'

export default routes((route) => {
const withAuth = auth()
Expand Down
6 changes: 0 additions & 6 deletions src/back/utils/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ export function validateAddress(address: string) {
}
}

export function validateUniqueAddresses(addresses: string[]): boolean {
const uniqueSet = new Set(addresses.map((address) => address.toLowerCase()))

return uniqueSet.size === addresses.length
}

export function validateProposalSnapshotId(proposalSnapshotId?: string) {
if (!proposalSnapshotId || proposalSnapshotId.length === 0) {
throw new RequestError('Invalid snapshot id')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import { Modal, ModalProps } from 'decentraland-ui/dist/components/Modal/Modal'
import Icon from 'semantic-ui-react/dist/commonjs/elements/Icon'
import isEthereumAddress from 'validator/lib/isEthereumAddress'

import { validateUniqueAddresses } from '../../../back/utils/validations'
import { Governance } from '../../../clients/Governance'
import { ProposalAttributes, ProposalStatus, ProposalType } from '../../../entities/Proposal/types'
import { validateUniqueAddresses } from '../../../entities/Transparency/utils'
import useFormatMessage from '../../../hooks/useFormatMessage'
import Label from '../../Common/Typography/Label'
import Markdown from '../../Common/Typography/Markdown'
Expand Down
5 changes: 5 additions & 0 deletions src/entities/Transparency/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,8 @@ export function blockExplorerLink(wallet: TokenInWallet): BlockExplorerLink {
return { name: '', link: '/' }
}
}

export function validateUniqueAddresses(addresses: string[]): boolean {
const uniqueSet = new Set(addresses.map((address) => address.toLowerCase()))
return uniqueSet.size === addresses.length
}
Loading