2020-06-19 06:57:57 +03:00
|
|
|
import "isomorphic-fetch";
|
2020-02-19 09:30:47 +03:00
|
|
|
|
2020-06-19 06:57:57 +03:00
|
|
|
import * as State from "~/common/state";
|
|
|
|
import * as Strings from "~/common/strings";
|
2020-02-19 09:30:47 +03:00
|
|
|
|
|
|
|
const REQUEST_HEADERS = {
|
2020-06-19 06:57:57 +03:00
|
|
|
Accept: "application/json",
|
|
|
|
"Content-Type": "application/json",
|
2020-02-19 09:30:47 +03:00
|
|
|
};
|
|
|
|
|
2020-07-22 09:04:54 +03:00
|
|
|
export const sendFilecoin = async (data) => {
|
2020-04-09 00:29:13 +03:00
|
|
|
if (Strings.isEmpty(data.source)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Strings.isEmpty(data.target)) {
|
|
|
|
return null;
|
2020-02-19 09:30:47 +03:00
|
|
|
}
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
if (!data.amount) {
|
|
|
|
return null;
|
2020-02-19 09:30:47 +03:00
|
|
|
}
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
const options = {
|
2020-06-19 06:57:57 +03:00
|
|
|
method: "POST",
|
2020-04-09 00:29:13 +03:00
|
|
|
headers: REQUEST_HEADERS,
|
2020-06-19 06:57:57 +03:00
|
|
|
credentials: "include",
|
2020-07-22 09:04:54 +03:00
|
|
|
body: JSON.stringify({ data }),
|
2020-04-09 00:29:13 +03:00
|
|
|
};
|
|
|
|
|
2020-07-22 09:04:54 +03:00
|
|
|
const response = await fetch(`/api/addresses/send`, options);
|
2020-04-09 00:29:13 +03:00
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
2020-02-19 09:30:47 +03:00
|
|
|
};
|
2020-07-17 13:24:20 +03:00
|
|
|
|
2020-07-22 07:11:13 +03:00
|
|
|
export const updateViewer = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`/api/users/update`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
2020-07-21 14:36:50 +03:00
|
|
|
|
|
|
|
export const signIn = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`/api/sign-in`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2020-07-22 08:53:29 +03:00
|
|
|
export const hydrateAuthenticatedUser = async () => {
|
2020-07-17 13:24:20 +03:00
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
};
|
|
|
|
|
2020-07-21 09:17:34 +03:00
|
|
|
const response = await fetch(`/api/hydrate`, options);
|
2020-07-17 13:24:20 +03:00
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2020-07-22 08:53:29 +03:00
|
|
|
export const deleteViewer = async () => {
|
2020-07-17 13:24:20 +03:00
|
|
|
const options = {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
};
|
|
|
|
|
2020-07-21 09:17:34 +03:00
|
|
|
const response = await fetch(`/api/users/delete`, options);
|
2020-07-17 13:24:20 +03:00
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const createUser = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
};
|
|
|
|
|
2020-07-21 09:17:34 +03:00
|
|
|
const response = await fetch(`/api/users/create`, options);
|
2020-07-17 13:24:20 +03:00
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2020-07-24 10:45:21 +03:00
|
|
|
export const checkCIDStatus = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`/api/data/cid-status`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2020-07-17 13:24:20 +03:00
|
|
|
export const health = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data: { success: true } }),
|
|
|
|
};
|
|
|
|
|
2020-07-21 09:17:34 +03:00
|
|
|
const response = await fetch(`/api/_`, options);
|
2020-07-17 13:24:20 +03:00
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|