From d76587c976c459eaf7fcabb9eae993103669f30d Mon Sep 17 00:00:00 2001 From: Jaco Date: Thu, 9 Feb 2023 15:38:40 +0200 Subject: [PATCH] Adjust address conversion (32 can convert to H160) (#8991) --- .../src/InputAddress/createItem.tsx | 32 ++++++++++--------- packages/react-hooks/src/ctx/Keyring.tsx | 6 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/react-components/src/InputAddress/createItem.tsx b/packages/react-components/src/InputAddress/createItem.tsx index 685b48ac68..b724b75a20 100644 --- a/packages/react-components/src/InputAddress/createItem.tsx +++ b/packages/react-components/src/InputAddress/createItem.tsx @@ -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: ( + + ) + }; } } catch { - return null; + // ignore } - return { - ...option, - text: ( - - ) - }; + return null; } diff --git a/packages/react-hooks/src/ctx/Keyring.tsx b/packages/react-hooks/src/ctx/Keyring.tsx index ae13179625..34bb3e6911 100644 --- a/packages/react-hooks/src/ctx/Keyring.tsx +++ b/packages/react-hooks/src/ctx/Keyring.tsx @@ -48,12 +48,10 @@ function filter (isEthereum: boolean, items: string[], others: string[] = []): s return items.reduce((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);