Skip to content

Commit

Permalink
Add warning for proposals containing known spam links
Browse files Browse the repository at this point in the history
  • Loading branch information
tombeynon committed Oct 24, 2023
1 parent 9fbf857 commit 37daf73
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/components/ProposalDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ function ProposalDetails(props) {
{error}
</AlertMessage>
}
{proposal.isSpam &&
<AlertMessage variant="danger" className="text-break small" dismissible={false}>
This proposal appears to be spam - do not click any links!
</AlertMessage>
}
<div className="row">
<div className="col-12 col-lg-6">
<Table>
Expand Down Expand Up @@ -155,7 +160,7 @@ function ProposalDetails(props) {
<div className="col">
<h5 className="mb-3">{title}</h5>
<ReactMarkdown
children={fixDescription}
children={fixDescription}
remarkPlugins={[remarkGfm]}
components={{
h1: 'h5',
Expand All @@ -173,4 +178,4 @@ function ProposalDetails(props) {
)
}

export default ProposalDetails
export default ProposalDetails
20 changes: 14 additions & 6 deletions src/components/Proposals.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import {
Button,
Nav,
} from 'react-bootstrap'
import { XCircle } from "react-bootstrap-icons";
import { XCircle, ExclamationTriangle } from "react-bootstrap-icons";

import ProposalProgress from './ProposalProgress';
import { PROPOSAL_STATUSES } from '../utils/Proposal.mjs';
import TooltipIcon from './TooltipIcon';

function Proposals(props) {
const { proposals, tallies, votes } = props
Expand Down Expand Up @@ -77,12 +78,19 @@ function Proposals(props) {
const proposalId = proposal.proposal_id
const vote = votes[proposalId]
return (
<tr key={proposalId}>
<tr key={proposalId} className={proposal.isSpam ? 'opacity-50' : ''}>
<td className="d-none d-md-table-cell">{proposalId}</td>
<td>
<span role="button" onClick={() => props.showProposal(proposal)}>
{proposal.title}
</span>
<div className="d-flex align-items-center">
<span role="button" onClick={() => props.showProposal(proposal)}>
{proposal.title}
</span>
{proposal.isSpam && (
<div className="ms-auto d-flex align-items-center text-danger">
<TooltipIcon icon={<ExclamationTriangle />} identifier={proposalId} tooltip="This proposal appears to be spam - do not click any links!" />
</div>
)}
</div>
</td>
<td className="d-none d-sm-table-cell text-center text-nowrap">
{proposal.statusHuman}
Expand All @@ -104,7 +112,7 @@ function Proposals(props) {
</td>
<td>
<div className="d-grid gap-2 d-md-flex justify-content-end">
<Button size="sm" onClick={() => props.showProposal(proposal)}>
<Button size="sm" variant={proposal.isSpam ? 'danger' : 'primary'} onClick={() => props.showProposal(proposal)}>
View
</Button>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/utils/Proposal.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export const PROPOSAL_STATUSES = {
'PROPOSAL_STATUS_FAILED': 'Failed'
}

export const PROPOSAL_SCAM_URLS = [
'v2terra.d',
'terrapro.a',
'cosmos-network.io'
]

const Proposal = (data) => {
let { proposal_id, content, messages, metadata } = data
if(!proposal_id && data.id) proposal_id = data.id
Expand All @@ -27,7 +33,7 @@ const Proposal = (data) => {
messages = messages.filter(el => el['@type'] !== '/cosmos.gov.v1.MsgExecLegacyContent')
typeHuman = messages.map(el => el['@type'].split('.').reverse()[0]).join(', ')
}

if(content){
title = title || content.title
description = description || content.description
Expand All @@ -37,10 +43,12 @@ const Proposal = (data) => {
title = title || typeHuman
description = description || metadata


const statusHuman = PROPOSAL_STATUSES[data.status]

const isDeposit = data.status === 'PROPOSAL_STATUS_DEPOSIT_PERIOD'
const isVoting = data.status === 'PROPOSAL_STATUS_VOTING_PERIOD'
const isSpam = PROPOSAL_SCAM_URLS.some(url => description && description.toLowerCase().includes(url))

return {
...data,
Expand All @@ -53,7 +61,8 @@ const Proposal = (data) => {
metadata,
messages,
isDeposit,
isVoting
isVoting,
isSpam
}
}

Expand Down

0 comments on commit 37daf73

Please sign in to comment.