From 9e994dfd552fd0120eed2c7f2c95dfed4c1bc338 Mon Sep 17 00:00:00 2001 From: fmtabbara Date: Tue, 25 Jan 2022 11:51:36 +0000 Subject: [PATCH] set-up inclusion probability --- nym-wallet/src/pages/settings/index.tsx | 3 ++- .../src/pages/settings/system-variables.tsx | 10 +++++---- .../src/pages/settings/useSettingsState.ts | 22 ++++++++++++++++--- nym-wallet/src/requests/index.ts | 4 ++++ nym-wallet/src/types/rust/index.ts | 2 ++ 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/nym-wallet/src/pages/settings/index.tsx b/nym-wallet/src/pages/settings/index.tsx index 893f29e4d8..f9ded85723 100644 --- a/nym-wallet/src/pages/settings/index.tsx +++ b/nym-wallet/src/pages/settings/index.tsx @@ -16,7 +16,7 @@ export const Settings = () => { const [selectedTab, setSelectedTab] = useState(0) const { mixnodeDetails, showSettings, handleShowSettings, getBondDetails } = useContext(ClientContext) - const { status, saturation, rewardEstimation } = useSettingsState(showSettings) + const { status, saturation, rewardEstimation, inclusionProbability } = useSettingsState(showSettings) const handleTabChange = (_: React.SyntheticEvent, newTab: number) => setSelectedTab(newTab) @@ -46,6 +46,7 @@ export const Settings = () => { saturation={saturation} rewardEstimation={rewardEstimation} onUpdate={getBondDetails} + inclusionProbability={inclusionProbability} /> )} {selectedTab === 2 && mixnodeDetails && } diff --git a/nym-wallet/src/pages/settings/system-variables.tsx b/nym-wallet/src/pages/settings/system-variables.tsx index 68df022e22..1c4678b65a 100644 --- a/nym-wallet/src/pages/settings/system-variables.tsx +++ b/nym-wallet/src/pages/settings/system-variables.tsx @@ -15,9 +15,9 @@ import { AccessTimeOutlined, PercentOutlined } from '@mui/icons-material' import { yupResolver } from '@hookform/resolvers/yup' import { useForm } from 'react-hook-form' import { InfoTooltip } from '../../components/InfoToolTip' -import { TMixnodeBondDetails } from '../../types' +import { InclusionProbabilityResponse, TMixnodeBondDetails } from '../../types' import { validationSchema } from './validationSchema' -import { getGasFee, updateMixnode } from '../../requests' +import { updateMixnode } from '../../requests' import { ClientContext, MAJOR_CURRENCY } from '../../context/main' import { Fee } from '../../components' @@ -29,11 +29,13 @@ export const SystemVariables = ({ mixnodeDetails, saturation, rewardEstimation, + inclusionProbability, onUpdate, }: { mixnodeDetails: TMixnodeBondDetails['mix_node'] saturation: number rewardEstimation: number + inclusionProbability: InclusionProbabilityResponse onUpdate: () => void }) => { const [nodeUpdateResponse, setNodeUpdateResponse] = useState<'success' | 'failed'>() @@ -91,12 +93,12 @@ export const SystemVariables = ({ } />} + Indicator={} /> } />} + Indicator={} /> { const [status, setStatus] = useState('not_found') const [saturation, setSaturation] = useState(0) const [rewardEstimation, setRewardEstimation] = useState(0) + const [inclusionProbability, setInclusionProbability] = useState({ + in_active: 0, + in_reserve: 0, + }) const { mixnodeDetails } = useContext(ClientContext) - + console.log(inclusionProbability) const getStatus = async () => { if (mixnodeDetails?.mix_node.identity_key) { const status = await getMixnodeStatus(mixnodeDetails?.mix_node.identity_key) @@ -43,11 +47,22 @@ export const useSettingsState = (shouldUpdate: boolean) => { } } + const getMixnodeInclusionProbability = async () => { + if (mixnodeDetails?.mix_node.identity_key) { + const probability = await getInclusionProbability(mixnodeDetails?.mix_node.identity_key) + + if (probability) { + setInclusionProbability(probability) + } + } + } + useEffect(() => { if (shouldUpdate) { getStatus() getStakeSaturation() getRewardEstimation() + getMixnodeInclusionProbability() } }, [shouldUpdate]) @@ -55,5 +70,6 @@ export const useSettingsState = (shouldUpdate: boolean) => { status, saturation, rewardEstimation, + inclusionProbability, } } diff --git a/nym-wallet/src/requests/index.ts b/nym-wallet/src/requests/index.ts index 0afffa5bb2..b5720f2644 100644 --- a/nym-wallet/src/requests/index.ts +++ b/nym-wallet/src/requests/index.ts @@ -5,6 +5,7 @@ import { DelegationResult, EnumNodeType, Gateway, + InclusionProbabilityResponse, MixNode, MixnodeStatusResponse, Operation, @@ -98,3 +99,6 @@ export const getMixnodeStatus = async (identity: string): Promise await invoke('update_mixnode', { profitMarginPercent }) + +export const getInclusionProbability = async (identity: string): Promise => + await invoke('mixnode_inclusion_probability', { identity }) diff --git a/nym-wallet/src/types/rust/index.ts b/nym-wallet/src/types/rust/index.ts index 7f2af1e476..5421bcc67f 100644 --- a/nym-wallet/src/types/rust/index.ts +++ b/nym-wallet/src/types/rust/index.ts @@ -14,3 +14,5 @@ export * from './mixnodestatusresponse' export * from './stakesaturaionresponse' export * from './rewardestimationresponse' export * from './mixnodestatus' +export * from './mixnodestatusresponse' +export * from './inclusionprobabilityresponse'