Make skipping prefix explicit
This commit is contained in:
parent
17f9c84544
commit
c123f6fb72
@ -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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user