slate/components/sidebars/SidebarFileStorageDeal.js

177 lines
4.3 KiB
JavaScript
Raw Normal View History

2020-07-09 06:35:54 +03:00
import * as React from "react";
import * as Strings from "~/common/strings";
import * as Constants from "~/common/constants";
import * as SVG from "~/components/system/svg";
import * as System from "~/components/system";
2020-07-09 06:35:54 +03:00
import { css } from "@emotion/react";
const STYLES_FILE_HIDDEN = css`
height: 1px;
width: 1px;
opacity: 0;
visibility: hidden;
position: fixed;
top: -1px;
left: -1px;
`;
const STYLES_FOCUS = css`
font-size: ${Constants.typescale.lvl1};
font-family: ${Constants.font.medium};
overflow-wrap: break-word;
width: 100%;
strong {
font-family: ${Constants.font.semiBold};
font-weight: 400;
}
`;
const STYLES_SUBTEXT = css`
margin-top: 8px;
font-size: 12px;
`;
const STYLES_ITEM = css`
margin-top: 16px;
`;
const STYLES_IMAGE_PREVIEW = css`
display: block;
width: 100%;
margin-top: 48px;
`;
export default class SidebarFileStorageDeal extends React.Component {
state = {
2020-08-04 10:35:55 +03:00
settings_cold_default_duration: this.props.viewer
.settings_cold_default_duration,
settings_cold_default_replication_factor: this.props.viewer
.settings_cold_default_replication_factor,
};
async componentDidMount() {
if (!this.props.viewer.settings_deals_auto_approve) {
return null;
}
console.log("SETTINGS: AUTO DEAL");
await this._handleSubmit();
}
_handleMakeDeal = async ({ ipfs }) => {
const options = {
2020-07-09 06:35:54 +03:00
method: "POST",
credentials: "include",
headers: {
2020-07-09 06:35:54 +03:00
Accept: "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({ ipfs }),
};
const response = await fetch("/api/data/storage-deal", options);
const json = await response.json();
console.log(json);
return json;
};
_handleSubmit = async (e) => {
if (e) {
e.persist();
}
this.props.onSidebarLoading(true);
await this._handleMakeDeal({ ipfs: this.props.data.ipfs });
await this.props.onSubmit({});
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
const file = this.props.data;
return (
<React.Fragment>
2020-08-04 10:35:55 +03:00
<System.P style={{ fontFamily: Constants.font.semiBold }}>
Make Filecoin storage deal
</System.P>
2020-07-01 14:31:06 +03:00
<div>
<div css={STYLES_ITEM}>
<div css={STYLES_FOCUS}>{file.name}</div>
<div css={STYLES_SUBTEXT}>Name</div>
</div>
<div css={STYLES_ITEM}>
<div css={STYLES_FOCUS}>{Strings.bytesToSize(file.size)}</div>
<div css={STYLES_SUBTEXT}>File size</div>
</div>
</div>
{!this.props.sidebarLoading ? (
<System.Input
containerStyle={{ marginTop: 48 }}
label="Deal duration"
name="settings_cold_default_duration"
placeholder="Type in epochs (~25 seconds)"
type="number"
value={this.state.settings_cold_default_duration}
onChange={this._handleChange}
/>
) : null}
{!this.props.sidebarLoading ? (
<System.Input
containerStyle={{ marginTop: 24 }}
label="Replication factor"
name="settings_cold_default_replication_factor"
value={this.state.settings_cold_default_replication_factor}
onChange={this._handleChange}
/>
) : null}
{!this.props.sidebarLoading ? (
<System.SelectMenu
full
containerStyle={{ marginTop: 24 }}
name="address"
label="Payment address"
value={this.props.selected.address}
category="address"
onChange={this.props.onSelectedChange}
options={this.props.viewer.addresses}
/>
) : null}
2020-08-02 22:17:13 +03:00
<System.ButtonPrimary
full
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
2020-08-04 10:35:55 +03:00
loading={this.props.sidebarLoading}
>
Make storage deal
2020-08-02 22:17:13 +03:00
</System.ButtonPrimary>
{!this.props.sidebarLoading ? (
2020-08-02 22:17:13 +03:00
<System.ButtonSecondary
full
style={{ marginTop: 16 }}
onClick={this._handleCancel}
>
Cancel deal
2020-08-02 22:17:13 +03:00
</System.ButtonSecondary>
) : null}
</React.Fragment>
);
}
}