import * as React from "react"; import * as Actions from "~/common/actions"; import * as System from "~/components/system"; import * as Strings from "~/common/strings"; import * as SVG from "~/common/svg"; import * as Constants from "~/common/constants"; import * as Events from "~/common/custom-events"; import { css } from "@emotion/react"; import { LoaderSpinner } from "~/components/system/components/Loaders"; import { FilecoinNumber } from "@glif/filecoin-number"; import Section from "~/components/core/Section"; import ScenePage from "~/components/core/ScenePage"; import ScenePageHeader from "~/components/core/ScenePageHeader"; export const createState = (config) => { return { ...config, }; }; let mounted = false; const STYLES_ROW = css` display: flex; align-items: flex-start; justify-content: space-between; `; const STYLES_LEFT = css` color: ${Constants.system.black}; transition: 200ms ease all; min-width: 10%; width: 100%; :visited { color: ${Constants.system.black}; } `; const STYLES_RIGHT = css` flex-shrink: 0; transition: 200ms ease all; cursor: pointer; :hover { color: ${Constants.system.brand}; } `; export default class SceneSettings extends React.Component { state = {}; _deferredSave = null; async componentDidMount() { if (mounted) { return null; } mounted = true; this.setState({ networkViewer: this.props.networkViewer, ...createState(this.props.networkViewer.settings), }); } componentWillUnmount() { mounted = false; } _handleSave = async () => { this.setState({ loading: true }); const response = await Actions.updateViewer({ type: "SAVE_DEFAULT_ARCHIVE_CONFIG", config: { addr: this.state.addr, countryCodes: this.state.countryCodes, dealMinDuration: this.state.dealMinDuration, dealStartOffset: this.state.dealStartOffset, excludedMiners: this.state.excludedMiners, fastRetrieval: this.state.fastRetrieval, maxPrice: this.state.maxPrice, renew: { enabled: this.state.renewEnabled, threshold: this.state.renewThreshold }, repFactor: Number(this.state.repFactor), trustedMiners: this.state.trustedMiners, }, }); this.setState({ loading: false }); return Events.dispatchMessage({ message: "Your default settings are saved.", status: "INFO" }); }; _handleAddTrustedMiner = () => { const miner = prompt("Enter the Miner ID to trust."); if (Strings.isEmpty(miner)) { return Events.dispatchMessage({ message: "You must provide a miner ID." }); } if (this.state.trustedMiners.includes(miner)) { return Events.dispatchMessage({ message: `${miner} is already on your list of miners to try.`, }); } this.setState({ trustedMiners: [miner, ...this.state.trustedMiners], }); }; _handleAddExcludedMiner = () => { const miner = prompt("Enter the Miner ID to exclude."); if (Strings.isEmpty(miner)) { return Events.dispatchMessage({ message: "You must provide a miner ID." }); } if (this.state.excludedMiners.includes(miner)) { return Events.dispatchMessage({ message: `${miner} is already on your list of miners to exclude.`, }); } this.setState({ excludedMiners: [miner, ...this.state.excludedMiners], }); }; _handleRemoveTrustedMiner = (minerId) => { this.setState({ trustedMiners: this.state.trustedMiners.filter((m) => m !== minerId), }); }; _handleRemoveExcludedMiner = (minerId) => { this.setState({ excludedMiners: this.state.excludedMiners.filter((m) => m !== minerId), }); }; _handleChange = (e) => { this.setState({ [e.target.name]: e.target.value }); }; render() { let inFil = 0; let inFilRenew = 0; if (this.state.networkViewer) { const filecoinNumber = new FilecoinNumber( `${Strings.isEmpty(this.state.maxPrice) ? `0` : this.state.maxPrice}`, "attofil" ); const filecoinNumber2 = new FilecoinNumber( `${Strings.isEmpty(this.state.renewThreshold) ? `0` : this.state.renewThreshold}`, "attofil" ); inFil = filecoinNumber.toFil(); inFilRenew = filecoinNumber2.toFil(); } return ( {this.state.networkViewer ? (
{ return { miner: (
{miner} this._handleRemoveTrustedMiner(miner)} >
), }; }), }} />
{ return { miner: (
Excluding: {miner} this._handleRemoveExcludedMiner(miner)} >
), }; }), }} />
Enable auto renew for Filecoin storage deals.
Save configuration
) : ( )}
); } }