2020-06-17 21:05:13 +03:00
import * as React from "react" ;
import * as Actions from "~/common/actions" ;
import * as System from "~/components/system" ;
2020-04-09 00:29:13 +03:00
2020-06-17 21:05:13 +03:00
import { css } from "@emotion/react" ;
2020-04-09 00:29:13 +03:00
2020-06-17 21:05:13 +03:00
import ScenePage from "~/components/core/ScenePage" ;
2020-04-09 00:29:13 +03:00
const STYLES _GROUP = css `
display : flex ;
align - items : center ;
justify - content : space - between ;
` ;
2020-06-04 09:26:20 +03:00
const STYLES _SUBGROUP = css `
padding - left : 24 px ;
` ;
2020-04-09 00:29:13 +03:00
const STYLES _LEFT = css `
flex - shrink : 0 ;
padding : 12 px 0 0 0 ;
min - width : 480 px ;
` ;
const STYLES _RIGHT = css `
min - width : 10 % ;
padding - left : 48 px ;
2020-06-04 09:26:20 +03:00
padding - top : 24 px ;
2020-04-09 00:29:13 +03:00
width : 100 % ;
` ;
export default class SceneSettings extends React . Component {
2020-06-08 09:45:53 +03:00
_deferredSave = null ;
_handleSave = async ( ) => {
2020-06-09 21:00:36 +03:00
await Actions . setDefaultConfig ( {
2020-06-08 09:45:53 +03:00
config : {
hot : {
enabled : this . props . viewer . settings _cold _enabled ,
allowUnfreeze : this . props . viewer . settings _hot _allow _unfreeze ,
ipfs : {
addTimeout : this . props . viewer . settings _hot _ipfs _add _timeout ,
} ,
} ,
cold : {
enabled : this . props . viewer . settings _cold _enabled ,
filecoin : {
addr : this . props . viewer . settings _cold _default _address ,
2020-06-09 21:00:36 +03:00
dealMinDuration : this . props . viewer . settings _cold _default _duration ,
2020-06-17 21:05:13 +03:00
repFactor : this . props . viewer
. settings _cold _default _replication _factor ,
excludedMinersList : this . props . viewer
. settings _cold _default _excluded _miners ,
trustedMinersList : this . props . viewer
. settings _cold _default _trusted _miners ,
2020-06-08 09:45:53 +03:00
maxPrice : this . props . viewer . settings _cold _default _max _price ,
renew : {
enabled : this . props . viewer . settings _cold _default _auto _renew ,
2020-06-17 21:05:13 +03:00
threshold : this . props . viewer
. settings _cold _default _auto _renew _max _price ,
2020-06-08 09:45:53 +03:00
} ,
} ,
} ,
} ,
} ) ;
} ;
2020-04-09 00:29:13 +03:00
_handleChange = ( e ) => {
2020-06-08 09:45:53 +03:00
window . clearTimeout ( this . _deferredSave ) ;
this . _deferredSave = null ;
2020-04-09 00:29:13 +03:00
this . props . onViewerChange ( e ) ;
2020-06-08 09:45:53 +03:00
this . _deferredSave = window . setTimeout ( async ( ) => {
await this . _handleSave ( ) ;
} , 2000 ) ;
2020-04-09 00:29:13 +03:00
} ;
render ( ) {
2020-06-04 09:26:20 +03:00
let addresses = { } ;
this . props . viewer . addresses . forEach ( ( a ) => {
addresses [ a . address ] = a ;
} ) ;
2020-06-17 21:05:13 +03:00
const currentAddress =
addresses [ this . props . viewer . settings _cold _default _address ] ;
2020-06-04 09:26:20 +03:00
2020-04-09 00:29:13 +03:00
return (
< ScenePage >
< System . H1 > Settings < / S y s t e m . H 1 >
< System . H2 style = { { marginTop : 48 } } > Storage defaults < / S y s t e m . H 2 >
< div css = { STYLES _GROUP } style = { { marginTop : 32 } } >
< div css = { STYLES _LEFT } >
< System . DescriptionGroup
label = "Automatically approve deals"
tooltip = "When this is enabled you will skip the confirmation step, but if you do not have enough Filecoin you will receive a warning."
description = "Enable this if every storage deal should be automatically approved to skip confirmation."
/ >
< / d i v >
< div css = { STYLES _RIGHT } >
< System . Toggle
name = "settings_deals_auto_approve"
onChange = { this . _handleChange }
active = { this . props . viewer . settings _deals _auto _approve }
/ >
< / d i v >
< / d i v >
2020-06-04 09:26:20 +03:00
< div css = { STYLES _GROUP } style = { { marginTop : 32 } } >
< div css = { STYLES _LEFT } >
< System . DescriptionGroup
label = "Enable cold storage"
tooltip = "Placeholder"
description = "By enabling cold storage, every time you make a deal your data will be stored on the Filecoin Network."
/ >
< / d i v >
< div css = { STYLES _RIGHT } >
< System . Toggle
name = "settings_cold_enabled"
onChange = { this . _handleChange }
active = { this . props . viewer . settings _cold _enabled }
/ >
< / d i v >
< / d i v >
{ this . props . viewer . settings _cold _enabled ? (
< div css = { STYLES _SUBGROUP } >
< System . SelectMenu
containerStyle = { { marginTop : 24 } }
label = "Default Filecoin address"
description = "Default Filecoin address settings description."
tooltip = "Placeholder."
name = "settings_cold_default_address"
value = { this . props . viewer . settings _cold _default _address }
category = "address"
onChange = { this . _handleChange }
2020-06-17 21:05:13 +03:00
options = { this . props . viewer . addresses }
>
{ currentAddress ? currentAddress . name : "None" }
2020-06-04 09:26:20 +03:00
< / S y s t e m . S e l e c t M e n u >
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Default Filecoin deal duration"
2020-06-17 21:05:13 +03:00
description = "Default Filecoin deal duration settings description. Current deal duration is in epochs but should change to months/weeks/days."
2020-06-04 09:26:20 +03:00
tooltip = "Placeholder."
name = "settings_cold_default_duration"
2020-06-09 21:00:36 +03:00
type = "number"
2020-06-04 09:26:20 +03:00
value = { this . props . viewer . settings _cold _default _duration }
2020-06-17 21:05:13 +03:00
placeholder = "Type in epochs (~25 seconds)"
2020-06-04 09:26:20 +03:00
onChange = { this . _handleChange }
/ >
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Default Filecoin replication factor"
description = "Default Filecoin replication factor settings description."
tooltip = "Placeholder."
name = "settings_cold_default_replication_factor"
value = { this . props . viewer . settings _cold _default _replication _factor }
placeholder = "Type in amount of miners"
onChange = { this . _handleChange }
/ >
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Max Filecoin price."
description = "Set the maximum Filecoin price you're willing to pay."
tooltip = "Placeholder."
name = "settings_cold_default_max_price"
value = { this . props . viewer . settings _cold _default _max _price }
placeholder = "Type in amount of Filecoin"
onChange = { this . _handleChange }
/ >
< System . CheckBox
style = { { marginTop : 48 } }
name = "settings_cold_default_auto_renew"
value = { this . props . viewer . settings _cold _default _auto _renew }
2020-06-17 21:05:13 +03:00
onChange = { this . _handleChange }
>
2020-06-04 09:26:20 +03:00
Enable auto renew for Filecoin Network deals .
< / S y s t e m . C h e c k B o x >
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Max Filecoin deal auto renew price."
description = "Set the maximum Filecoin price you're willing to pay for auto renew."
tooltip = "Placeholder."
name = "settings_cold_default_auto_renew_max_price"
2020-06-17 21:05:13 +03:00
value = {
this . props . viewer . settings _cold _default _auto _renew _max _price
}
2020-06-04 09:26:20 +03:00
placeholder = "Type in amount of Filecoin"
onChange = { this . _handleChange }
/ >
< / d i v >
) : null }
< div css = { STYLES _GROUP } style = { { marginTop : 32 } } >
< div css = { STYLES _LEFT } >
< System . DescriptionGroup
label = "Enable hot storage"
tooltip = "Placeholder"
description = "By enabling hot storage, every time you make a deal your data will be stored on IPFS."
/ >
< / d i v >
< div css = { STYLES _RIGHT } >
< System . Toggle
name = "settings_hot_enabled"
onChange = { this . _handleChange }
active = { this . props . viewer . settings _hot _enabled }
/ >
< / d i v >
< / d i v >
{ this . props . viewer . settings _hot _enabled ? (
< div css = { STYLES _SUBGROUP } >
< System . CheckBox
style = { { marginTop : 48 } }
name = "settings_hot_allow_unfreeze"
value = { this . props . viewer . settings _hot _allow _unfreeze }
2020-06-17 21:05:13 +03:00
onChange = { this . _handleChange }
>
2020-06-04 09:26:20 +03:00
IPFS allow unfreeze setting description .
< / S y s t e m . C h e c k B o x >
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Add timeout"
description = "Add IPFS timeout setting description."
tooltip = "Placeholder."
name = "settings_hot_ipfs_add_timeout"
value = { this . props . viewer . settings _hot _ipfs _add _timeout }
placeholder = "Type in seconds"
onChange = { this . _handleChange }
/ >
< / d i v >
) : null }
< / S c e n e P a g e >
) ;
}
}
/ *
2020-04-09 00:29:13 +03:00
< System . Input
containerStyle = { { marginTop : 24 } }
label = "Default deal location"
description = "Choose the amount of months you expect to keep files on the network for."
tooltip = "This is a default value that makes sealing and storing data easier on the network. You can change this value at any time you like. Changing this value will not affect your current deals."
name = "settings_deal_default_duration"
value = { this . props . viewer . settings _deal _default _duration }
placeholder = "Type in an amount of months"
onChange = { this . _handleChange }
/ >
< System . Input
containerStyle = { { marginTop : 32 } }
label = "Default maximum storage"
description = "Choose the maximum Filecoin you are willing to pay for storage."
tooltip = "Changing this value will not affect your current deals."
name = "settings_deal_maximum_storage_payment"
value = { this . props . viewer . settings _deal _maximum _storage _payment }
placeholder = "Type in an amount of Filecoin"
onChange = { this . _handleChange }
/ >
< System . Input
containerStyle = { { marginTop : 32 } }
label = "Default replication factor"
description = "Choose the default amount of times your files should replicate."
tooltip = "Changing this value will not affect your current deals."
name = "settings_deal_replication_factor"
value = { this . props . viewer . settings _deal _replication _factor }
placeholder = "Type a number"
onChange = { this . _handleChange }
/ >
< System . DescriptionGroup
style = { { marginTop : 32 } }
label = "Default miners by ID"
tooltip = "Changing this value will not affect your current deals."
description = "Enter the miner IDs separated by a comma for the miners you specifically want to use."
/ >
< System . Textarea
value = { this . props . viewer . settings _deal _default _miners }
name = "settings_deal_default_miners"
onChange = { this . _handleChange }
/ >
< System . SelectMenu
containerStyle = { { marginTop : 32 } }
label = "Geographic preference"
description = "Pick any location in the world you would like your files to be stored."
tooltip = "Changing this value will not affect your current deals."
name = "settings_deal_country"
value = { this . props . viewer . settings _deal _country }
onChange = { this . _handleChange }
2020-06-04 09:26:20 +03:00
options = { SELECT _MENU _OPTIONS } >
2020-04-09 00:29:13 +03:00
{ SELECT _MENU _MAP [ this . props . viewer . settings _deal _country ] }
< / S y s t e m . S e l e c t M e n u >
2020-06-04 09:26:20 +03:00
* /