slate/scenes/SceneArchive.js

206 lines
5.9 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 Section from "~/components/core/Section";
import ScenePage from "~/components/core/ScenePage";
import ScenePageHeader from "~/components/core/ScenePageHeader";
import TestnetBanner from "~/components/core/TestnetBanner";
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,
2020-09-27 19:38:20 +03:00
allow_automatic_data_storage: this.props.viewer
.allow_automatic_data_storage,
2020-09-27 04:54:39 +03:00
allow_encrypted_data_storage: this.props.viewer
.allow_encrypted_data_storage,
};
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-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
2020-09-23 22:46:56 +03:00
storage deal. Once you make a storage deal, you can view the logs
2020-09-25 10:08:08 +03:00
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 }}
label="Encryption settings"
description="You may not want others to be able to read your data on the network."
/>
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.
</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).
</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
<Section
2020-09-23 22:46:56 +03:00
title="Archive deal logs"
style={{ minWidth: "auto", marginTop: 48 }}
2020-09-09 20:56:35 +03:00
>
2020-09-23 22:46:56 +03:00
<System.Table
data={{
columns: [
{
key: "job",
name: "Job Message",
width: "100%",
},
],
rows: this.state.networkViewer.archive.jobs.map((job) => {
return {
job: job.msg,
};
}),
}}
/>
2020-09-09 20:56:35 +03:00
</Section>
<Section
2020-09-23 22:46:56 +03:00
title="(one-off) Storage deal logs"
style={{ minWidth: "auto", marginTop: 48 }}
>
2020-09-09 20:56:35 +03:00
<System.Table
data={{
columns: [
{
key: "job",
name: "Job Message",
width: "100%",
},
],
2020-09-23 22:46:56 +03:00
rows: this.state.networkViewer.dealJobs.map((job) => {
2020-09-09 20:56:35 +03:00
return {
job: job.msg,
};
}),
}}
/>
</Section>
</React.Fragment>
) : (
<LoaderSpinner style={{ marginTop: 48, height: 32, width: 32 }} />
)}
</ScenePage>
);
}
}