on master help sign in
bridge/src/lib/inviteMail.js
46 lines 1.2 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
5import { isGoerli } from './flags';
7const port = isGoerli ? '3012' : '3002';
8const baseUrl = `https://onboarding-emails.urbit.org:${port}`;
10function sendRequest(where, what) {
11 return new Promise((resolve, reject) => {
12 fetch(baseUrl + where, {
13 method: 'POST',
14 cache: 'no-cache',
15 headers: {
16 'Content-Type': 'application/json',
17 },
18 body: JSON.stringify(what),
19 })
20 .then(response => {
21 if (response.ok) {
22 resolve(response.json());
23 } else {
24 reject(response);
25 }
26 })
27 .catch(reject);
28 });
31async function hasReceived(recipient) {
32 const res = await sendRequest('/has-received', { recipient });
33 return res.hasReceived;
36function sendMail(recipient, ticket, sender, message, tx) {
37 return sendRequest('/send-ticket', {
38 recipient,
39 ticket,
40 sender,
41 message,
42 tx,
43 });
46export { hasReceived, sendMail };