display loading modal for initial loading of values
run cargo fmt fix clippy error minor fixes
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
use crate::api_client;
|
||||
use crate::error::BackendError;
|
||||
use crate::state::WalletState;
|
||||
use mixnet_contract_common::{reward_params::Performance, IdentityKeyRef, MixId, Percent, Coin};
|
||||
use mixnet_contract_common::{reward_params::Performance, Coin, IdentityKeyRef, MixId, Percent};
|
||||
use validator_client::models::{
|
||||
ComputeRewardEstParam, GatewayCoreStatusResponse, InclusionProbabilityResponse,
|
||||
MixnodeCoreStatusResponse, MixnodeStatusResponse, RewardEstimationResponse,
|
||||
StakeSaturationResponse, GatewayStatusReportResponse
|
||||
ComputeRewardEstParam, GatewayCoreStatusResponse, GatewayStatusReportResponse,
|
||||
InclusionProbabilityResponse, MixnodeCoreStatusResponse, MixnodeStatusResponse,
|
||||
RewardEstimationResponse, StakeSaturationResponse,
|
||||
};
|
||||
|
||||
#[tauri::command]
|
||||
@@ -63,7 +63,6 @@ pub async fn mixnode_reward_estimation(
|
||||
pub async fn compute_mixnode_reward_estimation(
|
||||
mix_id: u32,
|
||||
performance: Option<Performance>,
|
||||
_active_in_rewarded_set: Option<bool>,
|
||||
pledge_amount: Option<u64>,
|
||||
total_delegation: Option<u64>,
|
||||
interval_operating_cost: Option<Coin>,
|
||||
@@ -76,7 +75,7 @@ pub async fn compute_mixnode_reward_estimation(
|
||||
pledge_amount,
|
||||
total_delegation,
|
||||
interval_operating_cost,
|
||||
profit_margin_percent
|
||||
profit_margin_percent,
|
||||
};
|
||||
Ok(api_client!(state)
|
||||
.compute_mixnode_reward_estimation(mix_id, &request_body)
|
||||
|
||||
@@ -70,6 +70,7 @@ export const Inputs = ({
|
||||
InputProps={{
|
||||
endAdornment: <Typography sx={{ color: 'grey.600' }}>{field.isPercentage ? '%' : 'NYM'}</Typography>,
|
||||
}}
|
||||
InputLabelProps={{ shrink: true }}
|
||||
/>
|
||||
</Grid>
|
||||
))}{' '}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { isGreaterThan, isLessThan } from 'src/utils';
|
||||
|
||||
export const inputValidationSchema = Yup.object().shape({
|
||||
profitMargin: Yup.string()
|
||||
.required()
|
||||
.required('profit margin is a required field')
|
||||
.test('Is valid profit margin value', (value, ctx) => {
|
||||
const stringValueToNumber = Math.round(Number(value));
|
||||
|
||||
@@ -31,9 +31,11 @@ export const inputValidationSchema = Yup.object().shape({
|
||||
return ctx.createError({ message: 'Delegations must be a valid number' });
|
||||
}),
|
||||
operatorCost: Yup.string()
|
||||
.required()
|
||||
.required('operator cost is a required field')
|
||||
.test('Is valid operator cost value', (value, ctx) => {
|
||||
if (Number(value)) return true;
|
||||
const stringValueToNumber = Math.round(Number(value));
|
||||
|
||||
if (isGreaterThan(stringValueToNumber, -1) && isLessThan(stringValueToNumber, 101)) return true;
|
||||
return ctx.createError({ message: 'Operator cost must be a valid number' });
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -8,6 +8,7 @@ import { Inputs, CalculateArgs } from 'src/components/RewardsPlayground/Inputs';
|
||||
import { AppContext, TBondedMixnode } from 'src/context';
|
||||
import { computeEstimate, computeStakeSaturation, handleCalculatePeriodRewards } from './utils';
|
||||
import { useSnackbar } from 'notistack';
|
||||
import { LoadingModal } from 'src/components/Modals/LoadingModal';
|
||||
|
||||
export type DefaultInputValues = {
|
||||
profitMargin: string;
|
||||
@@ -28,6 +29,7 @@ export const ApyPlayground = ({ bondedNode }: { bondedNode: TBondedMixnode }) =>
|
||||
|
||||
const [defaultInputValues, setDefaultInputValues] = useState<DefaultInputValues>();
|
||||
const [stakeSaturation, setStakeSaturation] = useState<string>();
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
|
||||
const initialise = async (node: TBondedMixnode) => {
|
||||
try {
|
||||
@@ -58,6 +60,7 @@ export const ApyPlayground = ({ bondedNode }: { bondedNode: TBondedMixnode }) =>
|
||||
delegations: delegations.total_delegations.amount,
|
||||
operatorCost: node.operatorCost.amount,
|
||||
});
|
||||
setIsLoading(false);
|
||||
} catch (e) {
|
||||
enqueueSnackbar(e as string, { variant: 'error' });
|
||||
}
|
||||
@@ -69,6 +72,8 @@ export const ApyPlayground = ({ bondedNode }: { bondedNode: TBondedMixnode }) =>
|
||||
}
|
||||
}, []);
|
||||
|
||||
if (isLoading) return <LoadingModal />;
|
||||
|
||||
const handleCalculateEstimate = async ({ bond, delegations, uptime, profitMargin, operatorCost }: CalculateArgs) => {
|
||||
try {
|
||||
const { estimation, reward_params } = await computeEstimate({
|
||||
@@ -91,7 +96,7 @@ export const ApyPlayground = ({ bondedNode }: { bondedNode: TBondedMixnode }) =>
|
||||
reward_params.interval.stake_saturation_point,
|
||||
);
|
||||
|
||||
setStakeSaturation(decimalToPercentage(computedStakeSaturation.toString()));
|
||||
setStakeSaturation(computedStakeSaturation);
|
||||
setResults(estimationResult);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { percentToDecimal } from '@nymproject/types';
|
||||
import { decimalToPercentage, percentToDecimal } from '@nymproject/types';
|
||||
import { computeMixnodeRewardEstimation } from 'src/requests';
|
||||
|
||||
const SCALE_FACTOR = 1_000_000;
|
||||
|
||||
export const computeStakeSaturation = (bond: string, delegations: string, stakeSaturationPoint: string) => {
|
||||
const res = ((+bond + +delegations) * SCALE_FACTOR) / +stakeSaturationPoint;
|
||||
console.log(bond, delegations, stakeSaturationPoint, res);
|
||||
|
||||
return res;
|
||||
return decimalToPercentage(res.toFixed(18).toString());
|
||||
};
|
||||
|
||||
export const computeEstimate = async ({
|
||||
@@ -28,7 +26,6 @@ export const computeEstimate = async ({
|
||||
const computedEstimate = await computeMixnodeRewardEstimation({
|
||||
mixId: mixId,
|
||||
performance: percentToDecimal(uptime),
|
||||
isActive: true,
|
||||
pledgeAmount: Math.round(+pledgeAmount * SCALE_FACTOR),
|
||||
totalDelegation: Math.round(+totalDelegation * SCALE_FACTOR),
|
||||
profitMarginPercent: percentToDecimal(profitMargin),
|
||||
|
||||
@@ -56,7 +56,6 @@ export const getGatewayReport = async (identity: string) =>
|
||||
export const computeMixnodeRewardEstimation = async (args: {
|
||||
mixId: number;
|
||||
performance: string;
|
||||
isActive: boolean;
|
||||
pledgeAmount: number;
|
||||
totalDelegation: number;
|
||||
profitMarginPercent: string;
|
||||
|
||||
Reference in New Issue
Block a user