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-17 13:24:20 +03:00
|
|
|
const dev = process.env.NODE_ENV !== "www";
|
|
|
|
const SERVER_PATH = dev ? "http://localhost:1337" : "https://slate.host";
|
2020-06-08 09:45:53 +03:00
|
|
|
|
|
|
|
export const setDefaultConfig = async (data) => {
|
|
|
|
const options = {
|
2020-06-19 06:57:57 +03:00
|
|
|
method: "POST",
|
2020-06-08 09:45:53 +03:00
|
|
|
headers: REQUEST_HEADERS,
|
2020-06-19 06:57:57 +03:00
|
|
|
credentials: "include",
|
2020-06-08 09:45:53 +03:00
|
|
|
body: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`${SERVER_PATH}/_/settings`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
2020-06-04 09:26:20 +03:00
|
|
|
};
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
export const createWalletAddress = async (data) => {
|
|
|
|
if (Strings.isEmpty(data.name)) {
|
|
|
|
return null;
|
2020-02-19 09:30:47 +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-04-09 00:29:13 +03:00
|
|
|
body: JSON.stringify(data),
|
2020-02-19 09:30:47 +03:00
|
|
|
};
|
|
|
|
|
2020-06-08 09:45:53 +03:00
|
|
|
const response = await fetch(`${SERVER_PATH}/_/wallet/create`, options);
|
2020-02-19 09:30:47 +03:00
|
|
|
const json = await response.json();
|
|
|
|
|
2020-04-09 00:29:13 +03:00
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const sendWalletAddressFilecoin = async (data) => {
|
|
|
|
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-04-09 00:29:13 +03:00
|
|
|
body: JSON.stringify(data),
|
|
|
|
};
|
|
|
|
|
2020-06-08 09:45:53 +03:00
|
|
|
const response = await fetch(`${SERVER_PATH}/_/wallet/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
|
|
|
|
|
|
|
// NOTE(jim):
|
|
|
|
// New WWW Requests.
|
|
|
|
export const hydrateAuthenticatedUser = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`${SERVER_PATH}/api/hydrate`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const deleteUser = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "DELETE",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`${SERVER_PATH}/api/users/delete`, options);
|
|
|
|
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 }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`${SERVER_PATH}/api/users/create`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const health = async (data) => {
|
|
|
|
const options = {
|
|
|
|
method: "POST",
|
|
|
|
headers: REQUEST_HEADERS,
|
|
|
|
credentials: "include",
|
|
|
|
body: JSON.stringify({ data: { success: true } }),
|
|
|
|
};
|
|
|
|
|
|
|
|
const response = await fetch(`${SERVER_PATH}/api/_`, options);
|
|
|
|
const json = await response.json();
|
|
|
|
return json;
|
|
|
|
};
|