on master help sign in
Add support for has-received in /lib/inviteMail
commit0d39f11432a509c813ba3a41caae5d6ceaf9eaf0 authorFang <git@fang.io> dateThu 9 May 2019, 21:28 (7 years ago) parent968321a
1 file changed+21−4
src/bridge/lib/inviteMail.js+21−4
src/bridge/lib/inviteMail.js+21−4
@@ -4,22 +4,39 @@
44// https://stackoverflow.com/a/53011185/1334324
55const baseUrl = 'https://localhost:3002'
66
7−function sendMail(recipient, ticket) {
7+function sendRequest(where, what) {
88 return new Promise((resolve, reject) => {
9− fetch(baseUrl + '/send-ticket', {
9+ fetch(baseUrl + where, {
1010 method: 'POST',
1111 cache: 'no-cache',
1212 headers: {
1313 'Content-Type': 'application/json'
1414 },
15− body: JSON.stringify({recipient,ticket}),
15+ body: JSON.stringify(what)
16+ })
17+ .then(response => {
18+ if (response.ok) {
19+ resolve(response.json());
20+ } else {
21+ reject(response);
22+ }
1623 })
17− .then(response => resolve(response.ok))
1824 .catch(reject);
1925 });
2026}
2127
28+async function hasReceived(recipient) {
29+ const res = await sendRequest('/has-received', {recipient});
30+ console.log('got fetch result', res);
31+ return res.hasReceived;
32+}
33+
34+function sendMail(recipient, ticket, tx) {
35+ return sendRequest('/send-ticket', {recipient,ticket,tx});
36+}
37+
2238export {
39+ hasReceived,
2340 sendMail
2441}
2542