get node uptime
This commit is contained in:
@@ -11,6 +11,7 @@ use nym_types::mixnode::{MixNodeCostParams, MixNodeDetails};
|
||||
use nym_types::transaction::TransactionExecuteResult;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::time::Duration;
|
||||
use validator_client::models::UptimeResponse;
|
||||
use validator_client::nymd::traits::{MixnetQueryClient, MixnetSigningClient};
|
||||
use validator_client::nymd::Fee;
|
||||
|
||||
@@ -341,3 +342,18 @@ pub async fn get_mix_node_description(
|
||||
.json()
|
||||
.await?)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_mixnode_uptime(
|
||||
mix_id: NodeId,
|
||||
state: tauri::State<'_, WalletState>,
|
||||
) -> Result<u8, BackendError> {
|
||||
log::info!(">>> Get mixnode uptime");
|
||||
|
||||
let guard = state.read().await;
|
||||
let client = guard.current_client()?;
|
||||
let uptime = client.validator_api.get_mixnode_avg_uptime(mix_id).await?;
|
||||
|
||||
log::info!(">>> Uptime response: {}", uptime.avg_uptime);
|
||||
Ok(uptime.avg_uptime)
|
||||
}
|
||||
|
||||
@@ -2,18 +2,19 @@ import React from 'react';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { Button, Grid, TextField, Typography } from '@mui/material';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { DefaultInputValues } from 'src/pages/bonding/node-settings/apy-playground';
|
||||
import { inputValidationSchema } from './inputsValidationSchema';
|
||||
import { useBondingContext } from 'src/context';
|
||||
|
||||
export type InputFields = {
|
||||
label: string;
|
||||
name: 'profitMargin' | 'uptime' | 'bond' | 'delegations' | 'operatorCost';
|
||||
name: 'profitMargin' | 'uptime' | 'bond' | 'delegations' | 'operatorCost' | 'uptime';
|
||||
isPercentage?: boolean;
|
||||
}[];
|
||||
|
||||
export type calculateArgs = {
|
||||
export type CalculateArgs = {
|
||||
bond: string;
|
||||
delegations: string;
|
||||
uptime: string;
|
||||
};
|
||||
|
||||
const inputFields: InputFields = [
|
||||
@@ -24,11 +25,15 @@ const inputFields: InputFields = [
|
||||
{ label: 'Uptime', name: 'uptime', isPercentage: true },
|
||||
];
|
||||
|
||||
export const Inputs = ({ onCalculate }: { onCalculate: (args: calculateArgs) => Promise<void> }) => {
|
||||
const { bondedNode } = useBondingContext();
|
||||
|
||||
const handleCalculate = (args: calculateArgs) => {
|
||||
onCalculate({ bond: args.bond, delegations: args.delegations });
|
||||
export const Inputs = ({
|
||||
onCalculate,
|
||||
defaultValues,
|
||||
}: {
|
||||
onCalculate: (args: CalculateArgs) => Promise<void>;
|
||||
defaultValues: DefaultInputValues | undefined;
|
||||
}) => {
|
||||
const handleCalculate = async (args: CalculateArgs) => {
|
||||
onCalculate({ bond: args.bond, delegations: args.delegations, uptime: args.uptime });
|
||||
};
|
||||
|
||||
const {
|
||||
@@ -37,19 +42,13 @@ export const Inputs = ({ onCalculate }: { onCalculate: (args: calculateArgs) =>
|
||||
formState: { errors },
|
||||
} = useForm({
|
||||
resolver: yupResolver(inputValidationSchema),
|
||||
defaultValues: {
|
||||
profitMargin: bondedNode?.profitMargin || '',
|
||||
uptime: 100,
|
||||
bond: bondedNode?.bond.amount || '',
|
||||
delegations: '',
|
||||
operatorCost: '',
|
||||
},
|
||||
defaultValues,
|
||||
});
|
||||
|
||||
return (
|
||||
<Grid container spacing={3}>
|
||||
{inputFields.map((field) => (
|
||||
<Grid item xs={12} lg={2}>
|
||||
<Grid item xs={12} lg={2} key={field.name}>
|
||||
<TextField
|
||||
{...register(field.name)}
|
||||
fullWidth
|
||||
|
||||
@@ -7,14 +7,14 @@ export const NodeDetails = ({
|
||||
saturation,
|
||||
selectionProbability,
|
||||
}: {
|
||||
saturation: number;
|
||||
saturation?: string;
|
||||
selectionProbability: SelectionChance;
|
||||
}) => (
|
||||
<Card variant="outlined" sx={{ p: 1 }}>
|
||||
<CardContent>
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
<Typography fontWeight="medium">Stake saturation</Typography>
|
||||
<Typography>{saturation}%</Typography>
|
||||
<Typography>{saturation || '- '}%</Typography>
|
||||
</Stack>
|
||||
<Divider sx={{ my: 1 }} />
|
||||
<Stack direction="row" justifyContent="space-between">
|
||||
|
||||
@@ -157,11 +157,14 @@ export const BondingContextProvider = ({ children }: { children?: React.ReactNod
|
||||
} = {
|
||||
status: 'not_found',
|
||||
stakeSaturation: '0',
|
||||
uptime: 0,
|
||||
};
|
||||
|
||||
try {
|
||||
const statusResponse = await getMixnodeStatus(mixId);
|
||||
const uptime = await getMixnodeUptime(mixId);
|
||||
additionalDetails.status = statusResponse.status;
|
||||
additionalDetails.uptime = uptime;
|
||||
} catch (e) {
|
||||
Console.log('getMixnodeStatus fails', e);
|
||||
}
|
||||
@@ -279,6 +282,7 @@ export const BondingContextProvider = ({ children }: { children?: React.ReactNod
|
||||
delegators: rewarding_details.unique_delegations,
|
||||
proxy: bond_information.proxy,
|
||||
operatorRewards,
|
||||
uptime,
|
||||
status,
|
||||
stakeSaturation,
|
||||
operatorCost: decCoinToDisplay(rewarding_details.cost_params.interval_operating_cost),
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Box, Typography, Stack, IconButton, Divider } from '@mui/material';
|
||||
import { Close } from '@mui/icons-material';
|
||||
import { useTheme } from '@mui/material/styles';
|
||||
import { ConfirmationDetailProps, ConfirmationDetailsModal } from 'src/components/Bonding/modals/ConfirmationModal';
|
||||
import { TestNode } from 'src/pages/bonding/node-settings/test-my-node';
|
||||
import { Node as NodeIcon } from 'src/svg-icons/node';
|
||||
import { LoadingModal } from 'src/components/Modals/LoadingModal';
|
||||
import { NymCard } from 'src/components';
|
||||
|
||||
@@ -1,31 +1,59 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Box, Card, CardContent, CardHeader, Grid, Typography } from '@mui/material';
|
||||
import { ResultsTable } from 'src/components/RewardsPlayground/ResultsTable';
|
||||
import { computeMixnodeRewardEstimation } from 'src/requests';
|
||||
import { computeMixnodeRewardEstimation, getDelegationSummary } from 'src/requests';
|
||||
import { NodeDetails } from 'src/components/RewardsPlayground/NodeDetail';
|
||||
import { Inputs, calculateArgs } from 'src/components/RewardsPlayground/Inputs';
|
||||
import { useBondingContext } from 'src/context';
|
||||
import { useDelegationContext } from 'src/context/delegations';
|
||||
import { Inputs, CalculateArgs } from 'src/components/RewardsPlayground/Inputs';
|
||||
import { TBondedMixnode, useBondingContext } from 'src/context';
|
||||
import { isMixnode } from 'src/types';
|
||||
import { SelectionChance } from '@nymproject/types';
|
||||
|
||||
const MAJOR_AMOUNT_FOR_CALCS = 1000;
|
||||
|
||||
export type DefaultInputValues = {
|
||||
profitMargin: string;
|
||||
uptime: string;
|
||||
bond: string;
|
||||
delegations: string;
|
||||
operatorCost: string;
|
||||
};
|
||||
|
||||
export const ApyPlayground = () => {
|
||||
const { bondedNode } = useBondingContext();
|
||||
const { totalDelegations } = useDelegationContext();
|
||||
|
||||
console.log(totalDelegations);
|
||||
|
||||
const [results, setResults] = useState({
|
||||
total: { daily: '-', monthly: '-', yearly: '-' },
|
||||
operator: { daily: '-', monthly: '-', yearly: '-' },
|
||||
delegator: { daily: '-', monthly: '-', yearly: '-' },
|
||||
stakeSaturation: '',
|
||||
selectionProbability: 'Low' as SelectionChance,
|
||||
});
|
||||
|
||||
const handleCalculate = async ({ bond, delegations }: calculateArgs) => {
|
||||
const [defaultInputValues, setDefaultInputValues] = useState<DefaultInputValues>();
|
||||
|
||||
const initialiseInputs = async (node: TBondedMixnode) => {
|
||||
const delegations = await getDelegationSummary();
|
||||
|
||||
setDefaultInputValues({
|
||||
profitMargin: node.profitMargin,
|
||||
uptime: (node.uptime || 0).toString(),
|
||||
bond: node.bond.amount || '',
|
||||
delegations: delegations.total_delegations.amount,
|
||||
operatorCost: '',
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (bondedNode && isMixnode(bondedNode)) {
|
||||
initialiseInputs(bondedNode);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const handleCalculate = async ({ bond, delegations, uptime }: CalculateArgs) => {
|
||||
try {
|
||||
const res = await computeMixnodeRewardEstimation({
|
||||
identity: 'HsnGQDiTL9hfY4ZkCBWoVFDdVDQWXKaK9ojXSkmUT44z',
|
||||
uptime: 10,
|
||||
identity: bondedNode?.identityKey || '',
|
||||
uptime: parseInt(uptime, 10),
|
||||
isActive: true,
|
||||
pledgeAmount: Math.floor(+bond * 1_000_000),
|
||||
totalDelegation: Math.floor(+delegations * 1_000_000),
|
||||
@@ -53,6 +81,8 @@ export const ApyPlayground = () => {
|
||||
monthly: (delegatorReward * 30).toString(),
|
||||
yearly: (delegatorReward * 365).toString(),
|
||||
},
|
||||
stakeSaturation: '0',
|
||||
selectionProbability: 'High',
|
||||
});
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
@@ -77,7 +107,8 @@ export const ApyPlayground = () => {
|
||||
}
|
||||
/>
|
||||
<CardContent>
|
||||
<Inputs onCalculate={handleCalculate} />
|
||||
{console.log(defaultInputValues?.uptime)}
|
||||
{defaultInputValues && <Inputs onCalculate={handleCalculate} defaultValues={defaultInputValues} />}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Grid container spacing={3}>
|
||||
@@ -85,7 +116,7 @@ export const ApyPlayground = () => {
|
||||
<ResultsTable results={results} />
|
||||
</Grid>
|
||||
<Grid item xs={12} md={4}>
|
||||
<NodeDetails saturation={10} selectionProbability="High" />
|
||||
<NodeDetails saturation={results.stakeSaturation} selectionProbability={results.selectionProbability} />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Box>
|
||||
|
||||
@@ -59,3 +59,5 @@ export const computeMixnodeRewardEstimation = async (args: {
|
||||
pledgeAmount: number;
|
||||
totalDelegation: number;
|
||||
}) => invokeWrapper<any>('compute_mixnode_reward_estimation', args);
|
||||
|
||||
export const getMixnodeUptime = async (mixId: number) => invokeWrapper<number>('get_mixnode_uptime', { mixId });
|
||||
|
||||
Reference in New Issue
Block a user