From ae62b726ce424bb0f051e9aba6ac8210a7737c76 Mon Sep 17 00:00:00 2001 From: William O'Beirne Date: Sat, 23 Feb 2019 15:19:33 -0500 Subject: [PATCH 1/2] Rip sprout out. (#254) --- backend/grant/proposal/models.py | 7 +- .../ContributionModal/PaymentInfo.tsx | 109 +++++++++++------- frontend/types/contribution.ts | 5 +- 3 files changed, 74 insertions(+), 47 deletions(-) diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index ca3d88a1..7e025e35 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -700,7 +700,12 @@ class ProposalContributionSchema(ma.Schema): return dt_to_unix(obj.date_created) def get_addresses(self, obj): - return blockchain_get('/contribution/addresses', {'contributionId': obj.id}) + # Omit 'memo' and 'sprout' for now + # TODO: Add back in 'sapling' when ready + addresses = blockchain_get('/contribution/addresses', {'contributionId': obj.id}) + return { + 'transparent': addresses['transparent'], + } proposal_contribution_schema = ProposalContributionSchema() diff --git a/frontend/client/components/ContributionModal/PaymentInfo.tsx b/frontend/client/components/ContributionModal/PaymentInfo.tsx index 8a2acb55..ed8a0df0 100644 --- a/frontend/client/components/ContributionModal/PaymentInfo.tsx +++ b/frontend/client/components/ContributionModal/PaymentInfo.tsx @@ -1,6 +1,6 @@ import React, { ReactNode } from 'react'; import classnames from 'classnames'; -import { Button, Form, Icon, Radio } from 'antd'; +import { Button, Form, Icon, Radio, Alert } from 'antd'; import { RadioChangeEvent } from 'antd/lib/radio'; import QRCode from 'qrcode.react'; import { formatZcashCLI, formatZcashURI } from 'utils/formatters'; @@ -22,7 +22,7 @@ interface State { export default class PaymentInfo extends React.Component { state: State = { - sendType: 'sprout', + sendType: 'transparent', }; render() { @@ -36,14 +36,73 @@ export default class PaymentInfo extends React.Component { if (contribution) { if (sendType !== 'transparent') { - memo = contribution.addresses.memo; + memo = 'Fix me'; + // memo = contribution.addresses.memo; } - address = contribution.addresses[sendType]; + // address = contribution.addresses[sendType]; + address = contribution.addresses.transparent; amount = contribution.amount; cli = formatZcashCLI(address, amount, memo); uri = formatZcashURI(address, amount, memo); } + let content; + if (sendType === 'sprout') { + content = ( + + ); + } else { + content = ( + <> +
+
+ + + + {!uri && } +
+
+ + +
+
+ +
+
+ + {memo && } +
+
+ +
+
+ + ); + } + return (
@@ -53,53 +112,15 @@ export default class PaymentInfo extends React.Component { you, and we'll let you know when your contribution has been confirmed. `}
- - Z Address (Private) T Address (Public) + Z Address (Private) - -
-
- - - - {!uri && } -
-
- - -
-
- -
-
- - {memo && } -
-
- -
-
+ {content}
); } diff --git a/frontend/types/contribution.ts b/frontend/types/contribution.ts index e79a143b..8e20dd50 100644 --- a/frontend/types/contribution.ts +++ b/frontend/types/contribution.ts @@ -11,9 +11,10 @@ export interface Contribution { export interface ContributionWithAddresses extends Contribution { addresses: { - sprout: string; transparent: string; - memo: string; + // TODO: Add sapling and memo in when ready + // sprout: string; + // memo: string; }; } From c35b62b6c46910503dfd1cffccb05827deab9ae1 Mon Sep 17 00:00:00 2001 From: William O'Beirne Date: Sat, 23 Feb 2019 15:33:19 -0500 Subject: [PATCH 2/2] Email subscription fixes (#243) * Lookup user email subscription settings by email instead of hoping a user is passed. * Functioning unsubscribe URLs --- backend/grant/email/send.py | 27 ++++++++++++-------- backend/grant/templates/emails/template.html | 2 +- backend/grant/templates/emails/template.txt | 2 +- frontend/client/utils/email.tsx | 4 +-- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/backend/grant/email/send.py b/backend/grant/email/send.py index aa759bbc..49458939 100644 --- a/backend/grant/email/send.py +++ b/backend/grant/email/send.py @@ -9,9 +9,9 @@ from .subscription_settings import EmailSubscription, is_subscribed default_template_args = { 'home_url': make_url('/'), - 'account_url': make_url('/user'), - 'email_settings_url': make_url('/settings'), - 'unsubscribe_url': make_url('/unsubscribe'), + 'account_url': make_url('/profile'), + 'email_settings_url': make_url('/profile/settings?tab=emails'), + 'unsubscribe_url': make_url('/profile/settings?tab=emails'), } @@ -113,6 +113,7 @@ def proposal_failed(email_args): 'preview': 'Your proposal entitled {} failed to get enough funding by the deadline'.format( email_args['proposal'].title, ), + 'subscription': EmailSubscription.MY_PROPOSAL_FUNDED, } @@ -267,7 +268,7 @@ get_info_lookup = { } -def generate_email(type, email_args): +def generate_email(type, email_args, user=None): info = get_info_lookup[type](email_args) body_text = render_template( 'emails/%s.txt' % (type), @@ -280,10 +281,15 @@ def generate_email(type, email_args): UI=UI, ) + template_args = { **default_template_args } + if user: + template_args['unsubscribe_url'] = make_url('/email/unsubscribe?code={}'.format(user.email_verification.code)) + + html = render_template( 'emails/template.html', args={ - **default_template_args, + **template_args, **info, 'body': Markup(body_html), }, @@ -292,7 +298,7 @@ def generate_email(type, email_args): text = render_template( 'emails/template.txt', args={ - **default_template_args, + **template_args, **info, 'body': body_text, }, @@ -310,17 +316,18 @@ def send_email(to, type, email_args): if current_app and current_app.config.get("TESTING"): return + from grant.user.models import User + user = User.get_by_email(to) info = get_info_lookup[type](email_args) - if 'subscription' in info and 'user' in email_args: - user = email_args['user'] + if user and 'subscription' in info: sub = info['subscription'] - if not is_subscribed(user.settings.email_subscriptions, sub): + if user and not is_subscribed(user.settings.email_subscriptions, sub): print(f'Ignoring send_email to {to} of type {type} because user is unsubscribed.') return try: - email = generate_email(type, email_args) + email = generate_email(type, email_args, user) sg = sendgrid.SendGridAPIClient(apikey=SENDGRID_API_KEY) mail = Mail( diff --git a/backend/grant/templates/emails/template.html b/backend/grant/templates/emails/template.html index bcc04745..e7d21a21 100644 --- a/backend/grant/templates/emails/template.html +++ b/backend/grant/templates/emails/template.html @@ -183,7 +183,7 @@

- Don’t want anymore emails? + Don’t want any more emails? Click here to unsubscribe diff --git a/backend/grant/templates/emails/template.txt b/backend/grant/templates/emails/template.txt index 2cd24b22..e90aef67 100644 --- a/backend/grant/templates/emails/template.txt +++ b/backend/grant/templates/emails/template.txt @@ -6,4 +6,4 @@ 123 Address Street City, ST 12345 -Unsubscribe here: {{ args.unsubscribe_url }} \ No newline at end of file +Don't want any more emails? Unsubscribe here: {{ args.unsubscribe_url }} \ No newline at end of file diff --git a/frontend/client/utils/email.tsx b/frontend/client/utils/email.tsx index 3319d620..b3b29a55 100644 --- a/frontend/client/utils/email.tsx +++ b/frontend/client/utils/email.tsx @@ -31,7 +31,7 @@ export const EMAIL_SUBSCRIPTIONS: { [key in ESKey]: EmailSubscriptionInfo } = { value: false, }, fundedProposalFunded: { - description: 'gets full funding', + description: 'gets fully funded or fails to get funding', category: EMAIL_SUBSCRIPTION_CATEGORY.FUNDED, value: false, }, @@ -63,7 +63,7 @@ export const EMAIL_SUBSCRIPTIONS: { [key in ESKey]: EmailSubscriptionInfo } = { value: false, }, myProposalFunded: { - description: 'gets fully funded', + description: 'gets fully funded or fails to get funding', category: EMAIL_SUBSCRIPTION_CATEGORY.PROPOSAL, value: false, },