slate/components/sidebars/SidebarFilecoinArchive.js

116 lines
2.8 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as Constants from "~/common/constants";
import * as Actions from "~/common/actions";
import * as System from "~/components/system";
import * as Window from "~/common/window";
2020-09-23 22:46:56 +03:00
import * as Messages from "~/common/messages";
2020-09-12 01:25:33 +03:00
import { dispatchCustomEvent } from "~/common/custom-events";
2020-10-30 12:53:56 +03:00
const DEFAULT_ERROR_MESSAGE = "We could not make your deal. Please try again later.";
2020-09-23 22:46:56 +03:00
export default class SidebarFilecoinArchive extends React.Component {
2020-09-18 04:18:42 +03:00
state = { response: null };
2020-09-09 20:56:35 +03:00
async componentDidMount() {}
_handleMakeDeal = async () => {
return await Actions.archive({});
};
_handleSubmit = async (e) => {
if (e) {
e.persist();
}
this.props.onSidebarLoading(true);
2020-09-23 22:46:56 +03:00
const response = await this._handleMakeDeal();
if (!response) {
this.props.onSidebarLoading(false);
return dispatchCustomEvent({
name: "create-alert",
detail: {
alert: {
message: DEFAULT_ERROR_MESSAGE,
},
},
});
}
if (response.error) {
this.props.onSidebarLoading(false);
if (response.message) {
return dispatchCustomEvent({
name: "create-alert",
detail: {
alert: {
message: `From Textile: ${response.message}`,
},
},
});
}
return dispatchCustomEvent({
name: "create-alert",
detail: {
alert: {
message: Messages.error[response.decorator]
? Messages.error[response.decorator]
: DEFAULT_ERROR_MESSAGE,
},
},
});
}
await Window.delay(5000);
2020-10-30 12:53:56 +03:00
alert(
"Your storage deal was put in the queue. This can take up to 36 hours, check back later."
);
window.location.reload();
};
_handleCancel = () => {
this.props.onCancel();
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
return (
<React.Fragment>
2020-09-08 02:28:50 +03:00
<System.P
style={{
fontFamily: Constants.font.semiBold,
fontSize: Constants.typescale.lvl3,
}}
>
2020-09-27 19:38:20 +03:00
Archive your data
</System.P>
<System.P style={{ marginTop: 24 }}>
2020-10-30 12:53:56 +03:00
This will archive all of your data onto the Filecoin Network with a storage deal using
your default settings.
</System.P>
<System.ButtonPrimary
full
style={{ marginTop: 48 }}
onClick={this._handleSubmit}
loading={this.props.sidebarLoading}
>
Make storage deal
</System.ButtonPrimary>
2020-09-09 20:56:35 +03:00
2020-09-18 04:18:42 +03:00
{this.state.response ? (
<div style={{ whiteSpace: "pre-wrap", marginTop: 48 }}>
{JSON.stringify(this.state.response, null, 2)}
</div>
) : null}
</React.Fragment>
);
}
}