mirror of
https://github.com/bitsocialnet/5chan.git
synced 2026-08-03 07:41:04 +02:00
fix plebbitOptions, improve error messages
This commit is contained in:
@@ -36,6 +36,17 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
const importRef = useRef();
|
||||
const nameRef = useRef();
|
||||
|
||||
const defaultGatewayUrls = [
|
||||
'https://ipfs.io',
|
||||
'https://ipfsgateway.xyz',
|
||||
'https://cloudflare-ipfs.com',
|
||||
'https://plebpubsub.live'
|
||||
];
|
||||
const defaultPubsubHttpClientsOptions = [
|
||||
'https://pubsubprovider.xyz/api/v0',
|
||||
'https://plebpubsub.live/api/v0'
|
||||
];
|
||||
|
||||
const isValidURL = (url) => {
|
||||
try {
|
||||
new URL(url);
|
||||
@@ -46,14 +57,26 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
};
|
||||
|
||||
const handleSavePlebbitOptions = async () => {
|
||||
const gatewayUrls = gatewayRef.current.value.split('\n').filter(url => url.trim());
|
||||
const ipfsClientsOptions = ipfsRef.current.value.split('\n').filter(url => url.trim()) || undefined;
|
||||
const pubsubClientsOptions = pubsubRef.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 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;
|
||||
}
|
||||
|
||||
const invalidUrls = [
|
||||
...gatewayUrls,
|
||||
...gatewayUrls || defaultGatewayUrls,
|
||||
...(ipfsClientsOptions || []),
|
||||
...pubsubClientsOptions,
|
||||
...pubsubClientsOptions || defaultPubsubHttpClientsOptions,
|
||||
].filter((url) => !isValidURL(url));
|
||||
|
||||
if (invalidUrls.length > 0) {
|
||||
@@ -72,7 +95,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
localStorage.setItem("successToast", "Settings Saved");
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
setNewErrorMessage(error.message);
|
||||
setNewErrorMessage(error.message); console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -81,13 +104,6 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
setNewErrorMessage(null);
|
||||
setNewSuccessMessage(null);
|
||||
|
||||
const defaultGatewayUrls = [
|
||||
'https://ipfs.io',
|
||||
'https://ipfsgateway.xyz',
|
||||
'https://cloudflare-ipfs.com'
|
||||
];
|
||||
const defaultPubsubHttpClientsOptions = ['https://pubsubprovider.xyz/api/v0'];
|
||||
|
||||
gatewayRef.current.value = defaultGatewayUrls.join('\n');
|
||||
ipfsRef.current.value = "";
|
||||
pubsubRef.current.value = defaultPubsubHttpClientsOptions.join('\n');
|
||||
@@ -105,7 +121,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
localStorage.setItem("successToast", "Settings Reset");
|
||||
window.location.reload();
|
||||
} catch (error) {
|
||||
setNewErrorMessage(error.message);
|
||||
setNewErrorMessage(error.message); console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -169,7 +185,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
setNewSuccessMessage("Account Imported");
|
||||
|
||||
} catch (error) {
|
||||
setNewErrorMessage(error.message);
|
||||
setNewErrorMessage(error.message); console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -190,7 +206,7 @@ const SettingsModal = ({ isOpen, closeModal }) => {
|
||||
}});
|
||||
setNewSuccessMessage("Account Name Saved");
|
||||
} catch (error) {
|
||||
setNewErrorMessage(error.message);
|
||||
setNewErrorMessage(error.message); console.log(error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user