diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 6ea56a6..3756e40 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -13,6 +13,7 @@ import { Bars3BottomLeftIcon, XMarkIcon, CheckCircleIcon, + XCircleIcon, } from '@heroicons/react/24/outline'; import { ChevronDownIcon, @@ -20,6 +21,7 @@ import { CommandLineIcon, } from '@heroicons/react/24/solid'; import axios from 'axios'; +import { AxiosError } from 'axios'; import { Fragment, useEffect, useState } from 'react'; import { useRef } from 'react'; import { CopyToClipboard } from 'react-copy-to-clipboard'; @@ -137,6 +139,11 @@ interface INotification { active: boolean; } +interface NodeError { + code: number; + message: string; +} + export default function Example() { const handleVersionChange = (event: React.ChangeEvent) => { setSelectedVersion(event.target.value); @@ -166,6 +173,9 @@ export default function Example() { const [showHash, setShowHash] = useState(''); const [searchTerm, setSearchTerm] = useState(''); + const [hostname, setHostname] = useState(''); + const [authToken, setAuthToken] = useState(''); + useEffect(() => { const fetchJsonData = async (version: string) => { try { @@ -622,9 +632,9 @@ export default function Example() { {/* EXAMPLE TYPE MODAL */} - + -
- +
- - +
-
-
+ +
-
- {/* PLAYGROUND MODAL */} - - - -
- + +
+ {/* PLAYGROUND MODAL */} + + + +
+ -
-
- - -
-
-
-
- - Node Playground - -
-
- {/*

- Are you sure you want to deactivate your account? All - of your data will be permanently removed from our - servers forever. This action cannot be undone. -

*/} -
- {/* TABS */} -
- - {/* Use an "onChange" listener to redirect the user to the selected tab URL. */} - +
+
+ + +
+
+
+
- +
+
+ {/* TABS */} +
+ + {/* Use an "onChange" listener to redirect the user to the selected tab URL. */} + +
+
+ {/* PLAYGROUND */} + {currentTab == 0 && ( + + value && setCurrentRequest(value) + } + /> + )} + {currentTab == 1 && ( + + )} + {currentTab == 2 && ( +
+ +
+ + http:// + + setHostname(e.target.value)} /> - - ))} - +
+

+ ws:// or wss:// is not supported at this time +

+ +
+ setAuthToken(e.target.value)} + /> +
+

+ Only set this if you don't have the + --rpc.skip-auth flag set. +

+
+ )}
- {/* PLAYGROUND */} - {currentTab == 0 && ( - - value && setCurrentRequest(value) +
+
+
+ + +
+ + +
+
+
+
+ {/* NOTIFICATIONS */} + {/* I use playground open because the css is janky otherwise (due to pointer events and z index) */} + {playgroundOpen && ( +
+
+ +
+
+
+
+ {notification.success ? ( +
+
+

+ {notification.success + ? 'Request Succeeded' + : 'Request Failed With Error:'} +

+

+ {notification.message} +

+
+
+ +
-
- - -
- - -
-
-
-
- {/* NOTIFICATIONS NOT WORKING YET*/} - {/*
-
- -
-
-
-
-
-
-

- {notification.success ? 'Success' : 'Failure'} -

-

- {notification.message} -

-
-
- -
-
+
-
-
-
*/} + + )} + ); } @@ -1120,10 +1216,21 @@ const getExampleResponse = (method: Method): string => { ); }; -const sendRequest = async (request: string): Promise => { - const { data } = await axios.post( - 'http://localhost:26658', - JSON.parse(request) - ); +const sendRequest = async ( + request: string, + hostname: string, + authtoken: string +): Promise => { + if (hostname == '') { + hostname = 'http://localhost:26658'; + } else { + hostname = 'http://' + hostname; + } + + if (authtoken != '') { + axios.defaults.headers.common['Authorization'] = `Bearer ${authtoken}`; + } + + const { data } = await axios.post(hostname, JSON.parse(request)); return data; };