import * as React from "react"; import * as Actions from "~/common/actions"; import * as System from "~/components/system"; import * as Strings from "~/common/strings"; import { css } from "@emotion/core"; import { LoaderSpinner } from "~/components/system/components/Loaders"; import ScenePage from "~/components/core/ScenePage"; import ScenePageHeader from "~/components/core/ScenePageHeader"; const STYLES_GROUP = css` display: flex; align-items: center; justify-content: space-between; width: 100%; overflow-wrap: break-word; white-space: pre-wrap; max-width: 768px; `; const STYLES_SUBGROUP = css` width: 100%; overflow-wrap: break-word; white-space: pre-wrap; `; const STYLES_LEFT = css` padding: 12px 0 0 0; min-width: 10%; overflow-wrap: break-word; white-space: pre-wrap; `; const STYLES_RIGHT = css` padding-left: 48px; padding-top: 24px; flex-shrink: 0; `; export const createState = (config) => { return { settings_hot_enabled: config.hot.enabled, settings_hot_allow_unfreeze: config.hot.allowUnfreeze, settings_hot_ipfs_add_timeout: config.hot.ipfs.addTimeout, settings_cold_enabled: config.cold.enabled, settings_cold_default_address: config.cold.filecoin.addr, settings_cold_default_duration: config.cold.filecoin.dealMinDuration, settings_cold_default_replication_factor: config.cold.filecoin.repFactor, settings_cold_default_excluded_miners: config.cold.filecoin.excludedMinersList, settings_cold_default_trusted_miners: config.cold.filecoin.trustedMinersList, settings_cold_default_max_price: config.cold.filecoin.maxPrice, settings_cold_default_auto_renew: config.cold.filecoin.renew.enabled, settings_cold_default_auto_renew_max_price: config.cold.filecoin.renew.threshold, }; }; let mounted = false; export default class SceneSettings extends React.Component { state = {}; async componentDidMount() { if (mounted) { return null; } mounted = true; let networkViewer; try { const response = await fetch("/api/network"); const json = await response.json(); networkViewer = json.data; } catch (e) {} this.setState({ networkViewer, ...createState(networkViewer.powerInfo.defaultStorageConfig), }); } componentWillUnmount() { mounted = false; } _deferredSave = null; _handleSave = async () => { this.setState({ loading: true }); return alert(`Changing settings is currently disabled.`); await Actions.updateViewer({ type: "SET_DEFAULT_STORAGE_CONFIG", config: { hot: { enabled: this.state.settings_hot_enabled, allowUnfreeze: this.state.settings_hot_allow_unfreeze, ipfs: { addTimeout: this.state.settings_hot_ipfs_add_timeout, }, }, cold: { enabled: this.state.settings_cold_enabled, filecoin: { addr: this.state.settings_cold_default_address, dealMinDuration: this.state.settings_cold_default_duration, repFactor: this.state.settings_cold_default_replication_factor, excludedMinersList: this.state.settings_cold_default_excluded_miners, trustedMinersList: this.state.settings_cold_default_trusted_miners, maxPrice: this.state.settings_cold_default_max_price, renew: { enabled: this.state.settings_cold_default_auto_renew, threshold: this.state.settings_cold_default_auto_renew_max_price, }, }, }, }, }); this.setState({ loading: false }); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { return ( We do not allow changes to your deal settings at the moment. This is to ensure that your storage deals have the maximum chance of success. {this.state.networkViewer ? ( {/*
*/} {this.state.settings_cold_enabled ? (
{/* Enable auto renew for Filecoin Network deals. */}
) : null} {/*
Save
*/} {/*
*/} {this.state.settings_hot_enabled ? (
{/* IPFS allow unfreeze setting description. */}
) : null} {/*
Save
*/}
) : ( )}
); } }