on 64aee13 help sign in
bridge/src/lib/inviteMail.js
37 lines 1.1 kB history raw
1//NOTE if accessing this in a localhost configuration fails with "CORS request
2// did not succeed", you might need to visit localhost:3001 or whatever
3// explicitly and tell your browser that's safe to access.
4// https://stackoverflow.com/a/53011185/1334324
5const baseUrl = 'https://localhost:3002';
7function sendRequest(where, what) {
8 return new Promise((resolve, reject) => {
9 fetch(baseUrl + where, {
10 method: 'POST',
11 cache: 'no-cache',
12 headers: {
13 'Content-Type': 'application/json',
14 },
15 body: JSON.stringify(what),
16 })
17 .then(response => {
18 if (response.ok) {
19 resolve(response.json());
20 } else {
21 reject(response);
22 }
23 })
24 .catch(reject);
25 });
28async function hasReceived(recipient) {
29 const res = await sendRequest('/has-received', { recipient });
30 return res.hasReceived;
33function sendMail(recipient, ticket, sender, tx) {
34 return sendRequest('/send-ticket', { recipient, ticket, sender, tx });
37export { hasReceived, sendMail };