From 339705207a8d8f3eb0e2b078adeaf66c4a6063b0 Mon Sep 17 00:00:00 2001 From: William O'Beirne Date: Thu, 28 Mar 2019 13:25:34 -0400 Subject: [PATCH] Default target to '0' (#413) * Default proposal target to zero instead of None * Add frontend validation and 1 ZEC minimum --- backend/grant/proposal/models.py | 2 +- frontend/client/components/CreateFlow/Basics.tsx | 6 ++++++ frontend/client/modules/create/utils.ts | 2 +- frontend/client/utils/validators.ts | 4 +++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index 050a268e..84f610fa 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -405,7 +405,7 @@ class Proposal(db.Model): self.brief = brief[:255] self.category = category self.content = content[:300000] - self.target = target[:255] if target != '' else None + self.target = target[:255] if target != '' else '0' self.payout_address = payout_address[:255] self.deadline_duration = deadline_duration Proposal.simple_validate(vars(self)) diff --git a/frontend/client/components/CreateFlow/Basics.tsx b/frontend/client/components/CreateFlow/Basics.tsx index 2abbf5cf..cc205969 100644 --- a/frontend/client/components/CreateFlow/Basics.tsx +++ b/frontend/client/components/CreateFlow/Basics.tsx @@ -68,6 +68,12 @@ class CreateFlowBasics extends React.Component { const { title, brief, category, target, rfp, rfpOptIn } = this.state; const errors = getCreateErrors(this.state, true); + // Don't show target error at zero since it defaults to that + // Error just shows up at the end to prevent submission + if (target === '0') { + errors.target = undefined; + } + const rfpOptInRequired = rfp && (rfp.matching || (rfp.bounty && new BN(rfp.bounty).gtn(0))); diff --git a/frontend/client/modules/create/utils.ts b/frontend/client/modules/create/utils.ts index bbcd51eb..8ef9a107 100644 --- a/frontend/client/modules/create/utils.ts +++ b/frontend/client/modules/create/utils.ts @@ -107,7 +107,7 @@ export function getCreateErrors( const targetFloat = target ? parseFloat(target) : 0; if (target && !Number.isNaN(targetFloat)) { const limit = parseFloat(process.env.PROPOSAL_TARGET_MAX as string); - const targetErr = getAmountError(targetFloat, limit); + const targetErr = getAmountError(targetFloat, limit, 1); if (targetErr) { errors.target = targetErr; } diff --git a/frontend/client/utils/validators.ts b/frontend/client/utils/validators.ts index e7cd7957..0fa80bf4 100644 --- a/frontend/client/utils/validators.ts +++ b/frontend/client/utils/validators.ts @@ -1,4 +1,4 @@ -export function getAmountError(amount: number, max: number = Infinity) { +export function getAmountError(amount: number, max: number = Infinity, min?: number) { if (amount < 0) { return 'Amount must be a positive number'; } else if ( @@ -8,6 +8,8 @@ export function getAmountError(amount: number, max: number = Infinity) { return 'Must be in increments of 0.001'; } else if (amount > max) { return `Cannot exceed maximum (${max} ZEC)`; + } else if (min && amount < min) { + return `Must be at least ${min} ZEC`; } return null;