on master help sign in
Merge pull request #213 from urbit/mino-invite-email-hacks

InviteEmail hacks

commit74ef976474357346ce6578098e6e1a47087ae246 authorFang <Fang-@users.noreply.github.com> dateMon 29 Jul 2019, 20:08 (7 years ago) parent9e3f53c6e47f33
1 file changed+41−30
src/views/Invite/InviteEmail.js+41−30
src/views/Invite/InviteEmail.js+41−30
@@ -189,24 +189,29 @@ export default function InviteEmail() {
189189 }
190190
191191 //TODO want to do this on-input, but that gets weird. see #188
192− let errorCount = 0;
192+ let knowAll = true;
193+ let alreadyReceived = [];
193194 await Promise.all(
194195 inputs.map(async input => {
195196 const email = input.data;
196− const hasReceived = getHasReceived(email).matchWith({
197− Nothing: () => false, // loading
198− Just: p => p.value,
197+ getHasReceived(email).matchWith({
198+ Nothing: () => {
199+ knowAll = false;
200+ },
201+ Just: p => {
202+ if (p.value) alreadyReceived.push(email);
203+ },
199204 });
200− if (hasReceived) {
201− errorCount++;
202− addError({
203− [input.name]: `${email} has already received an invite.`,
204− });
205− }
206205 })
207206 );
208− if (errorCount > 0) {
209− throw new Error(`Some of these already have a point!`);
207+ if (!knowAll) {
208+ throw new Error('No word yet from email service...');
209+ }
210+ if (alreadyReceived.length > 0) {
211+ throw new Error(
212+ 'The following recipients already own a point: ' +
213+ alreadyReceived.join(', ')
214+ );
210215 }
211216
212217 const nonce = await _web3.eth.getTransactionCount(_wallet.address);
@@ -231,6 +236,7 @@ export default function InviteEmail() {
231236
232237 clearInvites();
233238 // NB(shrugs) - must be processed in serial because main thread, etc
239+ let errorCount = 0;
234240 for (let i = 0; i < inputs.length; i++) {
235241 const input = inputs[i];
236242 try {
@@ -315,7 +321,8 @@ export default function InviteEmail() {
315321 setStatus(STATUS.SENDING);
316322 clearReceipts();
317323
318− let errorCount = 0;
324+ let unsentInvites = [];
325+ let orphanedInvites = [];
319326 const txAndMailings = inputs.map(async input => {
320327 const invite = invites[input.name];
321328 try {
@@ -330,10 +337,7 @@ export default function InviteEmail() {
330337 if (!didConfirm) throw new Error();
331338 } catch (error) {
332339 console.error(error);
333− errorCount++;
334− addError({
335− [input.name]: `Transaction Failure for ${invite.email}`,
336− });
340+ unsentInvites.push(invite);
337341 return;
338342 }
339343
@@ -347,11 +351,7 @@ export default function InviteEmail() {
347351 if (!success) throw new Error('Failed to send mail');
348352 } catch (error) {
349353 console.error(error);
350− errorCount++;
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− });
354+ orphanedInvites.push(invite);
355355 }
356356
357357 addReceipt({ [input.name]: true });
@@ -359,13 +359,24 @@ export default function InviteEmail() {
359359
360360 await Promise.all(txAndMailings);
361361 // if there are any receipt errors, throw a general error
362− if (errorCount > 0) {
363− throw new Error(
364− `There ${pluralize(errorCount, 'was', 'were')} ${pluralize(
365− errorCount,
366− 'error'
367− )} while sending transactions.`
368− );
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 !== '') {
379+ throw new Error(errorString);
369380 }
370381 }, [
371382 web3,
@@ -375,7 +386,6 @@ export default function InviteEmail() {
375386 invites,
376387 point,
377388 wallet,
378− addError,
379389 sendMail,
380390 ]);
381391
@@ -406,6 +416,7 @@ export default function InviteEmail() {
406416 setGeneralError(new Error(`Duplicate email.`));
407417 } else {
408418 setGeneralError(null);
419+ setStatus(STATUS.INPUT);
409420 }
410421 }, [inputs]);
411422