Adjust address conversion (32 can convert to H160) (#8991)

This commit is contained in:
Jaco 2023-02-09 15:38:40 +02:00 committed by GitHub
parent 59946076ba
commit d76587c976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 19 deletions

View File

@ -12,24 +12,26 @@ import { decodeAddress } from '@polkadot/util-crypto';
import KeyPair from './KeyPair';
export default function createItem (option: KeyringSectionOption, isUppercase = true): Option | null {
try {
const u8a = decodeAddress(option.key);
const allowedLength = keyring.keyring.type === 'ethereum'
? 20
: 32;
if (u8a.length !== (keyring.keyring.type === 'ethereum' ? 20 : 32)) {
return null;
try {
if (decodeAddress(option.key).length >= allowedLength) {
return {
...option,
text: (
<KeyPair
address={option.key || ''}
isUppercase={isUppercase}
name={option.name}
/>
)
};
}
} catch {
return null;
// ignore
}
return {
...option,
text: (
<KeyPair
address={option.key || ''}
isUppercase={isUppercase}
name={option.name}
/>
)
};
return null;
}

View File

@ -48,12 +48,10 @@ function filter (isEthereum: boolean, items: string[], others: string[] = []): s
return items.reduce<string[]>((result, a) => {
if (!result.includes(a) && !others.includes(a)) {
try {
const u8a = decodeAddress(a);
if (u8a.length === allowedLength) {
if (decodeAddress(a).length >= allowedLength) {
result.push(a);
} else {
console.warn(`Not adding address ${a}, not in correct format for chain (requires ${allowedLength}-byte publickey)`);
console.warn(`Not adding address ${a}, not in correct format for chain (requires publickey from address)`);
}
} catch {
console.error(a, allowedLength);