@@ -189,24 +189,29 @@ export default function InviteEmail() {
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: () => {
198− Just: p => p.value,
201+ Just: p => {
202+ if (p.value) alreadyReceived.push(email);
203− [input.name]: `${email} has already received an invite.`,
208− if (errorCount > 0) {
207+ if (!knowAll) {
208+ throw new Error('No word yet from email service...');
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(', ')
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() {
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
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];
@@ -315,7 +321,8 @@ export default function InviteEmail() {
315 setStatus(STATUS.SENDING);
321 setStatus(STATUS.SENDING);
316 clearReceipts();
322 clearReceipts();
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];
@@ -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);
335− [input.name]: `Transaction Failure for ${invite.email}`,
@@ -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
353− [input.name]: `Mailing Failure for ${invite.email}, please send them this code manually: ${invite.ticket}`,
357 addReceipt({ [input.name]: true });
357 addReceipt({ [input.name]: true });
@@ -359,13 +359,24 @@ export default function InviteEmail() {
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) {
365+ 'Not all invite emails were sent. ' +
366+ 'Please send the following invite codes manually: ' +
367+ orphanedInvites.map(i => `${i.email}: ${i.ticket}`).join(', ') +
370+ if (unsentInvites.length > 0) {
373+ 'Not all invites were created. ' +
374+ 'Did not send invites for: ' +
375+ unsentInvites.map(i => i.email).join(', ') +
378+ if (errorString !== '') {
363− throw new Error(
379+ throw new Error(errorString);
364− `There ${pluralize(errorCount, 'was', 'were')} ${pluralize(
367− )} while sending transactions.`
@@ -375,7 +386,6 @@ export default function InviteEmail() {
379 sendMail,
389 sendMail,
@@ -406,6 +416,7 @@ export default function InviteEmail() {
406 setGeneralError(new Error(`Duplicate email.`));
416 setGeneralError(new Error(`Duplicate email.`));
408 setGeneralError(null);
418 setGeneralError(null);
419+ setStatus(STATUS.INPUT);
410 }, [inputs]);
421 }, [inputs]);