2023-04-20 10:03:36 +02:00
import React , { useState , useEffect , useRef } from "react" ;
2023-03-15 15:25:09 +01:00
import { Link , useLocation , useNavigate } from "react-router-dom" ;
import Modal from "react-modal" ;
2023-07-29 21:40:03 +02:00
import { deleteCaches , exportAccount , importAccount , setAccount , setActiveAccount , useAccount , useAccounts , useResolvedAuthorAddress } from "@plebbit/plebbit-react-hooks" ;
2023-05-24 12:15:43 +02:00
import { StyledModal } from "../styled/modals/SettingsModal.styled" ;
import useError from "../../hooks/useError" ;
import useSuccess from "../../hooks/useSuccess" ;
2023-06-16 14:42:23 +02:00
import useAnonModeStore from '../../hooks/stores/useAnonModeStore' ;
import useGeneralStore from '../../hooks/stores/useGeneralStore' ;
2023-05-24 12:15:43 +02:00
import packageJson from '../../../package.json'
2023-04-24 20:00:11 +00:00
const { version } = packageJson
2023-03-15 15:25:09 +01:00
const SettingsModal = ({ isOpen , closeModal }) => {
2023-05-26 17:25:49 +02:00
const {
selectedStyle ,
} = useGeneralStore ( state => state );
2023-06-16 14:42:23 +02:00
const { anonymousMode , setAnonymousMode } = useAnonModeStore ();
2023-05-26 17:25:49 +02:00
2023-03-15 15:25:09 +01:00
const navigate = useNavigate ();
const location = useLocation ();
2023-04-18 22:21:28 +02:00
const [ expanded , setExpanded ] = useState ([]);
2023-05-10 14:17:24 +02:00
const [ accountJson , setAccountJson ] = useState ( null );
2023-07-29 21:40:03 +02:00
const [ copyStatus , setCopyStatus ] = useState ( false );
const [ ensName , setEnsName ] = useState ( '' );
const [ checkedENS , setCheckedENS ] = useState ( false );
2023-05-10 14:17:24 +02:00
2023-06-22 15:55:33 +02:00
const [, setNewErrorMessage ] = useError ();
const [, setNewSuccessMessage ] = useSuccess ();
2023-03-15 15:25:09 +01:00
2023-04-20 10:03:36 +02:00
const account = useAccount ();
2023-05-10 14:55:06 +02:00
const { accounts } = useAccounts ();
2023-04-20 10:03:36 +02:00
const gatewayRef = useRef ();
const ipfsRef = useRef ();
const pubsubRef = useRef ();
2023-07-11 12:26:22 +02:00
const ethereumRpcRef = useRef ();
const polygonRpcRef = useRef ();
2023-04-20 10:03:36 +02:00
const dataPathRef = useRef ();
2023-05-10 14:17:24 +02:00
const importRef = useRef ();
2023-05-26 17:25:49 +02:00
const nameRef = useRef ();
2023-07-29 21:40:03 +02:00
const ensRef = useRef ();
const author = {... account ? . author , address : ensName };
const { resolvedAddress , state } = useResolvedAuthorAddress ({ author , cache : false });
useEffect (() => {
if ( checkedENS && resolvedAddress && state === 'succeeded' ) {
setCheckedENS ( false );
}
}, [ checkedENS , state , resolvedAddress ]);
const handleENSChange = () => {
const newEnsName = ensRef . current . value ;
setEnsName ( newEnsName );
};
const handleENSCheck = () => {
const newEnsName = ensRef . current . value ;
setEnsName ( newEnsName );
setCheckedENS ( true );
};
const handleENSSave = async () => {
if ( resolvedAddress === account ? . signer ? . address ) {
try {
await setAccount ({
... account ,
author : {
... account ? . author ,
address : ensName ,
},
});
setNewSuccessMessage ( "ENS Name Saved" );
} catch ( error ) {
setNewErrorMessage ( error . message );
console . log ( error );
}
} else if ( resolvedAddress !== account ? . signer ? . address ) {
setNewErrorMessage ( `Failed resolving address, ${ ensName } ` );
}
};
2023-04-20 10:03:36 +02:00
2023-07-02 11:45:56 +02:00
const defaultGatewayUrls = [
'https://ipfs.io' ,
'https://ipfsgateway.xyz' ,
'https://cloudflare-ipfs.com' ,
'https://plebpubsub.live'
];
2023-07-11 12:26:22 +02:00
2023-07-02 11:45:56 +02:00
const defaultPubsubHttpClientsOptions = [
'https://pubsubprovider.xyz/api/v0' ,
'https://plebpubsub.live/api/v0'
];
2023-07-11 12:26:22 +02:00
const defaultEthereumRpcUrls = [
2023-07-16 18:22:47 +02:00
'ethers.js' ,
2023-07-11 12:26:22 +02:00
'https://ethrpc.xyz' ,
2023-07-16 18:22:47 +02:00
'viem' ,
2023-07-11 12:26:22 +02:00
];
const defaultPolygonRpcUrls = [
'https://polygon-rpc.com' ,
];
2023-07-29 21:40:03 +02:00
2023-04-20 13:59:04 +02:00
const isValidURL = ( url ) => {
try {
new URL ( url );
return true ;
} catch {
return false ;
}
};
2023-07-11 12:26:22 +02:00
2023-07-29 21:40:03 +02:00
const handleCopyAddress = async () => {
try {
await navigator . clipboard . writeText ( account ? . author . address );
setCopyStatus ( true );
} catch ( err ) {
console . error ( 'Failed to copy text: ' , err );
}
};
useEffect (() => {
let copyStatusTimeoutId ;
let checkedENSTimeoutId ;
if ( copyStatus ) {
copyStatusTimeoutId = setTimeout (() => setCopyStatus ( false ), 3000 );
}
if ( checkedENS ) {
checkedENSTimeoutId = setTimeout (() => setCheckedENS ( false ), 5000 );
}
return () => {
clearTimeout ( copyStatusTimeoutId );
clearTimeout ( checkedENSTimeoutId );
};
}, [ copyStatus , checkedENS ]);
2023-04-20 13:59:04 +02:00
const handleSavePlebbitOptions = async () => {
2023-07-02 11:45:56 +02:00
let gatewayUrls = gatewayRef . current . value . split ( '\n' ). filter ( url => url . trim ());
let ipfsClientsOptions = ipfsRef . current . value . split ( '\n' ). filter ( url => url . trim ());
let pubsubClientsOptions = pubsubRef . current . value . split ( '\n' ). filter ( url => url . trim ());
if ( ! gatewayUrls . length ) {
gatewayUrls = defaultGatewayUrls ;
}
if ( ! ipfsClientsOptions . length ) {
ipfsClientsOptions = undefined ;
}
if ( ! pubsubClientsOptions . length ) {
pubsubClientsOptions = defaultPubsubHttpClientsOptions ;
}
2023-04-20 13:59:04 +02:00
const invalidUrls = [
2023-07-02 11:45:56 +02:00
... gatewayUrls || defaultGatewayUrls ,
2023-04-20 13:59:04 +02:00
...( ipfsClientsOptions || []),
2023-07-02 11:45:56 +02:00
... pubsubClientsOptions || defaultPubsubHttpClientsOptions ,
2023-04-20 13:59:04 +02:00
]. filter (( url ) => ! isValidURL ( url ));
if ( invalidUrls . length > 0 ) {
2023-06-22 15:55:33 +02:00
setNewErrorMessage ( `Invalid URL(s): ${ invalidUrls . join ( ', ' ) } ` );
2023-04-20 13:59:04 +02:00
return ;
}
const plebbitOptions = {
ipfsGatewayUrls : gatewayUrls ,
ipfsHttpClientsOptions : ipfsClientsOptions ,
pubsubHttpClientsOptions : pubsubClientsOptions ,
};
try {
await setAccount ({ ... account , plebbitOptions });
2023-05-16 13:26:05 +02:00
localStorage . setItem ( "successToast" , "Settings Saved" );
2023-04-20 13:59:04 +02:00
window . location . reload ();
} catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-04-20 13:59:04 +02:00
}
};
2023-07-11 12:26:22 +02:00
const handleSaveChainProviders = async () => {
let ethereumRpcUrls = ethereumRpcRef . current . value . split ( '\\n' ). filter ( url => url . trim ());
let polygonRpcUrls = polygonRpcRef . current . value . split ( '\\n' ). filter ( url => url . trim ());
if ( ! ethereumRpcUrls . length ) {
ethereumRpcUrls = defaultEthereumRpcUrls ;
}
if ( ! polygonRpcUrls . length ) {
polygonRpcUrls = defaultPolygonRpcUrls ;
}
const invalidUrls = [
... ethereumRpcUrls || defaultEthereumRpcUrls ,
... polygonRpcUrls || defaultPolygonRpcUrls ,
]. filter (( url ) => ! isValidURL ( url ));
if ( invalidUrls . length > 0 ) {
setNewErrorMessage ( `Invalid URL(s): ${ invalidUrls . join ( ', ' ) } ` );
return ;
}
const chainProviders = {
'eth' : {
urls : ethereumRpcUrls ,
chainId : 1 ,
},
'matic' : {
urls : polygonRpcUrls ,
chainId : 137 ,
}
}
try {
await setAccount ({
... account ,
plebbitOptions : {
2023-07-29 21:40:03 +02:00
... account ? . plebbitOptions ,
2023-07-11 12:26:22 +02:00
chainProviders ,
},
});
2023-07-16 18:22:47 +02:00
localStorage . setItem ( "successToast" , "Blockchain Options Saved" );
2023-07-11 12:26:22 +02:00
window . location . reload ();
} catch ( error ) {
setNewErrorMessage ( error . message ); console . log ( error );
}
};
2023-04-20 13:59:04 +02:00
const handleResetPlebbitOptions = async () => {
2023-06-22 15:55:33 +02:00
setNewErrorMessage ( null );
setNewSuccessMessage ( null );
2023-04-20 13:59:04 +02:00
gatewayRef . current . value = defaultGatewayUrls . join ( '\n' );
ipfsRef . current . value = "" ;
pubsubRef . current . value = defaultPubsubHttpClientsOptions . join ( '\n' );
dataPathRef . current . value = "" ;
try {
await setAccount ({
... account ,
plebbitOptions : {
ipfsGatewayUrls : defaultGatewayUrls ,
ipfsHttpClientsOptions : undefined ,
pubsubHttpClientsOptions : defaultPubsubHttpClientsOptions ,
},
});
2023-05-16 13:26:05 +02:00
localStorage . setItem ( "successToast" , "Settings Reset" );
2023-04-20 13:59:04 +02:00
window . location . reload ();
} catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-04-20 13:59:04 +02:00
}
};
2023-04-19 16:20:43 +02:00
2023-07-11 12:26:22 +02:00
const handleResetChainProviders = async () => {
setNewErrorMessage ( null );
setNewSuccessMessage ( null );
2023-07-16 18:22:47 +02:00
ethereumRpcRef . current . value = defaultEthereumRpcUrls . join ( '\n' );
polygonRpcRef . current . value = defaultPolygonRpcUrls . join ( '\n' );
2023-07-11 12:26:22 +02:00
const chainProviders = {
'eth' : {
urls : defaultEthereumRpcUrls ,
chainId : 1 ,
},
'matic' : {
urls : defaultPolygonRpcUrls ,
chainId : 137 ,
}
}
try {
await setAccount ({
... account ,
plebbitOptions : {
2023-07-29 21:40:03 +02:00
... account ? . plebbitOptions ,
2023-07-11 12:26:22 +02:00
chainProviders ,
},
});
2023-07-16 18:22:47 +02:00
localStorage . setItem ( "successToast" , "Blockchain Options Reset" );
2023-07-11 12:26:22 +02:00
window . location . reload ();
} catch ( error ) {
setNewErrorMessage ( error . message ); console . log ( error );
}
};
2023-03-15 15:25:09 +01:00
const handleCloseModal = () => {
2023-05-10 14:17:24 +02:00
setAccountJson ( null );
2023-05-03 17:35:38 +02:00
if ( location . pathname . endsWith ( "/settings" )) {
const newPath = location . pathname . slice ( 0 , - 9 );
closeModal ();
navigate ( newPath , { replace : true });
2023-03-15 15:25:09 +01:00
} else {
2023-05-03 17:35:38 +02:00
closeModal ();
2023-03-15 15:25:09 +01:00
}
2023-05-03 17:35:38 +02:00
};
2023-03-15 15:25:09 +01:00
2023-04-19 16:20:43 +02:00
2023-04-18 22:21:28 +02:00
const toggleExpanded = ( index ) => {
setExpanded (( prevExpanded ) => {
const newExpanded = [... prevExpanded ];
if ( newExpanded . includes ( index )) {
newExpanded . splice ( newExpanded . indexOf ( index ), 1 );
} else {
newExpanded . push ( index );
}
return newExpanded ;
});
};
2023-04-19 16:20:43 +02:00
2023-04-18 22:21:28 +02:00
const expandAll = () => {
2023-07-11 12:26:22 +02:00
if ( expanded . length === 4 ) {
2023-04-18 22:21:28 +02:00
setExpanded ([]);
} else {
2023-07-11 12:26:22 +02:00
setExpanded ([ 0 , 1 , 2 , 3 ]);
2023-04-18 22:21:28 +02:00
}
};
2023-04-19 16:20:43 +02:00
2023-04-19 16:00:31 +02:00
useEffect (() => {
if ( localStorage . getItem ( "cacheCleared" ) === "true" ) {
2023-06-22 15:55:33 +02:00
setNewSuccessMessage ( "Cache Cleared" );
2023-04-19 16:00:31 +02:00
localStorage . removeItem ( "cacheCleared" );
}
2023-06-22 15:55:33 +02:00
}, [ setNewSuccessMessage ]);
2023-05-10 14:17:24 +02:00
const handleExport = async () => {
const activeAccountJson = await exportAccount ();
setAccountJson ( activeAccountJson );
};
const handleImport = async () => {
const accountJson = importRef . current . value ;
try {
2023-05-16 13:26:05 +02:00
const parsedJson = JSON . parse ( accountJson );
2023-05-10 14:17:24 +02:00
await importAccount ( accountJson );
2023-05-16 13:26:05 +02:00
setActiveAccount ( parsedJson . account ? . name );
2023-06-22 15:55:33 +02:00
setNewSuccessMessage ( "Account Imported" );
2023-05-10 14:17:24 +02:00
} catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-05-10 14:17:24 +02:00
}
};
2023-05-10 14:55:06 +02:00
const handleAccountChange = ( e ) => {
setActiveAccount ( e . target . value );
};
2023-05-26 17:25:49 +02:00
const handleDisplayName = async () => {
const name = nameRef . current . value ;
try {
await setAccount ({
... account ,
2023-07-29 21:40:03 +02:00
name : name || account ? . name ,
2023-05-26 17:25:49 +02:00
author : {
2023-07-29 21:40:03 +02:00
... account ? . author ,
2023-05-26 17:25:49 +02:00
displayName : name ,
}});
2023-06-22 15:55:33 +02:00
setNewSuccessMessage ( "Account Name Saved" );
2023-05-26 17:25:49 +02:00
} catch ( error ) {
2023-07-02 11:45:56 +02:00
setNewErrorMessage ( error . message ); console . log ( error );
2023-05-26 17:25:49 +02:00
}
};
2023-06-09 18:06:01 +02:00
2023-04-18 22:21:28 +02:00
2023-03-15 15:25:09 +01:00
return (
< StyledModal
isOpen = { isOpen }
2023-05-03 17:35:38 +02:00
onRequestClose = { handleCloseModal }
2023-03-15 15:25:09 +01:00
contentLabel = "Settings"
2023-05-10 14:17:24 +02:00
style = {{ overlay : { backgroundColor : "rgba(0,0,0,.25)" }}}
2023-03-15 15:25:09 +01:00
selectedStyle = { selectedStyle }
2023-04-18 22:21:28 +02:00
expanded = { expanded }
2023-03-15 15:25:09 +01:00
>
< div className = "panel" >
< div className = "panel-header" >
2023-04-22 13:11:42 +02:00
< span id = "version" >
2023-07-04 13:42:19 +02:00
v { version } -& nbsp ;
{ window . electron && window . electron . isElectron ? (
< Link className = "all-button" id = "node-stats" to = "http://localhost:5001/webui/" target = "_blank" rel = "noreferrer" >
full node
</ Link >
) : (< span > web </ span >)
}
2023-04-22 13:11:42 +02:00
</ span >
2023-03-15 15:25:09 +01:00
Settings
< Link to = "" onClick = { handleCloseModal }>
< span className = "icon" title = "close" />
</ Link >
</ div >
2023-04-18 22:21:28 +02:00
< div className = "all-div" >
[
< button className = "all-button"
onClick = { expandAll } style = {{ all : "unset" , cursor : "pointer" }}>
2023-07-11 12:26:22 +02:00
{ expanded . length === 4 ? "Collapse All Settings" : "Expand All Settings" }
2023-04-18 22:21:28 +02:00
</ button >
]
</ div >
2023-06-17 20:24:38 +02:00
< ul >
2023-04-18 22:21:28 +02:00
< li className = "settings-cat-lbl" >
< span className = { ` ${ expanded . includes ( 1 ) ? 'minus' : 'plus' } ` }
onClick = {() => toggleExpanded ( 1 )}
/>
< span className = "settings-pointer" style = {{ cursor : "pointer" }}
onClick = {() => toggleExpanded ( 1 )}
2023-05-09 12:59:00 +02:00
> Account </ span >
< div className = "plebbit-options-buttons"
style = {{ display : expanded . includes ( 1 ) ? 'block' : 'none' }}
>
2023-07-29 21:40:03 +02:00
< button className = "save-button"
onClick = { handleExport }> Export </ button >
< button className = "reset-button"
onClick = { handleImport }
> Import </ button >
2023-05-09 12:59:00 +02:00
</ div >
2023-04-18 22:21:28 +02:00
</ li >
< ul className = "settings-cat" style = {{ display : expanded . includes ( 1 ) ? 'block' : 'none' }}>
2023-06-17 20:24:38 +02:00
< li className = "anon-off" >
< label title = { ! anonymousMode ?
"Enable anon mode" :
"Disable anon mode"
}>
< input
type = "checkbox"
checked = { anonymousMode }
onChange = {() => { setAnonymousMode ( ! anonymousMode )}}
/>
2023-07-29 21:40:03 +02:00
& nbsp ; Anon Mode
2023-06-17 20:24:38 +02:00
</ label >
</ li >
< li className = "settings-tip anon-tip" >
2023-06-29 17:09:22 +02:00
Automatically use a different u / address per thread to post .
2023-06-17 20:24:38 +02:00
</ li >
2023-05-10 14:17:24 +02:00
< li className = "settings-option disc" >
2023-05-26 17:25:49 +02:00
Account Data
2023-05-10 14:55:06 +02:00
</ li >
2023-05-10 14:17:24 +02:00
< li className = "settings-tip" >
To export , click "Export" , then save your account data displayed below in a safe place . To import , paste your account data into the box below , then click "Import" .
2023-04-18 22:21:28 +02:00
</ li >
2023-05-10 14:17:24 +02:00
< div className = "settings-input" >
2023-05-30 19:08:21 +02:00
{ accountJson ? (
< textarea value = { accountJson } readOnly />
) : (
< textarea ref = { importRef } />
)}
2023-05-10 14:17:24 +02:00
</ div >
2023-07-29 21:40:03 +02:00
< li className = "settings-option disc" >
2023-05-26 17:25:49 +02:00
Account Address : u / { account ? . author . shortAddress }
2023-05-10 14:55:06 +02:00
</ li >
< li className = "settings-tip" >
Select a different account to use in the dropdown below .
</ li >
< li >
< div className = "settings-input" >
< select className = "settings-select"
value = { account ? . name }
onChange = { handleAccountChange }
>
{ accounts . map (( account ) => (
< option key = { account ? . name } value = { account ? . name }>
{ account ? . name }
</ option >
))}
</ select >
2023-07-29 21:40:03 +02:00
{ account ? . author . address . endsWith ( ".eth" ) ? null : (
< button style = {{ marginLeft : '35px' }} className = "save-button" id = "save-name" onClick = { handleCopyAddress }>
{ copyStatus ? "Copied!" : "Copy Full Address" }
</ button >
)}
2023-05-10 14:55:06 +02:00
</ div >
</ li >
2023-07-29 21:40:03 +02:00
< li className = "settings-option disc" >
Crypto Address
</ li >
< li className = "settings-tip" >
{ account ? . author . address . endsWith ( ".eth" ) ? "Your account address is already an ENS name." : (
'Change your account address to an ENS name you own: in your ENS name page on ens.domains, click on "Records", "Edit Records", "Add record", add "plebbit-author-address" as record name, add your full address as value (copy it with the button above) and save.'
)}
</ li >
< div className = "settings-input" >
< input
className = "settings-input"
style = {{ marginLeft : '20px' }}
placeholder = "address.eth"
ref = { ensRef }
value = { ensName }
onChange = { handleENSChange }
disabled = { checkedENS }
/>
< button className = "save-button" id = "save-name" onClick = { handleENSSave }>
Save
</ button >
< button className = "save-button check-button" id = "save-name" onClick = { handleENSCheck }>
Check
</ button >
</ div >
{ checkedENS && ensName === account ? . signer ? . address && (
< li className = "settings-tip" style = {{ marginTop : '10px' , color : 'green' }}>
{ ensName } has been acquired by you correctly .
</ li >
)}
{ checkedENS && ensName !== account ? . signer ? . address && (
< li className = "settings-tip" style = {{ marginTop : '10px' , color : 'red' }}>
{ ensName } has not been acquired by you yet .
</ li >
)}
< li className = "settings-option disc" >
2023-05-26 17:25:49 +02:00
Account Name
</ li >
< li className = "settings-tip" >
Change both your account name ( default "Account 1" ) and display name ( default "Anonymous" ). This will not change your address .
</ li >
< li >
< div className = "settings-input" >
< input className = "settings-input" style = {{ marginLeft : '20px' }}
type = "text" ref = { nameRef } defaultValue = { account ? . author . displayName }
placeholder = "Anonymous"
/>
2023-07-29 21:40:03 +02:00
< button className = "save-button" id = "save-name" onClick = { handleDisplayName }>
Save
</ button >
2023-05-26 17:25:49 +02:00
</ div >
</ li >
</ ul >
2023-06-09 18:06:01 +02:00
</ ul >
2023-04-18 22:21:28 +02:00
< ul >
< li className = "settings-cat-lbl" >
2023-04-19 16:33:49 +02:00
< span className = { ` ${ expanded . includes ( 2 ) ? 'minus' : 'plus' } ` }
onClick = {() => toggleExpanded ( 2 )}
/>
< span className = "settings-pointer" style = {{ cursor : "pointer" }}
onClick = {() => toggleExpanded ( 2 )}
2023-07-16 18:22:47 +02:00
> IPFS Options </ span >
2023-04-19 16:33:49 +02:00
< div className = "plebbit-options-buttons"
2023-05-09 12:59:00 +02:00
style = {{ display : expanded . includes ( 2 ) ? 'block' : 'none' }}
2023-04-19 16:33:49 +02:00
>
2023-05-10 14:17:24 +02:00
< button className = "save-button"
onClick = { handleSavePlebbitOptions }> Save </ button >
< button className = "reset-button"
onClick = { handleResetPlebbitOptions }> Reset </ button >
2023-05-09 12:59:00 +02:00
</ div >
2023-04-18 22:21:28 +02:00
</ li >
2023-07-29 21:40:03 +02:00
< ul className = "settings-cat" style = {{ display : expanded . includes ( 2 ) ? 'block' : 'none' , marginTop : '-10px' }}>
2023-04-18 22:21:28 +02:00
< li className = "settings-option disc" >
2023-05-10 14:55:06 +02:00
IPFS Gateway URLs
</ li >
< li className = "settings-tip" >
Optional URLs of IPFS gateways .
</ li >
2023-04-18 22:21:28 +02:00
< div className = "settings-input" >
2023-04-19 14:00:45 +02:00
< textarea placeholder = "IPFS Gateway URLs"
2023-04-20 13:59:04 +02:00
defaultValue = { account ? . plebbitOptions ? . ipfsGatewayUrls . join ( "\n" )}
2023-04-20 10:03:36 +02:00
ref = { gatewayRef }
2023-04-19 13:56:38 +02:00
/>
2023-04-18 22:21:28 +02:00
</ div >
</ ul >
< ul className = "settings-cat" style = {{ display : expanded . includes ( 2 ) ? 'block' : 'none' }}>
< li className = "settings-option disc" >
2023-04-20 10:03:36 +02:00
IPFS HTTP Clients Options </ li >
< li className = "settings-tip" > Optional URLs of IPFS APIs or IpfsHttpClientOptions , 'http://localhost:5001/api/v0' to use a local IPFS node .</ li >
2023-04-18 22:21:28 +02:00
< div className = "settings-input" >
2023-04-21 10:00:01 +02:00
< textarea placeholder = "IPFS HTTP Clients Options"
2023-04-20 13:59:04 +02:00
defaultValue = { account ? . plebbitOptions ? . ipfsHttpClientsOptions ? account ? . plebbitOptions ? . ipfsHttpClientsOptions . join ( "\n" ) : '' }
2023-04-20 10:03:36 +02:00
ref = { ipfsRef }
/>
2023-04-18 22:21:28 +02:00
</ div >
</ ul >
< ul className = "settings-cat" style = {{ display : expanded . includes ( 2 ) ? 'block' : 'none' }}>
< li className = "settings-option disc" >
2023-04-20 10:03:36 +02:00
PubSub HTTP Clients Options </ li >
< li className = "settings-tip" > Optional URLs or IpfsHttpClientOptions used for pubsub publishing when ipfsHttpClientOptions isn 't available, like in the browser.</li>
2023-04-18 22:21:28 +02:00
<div className="settings-input">
2023-04-21 10:00:01 +02:00
<textarea placeholder="PubSub HTTP Clients Options"
2023-04-20 13:59:04 +02:00
defaultValue={account?.plebbitOptions?.pubsubHttpClientsOptions.join("\n")}
2023-04-20 10:03:36 +02:00
ref={pubsubRef}
/>
2023-04-19 13:56:38 +02:00
</div>
</ul>
<ul className="settings-cat" style={{ display: expanded.includes(2) ? ' block ' : ' none ' }}>
<li className="settings-option disc">
Data Path (Node Only)</li>
2023-04-19 14:00:45 +02:00
<li className="settings-tip">Optional folder path to create/resume the user and subplebbit databases.</li>
2023-04-19 13:56:38 +02:00
<div className="settings-input">
2023-04-21 10:00:01 +02:00
<textarea placeholder="Data Path (Node Only)"
2023-04-20 10:03:36 +02:00
ref={dataPathRef}
/>
2023-04-18 22:21:28 +02:00
</div>
</ul>
2023-07-11 12:26:22 +02:00
</ul>
<ul>
<li className="settings-cat-lbl">
<span className={`${expanded.includes(3) ? ' minus ' : ' plus '}`}
onClick={() => toggleExpanded(3)}
/>
<span className="settings-pointer" style={{cursor: "pointer"}}
onClick={() => toggleExpanded(3)}
2023-07-16 18:22:47 +02:00
>Blockchain Options</span>
2023-07-11 12:26:22 +02:00
<div className="plebbit-options-buttons"
style={{ display: expanded.includes(3) ? ' block ' : ' none ' }}
>
<button className="save-button" onClick={handleSaveChainProviders}>Save</button>
<button className="save-button" onClick={handleResetChainProviders}>Reset</button>
</div>
</li>
2023-07-29 21:40:03 +02:00
<ul className="settings-cat" style={{ display: expanded.includes(3) ? ' block ' : ' none ', marginTop: ' - 10 px '}}>
2023-07-11 12:26:22 +02:00
<li className="settings-option disc">Ethereum RPC</li>
2023-07-29 21:40:03 +02:00
<li className="settings-tip">Needed for .eth addresses.</li>
2023-07-11 12:26:22 +02:00
<div className="settings-input">
<textarea placeholder="Ethereum RPC URLs"
defaultValue={account?.plebbitOptions?.chainProviders?.[' eth ']?.urls.join("\n")}
ref={ethereumRpcRef}
/>
</div>
2023-07-29 21:40:03 +02:00
{/* <li className="settings-option disc">Polygon RPC</li>
<li className="settings-tip">Needed for XPLEB NFTs.</li>
2023-07-11 12:26:22 +02:00
<div className="settings-input">
<textarea placeholder="Polygon RPC URLs"
defaultValue={account?.plebbitOptions?.chainProviders?.[' matic ' ] ? . urls . join ( "\n" )}
ref = { polygonRpcRef }
/>
2023-07-29 21:40:03 +02:00
</ div > * /}
2023-07-11 12:26:22 +02:00
</ ul >
2023-04-18 22:21:28 +02:00
</ ul >
2023-04-19 13:56:38 +02:00
< div >
2023-06-09 18:06:01 +02:00
< button
className = "cache-button"
onClick = { async () => {
if ( window . confirm ( "Are you sure you want to clear the cache?" )) {
await deleteCaches ();
localStorage . setItem ( "cacheCleared" , "true" );
window . location . reload ();
}
}}
>
Clear Cache
</ button >
2023-04-19 13:56:38 +02:00
</ div >
2023-03-15 15:25:09 +01:00
</ div >
</ StyledModal >
);
}
Modal . setAppElement ( "#root" );
export default SettingsModal ;