1import { useCallback } from 'react';
2import Maybe from 'folktale/maybe';
4import { hasReceived, sendMail } from './inviteMail';
5import useSetState from './useSetState';
7const STUB_MAILER = process.env.REACT_APP_STUB_MAILER === 'true';
9function useHasReceivedCache() {
10 const [cache, addToCache] = useSetState();
12 const getHasRecieved = useCallback(
13 email => cache[email] || Maybe.Nothing(), //
17 const syncHasReceivedForEmail = useCallback(
19 if (Maybe.Just.hasInstance(getHasRecieved(email))) {
20 // never update the cache after we know about it
25 // always allow sending emails when stubbing
26 return addToCache({ [email]: Maybe.Just(false) });
29 const _hasReceived = await hasReceived(email);
30 addToCache({ [email]: Maybe.Just(_hasReceived) });
32 [getHasRecieved, addToCache]
35 return { getHasRecieved, syncHasReceivedForEmail };
38export default function useMailer(emails) {
39 const hasReceivedCache = useHasReceivedCache(emails);
41 // prefix to avoid clobbering sendMail import
42 // also throws if return value is false
43 const _sendMail = useCallback(async (email, ticket, rawTx) => {
45 console.log(`${email} - ${ticket}`);
49 const mailSuccess = await sendMail(email, ticket, rawTx);
52 throw new Error(`Internal mailing error when mailing ${email}`);
56 return { ...hasReceivedCache, sendMail: _sendMail };
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list