diff --git a/nym-wallet/src-tauri/src/operations/nym_api/status.rs b/nym-wallet/src-tauri/src/operations/nym_api/status.rs index 3b3bc1bd88..873a1fa0a4 100644 --- a/nym-wallet/src-tauri/src/operations/nym_api/status.rs +++ b/nym-wallet/src-tauri/src/operations/nym_api/status.rs @@ -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, - _active_in_rewarded_set: Option, pledge_amount: Option, total_delegation: Option, interval_operating_cost: Option, @@ -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) diff --git a/nym-wallet/src/components/RewardsPlayground/Inputs.tsx b/nym-wallet/src/components/RewardsPlayground/Inputs.tsx index a3e0e2b735..1f1dbac935 100644 --- a/nym-wallet/src/components/RewardsPlayground/Inputs.tsx +++ b/nym-wallet/src/components/RewardsPlayground/Inputs.tsx @@ -70,6 +70,7 @@ export const Inputs = ({ InputProps={{ endAdornment: {field.isPercentage ? '%' : 'NYM'}, }} + InputLabelProps={{ shrink: true }} /> ))}{' '} diff --git a/nym-wallet/src/components/RewardsPlayground/inputsValidationSchema.ts b/nym-wallet/src/components/RewardsPlayground/inputsValidationSchema.ts index 15e8562288..ef5d9ecc0d 100644 --- a/nym-wallet/src/components/RewardsPlayground/inputsValidationSchema.ts +++ b/nym-wallet/src/components/RewardsPlayground/inputsValidationSchema.ts @@ -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' }); }), }); diff --git a/nym-wallet/src/pages/bonding/node-settings/apy-playground/index.tsx b/nym-wallet/src/pages/bonding/node-settings/apy-playground/index.tsx index 9963d1af9d..5a3b5f4c6b 100644 --- a/nym-wallet/src/pages/bonding/node-settings/apy-playground/index.tsx +++ b/nym-wallet/src/pages/bonding/node-settings/apy-playground/index.tsx @@ -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(); const [stakeSaturation, setStakeSaturation] = useState(); + 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 ; + 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); diff --git a/nym-wallet/src/pages/bonding/node-settings/apy-playground/utils.tsx b/nym-wallet/src/pages/bonding/node-settings/apy-playground/utils.tsx index 0acc483944..bc99898b45 100644 --- a/nym-wallet/src/pages/bonding/node-settings/apy-playground/utils.tsx +++ b/nym-wallet/src/pages/bonding/node-settings/apy-playground/utils.tsx @@ -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), diff --git a/nym-wallet/src/requests/queries.ts b/nym-wallet/src/requests/queries.ts index 6e8e9504f3..640fc79abb 100644 --- a/nym-wallet/src/requests/queries.ts +++ b/nym-wallet/src/requests/queries.ts @@ -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;