How to use the @polkadot/ui-keyring.getAddress function in @polkadot/ui-keyring

To help you get started, we’ve selected a few @polkadot/ui-keyring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polkadot-js / apps / packages / react-components / src / util / getAddressMeta.ts View on Github external
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 || {};
}
github dappforce / dappforce-subsocial-ui / src / components / utils / index.tsx View on Github external
export function findNameByAddress (address: string): string | undefined {
  try {
    return keyring.getAccount(address).getMeta().name;
  } catch (error) {
    try {
      return keyring.getAddress(address).getMeta().name;
    } catch (error) {
      // ok, we don't have account or address
      return undefined;
    }
  }
}
github polkadot-js / apps / packages / react-components / src / InputAddress / index.tsx View on Github external
function createOption (address: string): Option {
  let isRecent: boolean | undefined;
  const pair = keyring.getAccount(address);
  let name: string | undefined;

  if (pair) {
    name = pair.meta.name;
  } else {
    const addr = keyring.getAddress(address);

    if (addr) {
      name = addr.meta.name;
      isRecent = addr.meta.isRecent;
    } else {
      isRecent = true;
    }
  }

  return createItem(createKeyringItem(address, name), !isRecent);
}
github polkadot-js / apps / packages / app-address-book / src / Creator.tsx View on Github external
(prevState: State): State => {
        let { address = prevState.address, name = prevState.name, tags = prevState.tags } = newState;
        let isAddressValid = true;
        let isAddressExisting = false;
        let newAddress = address;

        try {
          newAddress = keyring.encodeAddress(
            keyring.decodeAddress(address)
          );
          isAddressValid = keyring.isAvailable(newAddress);

          if (!isAddressValid) {
            const old = keyring.getAddress(newAddress);

            if (old.isValid) {
              if (!allowEdit) {
                name = old.getMeta().name || name;
              }

              isAddressExisting = true;
              isAddressValid = true;
            }
          }
        } catch (error) {
          isAddressValid = false;
        }

        const isNameValid = !!name;
github polkadot-js / apps / packages / app-address-book / src / modals / Create.tsx View on Github external
const _onChangeAddress = (input: string): void => {
    let address = '';
    let isAddressValid = true;
    let isAddressExisting = false;

    try {
      address = keyring.encodeAddress(
        keyring.decodeAddress(input)
      );
      isAddressValid = keyring.isAvailable(address);

      if (!isAddressValid) {
        const old = keyring.getAddress(address);

        if (old) {
          const newName = old.meta.name || name;

          isAddressExisting = true;
          isAddressValid = true;

          setName({ isNameValid: !!(newName || '').trim(), name: newName });
        }
      }
    } catch (error) {
      isAddressValid = false;
    }

    setAddress({ address: address || input, isAddressExisting, isAddressValid });
  };
github polkadot-js / apps / packages / app-address-book / src / Editor.tsx View on Github external
onChangeAddress = (accountId: string): void => {
    const current = accountId && keyring.decodeAddress(accountId)
      ? (keyring.getAddress(accountId) || null)
      : null;

    this.nextState({ current } as State);
  }
github polkadot-js / apps / packages / app-address-book / src / Address.tsx View on Github external
useEffect((): void => {
    const current = keyring.getAddress(address);

    setCurrent(current || null);
    setGenesisHash((current && current.meta.genesisHash) || null);
  }, []);
github polkadot-js / apps / packages / app-address-book / src / Address.tsx View on Github external
const _onGenesisChange = (genesisHash: string | null): void => {
    setGenesisHash(genesisHash);

    const account = keyring.getAddress(address);

    account && keyring.saveAddress(address, { ...account.meta, genesisHash });

    setGenesisHash(genesisHash);
  };