merge develop
This commit is contained in:
@@ -44,9 +44,7 @@ export const Settings = () => {
|
||||
</Alert>
|
||||
)}
|
||||
{selectedTab === 0 && mixnodeDetails && <Profile />}
|
||||
{selectedTab === 1 && mixnodeDetails && (
|
||||
<SystemVariables mixnodeDetails={mixnodeDetails.mix_node} pledge={mixnodeDetails.pledge_amount} />
|
||||
)}
|
||||
{selectedTab === 1 && mixnodeDetails && <SystemVariables mixnodeDetails={mixnodeDetails.mix_node} />}
|
||||
{selectedTab === 2 && mixnodeDetails && <NodeStats mixnodeId={mixnodeDetails.mix_node.identity_key} />}
|
||||
</>
|
||||
</NymCard>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React, { useContext, useState } from 'react'
|
||||
import React, { useContext, useEffect, useState } from 'react'
|
||||
import {
|
||||
Box,
|
||||
Button,
|
||||
@@ -15,24 +15,18 @@ 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 { EnumNodeType, TMixnodeBondDetails } from '../../types'
|
||||
import { TMixnodeBondDetails } from '../../types'
|
||||
import { validationSchema } from './validationSchema'
|
||||
import { bond, unbond } from '../../requests'
|
||||
import { ClientContext } from '../../context/main'
|
||||
import { getGasFee, updateMixnode } from '../../requests'
|
||||
import { ClientContext, MAJOR_CURRENCY } from '../../context/main'
|
||||
|
||||
type TFormData = {
|
||||
profitMarginPercent: number
|
||||
signature: string
|
||||
}
|
||||
|
||||
export const SystemVariables = ({
|
||||
mixnodeDetails,
|
||||
pledge,
|
||||
}: {
|
||||
mixnodeDetails: TMixnodeBondDetails['mix_node']
|
||||
pledge: TMixnodeBondDetails['pledge_amount']
|
||||
}) => {
|
||||
export const SystemVariables = ({ mixnodeDetails }: { mixnodeDetails: TMixnodeBondDetails['mix_node'] }) => {
|
||||
const [nodeUpdateResponse, setNodeUpdateResponse] = useState<'success' | 'failed'>()
|
||||
const [configFee, setConfigFee] = useState<string>()
|
||||
|
||||
const {
|
||||
register,
|
||||
@@ -40,28 +34,28 @@ export const SystemVariables = ({
|
||||
formState: { errors, isSubmitting },
|
||||
} = useForm({
|
||||
resolver: yupResolver(validationSchema),
|
||||
defaultValues: { profitMarginPercent: mixnodeDetails.profit_margin_percent.toString(), signature: '' },
|
||||
defaultValues: { profitMarginPercent: mixnodeDetails.profit_margin_percent.toString() },
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
const fee = await getGasFee('UpdateMixnodeConfig')
|
||||
setConfigFee(fee.amount)
|
||||
})()
|
||||
}, [])
|
||||
|
||||
const { userBalance } = useContext(ClientContext)
|
||||
|
||||
const onSubmit = async (data: TFormData) => {
|
||||
await unbond(EnumNodeType.mixnode)
|
||||
await bond({
|
||||
type: EnumNodeType.mixnode,
|
||||
data: { ...mixnodeDetails, profit_margin_percent: data.profitMarginPercent },
|
||||
pledge: { denom: 'Minor', amount: pledge.amount },
|
||||
//hardcoded for the moment as required in bonding but not necessary
|
||||
ownerSignature: data.signature,
|
||||
})
|
||||
.then(() => {
|
||||
try {
|
||||
await updateMixnode({ profitMarginPercent: data.profitMarginPercent }).then(() => {
|
||||
userBalance.fetchBalance()
|
||||
setNodeUpdateResponse('success')
|
||||
})
|
||||
.catch((e) => {
|
||||
setNodeUpdateResponse('failed')
|
||||
console.log(e)
|
||||
})
|
||||
} catch (e) {
|
||||
setNodeUpdateResponse('failed')
|
||||
console.log(e)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -80,13 +74,6 @@ export const SystemVariables = ({
|
||||
error={!!errors.profitMarginPercent}
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
<TextField
|
||||
{...register('signature')}
|
||||
label="Owner signature"
|
||||
error={!!errors.signature}
|
||||
helperText={!!errors.signature && errors.signature.message}
|
||||
disabled={isSubmitting}
|
||||
/>
|
||||
<Divider />
|
||||
<DataField
|
||||
title="Estimated reward"
|
||||
@@ -128,7 +115,9 @@ export const SystemVariables = ({
|
||||
) : nodeUpdateResponse === 'failed' ? (
|
||||
<Typography sx={{ color: 'error.main', fontWeight: 600 }}>Node updated failed</Typography>
|
||||
) : (
|
||||
<Box />
|
||||
<Typography sx={{ color: 'nym.fee' }}>
|
||||
Fee for this transaction: {`${configFee} ${MAJOR_CURRENCY}`}{' '}
|
||||
</Typography>
|
||||
)}
|
||||
<Button
|
||||
variant="contained"
|
||||
|
||||
@@ -2,5 +2,4 @@ import * as Yup from 'yup'
|
||||
|
||||
export const validationSchema = Yup.object({
|
||||
profitMarginPercent: Yup.number().typeError('profit margin percent must be a number').min(0).max(100).required(),
|
||||
signature: Yup.string().required(),
|
||||
})
|
||||
|
||||
@@ -51,6 +51,7 @@ export const undelegate = async ({
|
||||
|
||||
export const send = async (args: { amount: Coin; address: string; memo: string }): Promise<TauriTxResult> =>
|
||||
await invoke('send', args)
|
||||
|
||||
export const checkMixnodeOwnership = async (): Promise<boolean> => await invoke('owns_mixnode')
|
||||
|
||||
export const checkGatewayOwnership = async (): Promise<boolean> => await invoke('owns_gateway')
|
||||
@@ -90,3 +91,6 @@ export const getMixnodeStakeSaturation = async (identity: string): Promise<Stake
|
||||
|
||||
export const getMixnodeStatus = async (identity: string): Promise<MixnodeStatusResponse> =>
|
||||
await invoke('mixnode_status', { identity })
|
||||
|
||||
export const updateMixnode = async ({ profitMarginPercent }: { profitMarginPercent: number }) =>
|
||||
await invoke('update_mixnode', { profitMarginPercent })
|
||||
|
||||
Reference in New Issue
Block a user