slate/scenes/SceneArchive.js

168 lines
5.0 KiB
JavaScript
Raw Normal View History

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";
import { css } from "@emotion/react";
2020-09-09 20:56:35 +03:00
import { LoaderSpinner } from "~/components/system/components/Loaders";
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;
export default class SceneArchive extends React.Component {
2020-09-27 04:54:39 +03:00
state = {
networkViewer: null,
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: {
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,
},
});
await this.props.onRehydrate();
this.setState({ changingFilecoin: false });
};
2020-09-23 12:46:59 +03:00
componentWillUnmount() {
mounted = false;
}
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);
}
return (
<ScenePage>
2020-09-27 19:38:20 +03:00
<ScenePageHeader title="Filecoin">
Use this section to archive all of your data on to Filecoin through a storage deal. Once
you make a storage deal, you can view the logs here. <br />
</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}
>
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}
>
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}
>
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 }} />
)}
</ScenePage>
);
}
}