From 560f63847ee308813d677dcba21c4531c17a94f2 Mon Sep 17 00:00:00 2001 From: Will O'Beirne Date: Mon, 25 Feb 2019 14:46:47 -0500 Subject: [PATCH] More considerations for anonymous contributions on the frontend. --- backend/grant/proposal/models.py | 5 ++++ .../ContributionModal/PaymentInfo.tsx | 23 ++++++++++++++----- .../components/ContributionModal/index.tsx | 23 +++++++++++++------ frontend/types/contribution.ts | 1 + 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index 664437a0..fa671fa2 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -715,12 +715,14 @@ class ProposalContributionSchema(ma.Schema): "amount", "date_created", "addresses", + "is_anonymous", ) proposal = ma.Nested("ProposalSchema") user = ma.Nested("UserSchema", default=anonymous_user) date_created = ma.Method("get_date_created") addresses = ma.Method("get_addresses") + is_anonymous = ma.Method("get_is_anonymous") def get_date_created(self, obj): return dt_to_unix(obj.date_created) @@ -732,6 +734,9 @@ class ProposalContributionSchema(ma.Schema): return { 'transparent': addresses['transparent'], } + + def get_is_anonymous(self, obj): + return not obj.user @post_dump def stub_anonymous_user(self, data): diff --git a/frontend/client/components/ContributionModal/PaymentInfo.tsx b/frontend/client/components/ContributionModal/PaymentInfo.tsx index ed8a0df0..654958ae 100644 --- a/frontend/client/components/ContributionModal/PaymentInfo.tsx +++ b/frontend/client/components/ContributionModal/PaymentInfo.tsx @@ -26,8 +26,9 @@ export default class PaymentInfo extends React.Component { }; render() { - const { contribution, text } = this.props; + const { contribution } = this.props; const { sendType } = this.state; + let text = this.props.text; let address; let memo; let amount; @@ -103,14 +104,24 @@ export default class PaymentInfo extends React.Component { ); } + if (!text) { + if (contribution && contribution.isAnonymous) { + text = ` + Thank you for contributing! Just send using whichever method works best for + you, and your contribution will show up anonymously once it's been confirmed. + ` + } else { + text = ` + Thank you for contributing! Just send using whichever method works best for + you, and we'll let you know once it's been confirmed. + `; + } + } + return (
- {text || - ` - Thank you for contributing! Just send using whichever method works best for - you, and we'll let you know when your contribution has been confirmed. - `} + {text}
{ } // If contribution is provided, update it if (contribution !== this.props.contribution) { + this.setState({ contribution: contribution || null }); + } + // When the modal is closed, clear out the contribution and anonymous check + if (this.props.isVisible && !isVisible) { this.setState({ - contribution: contribution || null, - hasConfirmedAnonymous: contribution - ? !!contribution.user.userid - : nextState.hasConfirmedAnonymous, + contribution: null, + hasConfirmedAnonymous: false, }); } } @@ -113,9 +115,16 @@ export default class ContributionModal extends React.Component { title="Thank you for your contribution!" description={ <> - Your contribution should be confirmed in about 20 minutes. You can keep an - eye on it at the{' '} - funded tab on your profile. + Your transaction should be confirmed in about 20 minutes.{' '} + {isAnonymous + ? 'Once it’s confirmed, it’ll show up in the contributions tab.' + : ( + <> + You can keep an eye on it at the{' '} + funded tab on your profile. + + ) + } } style={{ width: '90%' }} diff --git a/frontend/types/contribution.ts b/frontend/types/contribution.ts index fb2f8132..e72b8a2f 100644 --- a/frontend/types/contribution.ts +++ b/frontend/types/contribution.ts @@ -7,6 +7,7 @@ export interface Contribution { amount: string; dateCreated: number; status: 'PENDING' | 'CONFIRMED'; + isAnonymous: boolean; } export interface ContributionWithAddresses extends Contribution {