implemented rating
This commit is contained in:
parent
b540e1372e
commit
f9f92107c2
@ -86,26 +86,26 @@ function NodeItem({node, auth}: {node: Node, auth: AccountInfo}) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const disconnect = async () => {
|
const sendPayment = async (isRatingProvided: boolean, rating: BigInt) => {
|
||||||
try{
|
try{
|
||||||
// const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
|
||||||
// const sig = await signMessage(String(nonce),auth.providerWithInfo.provider, auth.accounts[0]);
|
|
||||||
// const res_string = String(nonce) + '\n' + sig;
|
|
||||||
// let response = await axios.post(getUrl() + "/disconnect", res_string);
|
|
||||||
// console.log(response.data);
|
|
||||||
const storedInfo = localStorage.getItem(node.address);
|
const storedInfo = localStorage.getItem(node.address);
|
||||||
if(!storedInfo){
|
if(!storedInfo){
|
||||||
console.error("No active connection info");
|
console.error("No active connection info");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const connectionInfo = JSON.parse(storedInfo);
|
const connectionInfo = JSON.parse(storedInfo);
|
||||||
|
if (isRatingProvided) {
|
||||||
|
const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
connectionInfo.clientSignature = await signMessage(nonce + connectionInfo.vpnClientPublicKey + connectionInfo.connectionStartTime + connectionInfo.agreedPricePerMinute + rating,auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
localStorage.setItem(node.address,JSON.stringify(connectionInfo))
|
||||||
|
}
|
||||||
await processPayment(auth.providerWithInfo.provider, auth.accounts[0],
|
await processPayment(auth.providerWithInfo.provider, auth.accounts[0],
|
||||||
node.address,
|
node.address,
|
||||||
connectionInfo.vpnClientPublicKey,
|
connectionInfo.vpnClientPublicKey,
|
||||||
BigInt(connectionInfo.connectionStartTime),
|
BigInt(connectionInfo.connectionStartTime),
|
||||||
BigInt(connectionInfo.agreedPricePerMinute),
|
BigInt(connectionInfo.agreedPricePerMinute),
|
||||||
false,
|
isRatingProvided,
|
||||||
BigInt(0),
|
rating,
|
||||||
connectionInfo.clientSignature,
|
connectionInfo.clientSignature,
|
||||||
connectionInfo.nodeSignature
|
connectionInfo.nodeSignature
|
||||||
);
|
);
|
||||||
@ -113,32 +113,43 @@ function NodeItem({node, auth}: {node: Node, auth: AccountInfo}) {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error:', error);
|
console.error('Error:', error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const disconnect = async () => {
|
||||||
|
// try{
|
||||||
|
// const nonce: BigInt = await getNextNonce(auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
// const sig = await signMessage(String(nonce),auth.providerWithInfo.provider, auth.accounts[0]);
|
||||||
|
// const res_string = String(nonce) + '\n' + sig;
|
||||||
|
// let response = await axios.post(getUrl() + "/disconnect", res_string);
|
||||||
|
// console.log(response.data);
|
||||||
|
// } catch (error) {
|
||||||
|
// console.error('Error:', error);
|
||||||
|
// }
|
||||||
setRatingOpen(true);
|
setRatingOpen(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleNoRating = () => {
|
||||||
|
console.log("no rating");
|
||||||
|
sendPayment(false, BigInt(0));
|
||||||
|
handleCloseRating()
|
||||||
|
}
|
||||||
|
|
||||||
const handleCloseRating = () => {
|
const handleCloseRating = () => {
|
||||||
setRatingOpen(false);
|
setRatingOpen(false);
|
||||||
setRatingValue(null);
|
setRatingValue(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleSubmitRating = async () => {
|
const handleSubmitRating = () => {
|
||||||
if (ratingValue == null) {
|
if (ratingValue == null) {
|
||||||
|
console.log("no rating value");
|
||||||
|
sendPayment(false, BigInt(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
console.log("submit rating:", ratingValue);
|
||||||
setSubmittingRating(true);
|
setSubmittingRating(true);
|
||||||
try {
|
sendPayment(true, BigInt(ratingValue));
|
||||||
await axios.post('http://' + node.ip + ":8080/rate", {
|
setSubmittingRating(false);
|
||||||
rating: ratingValue,
|
handleCloseRating();
|
||||||
}, {
|
|
||||||
headers: { "Content-Type": "application/json" }
|
|
||||||
});
|
|
||||||
console.log('Rating submitted');
|
|
||||||
} catch (err) {
|
|
||||||
console.error('Failed to submit rating', err);
|
|
||||||
} finally {
|
|
||||||
setSubmittingRating(false);
|
|
||||||
handleCloseRating();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -216,7 +227,7 @@ function NodeItem({node, auth}: {node: Node, auth: AccountInfo}) {
|
|||||||
</CardActions>
|
</CardActions>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Dialog open={ratingOpen} onClose={handleCloseRating}>
|
<Dialog open={ratingOpen} onClose={handleNoRating}>
|
||||||
<DialogTitle>Rate this server</DialogTitle>
|
<DialogTitle>Rate this server</DialogTitle>
|
||||||
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 320 }}>
|
<DialogContent sx={{ display: 'flex', flexDirection: 'column', gap: 2, minWidth: 320 }}>
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
@ -229,7 +240,7 @@ function NodeItem({node, auth}: {node: Node, auth: AccountInfo}) {
|
|||||||
</Box>
|
</Box>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button onClick={handleCloseRating} disabled={submittingRating}>Cancel</Button>
|
<Button onClick={handleNoRating} disabled={submittingRating}>Cancel</Button>
|
||||||
<Button onClick={handleSubmitRating} disabled={submittingRating || ratingValue == null} variant="contained">Submit</Button>
|
<Button onClick={handleSubmitRating} disabled={submittingRating || ratingValue == null} variant="contained">Submit</Button>
|
||||||
</DialogActions>
|
</DialogActions>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user