diff --git a/backend/grant/proposal/models.py b/backend/grant/proposal/models.py index 22a44834..148f68bb 100644 --- a/backend/grant/proposal/models.py +++ b/backend/grant/proposal/models.py @@ -517,12 +517,13 @@ class Proposal(db.Model): 'support_url': make_url('/contact'), }) for c in self.contributions: - send_email(c.user.email_address, 'contribution_proposal_canceled', { - 'contribution': c, - 'proposal': self, - 'refund_address': c.user.settings.refund_address, - 'account_settings_url': make_url('/profile/settings?tab=account') - }) + if c.user: + send_email(c.user.email_address, 'contribution_proposal_canceled', { + 'contribution': c, + 'proposal': self, + 'refund_address': c.user.settings.refund_address, + 'account_settings_url': make_url('/profile/settings?tab=account') + }) @hybrid_property def contributed(self): diff --git a/backend/grant/proposal/views.py b/backend/grant/proposal/views.py index de00e6e3..89839345 100644 --- a/backend/grant/proposal/views.py +++ b/backend/grant/proposal/views.py @@ -461,15 +461,15 @@ def get_proposal_contributions(proposal_id): @blueprint.route("//contributions/", methods=["GET"]) def get_proposal_contribution(proposal_id, contribution_id): proposal = Proposal.query.filter_by(id=proposal_id).first() - if proposal: - contribution = ProposalContribution.query.filter_by(id=contribution_id).first() - if contribution: - return proposal_contribution_schema.dump(contribution) - else: - return {"message": "No contribution matching id"} - else: + if not proposal: return {"message": "No proposal matching id"}, 404 + contribution = ProposalContribution.query.filter_by(id=contribution_id).first() + if not contribution: + return {"message": "No contribution matching id"}, 404 + + return proposal_contribution_schema.dump(contribution) + @blueprint.route("//contributions", methods=["POST"]) # TODO add gaurd (minimum, maximum) diff --git a/frontend/client/components/Profile/ProfileContribution.tsx b/frontend/client/components/Profile/ProfileContribution.tsx index 1fb97adc..5863e792 100644 --- a/frontend/client/components/Profile/ProfileContribution.tsx +++ b/frontend/client/components/Profile/ProfileContribution.tsx @@ -8,6 +8,7 @@ import { formatTxExplorerUrl } from 'utils/formatters'; import { deleteContribution } from 'modules/users/actions'; import { UserContribution } from 'types'; import './ProfileContribution.less'; +import { PROPOSAL_STAGE } from 'api/constants'; interface OwnProps { userId: number; @@ -26,7 +27,10 @@ class ProfileContribution extends React.Component { const { contribution } = this.props; const { proposal } = contribution; const isConfirmed = contribution.status === 'CONFIRMED'; - const isExpired = !isConfirmed && contribution.dateCreated < Date.now() / 1000 - ONE_DAY; + const isExpired = + (!isConfirmed && contribution.dateCreated < Date.now() / 1000 - ONE_DAY) || + (proposal.stage === PROPOSAL_STAGE.CANCELED || + proposal.stage === PROPOSAL_STAGE.FAILED); let tag; let actions: React.ReactNode; @@ -43,15 +47,14 @@ class ProfileContribution extends React.Component { } else if (isExpired) { tag = Expired; // TODO: Link to support - actions = <> - - Delete - - Contact support - ; + actions = ( + <> + + Delete + + Contact support + + ); } else { tag = Pending; actions = ( @@ -76,9 +79,7 @@ class ProfileContribution extends React.Component {
+
-
- {actions} -
+
{actions}
); @@ -89,6 +90,9 @@ class ProfileContribution extends React.Component { }; } -export default connect<{}, DispatchProps, OwnProps, {}>(undefined, { - deleteContribution, -})(ProfileContribution); +export default connect<{}, DispatchProps, OwnProps, {}>( + undefined, + { + deleteContribution, + }, +)(ProfileContribution);