Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
fmtabbara committed Oct 15, 2024
1 parent 854376f commit 54d1359
Show file tree
Hide file tree
Showing 22 changed files with 66 additions and 197 deletions.
4 changes: 2 additions & 2 deletions nym-wallet/nym-wallet-types/src/network/qa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) const STAKE_DENOM: DenomDetails = DenomDetails::new("unyx", "nyx", 6)
// -- Contract addresses --

pub(crate) const MIXNET_CONTRACT_ADDRESS: &str =
"n1khq8f8vhah0gtljahrnsr3utl5lrhlf0xafs6pkvetnyumv7vt4qxh2ckx";
"n1hm4y6fzgxgu688jgf7ek66px6xkrtmn3gyk8fax3eawhp68c2d5qujz296";
pub(crate) const VESTING_CONTRACT_ADDRESS: &str =
"n1jlzdxnyces4hrhqz68dqk28mrw5jgwtcfq0c2funcwrmw0dx9l9s8nnnvj";
pub(crate) const ECASH_CONTRACT_ADDRESS: &str =
Expand All @@ -28,7 +28,7 @@ pub(crate) const COCONUT_DKG_CONTRACT_ADDRESS: &str =

pub(crate) fn validators() -> Vec<ValidatorDetails> {
vec![ValidatorDetails::new(
"https://benny-validator.qa.nymte.ch/",
"https://qa-validator.qa.nymte.ch/",
Some("https://qa-nym-api.qa.nymte.ch/api"),
Some("wss://qa-validator.qa.nymte.ch/websocket"),
)]
Expand Down
11 changes: 1 addition & 10 deletions nym-wallet/src/components/Bonding/BondUpdateCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import React from 'react';
import { Box, Button, Stack, Tooltip, Typography } from '@mui/material';
import { Network } from 'src/types';
import { NymCard } from 'src/components';
import { TBondedMixnode } from 'src/requests/mixnodeDetails';

export const BondUpdateCard = ({
setSuccesfullUpdate,
}: {
mixnode: TBondedMixnode;
network?: Network;
setSuccesfullUpdate: (staus: boolean) => void;
}) => (
export const BondUpdateCard = ({ setSuccesfullUpdate }: { setSuccesfullUpdate: (staus: boolean) => void }) => (
<Stack gap={2}>
<NymCard
borderless
Expand Down Expand Up @@ -47,7 +39,6 @@ export const BondUpdateCard = ({
</Tooltip>
</Box>
}
children={undefined}
/>
</Stack>
);
1 change: 0 additions & 1 deletion nym-wallet/src/components/Bonding/BondedNymNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const BondedNymNode = ({
operatorRewards,
operatorCost,
delegators,
role,
identityKey,
host,
} = nymnode;
Expand Down
8 changes: 1 addition & 7 deletions nym-wallet/src/components/Bonding/NodeStats.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { Stack, Typography, Box, useTheme, Grid, LinearProgress, LinearProgressProps, Button } from '@mui/material';
import { useNavigate } from 'react-router-dom';
import { Stack, Typography, Box, useTheme, Grid, LinearProgress, LinearProgressProps } from '@mui/material';
import { Cell, Pie, PieChart, Legend, ResponsiveContainer } from 'recharts';
import { SelectionChance } from '@nymproject/types';
import { TBondedMixnode } from 'src/requests/mixnodeDetails';
Expand Down Expand Up @@ -50,7 +49,6 @@ const StatRow = ({
export const NodeStats = ({ mixnode }: { mixnode: TBondedMixnode }) => {
const { activeSetProbability, routingScore } = mixnode;
const theme = useTheme();
const navigate = useNavigate();

// clamp routing score to [0-100]
const score = Math.min(Math.max(routingScore || 0, 0), 100);
Expand All @@ -74,10 +72,6 @@ export const NodeStats = ({ mixnode }: { mixnode: TBondedMixnode }) => {
}
};

const handleGoToTestNode = () => {
navigate('/bonding/node-settings', { state: 'test-node' });
};

const renderLegend = () => (
<Stack
alignItems="center"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Box } from '@mui/material';
import { NodeTypeSelector } from 'src/components';
import { CurrencyDenom, TNodeType } from '@nymproject/types';
import { GatewayAmount, GatewayData, Signature } from 'src/pages/bonding/types';
import { GatewayAmount, GatewayData } from 'src/pages/bonding/types';
import GatewayInitForm from './GatewayInitForm';
import GatewayAmountForm from './GatewayAmountForm';

Expand All @@ -15,7 +15,6 @@ export const BondGatewayForm = ({
onSelectNodeType,
onValidateGatewayData,
onValidateAmountData,
onValidateSignature,
}: {
step: 1 | 2 | 3 | 4;
gatewayData: GatewayData;
Expand All @@ -25,7 +24,6 @@ export const BondGatewayForm = ({
onSelectNodeType: (nodeType: TNodeType) => void;
onValidateGatewayData: (data: GatewayData) => void;
onValidateAmountData: (data: GatewayAmount) => Promise<void>;
onValidateSignature: (signature: Signature) => void;
}) => (
<>
{step === 1 && (
Expand Down
51 changes: 31 additions & 20 deletions nym-wallet/src/components/Bonding/forms/nym-node/FormContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useState } from 'react';
import React, { createContext, useContext, useMemo, useState } from 'react';
import { CurrencyDenom } from '@nymproject/types';
import { TBondNymNodeArgs, TBondMixNodeArgs } from 'src/types';

Expand Down Expand Up @@ -44,7 +44,7 @@ const FormContext = createContext<FormContextType>({
signature: undefined,
setSignature: () => {},

onError: (e: string) => {},
onError: () => {},
});

const FormContextProvider = ({ children }: { children: React.ReactNode }) => {
Expand All @@ -61,25 +61,36 @@ const FormContextProvider = ({ children }: { children: React.ReactNode }) => {
console.error(e);
};

return (
<FormContext.Provider
value={{
step,
setStep,
nymNodeData,
setNymNodeData,
costParams,
setCostParams,
amountData,
setAmountData,
signature,
setSignature,
onError,
}}
>
{children}
</FormContext.Provider>
const value = useMemo(
() => ({
step,
setStep,
nymNodeData,
setNymNodeData,
costParams,
setCostParams,
amountData,
setAmountData,
signature,
setSignature,
onError,
}),
[
step,
setStep,
nymNodeData,
setNymNodeData,
costParams,
setCostParams,
amountData,
setAmountData,
signature,
setSignature,
onError,
],
);

return <FormContext.Provider value={value}>{children}</FormContext.Provider>;
};

export const useFormContext = () => useContext(FormContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Stack, TextField, Box, FormHelperText } from '@mui/material';
import { useForm } from 'react-hook-form';
import { TBondNymNodeArgs } from 'src/types';
import { yupResolver } from '@hookform/resolvers/yup';
import { SimpleModal } from 'src/components/Modals/SimpleModal';
import { nymNodeAmountSchema } from './amountValidationSchema';
import { CurrencyFormField } from '@nymproject/react/currency/CurrencyFormField';
import { checkHasEnoughFunds } from 'src/utils';
import { nymNodeAmountSchema } from './amountValidationSchema';

const defaultNymNodeCostParamValues: TBondNymNodeArgs['costParams'] = {
profit_margin_percent: '10',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Stack, TextField, FormControlLabel, Checkbox } from '@mui/material';
import { useForm } from 'react-hook-form';
import { IdentityKeyFormField } from '@nymproject/react/mixnodes/IdentityKeyFormField';
import { TBondNymNodeArgs } from 'src/types';
import { useFormContext } from './FormContext';
import { yupResolver } from '@hookform/resolvers/yup';
import * as yup from 'yup';
import { isValidHostname, validateRawPort } from 'src/utils';
Expand All @@ -21,9 +20,7 @@ const yupValidationSchema = yup.object().shape({
.string()
.required('A host is required')
.test('no-whitespace', 'Host cannot contain whitespace', (value) => !/\s/.test(value || ''))
.test('valid-host', 'A valid host is required', (value) => {
return value ? isValidHostname(value) : false;
}),
.test('valid-host', 'A valid host is required', (value) => (value ? isValidHostname(value) : false)),

custom_http_port: yup
.number()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,19 @@ const NymNodeSignature = ({

const {
register,
handleSubmit,
formState: { errors },
} = useForm<Signature>();

const generateMessage = async () => {
try {
const message = await generateNymNodeMsgPayload({
const msg = await generateNymNodeMsgPayload({
nymNode,
pledge,
costParams,
});

if (message) {
setMessage(message);
if (msg) {
setMessage(msg);
}
} catch (e) {
console.error(e);
Expand Down
23 changes: 2 additions & 21 deletions nym-wallet/src/components/Bonding/modals/BondGatewayModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { ModalListItem } from 'src/components/Modals/ModalListItem';
import { SimpleModal } from 'src/components/Modals/SimpleModal';
import { TPoolOption } from 'src/components/TokenPoolSelector';
import { useGetFee } from 'src/hooks/useGetFee';
import { GatewayAmount, GatewayData, Signature } from 'src/pages/bonding/types';
import { simulateBondGateway, simulateVestingBondGateway } from 'src/requests';
import { GatewayAmount, GatewayData } from 'src/pages/bonding/types';
import { TBondGatewayArgs } from 'src/types';
import { BalanceWarning } from 'src/components/FeeWarning';
import { AppContext } from 'src/context';
Expand Down Expand Up @@ -49,9 +48,8 @@ export const BondGatewayModal = ({
const [step, setStep] = useState<1 | 2 | 3>(1);
const [gatewayData, setGatewayData] = useState<GatewayData>(defaultGatewayValues);
const [amountData, setAmountData] = useState<GatewayAmount>(defaultAmountValues(denom));
const [signature, setSignature] = useState<string>();

const { fee, getFee, resetFeeState, feeError } = useGetFee();
const { fee, resetFeeState, feeError } = useGetFee();
const { userBalance } = useContext(AppContext);

useEffect(() => {
Expand Down Expand Up @@ -83,22 +81,6 @@ export const BondGatewayModal = ({
setStep(3);
};

const handleUpdateSignature = async (data: Signature) => {
setSignature(data.signature);

const payload = {
pledge: amountData.amount,
msgSignature: data.signature,
gateway: gatewayToTauri(gatewayData),
};

if (amountData.tokenPool === 'balance') {
await getFee<TBondGatewayArgs>(simulateBondGateway, payload);
} else {
await getFee<TBondGatewayArgs>(simulateVestingBondGateway, payload);
}
};

const handleConfirm = async () => {
await onBondGateway(
{
Expand Down Expand Up @@ -154,7 +136,6 @@ export const BondGatewayModal = ({
hasVestingTokens={hasVestingTokens}
onValidateGatewayData={handleUpdateGatwayData}
onValidateAmountData={handleUpdateAmountData}
onValidateSignature={handleUpdateSignature}
onSelectNodeType={onSelectNodeType}
/>
</Box>
Expand Down
14 changes: 3 additions & 11 deletions nym-wallet/src/components/Bonding/modals/BondNymNodeModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useContext, useEffect } from 'react';
import React, { useContext, useEffect } from 'react';
import { ConfirmTx } from 'src/components/ConfirmTX';
import { ModalListItem } from 'src/components/Modals/ModalListItem';
import { useGetFee } from 'src/hooks/useGetFee';
import { MixnodeAmount, Signature } from 'src/pages/bonding/types';
import { Signature } from 'src/pages/bonding/types';
import { BalanceWarning } from 'src/components/FeeWarning';
import { AppContext } from 'src/context';
import FormContextProvider, { useFormContext } from '../forms/nym-node/FormContext';
Expand All @@ -11,7 +11,7 @@ import NymNodeAmount from '../forms/nym-node/NymNodeAmount';
import NymNodeSignature from '../forms/nym-node/NymNodeSignature';

export const BondNymNodeModal = ({ onClose }: { onClose: () => void }) => {
const { fee, getFee, resetFeeState, feeError } = useGetFee();
const { fee, resetFeeState, feeError } = useGetFee();
const { userBalance } = useContext(AppContext);
const { setStep, step, onError, setSignature, amountData, costParams, nymNodeData } = useFormContext();

Expand All @@ -21,18 +21,10 @@ export const BondNymNodeModal = ({ onClose }: { onClose: () => void }) => {
}
}, [feeError]);

const handleBack = () => {
setStep(step);
};

const handleUpdateMixnodeData = async () => {
setStep(2);
};

const handleUpdateAmountData = async (data: MixnodeAmount) => {
setStep(3);
};

const handleUpdateSignature = async (data: Signature) => {
setSignature(data.signature);
};
Expand Down
Loading

0 comments on commit 54d1359

Please sign in to comment.