Fix main merge

This commit is contained in:
abefernan
2023-04-12 16:30:47 +02:00
parent 5515c65a1d
commit 4daa6ea042
4 changed files with 22 additions and 47 deletions
+8 -8
View File
@@ -1,14 +1,14 @@
import axios from "axios";
import { Account, calculateFee } from "@cosmjs/stargate";
import { Decimal } from "@cosmjs/math";
import { Account, calculateFee } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
import axios from "axios";
import { NextRouter, withRouter } from "next/router";
import React, { useState } from "react";
import { withRouter, NextRouter } from "next/router";
import { useAppContext } from "../../context/AppContext";
import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
import Button from "../inputs/Button";
import Input from "../inputs/Input";
import StackableContainer from "../layout/StackableContainer";
import { checkValidatorAddress } from "../../lib/displayHelpers";
interface Props {
address: string | null;
@@ -67,8 +67,8 @@ const ReDelegationForm = (props: Props) => {
const handleCreate = async () => {
assert(state.chain.addressPrefix, "addressPrefix missing");
const validatorSrcAddressError = checkValidatorAddress(validatorSrcAddress, "cosmosvaloper");
const validatorDstAddressError = checkValidatorAddress(validatorDstAddress, "cosmosvaloper");
const validatorSrcAddressError = checkAddress(validatorSrcAddress, state.chain.addressPrefix);
const validatorDstAddressError = checkAddress(validatorDstAddress, state.chain.addressPrefix);
if (validatorSrcAddressError) {
setAddressError(
`Invalid address for network ${state.chain.chainId}: ${validatorSrcAddressError}`,
@@ -109,7 +109,7 @@ const ReDelegationForm = (props: Props) => {
setValidatorSrcAddress(e.target.value)
}
error={addressError}
placeholder={`E.g. cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0`}
placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)}`}
/>
</div>
<div className="form-item">
@@ -121,7 +121,7 @@ const ReDelegationForm = (props: Props) => {
setValidatorDstAddress(e.target.value)
}
error={addressError}
placeholder={`E.g. cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0`}
placeholder={`E.g. ${exampleValidatorAddress(1, state.chain.addressPrefix)}`}
/>
</div>
<div className="form-item">
+7 -7
View File
@@ -1,14 +1,14 @@
import axios from "axios";
import { Account, calculateFee } from "@cosmjs/stargate";
import { Decimal } from "@cosmjs/math";
import { Account, calculateFee } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
import React, { useState } from "react";
import { withRouter, NextRouter } from "next/router";
import axios from "axios";
import { NextRouter, withRouter } from "next/router";
import { useState } from "react";
import { useAppContext } from "../../context/AppContext";
import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
import Button from "../inputs/Button";
import Input from "../inputs/Input";
import StackableContainer from "../layout/StackableContainer";
import { checkValidatorAddress } from "../../lib/displayHelpers";
interface Props {
address: string | null;
@@ -60,7 +60,7 @@ const RewardsForm = (props: Props) => {
const handleCreate = async () => {
assert(state.chain.addressPrefix, "addressPrefix missing");
const validatorAddressError = checkValidatorAddress(validatorAddress, "cosmosvaloper");
const validatorAddressError = checkAddress(validatorAddress, state.chain.addressPrefix);
if (validatorAddressError) {
setAddressError(
`Invalid address for network ${state.chain.chainId}: ${validatorAddressError}`,
@@ -93,7 +93,7 @@ const RewardsForm = (props: Props) => {
value={validatorAddress}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setValidatorAddress(e.target.value)}
error={addressError}
placeholder={`E.g. cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0`}
placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)})}`}
/>
</div>
<div className="form-item">
+7 -7
View File
@@ -1,14 +1,14 @@
import axios from "axios";
import { Account, calculateFee } from "@cosmjs/stargate";
import { Decimal } from "@cosmjs/math";
import { Account, calculateFee } from "@cosmjs/stargate";
import { assert } from "@cosmjs/utils";
import React, { useState } from "react";
import { withRouter, NextRouter } from "next/router";
import axios from "axios";
import { NextRouter, withRouter } from "next/router";
import { useState } from "react";
import { useAppContext } from "../../context/AppContext";
import { checkAddress, exampleValidatorAddress } from "../../lib/displayHelpers";
import Button from "../inputs/Button";
import Input from "../inputs/Input";
import StackableContainer from "../layout/StackableContainer";
import { checkValidatorAddress } from "../../lib/displayHelpers";
interface Props {
address: string | null;
@@ -60,7 +60,7 @@ const UnDelegationForm = (props: Props) => {
const handleCreate = async () => {
assert(state.chain.addressPrefix, "addressPrefix missing");
const validatorAddressError = checkValidatorAddress(validatorAddress, "cosmosvaloper");
const validatorAddressError = checkAddress(validatorAddress, state.chain.addressPrefix);
if (validatorAddressError) {
setAddressError(
`Invalid address for network ${state.chain.chainId}: ${validatorAddressError}`,
@@ -93,7 +93,7 @@ const UnDelegationForm = (props: Props) => {
value={validatorAddress}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setValidatorAddress(e.target.value)}
error={addressError}
placeholder={`E.g. cosmosvaloper1sjllsnramtg3ewxqwwrwjxfgc4n4ef9u2lcnj0`}
placeholder={`E.g. ${exampleValidatorAddress(0, state.chain.addressPrefix)})}`}
/>
</div>
<div className="form-item">
-25
View File
@@ -137,31 +137,7 @@ const checkAddress = (input: string, chainAddressPrefix: string) => {
return null;
};
/**
* Returns an error message for invalid addresses.
*
* Returns null of there is no error.
*/
const checkValidatorAddress = (input: string, chainAddressPrefix: string): string | null => {
if (!input) return "Empty";
let prefix;
try {
({ prefix } = fromBech32(input));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
return error.toString();
}
if (prefix !== chainAddressPrefix) {
return `Expected address prefix '${chainAddressPrefix}' but got '${prefix}'`;
}
if (input.length !== 52) {
return "Invalid address length in validator address. Must be 52 bytes.";
}
return null;
};
/**
* Returns a link to a transaction in an explorer if an explorer is configured
* for transactions. Returns null otherwise.
@@ -182,5 +158,4 @@ export {
examplePubkey,
checkAddress,
explorerLinkTx,
checkValidatorAddress,
};