1import { useCallback } from 'react';
2import { Just, Nothing } 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 getHasReceived = useCallback(
13 email => cache[email] || Nothing(), //
17 const syncHasReceivedForEmail = useCallback(
19 if (Just.hasInstance(getHasReceived(email))) {
20 // never update the cache after we know about it
25 // always allow sending emails when stubbing
26 return addToCache({ [email]: Just(false) });
29 const _hasReceived = await hasReceived(email);
30 addToCache({ [email]: Just(_hasReceived) });
32 [getHasReceived, addToCache]
35 return { getHasReceived, 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 return await sendMail(email, ticket, rawTx);
52 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