ghost-portal/packages/react-components/src/util/getAddressMeta.ts
2021-01-03 11:33:39 +01:00

21 lines
600 B
TypeScript

// Copyright 2017-2021 @polkadot/react-components authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { KeyringItemType, KeyringJson$Meta } from '@polkadot/ui-keyring/types';
import { keyring } from '@polkadot/ui-keyring';
export default function getAddressMeta (address: string, type: KeyringItemType | null = null): KeyringJson$Meta {
let meta: KeyringJson$Meta | undefined;
try {
const pair = keyring.getAddress(address, type);
meta = pair && pair.meta;
} catch (error) {
// we could pass invalid addresses, so it may throw
}
return meta || {};
}