1import { useCallback, useRef } from 'react';
3import { hasReceived, sendMail } from './inviteMail';
4import { timeout } from './timeout';
6const STUB_MAILER = import.meta.env.VITE_STUB_MAILER === 'true';
8export default function useMailer() {
9 const cache = useRef({});
11 const getHasReceived = useCallback(
13 if (!cache.current[email]) {
15 await timeout(350); // simulate request
16 cache.current[email] = false;
18 cache.current[email] = await hasReceived(email);
22 return cache.current[email];
27 // prefix to avoid clobbering sendMail import
28 // also throws if return value is false
29 const _sendMail = useCallback(
30 async (email, ticket, sender, message, rawTx) => {
32 console.log(`${email} - ${ticket}`);
33 await timeout(Math.random() * 1000); // simulate request with randomness
37 const success = await sendMail(email, ticket, sender, message, rawTx);
39 throw new Error('Failed to send mail');
45 return { getHasReceived, 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