Adjust address conversion (32 can convert to H160) (#8991)
This commit is contained in:
parent
59946076ba
commit
d76587c976
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user