feat: add gnosis and chiado network

This commit is contained in:
Wagalidoom
2025-07-11 11:33:56 +02:00
parent 1208ef8b86
commit f56689e593
5 changed files with 87 additions and 33 deletions

View File

@@ -1,4 +1,6 @@
import { Dispatch, SetStateAction, createContext, useState } from "react";
import { Dispatch, SetStateAction, createContext, useContext, useState } from "react";
import { Network, NetworkConfig } from "./types";
import { GlobalContext } from "./GlobalContext";
interface KeyCreationContextType {
folderLocation: string;
@@ -50,6 +52,7 @@ const KeyCreationContextWrapper = ({ children }: { children: React.ReactNode}) =
const [password, setPassword] = useState<string>("");
const [withdrawalAddress, setWithdrawalAddress] = useState<string>("");
const [compounding, setCompounding] = useState<boolean>(false);
const { network } = useContext(GlobalContext);
return (
<KeyCreationContext.Provider value={{
@@ -61,7 +64,7 @@ const KeyCreationContextWrapper = ({ children }: { children: React.ReactNode}) =
setMnemonic,
numberOfKeys,
setNumberOfKeys,
amount,
amount: amount / NetworkConfig[network].multiplier,
setAmount,
password,
setPassword,

View File

@@ -1,15 +1,33 @@
import { StepKey } from './types';
import { Network, NetworkConfig } from './types';
export const MNEMONIC_ERROR_SEARCH = "That is not a valid mnemonic";
export const VALID_MNEMONIC_LENGTHS = [12, 15, 18, 21, 24];
export const ETH_TO_GWEI = 10 ** 9;
export const getDepositAmountLimits = (network: Network) => {
const multiplier = NetworkConfig[network].multiplier;
return {
min: 1 / multiplier,
max: 2048 / multiplier,
};
};
export const formatDepositAmountError = (network: Network): string => {
const { min, max } = getDepositAmountLimits(network);
return `Amount must be between ${min} and ${max}.`;
};
export const formatAmountTooltip = (network: Network): string => {
const { min, max } = getDepositAmountLimits(network);
return `Enter the amount you would like to deposit for each validator. This value must be between ${min} and ${max} and can not have greater precision than 1 gwei. You must have withdrawal credentials defined and set "compounding".`;
};
export const errors = {
MNEMONIC_LENGTH_ERROR: `The Secret Recovery Phrase must be ${VALID_MNEMONIC_LENGTHS.slice(0, -1).join(", ")}, or ${VALID_MNEMONIC_LENGTHS.slice(-1)} words in length. Please verify each word and try again.`,
INVALID_MNEMONIC_ERROR: "The Secret Recovery Phrase provided is invalid. Please double check each word for any spelling errors.",
MNEMONICS_DONT_MATCH: "The Secret Recovery Phrase you entered does not match what was given to you. Please try again.",
NUMBER_OF_KEYS: "Please input a number between 1 and 1000.",
DEPOSIT_AMOUNT: "Amount must be between 1 and 2048.",
ADDRESS_FORMAT_ERROR: "Please enter a valid Ethereum address.",
WITHDRAW_ADDRESS_REQUIRED: "Please enter an Ethereum address.",
PASSWORD_STRENGTH: "Password must be at least 12 characters.",
@@ -30,7 +48,6 @@ export const errors = {
export const tooltips = {
IMPORT_MNEMONIC: "If you've already created a Secret Recovery Phrase, you can use it to regenerate your original keys, create more keys, or generate a BLS to execution change by importing the phrase here.",
NUMBER_OF_KEYS: "Enter how many new validator keys you'd like to create.",
AMOUNT: "Enter the amount you would like to deposit for each validator. This value must be between 1 and 2048 and can not have greater precision than 1 gwei. You must have withdrawal credentials defined and set \"compounding\".",
PASSWORD: "Pick a strong password (at least 12 characters) that will be used to protect your keys.",
STARTING_INDEX: "Each key is created sequentially, so we need to know how many you've created with this Secret Recovery Phrase in the past in order to create some new ones for you.",
ETH1_WITHDRAW_ADDRESS: "An optional Ethereum address for the withdrawal credentials.",
@@ -39,7 +56,7 @@ export const tooltips = {
BTEC_START_INDEX: "The index position for the keys to start generating withdrawal credentials. If you only created 1 validator key using this Secret Recovery Phrase, this is likely going to be 0. If you created many validator keys, this could be a higher value from where you want to start in the list of validators derived from your Secret Recovery Phrase.",
BTEC_INDICES: "A list of the chosen validator index number(s) as identified on the beacon chain. You can find your validator indice on beaconcha.in website on your validator page. It will be at the top of that page the form of a title like Validator XXXXX, where XXXXX is going to be your indice.",
BLS_CREDENTIALS: "A list of the old BLS withdrawal credentials of the given validator(s). You can find your validator BLS withdrawal credentials on beaconcha.in website on your validator page. It will be in the Deposits tab and it should start with 0x00.",
COMPOUNDING: "Compounding Credentials increases your maximum effective balance from 32 to 2048 ETH."
COMPOUNDING: "Compounding Credentials increases your maximum effective balance from 32 to 2048 ETH."
};
export const stepLabels = {
@@ -49,8 +66,8 @@ export const stepLabels = {
[StepKey.KeyGeneration]: 'Create Validator Key Files',
[StepKey.Finish]: 'Finish',
[StepKey.BTECConfiguration]: 'Configure Withdrawal Address',
[StepKey.BTECGeneration]: 'Create Credentials Change',
[StepKey.FinishBTEC]: 'Finish'
[StepKey.BTECGeneration]: 'Create Credentials Change',
[StepKey.FinishBTEC]: 'Finish'
};
export const CreateMnemonicFlow = [StepKey.MnemonicGeneration, StepKey.KeyConfiguration, StepKey.KeyGeneration, StepKey.Finish];

View File

@@ -57,8 +57,10 @@ const NetworkPickerModal = ({onClose, showModal}: NetworkPickerModalParams) => {
<FormControl variant="standard" focused>
<RadioGroup aria-label="gender" name="gender1" value={formNetwork} onChange={onNetworkChange}>
<FormControlLabel value={Network.MAINNET} control={<Radio />} label={Network.MAINNET} />
<FormControlLabel value={Network.GNOSIS} control={<Radio />} label={Network.GNOSIS} />
<Divider />
<Typography className="tw-text-xl tw-mt-5 tw-mb-4">Testnets</Typography>
<FormControlLabel value={Network.CHIADO} control={<Radio />} label={Network.CHIADO} />
<FormControlLabel value={Network.HOLESKY} control={<Radio />} label={Network.HOLESKY} />
<FormControlLabel value={Network.HOODI} control={<Radio />} label={Network.HOODI} />
</RadioGroup>

View File

@@ -16,7 +16,11 @@ import {
errors,
paths,
tooltips,
getDepositAmountLimits,
formatDepositAmountError,
formatAmountTooltip,
} from "../constants";
import { GlobalContext } from "../GlobalContext";
import { KeyCreationContext } from "../KeyCreationContext";
/**
@@ -42,9 +46,13 @@ const ConfigureValidatorKeys = () => {
compounding,
setCompounding,
} = useContext(KeyCreationContext);
const { network } = useContext(GlobalContext);
const history = useHistory();
const usingExistingFlow = history.location.pathname === paths.CONFIGURE_EXISTING;
// Get dynamic min/max values based on current network
const { min: minAmount, max: maxAmount } = getDepositAmountLimits(network);
const [passwordToVerify, setPasswordToVerify] = useState("");
const [verifyPassword, setVerifyPassword] = useState(false);
const [passwordVerifyError, setPasswordVerifyError] = useState(false);
@@ -136,7 +144,7 @@ const ConfigureValidatorKeys = () => {
setInputIndexError(false);
}
if (inputAmount < 1 || inputAmount > 2048) {
if (inputAmount < minAmount || inputAmount > maxAmount) {
setInputAmountError(true);
isError = true;
} else {
@@ -277,34 +285,34 @@ const ConfigureValidatorKeys = () => {
/>
</Tooltip>
<Tooltip title={tooltips.COMPOUNDING}>
<FormControlLabel
label="Compounding Credentials (0x02) - Must set a valid Withdrawal Address"
control={
<Checkbox
checked={inputCompounding}
disabled={!inputWithdrawalAddress}
onChange={updateCompounding}
/>
}
/>
</Tooltip>
</div>
<Tooltip title={tooltips.AMOUNT}>
<TextField
className="tw-flex-1"
disabled={!inputCompounding}
id="amount"
label="Deposit Amount"
type="number"
variant="outlined"
value={inputAmount}
onChange={updateAmount}
error={inputAmountError}
helperText={inputAmountError ? errors.DEPOSIT_AMOUNT : ""}
<Tooltip title={tooltips.COMPOUNDING}>
<FormControlLabel
label="Compounding Credentials (0x02) - Must set a valid Withdrawal Address"
control={
<Checkbox
checked={inputCompounding}
disabled={!inputWithdrawalAddress}
onChange={updateCompounding}
/>
}
/>
</Tooltip>
</div>
<Tooltip title={formatAmountTooltip(network)}>
<TextField
className="tw-flex-1"
disabled={!inputCompounding}
id="amount"
label="Deposit Amount"
type="number"
variant="outlined"
value={inputAmount}
onChange={updateAmount}
error={inputAmountError}
helperText={inputAmountError ? formatDepositAmountError(network) : ""}
/>
</Tooltip>
</div>
<div className="tw-w-full tw-flex tw-flex-row tw-gap-4">
<Tooltip title={tooltips.NUMBER_OF_KEYS}>

View File

@@ -24,4 +24,28 @@ export enum Network {
MAINNET = "Mainnet",
HOLESKY = "Holesky",
HOODI = "Hoodi",
GNOSIS = "Gnosis",
CHIADO = "Chiado",
}
export interface NetworkConfig {
multiplier: number;
}
export const NetworkConfig: Record<Network, NetworkConfig> = {
[Network.MAINNET]: {
multiplier: 1,
},
[Network.HOLESKY]: {
multiplier: 1,
},
[Network.HOODI]: {
multiplier: 1,
},
[Network.GNOSIS]: {
multiplier: 32,
},
[Network.CHIADO]: {
multiplier: 32,
},
};