Skip to content

Commit 62357f2

Browse files
The whole happy workflow works.
1 parent c515442 commit 62357f2

6 files changed

+115
-390
lines changed

src/components/ApproveRejectMilestoneCompletionButtons.jsx

+59-137
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
/* eslint-disable react/no-unescaped-entities */
22
import React, { Component, Fragment } from 'react';
33
import PropTypes from 'prop-types';
4-
import BigNumber from 'bignumber.js';
54

65
import Milestone from 'models/Milestone';
76
import User from 'models/User';
87
import MilestoneService from 'services/MilestoneService';
98
import ErrorPopup from 'components/ErrorPopup';
109
import ConversationModal from 'components/ConversationModal';
11-
import GA from 'lib/GoogleAnalytics';
12-
import { checkBalance } from 'lib/middleware';
1310

1411
class ApproveRejectMilestoneCompletionButtons extends Component {
1512
constructor() {
@@ -18,145 +15,72 @@ class ApproveRejectMilestoneCompletionButtons extends Component {
1815
}
1916

2017
approveMilestoneCompleted() {
21-
const { milestone, currentUser, balance } = this.props;
18+
const { milestone } = this.props;
2219

23-
checkBalance(balance)
24-
.then(() => {
25-
this.conversationModal.current
26-
.openModal({
27-
title: 'Approve milestone completion',
28-
description:
29-
'Optionally explain why you approve the completion of this milestone. Compliments are appreciated! This information will be publicly visible and emailed to the milestone owner.',
30-
textPlaceholder:
31-
'Optionally explain why you approve the completion of this milestone...',
32-
required: false,
33-
cta: 'Approve completion',
34-
enableAttachProof: false,
35-
})
36-
.then(proof => {
37-
MilestoneService.approveMilestoneCompletion({
38-
milestone,
39-
from: currentUser.address,
40-
proof,
41-
onTxHash: txUrl => {
42-
GA.trackEvent({
43-
category: 'Milestone',
44-
action: 'approved completion',
45-
label: milestone._id,
46-
});
47-
48-
React.toast.info(
49-
<p>
50-
Approving this milestone is pending...
51-
<br />
52-
<a href={txUrl} target="_blank" rel="noopener noreferrer">
53-
View transaction
54-
</a>
55-
</p>,
56-
);
57-
},
58-
onConfirmation: txUrl => {
59-
React.toast.success(
60-
<p>
61-
The milestone has been approved!
62-
<br />
63-
<a href={txUrl} target="_blank" rel="noopener noreferrer">
64-
View transaction
65-
</a>
66-
</p>,
67-
);
68-
},
69-
onError: (err, txUrl) => {
70-
if (err === 'patch-error') {
71-
ErrorPopup(
72-
"Something went wrong with approving this milestone's completion",
73-
err,
74-
);
75-
} else {
76-
ErrorPopup(
77-
'Something went wrong with the transaction.',
78-
`${txUrl} => ${JSON.stringify(err, null, 2)}`,
79-
);
80-
}
81-
},
82-
});
83-
});
20+
this.conversationModal.current
21+
.openModal({
22+
title: 'Approve milestone completion',
23+
description:
24+
'Optionally explain why you approve the completion of this milestone. Compliments are appreciated! This information will be publicly visible and emailed to the milestone owner.',
25+
textPlaceholder: 'Optionally explain why you approve the completion of this milestone...',
26+
required: false,
27+
cta: 'Approve completion',
28+
enableAttachProof: false,
8429
})
85-
.catch(err => {
86-
if (err === 'noBalance') {
87-
// handle no balance error
88-
}
30+
.then(proof => {
31+
MilestoneService.approveMilestoneCompletion({
32+
milestone,
33+
proof,
34+
onConfirmation: txUrl => {
35+
React.toast.success(
36+
<p>
37+
The milestone has been approved!
38+
<br />
39+
<a href={txUrl} target="_blank" rel="noopener noreferrer">
40+
View transaction
41+
</a>
42+
</p>,
43+
);
44+
},
45+
onError: err => {
46+
ErrorPopup('Failed to approve milestone completion', err);
47+
},
48+
});
8949
});
9050
}
9151

9252
rejectMilestoneCompleted() {
93-
const { milestone, currentUser } = this.props;
94-
95-
checkBalance(this.props.balance)
96-
.then(() => {
97-
this.conversationModal.current
98-
.openModal({
99-
title: 'Reject milestone completion',
100-
description:
101-
'Explain why you rejected the completion of this milestone. This information will be publicly visible and emailed to the milestone owner.',
102-
textPlaceholder: 'Explain why you rejected the completion of this milestone...',
103-
required: true,
104-
cta: 'Reject completion',
105-
enableAttachProof: false,
106-
})
107-
.then(proof => {
108-
MilestoneService.rejectMilestoneCompletion({
109-
milestone,
110-
from: currentUser.address,
111-
proof,
112-
onTxHash: txUrl => {
113-
GA.trackEvent({
114-
category: 'Milestone',
115-
action: 'rejected completion',
116-
label: milestone._id,
117-
});
53+
const { milestone } = this.props;
11854

119-
React.toast.info(
120-
<p>
121-
Rejecting this milestone's completion is pending...
122-
<br />
123-
<a href={txUrl} target="_blank" rel="noopener noreferrer">
124-
View transaction
125-
</a>
126-
</p>,
127-
);
128-
},
129-
onConfirmation: txUrl => {
130-
React.toast.success(
131-
<p>
132-
The milestone's completion has been rejected.
133-
<br />
134-
<a href={txUrl} target="_blank" rel="noopener noreferrer">
135-
View transaction
136-
</a>
137-
</p>,
138-
);
139-
},
140-
onError: (err, txUrl) => {
141-
if (err === 'patch-error') {
142-
ErrorPopup(
143-
"Something went wrong with rejecting this milestone's completion",
144-
err,
145-
);
146-
} else {
147-
ErrorPopup(
148-
'Something went wrong with the transaction.',
149-
`${txUrl} => ${JSON.stringify(err, null, 2)}`,
150-
);
151-
}
152-
},
153-
});
154-
});
55+
this.conversationModal.current
56+
.openModal({
57+
title: 'Reject milestone completion',
58+
description:
59+
'Explain why you rejected the completion of this milestone. This information will be publicly visible and emailed to the milestone owner.',
60+
textPlaceholder: 'Explain why you rejected the completion of this milestone...',
61+
required: true,
62+
cta: 'Reject completion',
63+
enableAttachProof: false,
15564
})
156-
.catch(err => {
157-
if (err === 'noBalance') {
158-
// handle no balance error
159-
}
65+
.then(proof => {
66+
MilestoneService.rejectMilestoneCompletion({
67+
milestone,
68+
proof,
69+
onConfirmation: txUrl => {
70+
React.toast.success(
71+
<p>
72+
The milestone's completion has been rejected.
73+
<br />
74+
<a href={txUrl} target="_blank" rel="noopener noreferrer">
75+
View transaction
76+
</a>
77+
</p>,
78+
);
79+
},
80+
onError: err => {
81+
ErrorPopup('Failed to reject milestone completion', err);
82+
},
83+
});
16084
});
16185
}
16286

@@ -167,8 +91,7 @@ class ApproveRejectMilestoneCompletionButtons extends Component {
16791
<Fragment>
16892
{currentUser &&
16993
milestone.reviewerAddress === currentUser.address &&
170-
milestone.status === 'NeedsReview' &&
171-
milestone.mined && (
94+
milestone.status === 'NeedsReview' && (
17295
<span>
17396
<button
17497
type="button"
@@ -198,7 +121,6 @@ class ApproveRejectMilestoneCompletionButtons extends Component {
198121

199122
ApproveRejectMilestoneCompletionButtons.propTypes = {
200123
currentUser: PropTypes.instanceOf(User).isRequired,
201-
balance: PropTypes.instanceOf(BigNumber).isRequired,
202124
milestone: PropTypes.instanceOf(Milestone).isRequired,
203125
};
204126

0 commit comments

Comments
 (0)