1import { useCallback, useEffect } from 'react';
2import Maybe from 'folktale/maybe';
4import { hasReceived, sendMail } from './inviteMail';
5import useSetState from './useSetState';
7function useHasReceivedCache(emails = []) {
8 const [cache, addToCache] = useSetState();
10 const getHasRecieved = useCallback(
11 email => cache[email] || Maybe.Nothing(), //
16 for (const email of emails) {
17 if (Maybe.Just.hasInstance(getHasRecieved(email))) {
18 // never update the cache after we know about it
23 addToCache({ [email]: await hasReceived(email) });
26 }, [emails, getHasRecieved, addToCache]);
28 return { getHasRecieved };
31export default function useMailer(emails) {
32 const { getHasRecieved } = useHasReceivedCache(emails);
34 // prefix to avoid clobbering sendMail import
35 const _sendMail = useCallback(async (email, ticket, rawTx) => {
36 const mailSuccess = await sendMail(email, ticket, rawTx);
39 throw new Error(`Internal mailing error when mailing ${email}`);
43 return { getHasRecieved, 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