on master help sign in
Do invite sending properly

Don't wait for transaction confirm to send the ticket off to the email sender.

commit877bc6ce8b6892d00ed7405ab3a6bb8b946359e0 authorFang <git@fang.io> dateThu 6 Jun 2019, 18:45 (7 years ago) parent71e9369
1 file changed+36−29
src/bridge/views/InvitesSend.js+36−29
src/bridge/views/InvitesSend.js+36−29
@@ -194,39 +194,46 @@ class InvitesSend extends React.Component {
194194
195195 for (let i = 0; i < invites.length; i++) {
196196 const invite = invites[i];
197− sendSignedTransaction(web3, Just(invite.signedTx), tankWasUsed, ()=>{})
198− .then(txHash => {
199− waitForTransactionConfirm(web3, txHash)
200− .then(async success => {
201− if (success) {
202− console.log('tx succeeded, sending mail', i);
203− success = await sendMail(
204− invite.recipient, invite.ticket, invite.rawTx
205− );
206− if (success) {
207− this.setEmailStatus(i, EMAIL_STATUS.DONE);
208− } else {
209− console.log('email send failed');
210− this.addError(
211− 'Invite email failed to send for ' + invite.recipient +
212− '. Please give them this ticket: ' + invite.ticket
213− );
214− //TODO but this doesn't catch sender-side failures... we may
215− // just need really good monitoring for that...
216− this.setEmailStatus(i, EMAIL_STATUS.FAIL);
217− }
218− } else {
219− console.log('invite tx rejected');
220− this.addError('Invite transaction failed for ' + invite.recipient);
221− this.setEmailStatus(i, EMAIL_STATUS.FAIL);
222− }
223− });
224− })
225− .catch(err => {
197+
198+ // send transaction, informing the user of failure
199+ const txHash = await sendSignedTransaction(
200+ web3, Just(invite.signedTx), tankWasUsed, ()=>{}
201+ ).catch(err => {
226202 console.error('invite tx sending failed', err);
227203 this.addError('Invite transaction not sent for ' + invite.recipient);
228204 this.setEmailStatus(i, EMAIL_STATUS.FAIL);
229205 });
206+
207+ // ask the email sender to send this. we can do this prior to tx confirm,
208+ // because the sender service waits for confirm & success for us.
209+ const mailSuccess = await sendMail(
210+ invite.recipient, invite.ticket, invite.rawTx
211+ );
212+ //TODO but this doesn't catch sender-side failures... we may
213+ // just need really good monitoring for that...
214+ if (mailSuccess) {
215+ this.setEmailStatus(i, EMAIL_STATUS.DONE);
216+ } else {
217+ console.log('email send failed');
218+ //NOTE this assumes that the transaction succeeds, but we don't know
219+ // that for a fact yet...
220+ this.addError(
221+ 'Invite email failed to send for ' + invite.recipient +
222+ '. Please give them this ticket: ' + invite.ticket
223+ );
224+ this.setEmailStatus(i, EMAIL_STATUS.FAIL);
225+ }
226+
227+ // update status on transaction confirm, but don't block on it
228+ waitForTransactionConfirm(web3, txHash)
229+ .then(async success => {
230+ if (!success) {
231+ console.log('invite tx rejected');
232+ this.addError('Invite transaction failed for ' + invite.recipient);
233+ this.setEmailStatus(i, EMAIL_STATUS.FAIL);
234+ }
235+ });
236+
230237 }
231238
232239 this.setState({ status: STATUS.DONE });