2020-09-10 02:52:45 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as System from "~/components/system";
|
2020-09-09 20:56:35 +03:00
|
|
|
import * as Constants from "~/common/constants";
|
2020-09-27 04:54:39 +03:00
|
|
|
import * as Actions from "~/common/actions";
|
2020-09-23 22:46:56 +03:00
|
|
|
import * as Strings from "~/common/strings";
|
2020-09-10 02:52:45 +03:00
|
|
|
|
2020-11-04 20:55:48 +03:00
|
|
|
import { css } from "@emotion/core";
|
2020-09-09 20:56:35 +03:00
|
|
|
import { LoaderSpinner } from "~/components/system/components/Loaders";
|
2020-09-10 02:52:45 +03:00
|
|
|
|
|
|
|
import ScenePage from "~/components/core/ScenePage";
|
|
|
|
import ScenePageHeader from "~/components/core/ScenePageHeader";
|
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
const STYLES_LABEL = css`
|
|
|
|
font-family: ${Constants.font.semiBold};
|
|
|
|
font-size: 16px;
|
|
|
|
margin-bottom: 16px;
|
|
|
|
`;
|
|
|
|
|
2020-09-23 12:46:59 +03:00
|
|
|
let mounted = false;
|
|
|
|
|
2020-09-10 02:52:45 +03:00
|
|
|
export default class SceneArchive extends React.Component {
|
2020-09-27 04:54:39 +03:00
|
|
|
state = {
|
|
|
|
networkViewer: null,
|
2020-10-18 22:57:39 +03:00
|
|
|
allow_filecoin_directory_listing: this.props.viewer.allow_filecoin_directory_listing,
|
|
|
|
allow_automatic_data_storage: this.props.viewer.allow_automatic_data_storage,
|
|
|
|
allow_encrypted_data_storage: this.props.viewer.allow_encrypted_data_storage,
|
2020-09-27 04:54:39 +03:00
|
|
|
};
|
2020-09-09 20:56:35 +03:00
|
|
|
|
|
|
|
async componentDidMount() {
|
2020-09-23 12:46:59 +03:00
|
|
|
if (mounted) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
mounted = true;
|
2020-09-09 20:56:35 +03:00
|
|
|
let networkViewer;
|
|
|
|
try {
|
|
|
|
const response = await fetch("/api/network");
|
|
|
|
const json = await response.json();
|
|
|
|
networkViewer = json.data;
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
|
|
this.setState({
|
|
|
|
networkViewer,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-27 04:54:39 +03:00
|
|
|
_handleCheckboxChange = (e) => {
|
|
|
|
this.setState({ [e.target.name]: e.target.value });
|
|
|
|
};
|
|
|
|
|
|
|
|
_handleSaveFilecoin = async (e) => {
|
|
|
|
this.setState({ changingFilecoin: true });
|
|
|
|
|
|
|
|
await Actions.updateViewer({
|
|
|
|
data: {
|
2020-10-18 22:57:39 +03:00
|
|
|
allow_filecoin_directory_listing: this.state.allow_filecoin_directory_listing,
|
2020-09-27 19:38:20 +03:00
|
|
|
allow_automatic_data_storage: this.state.allow_automatic_data_storage,
|
2020-09-27 04:54:39 +03:00
|
|
|
allow_encrypted_data_storage: this.state.allow_encrypted_data_storage,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
this.setState({ changingFilecoin: false });
|
|
|
|
};
|
|
|
|
|
2020-09-23 12:46:59 +03:00
|
|
|
componentWillUnmount() {
|
|
|
|
mounted = false;
|
|
|
|
}
|
|
|
|
|
2020-09-10 02:52:45 +03:00
|
|
|
render() {
|
2020-09-23 22:46:56 +03:00
|
|
|
const { networkViewer } = this.state;
|
|
|
|
const addressMap = {};
|
|
|
|
const addresses = [];
|
|
|
|
let selected = null;
|
|
|
|
let balance = 0;
|
|
|
|
|
|
|
|
if (networkViewer) {
|
|
|
|
networkViewer.powerInfo.balancesList.forEach((a) => {
|
|
|
|
addressMap[a.addr.addr] = { ...a.addr, balance: a.balance };
|
|
|
|
addresses.push({ ...a.addr, balance: a.balance });
|
|
|
|
});
|
|
|
|
|
|
|
|
if (addresses.length) {
|
|
|
|
selected = addresses[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
let transactions = [];
|
|
|
|
if (selected.transactions) {
|
|
|
|
transactions = [...selected.transactions];
|
|
|
|
}
|
|
|
|
|
|
|
|
balance = Strings.formatAsFilecoinConversion(selected.balance);
|
|
|
|
}
|
|
|
|
|
2020-09-10 02:52:45 +03:00
|
|
|
return (
|
|
|
|
<ScenePage>
|
2020-09-27 19:38:20 +03:00
|
|
|
<ScenePageHeader title="Filecoin">
|
2020-10-19 07:15:26 +03:00
|
|
|
Use this section to archive all of your data on to Filecoin through a storage deal. You
|
|
|
|
must have at last 100MB stored to make an archive storage deal. <br />
|
2020-09-10 02:52:45 +03:00
|
|
|
</ScenePageHeader>
|
|
|
|
|
2020-09-09 20:56:35 +03:00
|
|
|
{this.state.networkViewer ? (
|
|
|
|
<React.Fragment>
|
2020-09-25 10:08:08 +03:00
|
|
|
<br />
|
2020-09-23 22:46:56 +03:00
|
|
|
<System.ButtonPrimary
|
|
|
|
onClick={() =>
|
|
|
|
this.props.onAction({
|
|
|
|
type: "SIDEBAR",
|
|
|
|
value: "SIDEBAR_FILECOIN_ARCHIVE",
|
|
|
|
})
|
|
|
|
}
|
|
|
|
>
|
2020-09-27 19:38:20 +03:00
|
|
|
Archive your data
|
2020-09-23 22:46:56 +03:00
|
|
|
</System.ButtonPrimary>
|
|
|
|
|
2020-09-27 04:54:39 +03:00
|
|
|
<System.DescriptionGroup
|
|
|
|
style={{ marginTop: 64 }}
|
2020-09-27 20:01:38 +03:00
|
|
|
label="Archive automation settings"
|
|
|
|
description="Configure the automation settings for your archive storage deals."
|
2020-09-27 04:54:39 +03:00
|
|
|
/>
|
|
|
|
|
2020-09-29 00:30:12 +03:00
|
|
|
<System.CheckBox
|
|
|
|
style={{ marginTop: 24 }}
|
|
|
|
name="allow_filecoin_directory_listing"
|
|
|
|
value={this.state.allow_filecoin_directory_listing}
|
|
|
|
onChange={this._handleCheckboxChange}
|
|
|
|
>
|
2020-10-18 22:57:39 +03:00
|
|
|
Show your successful deals on a directory page where others can retrieve them.
|
2020-09-29 00:30:12 +03:00
|
|
|
</System.CheckBox>
|
|
|
|
|
2020-09-27 19:38:20 +03:00
|
|
|
<System.CheckBox
|
|
|
|
style={{ marginTop: 24 }}
|
|
|
|
name="allow_automatic_data_storage"
|
|
|
|
value={this.state.allow_automatic_data_storage}
|
|
|
|
onChange={this._handleCheckboxChange}
|
|
|
|
>
|
2020-10-18 22:57:39 +03:00
|
|
|
Allow Slate to make archive storage deals on your behalf to the Filecoin Network. You
|
|
|
|
will get a receipt in the Filecoin section.
|
2020-09-27 19:38:20 +03:00
|
|
|
</System.CheckBox>
|
|
|
|
|
2020-09-27 04:54:39 +03:00
|
|
|
<System.CheckBox
|
|
|
|
style={{ marginTop: 24 }}
|
|
|
|
name="allow_encrypted_data_storage"
|
|
|
|
value={this.state.allow_encrypted_data_storage}
|
|
|
|
onChange={this._handleCheckboxChange}
|
|
|
|
>
|
2020-10-18 22:57:39 +03:00
|
|
|
Force encryption on archive storage deals (only you can see retrieved data from the
|
|
|
|
Filecoin network).
|
2020-09-27 04:54:39 +03:00
|
|
|
</System.CheckBox>
|
|
|
|
|
|
|
|
<div style={{ marginTop: 24 }}>
|
|
|
|
<System.ButtonSecondary
|
|
|
|
onClick={this._handleSaveFilecoin}
|
|
|
|
loading={this.state.changingFilecoin}
|
|
|
|
>
|
|
|
|
Save archiving settings
|
|
|
|
</System.ButtonSecondary>
|
|
|
|
</div>
|
2020-09-09 20:56:35 +03:00
|
|
|
</React.Fragment>
|
|
|
|
) : (
|
|
|
|
<LoaderSpinner style={{ marginTop: 48, height: 32, width: 32 }} />
|
|
|
|
)}
|
2020-09-10 02:52:45 +03:00
|
|
|
</ScenePage>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|