Default target to '0' (#413)

* Default proposal target to zero instead of None

* Add frontend validation and 1 ZEC minimum
This commit is contained in:
William O'Beirne 2019-03-28 13:25:34 -04:00 committed by GitHub
parent edd2260423
commit 339705207a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 3 deletions

View File

@ -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))

View File

@ -68,6 +68,12 @@ class CreateFlowBasics extends React.Component<Props, State> {
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)));

View File

@ -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;
}

View File

@ -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;