Make skipping prefix explicit

This commit is contained in:
Simon Warta 2023-06-14 12:06:50 +02:00
parent 17f9c84544
commit c123f6fb72
2 changed files with 10 additions and 5 deletions

View File

@ -75,7 +75,7 @@ const MsgTransferForm = ({ fromAddress, setMsgGetter, deleteMsg }: MsgTransferFo
return false;
}
const addressErrorMsg = checkAddress(toAddress, ""); // Allow address from any chain
const addressErrorMsg = checkAddress(toAddress, null); // Allow address from any chain
if (addressErrorMsg) {
setToAddressError(`Invalid address for network ${state.chain.chainId}: ${addressErrorMsg}`);
return false;

View File

@ -117,10 +117,11 @@ function examplePubkey(index: number): string {
/**
* Returns an error message for invalid addresses.
*
* Returns null of there is no error.
*
* If `chainAddressPrefix` is null, the prefix check will be skipped.
*/
const checkAddress = (input: string, chainAddressPrefix: string) => {
const checkAddress = (input: string, chainAddressPrefix: string | null) => {
if (!input) return "Empty";
let data;
@ -132,8 +133,12 @@ const checkAddress = (input: string, chainAddressPrefix: string) => {
return error.toString();
}
if (!prefix.startsWith(chainAddressPrefix)) {
return `Expected address prefix '${chainAddressPrefix}' but got '${prefix}'`;
if (chainAddressPrefix) {
if (!prefix.startsWith(chainAddressPrefix)) {
return `Expected address prefix '${chainAddressPrefix}' but got '${prefix}'`;
}
} else {
// any prefix is allowed
}
if (data.length !== 20) {