mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-12-29 19:41:39 +03:00
settings fe: fix ping, add/remove providers
This commit is contained in:
parent
6e13ba55d1
commit
db726ed70b
@ -165,7 +165,7 @@
|
||||
margin-left: 6px;
|
||||
}
|
||||
</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">
|
||||
</head>
|
||||
|
||||
|
@ -68,7 +68,7 @@ function App() {
|
||||
}, []);
|
||||
|
||||
const apiCall = async (body: any) => {
|
||||
await fetch(APP_PATH, {
|
||||
return await fetch(APP_PATH, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(body),
|
||||
@ -106,6 +106,7 @@ function App() {
|
||||
const handlePeerPing = async (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(e.currentTarget);
|
||||
const form = e.currentTarget;
|
||||
const response = await fetch(APP_PATH, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
@ -117,14 +118,58 @@ function App() {
|
||||
}
|
||||
}),
|
||||
});
|
||||
const data = await response.json();
|
||||
if (data === null) {
|
||||
e.currentTarget.reset();
|
||||
form.reset();
|
||||
try {
|
||||
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!");
|
||||
} 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">
|
||||
<button
|
||||
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
|
||||
</button>
|
||||
<br />
|
||||
<br />
|
||||
<button
|
||||
onClick={handleReset}
|
||||
className="bg-yellow-500 hover:bg-yellow-600 text-white font-bold py-2 px-4 rounded w-full"
|
||||
>
|
||||
Reset KNS State
|
||||
</button>
|
||||
@ -183,12 +228,12 @@ function App() {
|
||||
<article id="eth-rpc-providers">
|
||||
<h2>ETH RPC providers</h2>
|
||||
<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="text" name="rpc-url" placeholder="wss://rpc-url.com" />
|
||||
<button type="submit">add provider</button>
|
||||
</form>
|
||||
<form id="remove-eth-provider">
|
||||
<form id="remove-eth-provider" onSubmit={handleRemoveEthProvider}>
|
||||
<input type="number" name="chain-id" placeholder="1" />
|
||||
<input type="text" name="rpc-url" placeholder="wss://rpc-url.com" />
|
||||
<button type="submit">remove provider</button>
|
||||
|
@ -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,
|
||||
// and respond with a simple "delivered" response
|
||||
// and respond with a simple "ack" response
|
||||
utils::parse_hello_message(
|
||||
&ext.our,
|
||||
&km,
|
||||
|
@ -415,7 +415,7 @@ pub async fn parse_hello_message(
|
||||
.message(Message::Response((
|
||||
Response {
|
||||
inherit: false,
|
||||
body: "delivered".as_bytes().to_vec(),
|
||||
body: b"ack".to_vec(),
|
||||
metadata: None,
|
||||
capabilities: vec![],
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user