();
const sNodeStatus = useAppSelector(selectNodeStatus);
const getNodeConfig = async () => {
- const nodeConfig = await electron.getNodeConfig();
- setNodeConfigRaw(JSON.stringify(nodeConfig, null, 2));
+ console.log('NodeConfig.tsx: getNodeConfig: ');
+ const nodeConfig = await electron.getNodeConfig(NODE);
+ setNodeConfig(nodeConfig);
+ const strRepresentation = nodeConfig.useDirectInput
+ ? nodeConfig.directInputConfig
+ : nodeConfig.asCliInput;
+ setNodeConfigRaw(JSON.stringify(strRepresentation, null, 2));
};
+ useEffect(() => {
+ if (sNodeConfig && Array.isArray(sNodeConfig.httpAllowedDomains)) {
+ if (
+ sNodeConfig.httpAllowedDomains.includes(METAMASK_CHROME_EXTENSION_ID) ||
+ sNodeConfig.httpAllowedDomains.includes(METAMASK_FIREFOX_EXTENSION_ID)
+ ) {
+ setMetaMaskEnabled(true);
+ return;
+ }
+ }
+ setMetaMaskEnabled(false);
+ }, [sNodeConfig]);
+
const setToDefaultNodeConfig = async () => {
- await electron.setToDefaultNodeConfig();
+ await electron.setToDefaultNodeConfig(NODE);
+ await getNodeConfig();
+ };
+
+ const toggleMetamaskConnections = async () => {
+ const currAllowedDomains = sNodeConfig?.httpAllowedDomains;
+
+ // add metamask extension IDs to allowed http origins
+ let newAllowedDomains: string[] = [];
+ if (Array.isArray(currAllowedDomains)) {
+ newAllowedDomains = currAllowedDomains;
+ }
+ if (sMetaMaskEnabled) {
+ // disable metamask
+ newAllowedDomains = newAllowedDomains.filter((domain) => {
+ return (
+ domain !== METAMASK_CHROME_EXTENSION_ID &&
+ domain !== METAMASK_FIREFOX_EXTENSION_ID
+ );
+ });
+ } else {
+ // enable metamask
+ if (!newAllowedDomains.includes(METAMASK_CHROME_EXTENSION_ID)) {
+ newAllowedDomains = newAllowedDomains.concat(
+ METAMASK_CHROME_EXTENSION_ID
+ );
+ }
+ if (!newAllowedDomains.includes(METAMASK_FIREFOX_EXTENSION_ID)) {
+ newAllowedDomains = newAllowedDomains.concat(
+ METAMASK_FIREFOX_EXTENSION_ID
+ );
+ }
+ }
+
+ await electron.changeNodeConfig(NODE, {
+ http: true,
+ httpAllowedDomains: newAllowedDomains,
+ });
await getNodeConfig();
};
@@ -24,10 +91,12 @@ const NodeConfig = () => {
getNodeConfig();
}, []);
- useEffect(() => {
- if (sNodeConfigRaw) {
+ const onChangeRawInput = (newRawInput: string) => {
+ setNodeConfigRaw(newRawInput);
+
+ if (newRawInput) {
try {
- const nodeConfigInput = JSON.parse(sNodeConfigRaw);
+ const nodeConfigInput = JSON.parse(newRawInput);
if (Array.isArray(nodeConfigInput)) {
const isAllStrings = nodeConfigInput.every(
(i) => typeof i === 'string'
@@ -38,7 +107,7 @@ const NodeConfig = () => {
);
return;
}
- electron.setStoreValue('nodeConfig', nodeConfigInput);
+ electron.setDirectInputNodeConfig(NODE, nodeConfigInput);
setParseError(undefined);
} else {
setParseError('Input is not an array.');
@@ -52,7 +121,7 @@ const NodeConfig = () => {
'Input an array of strings or just [] if no input desired.'
);
}
- }, [sNodeConfigRaw]);
+ };
const isConfigDisabled = !(
sNodeStatus === NODE_STATUS.readyToStart ||
@@ -66,6 +135,46 @@ const NodeConfig = () => {
{isConfigDisabled && (
The node must be stopped to make configuration changes.
)}
+ {sNodeConfig?.useDirectInput && (
+ Detected advanced usage from direct text input
+ )}
+
+
+
+
Runtime input passed directly to the node. Enter an array of strings.
@@ -82,21 +191,10 @@ const NodeConfig = () => {
minHeight: 150,
}}
value={sNodeConfigRaw}
- onChange={(e) => setNodeConfigRaw(e.target.value)}
+ onChange={(e) => onChangeRawInput(e.target.value)}
disabled={isConfigDisabled}
/>
-
-
-
{/* >