@@ -4,22 +4,39 @@
4// https://stackoverflow.com/a/53011185/1334324
4// https://stackoverflow.com/a/53011185/1334324
5const baseUrl = 'https://localhost:3002'
5const baseUrl = 'https://localhost:3002'
7−function sendMail(recipient, ticket) {
7+function sendRequest(where, what) {
8 return new Promise((resolve, reject) => {
8 return new Promise((resolve, reject) => {
9− fetch(baseUrl + '/send-ticket', {
9+ fetch(baseUrl + where, {
10 method: 'POST',
10 method: 'POST',
11 cache: 'no-cache',
11 cache: 'no-cache',
12 headers: {
12 headers: {
13 'Content-Type': 'application/json'
13 'Content-Type': 'application/json'
15− body: JSON.stringify({recipient,ticket}),
15+ body: JSON.stringify(what)
19+ resolve(response.json());
17− .then(response => resolve(response.ok))
18 .catch(reject);
24 .catch(reject);
28+async function hasReceived(recipient) {
29+ const res = await sendRequest('/has-received', {recipient});
30+ console.log('got fetch result', res);
31+ return res.hasReceived;
34+function sendMail(recipient, ticket, tx) {
35+ return sendRequest('/send-ticket', {recipient,ticket,tx});