on master help sign in
Merge pull request #213 from urbit/mino-invite-email-hacks
74ef976Fang
src/views/Invite/InviteEmail.js+41−30
@@ -189,24 +189,29 @@ export default function InviteEmail() {
189 }
189 }
190
190
191 //TODO want to do this on-input, but that gets weird. see #188
191 //TODO want to do this on-input, but that gets weird. see #188
192− let errorCount = 0;
192+ let knowAll = true;
193+ let alreadyReceived = [];
193 await Promise.all(
194 await Promise.all(
194 inputs.map(async input => {
195 inputs.map(async input => {
195 const email = input.data;
196 const email = input.data;
196− const hasReceived = getHasReceived(email).matchWith({
197+ getHasReceived(email).matchWith({
197− Nothing: () => false, // loading
198+ Nothing: () => {
199+ knowAll = false;
200+ },
198− Just: p => p.value,
201+ Just: p => {
202+ if (p.value) alreadyReceived.push(email);
203+ },
199 });
204 });
200− if (hasReceived) {
201− errorCount++;
202− addError({
203− [input.name]: `${email} has already received an invite.`,
204− });
205− }
206 })
205 })
207 );
206 );
208− if (errorCount > 0) {
207+ if (!knowAll) {
208+ throw new Error('No word yet from email service...');
209+ }
210+ if (alreadyReceived.length > 0) {
209− throw new Error(`Some of these already have a point!`);
211+ throw new Error(
212+ 'The following recipients already own a point: ' +
213+ alreadyReceived.join(', ')
214+ );
210 }
215 }
211
216
212 const nonce = await _web3.eth.getTransactionCount(_wallet.address);
217 const nonce = await _web3.eth.getTransactionCount(_wallet.address);
@@ -231,6 +236,7 @@ export default function InviteEmail() {
231
236
232 clearInvites();
237 clearInvites();
233 // NB(shrugs) - must be processed in serial because main thread, etc
238 // NB(shrugs) - must be processed in serial because main thread, etc
239+ let errorCount = 0;
234 for (let i = 0; i < inputs.length; i++) {
240 for (let i = 0; i < inputs.length; i++) {
235 const input = inputs[i];
241 const input = inputs[i];
236 try {
242 try {
@@ -315,7 +321,8 @@ export default function InviteEmail() {
315 setStatus(STATUS.SENDING);
321 setStatus(STATUS.SENDING);
316 clearReceipts();
322 clearReceipts();
317
323
318− let errorCount = 0;
324+ let unsentInvites = [];
325+ let orphanedInvites = [];
319 const txAndMailings = inputs.map(async input => {
326 const txAndMailings = inputs.map(async input => {
320 const invite = invites[input.name];
327 const invite = invites[input.name];
321 try {
328 try {
@@ -330,10 +337,7 @@ export default function InviteEmail() {
330 if (!didConfirm) throw new Error();
337 if (!didConfirm) throw new Error();
331 } catch (error) {
338 } catch (error) {
332 console.error(error);
339 console.error(error);
333− errorCount++;
340+ unsentInvites.push(invite);
334− addError({
335− [input.name]: `Transaction Failure for ${invite.email}`,
336− });
337 return;
341 return;
338 }
342 }
339
343
@@ -347,11 +351,7 @@ export default function InviteEmail() {
347 if (!success) throw new Error('Failed to send mail');
351 if (!success) throw new Error('Failed to send mail');
348 } catch (error) {
352 } catch (error) {
349 console.error(error);
353 console.error(error);
350− errorCount++;
354+ orphanedInvites.push(invite);
351− //TODO make sure this actually gets displayed
352− addError({
353− [input.name]: `Mailing Failure for ${invite.email}, please send them this code manually: ${invite.ticket}`,
354− });
355 }
355 }
356
356
357 addReceipt({ [input.name]: true });
357 addReceipt({ [input.name]: true });
@@ -359,13 +359,24 @@ export default function InviteEmail() {
359
359
360 await Promise.all(txAndMailings);
360 await Promise.all(txAndMailings);
361 // if there are any receipt errors, throw a general error
361 // if there are any receipt errors, throw a general error
362− if (errorCount > 0) {
362+ let errorString = '';
363+ if (orphanedInvites.length > 0) {
364+ errorString =
365+ 'Not all invite emails were sent. ' +
366+ 'Please send the following invite codes manually: ' +
367+ orphanedInvites.map(i => `${i.email}: ${i.ticket}`).join(', ') +
368+ '. ';
369+ }
370+ if (unsentInvites.length > 0) {
371+ errorString =
372+ errorString +
373+ 'Not all invites were created. ' +
374+ 'Did not send invites for: ' +
375+ unsentInvites.map(i => i.email).join(', ') +
376+ '.';
377+ }
378+ if (errorString !== '') {
363− throw new Error(
379+ throw new Error(errorString);
364− `There ${pluralize(errorCount, 'was', 'were')} ${pluralize(
365− errorCount,
366− 'error'
367− )} while sending transactions.`
368− );
369 }
380 }
370 }, [
381 }, [
371 web3,
382 web3,
@@ -375,7 +386,6 @@ export default function InviteEmail() {
375 invites,
386 invites,
376 point,
387 point,
377 wallet,
388 wallet,
378− addError,
379 sendMail,
389 sendMail,
380 ]);
390 ]);
381
391
@@ -406,6 +416,7 @@ export default function InviteEmail() {
406 setGeneralError(new Error(`Duplicate email.`));
416 setGeneralError(new Error(`Duplicate email.`));
407 } else {
417 } else {
408 setGeneralError(null);
418 setGeneralError(null);
419+ setStatus(STATUS.INPUT);
409 }
420 }
410 }, [inputs]);
421 }, [inputs]);
411
422