settings fe: fix ping, add/remove providers

This commit is contained in:
dr-frmr 2024-12-21 15:04:25 -05:00
parent 6e13ba55d1
commit db726ed70b
No known key found for this signature in database
4 changed files with 60 additions and 15 deletions

View File

@ -165,7 +165,7 @@
margin-left: 6px; margin-left: 6px;
} }
</style> </style>
<script type="module" crossorigin src="/settings:settings:sys/assets/index-C9KHa-Jo.js"></script> <script type="module" crossorigin src="/settings:settings:sys/assets/index-CrUC-dMu.js"></script>
<link rel="stylesheet" crossorigin href="/settings:settings:sys/assets/index-iGirBDd0.css"> <link rel="stylesheet" crossorigin href="/settings:settings:sys/assets/index-iGirBDd0.css">
</head> </head>

View File

@ -68,7 +68,7 @@ function App() {
}, []); }, []);
const apiCall = async (body: any) => { const apiCall = async (body: any) => {
await fetch(APP_PATH, { return await fetch(APP_PATH, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body), body: JSON.stringify(body),
@ -106,6 +106,7 @@ function App() {
const handlePeerPing = async (e: React.FormEvent<HTMLFormElement>) => { const handlePeerPing = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault(); e.preventDefault();
const formData = new FormData(e.currentTarget); const formData = new FormData(e.currentTarget);
const form = e.currentTarget;
const response = await fetch(APP_PATH, { const response = await fetch(APP_PATH, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json' },
@ -117,14 +118,58 @@ function App() {
} }
}), }),
}); });
const data = await response.json(); form.reset();
if (data === null) { try {
e.currentTarget.reset(); const data = await response.json();
if (data === null) {
setPeerPingResponse("ping successful!");
} else if (data === "HiTimeout") {
setPeerPingResponse("node timed out");
} else if (data === "HiOffline") {
setPeerPingResponse("node is offline");
}
} catch (err) {
setPeerPingResponse("ping successful!"); setPeerPingResponse("ping successful!");
} else if (data === "HiTimeout") { }
setPeerPingResponse("node timed out"); };
} else if (data === "HiOffline") {
setPeerPingResponse("node is offline"); const handleAddEthProvider = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const form = e.currentTarget;
const response = await apiCall({
"EthConfig": {
"AddProvider": {
chain_id: Number(formData.get('chain-id')),
node_or_rpc_url: { "RpcUrl": formData.get('rpc-url') as string }
}
}
});
try {
const data = await response.json();
console.log(data);
} catch (err) {
form.reset();
// this is actually a success
}
};
const handleRemoveEthProvider = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const formData = new FormData(e.currentTarget);
const form = e.currentTarget;
const response = await apiCall({
"EthConfig": {
"RemoveProvider": [Number(formData.get('chain-id')), formData.get('rpc-url') as string]
}
});
try {
const data = await response.json();
console.log(data);
} catch (err) {
form.reset();
// this is actually a success
} }
}; };
@ -149,14 +194,14 @@ function App() {
<div className="mt-16 flex flex-col justify-start"> <div className="mt-16 flex flex-col justify-start">
<button <button
onClick={handleShutdown} onClick={handleShutdown}
className="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded w-full mb-8" id="shutdown"
> >
Shutdown Node Shutdown Node
</button> </button>
<br /> <br />
<br />
<button <button
onClick={handleReset} onClick={handleReset}
className="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-2 px-4 rounded w-full"
> >
Reset KNS State Reset KNS State
</button> </button>
@ -183,12 +228,12 @@ function App() {
<article id="eth-rpc-providers"> <article id="eth-rpc-providers">
<h2>ETH RPC providers</h2> <h2>ETH RPC providers</h2>
<article id="provider-edits"> <article id="provider-edits">
<form id="add-eth-provider"> <form id="add-eth-provider" onSubmit={handleAddEthProvider}>
<input type="number" name="chain-id" placeholder="1" /> <input type="number" name="chain-id" placeholder="1" />
<input type="text" name="rpc-url" placeholder="wss://rpc-url.com" /> <input type="text" name="rpc-url" placeholder="wss://rpc-url.com" />
<button type="submit">add provider</button> <button type="submit">add provider</button>
</form> </form>
<form id="remove-eth-provider"> <form id="remove-eth-provider" onSubmit={handleRemoveEthProvider}>
<input type="number" name="chain-id" placeholder="1" /> <input type="number" name="chain-id" placeholder="1" />
<input type="text" name="rpc-url" placeholder="wss://rpc-url.com" /> <input type="text" name="rpc-url" placeholder="wss://rpc-url.com" />
<button type="submit">remove provider</button> <button type="submit">remove provider</button>

View File

@ -412,7 +412,7 @@ async fn handle_remote_request(
} }
_ => { _ => {
// if we can't parse this to a NetAction, treat it as a hello and print it, // if we can't parse this to a NetAction, treat it as a hello and print it,
// and respond with a simple "delivered" response // and respond with a simple "ack" response
utils::parse_hello_message( utils::parse_hello_message(
&ext.our, &ext.our,
&km, &km,

View File

@ -415,7 +415,7 @@ pub async fn parse_hello_message(
.message(Message::Response(( .message(Message::Response((
Response { Response {
inherit: false, inherit: false,
body: "delivered".as_bytes().to_vec(), body: b"ack".to_vec(),
metadata: None, metadata: None,
capabilities: vec![], capabilities: vec![],
}, },