diff --git a/app/Components/Metamask/Connections.tsx b/app/Components/Metamask/Connections.tsx index 6545c9f..7324b70 100644 --- a/app/Components/Metamask/Connections.tsx +++ b/app/Components/Metamask/Connections.tsx @@ -24,8 +24,6 @@ export const signMessage = async (message: string,provider: EIP1193Provider,user params: [msg, userAccount], }) - console.log("Encoded Public Key: ", msg); - return sig; } catch (err) { console.error(err) diff --git a/app/Components/ServerList.tsx b/app/Components/ServerList.tsx index 9e8e3f7..79eb831 100644 --- a/app/Components/ServerList.tsx +++ b/app/Components/ServerList.tsx @@ -20,23 +20,39 @@ interface Node { } function NodeItem({node}: {node: Node}) { + const port = 8080; const { auth } = useAuth(); const [ratingOpen, setRatingOpen] = React.useState(false); const [ratingValue, setRatingValue] = React.useState(null); const [submittingRating, setSubmittingRating] = React.useState(false); - const connect = async ({ip}: {ip: string}) => { - const publicKey = await getPublicKey(auth.providerWithInfo.provider, auth.accounts[0]); - const sig = await signMessage("H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]); + const getUrl = () => `http://${node.ip}:${port}`; + const connect = async () => { + // const publicKey = await getPublicKey(auth.providerWithInfo.provider, auth.accounts[0]); try { - const res_string = publicKey + '\n' + sig; - let response = await axios.post('http://' + ip + ":8080/connect", res_string); - console.log(response.data); // Log the response from the server + const iv = await axios.get(getUrl() + "/connect"); + console.log(iv.data); + + const sig = await signMessage(iv.data + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=",auth.providerWithInfo.provider, auth.accounts[0]); + const res_string = iv.data + '\n' + "H8zfXnSclIQ/wLy7GSt7GNqa1utAi4Uvr7Dg3p9vdHQ=" + '\n' + sig; + let response = await axios.post(getUrl() + "/connect", res_string); + console.log(response.data); } catch (error) { console.error('Error:', error); } } - const disconnect = ({ip}: {ip: string}) => { + const disconnect = async () => { + try{ + const iv = await axios.get(getUrl() + "/disconnect"); + console.log(iv.data); + + const sig = await signMessage(iv.data,auth.providerWithInfo.provider, auth.accounts[0]); + const res_string = iv.data + '\n' + sig; + let response = await axios.post(getUrl() + "/disconnect", res_string); + console.log(response.data); + } catch (error) { + console.error('Error:', error); + } setRatingOpen(true); } @@ -124,14 +140,14 @@ function NodeItem({node}: {node: Node}) { size="small" >