mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
add chain providers to settings
This commit is contained in:
@@ -32,6 +32,8 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
const gatewayRef = useRef();
|
const gatewayRef = useRef();
|
||||||
const ipfsRef = useRef();
|
const ipfsRef = useRef();
|
||||||
const pubsubRef = useRef();
|
const pubsubRef = useRef();
|
||||||
|
const ethereumRpcRef = useRef();
|
||||||
|
const polygonRpcRef = useRef();
|
||||||
const dataPathRef = useRef();
|
const dataPathRef = useRef();
|
||||||
const importRef = useRef();
|
const importRef = useRef();
|
||||||
const nameRef = useRef();
|
const nameRef = useRef();
|
||||||
@@ -42,11 +44,20 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
'https://cloudflare-ipfs.com',
|
'https://cloudflare-ipfs.com',
|
||||||
'https://plebpubsub.live'
|
'https://plebpubsub.live'
|
||||||
];
|
];
|
||||||
|
|
||||||
const defaultPubsubHttpClientsOptions = [
|
const defaultPubsubHttpClientsOptions = [
|
||||||
'https://pubsubprovider.xyz/api/v0',
|
'https://pubsubprovider.xyz/api/v0',
|
||||||
'https://plebpubsub.live/api/v0'
|
'https://plebpubsub.live/api/v0'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const defaultEthereumRpcUrls = [
|
||||||
|
'https://ethrpc.xyz',
|
||||||
|
];
|
||||||
|
|
||||||
|
const defaultPolygonRpcUrls = [
|
||||||
|
'https://polygon-rpc.com',
|
||||||
|
];
|
||||||
|
|
||||||
const isValidURL = (url) => {
|
const isValidURL = (url) => {
|
||||||
try {
|
try {
|
||||||
new URL(url);
|
new URL(url);
|
||||||
@@ -56,6 +67,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleSavePlebbitOptions = async () => {
|
const handleSavePlebbitOptions = async () => {
|
||||||
let gatewayUrls = gatewayRef.current.value.split('\n').filter(url => url.trim());
|
let gatewayUrls = gatewayRef.current.value.split('\n').filter(url => url.trim());
|
||||||
let ipfsClientsOptions = ipfsRef.current.value.split('\n').filter(url => url.trim());
|
let ipfsClientsOptions = ipfsRef.current.value.split('\n').filter(url => url.trim());
|
||||||
@@ -100,6 +112,55 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
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: {
|
||||||
|
...account.plebbitOptions,
|
||||||
|
chainProviders,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
localStorage.setItem("successToast", "Chain Providers Saved");
|
||||||
|
window.location.reload();
|
||||||
|
} catch (error) {
|
||||||
|
setNewErrorMessage(error.message); console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const handleResetPlebbitOptions = async () => {
|
const handleResetPlebbitOptions = async () => {
|
||||||
setNewErrorMessage(null);
|
setNewErrorMessage(null);
|
||||||
setNewSuccessMessage(null);
|
setNewSuccessMessage(null);
|
||||||
@@ -126,6 +187,41 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const handleResetChainProviders = async () => {
|
||||||
|
setNewErrorMessage(null);
|
||||||
|
setNewSuccessMessage(null);
|
||||||
|
|
||||||
|
ethereumRpcRef.current.value = defaultEthereumRpcUrls.join('\\n');
|
||||||
|
polygonRpcRef.current.value = defaultPolygonRpcUrls.join('\\n');
|
||||||
|
|
||||||
|
const chainProviders = {
|
||||||
|
'eth': {
|
||||||
|
urls: defaultEthereumRpcUrls,
|
||||||
|
chainId: 1,
|
||||||
|
},
|
||||||
|
'matic': {
|
||||||
|
urls: defaultPolygonRpcUrls,
|
||||||
|
chainId: 137,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setAccount({
|
||||||
|
...account,
|
||||||
|
plebbitOptions: {
|
||||||
|
...account.plebbitOptions,
|
||||||
|
chainProviders,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
localStorage.setItem("successToast", "Chain Providers Reset");
|
||||||
|
window.location.reload();
|
||||||
|
} catch (error) {
|
||||||
|
setNewErrorMessage(error.message); console.log(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const handleCloseModal = () => {
|
const handleCloseModal = () => {
|
||||||
setAccountJson(null);
|
setAccountJson(null);
|
||||||
|
|
||||||
@@ -153,10 +249,10 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
|
|
||||||
|
|
||||||
const expandAll = () => {
|
const expandAll = () => {
|
||||||
if (expanded.length === 3) {
|
if (expanded.length === 4) {
|
||||||
setExpanded([]);
|
setExpanded([]);
|
||||||
} else {
|
} else {
|
||||||
setExpanded([0, 1, 2]);
|
setExpanded([0, 1, 2, 3]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -240,7 +336,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
[
|
[
|
||||||
<button className="all-button"
|
<button className="all-button"
|
||||||
onClick={expandAll} style={{all: "unset", cursor: "pointer"}}>
|
onClick={expandAll} style={{all: "unset", cursor: "pointer"}}>
|
||||||
{expanded.length === 3 ? "Collapse All Settings" : "Expand All Settings"}
|
{expanded.length === 4 ? "Collapse All Settings" : "Expand All Settings"}
|
||||||
</button>
|
</button>
|
||||||
]
|
]
|
||||||
</div>
|
</div>
|
||||||
@@ -395,16 +491,40 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
{/* <ul className="settings-cat" style={{ display: expanded.includes(2) ? 'block' : 'none' }}>
|
</ul>
|
||||||
<li className="settings-option disc">
|
<ul>
|
||||||
Chain Providers</li>
|
<li className="settings-cat-lbl">
|
||||||
<li className="settings-tip">Optional provider RPC URLs and chain IDs.</li>
|
<span className={`${expanded.includes(3) ? 'minus' : 'plus'}`}
|
||||||
<ul>
|
onClick={() => toggleExpanded(3)}
|
||||||
<li className="settings-option disc">Ethereum</li>
|
/>
|
||||||
<li className="settings-option disc">Avalanche</li>
|
<span className="settings-pointer" style={{cursor: "pointer"}}
|
||||||
<li className="settings-option disc">Polygon</li>
|
onClick={() => toggleExpanded(3)}
|
||||||
</ul>
|
>Chain Providers</span>
|
||||||
</ul> */}
|
<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>
|
||||||
|
<ul className="settings-cat" style={{ display: expanded.includes(3) ? 'block' : 'none' }}>
|
||||||
|
<li className="settings-option disc">Ethereum RPC</li>
|
||||||
|
<li className="settings-tip">Needed for .eth addresses</li>
|
||||||
|
<div className="settings-input">
|
||||||
|
<textarea placeholder="Ethereum RPC URLs"
|
||||||
|
defaultValue={account?.plebbitOptions?.chainProviders?.['eth']?.urls.join("\n")}
|
||||||
|
ref={ethereumRpcRef}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<li className="settings-option disc">Polygon RPC</li>
|
||||||
|
<li className="settings-tip">Needed for XPLEB NFTs</li>
|
||||||
|
<div className="settings-input">
|
||||||
|
<textarea placeholder="Polygon RPC URLs"
|
||||||
|
defaultValue={account?.plebbitOptions?.chainProviders?.['matic']?.urls.join("\n")}
|
||||||
|
ref={polygonRpcRef}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</ul>
|
||||||
</ul>
|
</ul>
|
||||||
<div>
|
<div>
|
||||||
<button
|
<button
|
||||||
|
|||||||
Reference in New Issue
Block a user