Skip to content

Commit

Permalink
fix: move backend validation to utils so it can be imported from the …
Browse files Browse the repository at this point in the history
…front (#1222)
  • Loading branch information
1emu authored Aug 30, 2023
1 parent 5f1e7dd commit 9ec500f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
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
}

0 comments on commit 9ec500f

Please sign in to comment.