slate/common/actions.js

86 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-02-19 09:30:47 +03:00
import 'isomorphic-fetch';
import * as State from '~/common/state';
import * as Strings from '~/common/strings';
2020-02-19 09:30:47 +03:00
const REQUEST_HEADERS = {
Accept: 'application/json',
'Content-Type': 'application/json',
};
const dev = process.env.NODE_ENV !== 'production';
const SERVER_PATH = dev ? 'http://localhost:1337' : 'https://filecoin.onrender.com';
2020-02-19 09:30:47 +03:00
export const rehydrateViewer = async () => {
const options = {
method: 'POST',
headers: REQUEST_HEADERS,
credentials: 'include',
body: JSON.stringify({}),
};
const response = await fetch(`${SERVER_PATH}/_/viewer`, options);
const json = await response.json();
return json;
};
export const setDefaultConfig = async (data) => {
const options = {
method: 'POST',
headers: REQUEST_HEADERS,
credentials: 'include',
body: JSON.stringify(data),
};
const response = await fetch(`${SERVER_PATH}/_/settings`, options);
const json = await response.json();
return json;
};
export const createWalletAddress = async (data) => {
if (Strings.isEmpty(data.name)) {
return null;
2020-02-19 09:30:47 +03:00
}
const options = {
method: 'POST',
headers: REQUEST_HEADERS,
2020-02-19 09:30:47 +03:00
credentials: 'include',
body: JSON.stringify(data),
2020-02-19 09:30:47 +03:00
};
const response = await fetch(`${SERVER_PATH}/_/wallet/create`, options);
2020-02-19 09:30:47 +03:00
const json = await response.json();
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
}
if (!data.amount) {
return null;
2020-02-19 09:30:47 +03:00
}
const options = {
method: 'POST',
headers: REQUEST_HEADERS,
credentials: 'include',
body: JSON.stringify(data),
};
const response = await fetch(`${SERVER_PATH}/_/wallet/send`, options);
const json = await response.json();
return json;
2020-02-19 09:30:47 +03:00
};