import * as React from "react"; import * as Constants from "~/common/constants"; import * as Strings from "~/common/strings"; import { css } from "@emotion/core"; import { DescriptionGroup } from "~/components/system/components/fragments/DescriptionGroup"; import { SelectMenu } from "~/components/system/components/SelectMenus"; import { Toggle } from "~/components/system/components/Toggle"; import { Input } from "~/components/system/components/Input"; import { ButtonPrimary } from "~/components/system/components/Buttons"; import { CardTabGroup } from "~/components/system/components/CardTabGroup"; 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` padding-left: 24px; 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; `; const TAB_GROUP = [ { value: "general", label: "General" }, { value: "hot", label: "Hot Storage" }, { value: "cold", label: "Cold Storage" }, ]; export class FilecoinSettings extends React.Component { state = { tabGroup: "general", addrsList: [], fetchedAddrs: false, fetchedConfig: false, }; componentDidMount = () => { let newState = null; if (this.props.defaultStorageConfig) { newState = this.unbundleConfig(); } if (this.props.addrsList) { if (newState) { newState.addrsList = this.props.addrsList; newState.fetchedAddrs = true; } else { newState = { addrsList: this.props.addrsList, fetchedAddrs: true }; } } if (newState) { this.setState(newState); } }; componentDidUpdate = (prevProps) => { if (!this.state.fetchedAddrs || !this.state.fetchedConfig) { let newState = null; if (this.props.defaultStorageConfig != prevProps.defaultStorageConfig) { newState = this.unbundleConfig(); } if (this.props.addrsList != prevProps.addrsList) { if (newState) { newState.addrsList = this.props.addrsList; newState.fetchedAddrs = true; } else { newState = { addrsList: this.props.addrsList, fetchedAddrs: true }; } } if (newState) { this.setState(newState); } } }; unbundleConfig = () => { let config = { settings_hot_enabled: this.props.defaultStorageConfig.hot.enabled, settings_hot_allow_unfreeze: this.props.defaultStorageConfig.hot.allowUnfreeze, settings_hot_ipfs_add_timeout: this.props.defaultStorageConfig.hot.ipfs.addTimeout, settings_cold_enabled: this.props.defaultStorageConfig.cold.enabled, settings_cold_default_address: this.props.defaultStorageConfig.cold.filecoin.addr, settings_cold_default_duration: this.props.defaultStorageConfig.cold.filecoin.dealMinDuration, settings_cold_default_replication_factor: this.props.defaultStorageConfig.cold.filecoin .repFactor, settings_cold_default_excluded_miners: this.props.defaultStorageConfig.cold.filecoin .excludedMinersList, settings_cold_default_trusted_miners: this.props.defaultStorageConfig.cold.filecoin .trustedMinersList, settings_cold_country_codes_list: this.props.defaultStorageConfig.cold.filecoin .countryCodesList, settings_cold_default_max_price: this.props.defaultStorageConfig.cold.filecoin.maxPrice, settings_cold_default_auto_renew: this.props.defaultStorageConfig.cold.filecoin.renew.enabled, settings_cold_default_auto_renew_threshold: this.props.defaultStorageConfig.cold.filecoin .renew.threshold, settings_repairable: this.props.defaultStorageConfig.repairable, fetchedConfig: true, }; return config; }; _handleSave = async () => { this.props.onSave({ cold: { enabled: this.state.settings_cold_enabled, filecoin: { addr: this.state.settings_cold_default_address, countryCodesList: this.state.settings_cold_country_codes_list, dealMinDuration: this.state.settings_cold_default_duration, excludedMinersList: this.state.settings_cold_default_excluded_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_threshold, }, repFactor: this.state.settings_cold_default_replication_factor, trustedMinersList: this.state.settings_cold_default_trusted_miners, }, }, hot: { enabled: this.state.settings_hot_enabled, allowUnfreeze: this.state.settings_hot_allow_unfreeze, ipfs: { addTimeout: this.state.settings_hot_ipfs_add_timeout, }, }, repairable: this.state.settings_repairable, }); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { let addrsList = this.state.addrsList.map((each) => { return { value: each.addr, name: each.name, }; }); return (