How to use the @polkadot/ui-keyring.encodeAddress 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 paritytech / substrate-light-ui / packages / ui-components / src / util / toAddress.ts View on Github external
export default function toAddress (value?: string | Uint8Array): string | undefined {
  if (!value) {
    return;
  }

  try {
    return keyring.encodeAddress(
      isHex(value)
        ? hexToU8a(value)
        : keyring.decodeAddress(value)
    );
  } catch (error) {
    console.error('Unable to encode address', value);
  }
}
github polkadot-js / apps / packages / react-components / src / util / toAddress.ts View on Github external
export default function toAddress (value?: string | Uint8Array | null): string | undefined {
  if (!value) {
    return;
  }

  let address: string | undefined;

  try {
    address = keyring.encodeAddress(
      isHex(value)
        ? hexToU8a(value)
        : keyring.decodeAddress(value)
    );
  } catch (error) {
    console.error('Unable to encode address', value);
  }

  return address;
}
github polkadot-js / apps / packages / app-accounts / src / modals / Import.tsx View on Github external
const _onChangeFile = (file: Uint8Array): void => {
    try {
      const json = JSON.parse(u8aToString(file));
      const publicKey = keyring.decodeAddress(json.address, true);
      const address = keyring.encodeAddress(publicKey);
      const isFileValid = publicKey.length === 32 && isHex(json.encoded) && isObject(json.meta) && (
        Array.isArray(json.encoding.content)
          ? json.encoding.content[0] === 'pkcs8'
          : json.encoding.content === 'pkcs8'
      );

      setImport([address, json, isFileValid]);
    } catch (error) {
      setImport([null, null, false]);
      console.error(error);
    }
  };
github polkadot-js / ui / packages / exampleReactNative / App.tsx View on Github external
const _onClickNew = (): void => {
    const phrase = mnemonicGenerate(12);
    const { address } = keyring.createFromUri(phrase);

    setAddress(keyring.encodeAddress(address, ss58Format));
    setPhrase(phrase);
  };
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;
            }
          }
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 });
        }
      }
github polkadot-js / ui / packages / exampleReactNative / App.tsx View on Github external
useEffect((): void => {
    ready && address && setAddress(keyring.encodeAddress(address, ss58Format));
  }, [address, ss58Format]);
github polkadot-js / ui / packages / example-react / src / index.tsx View on Github external
const _onClickNew = (): void => {
    const phrase = mnemonicGenerate(12);
    const { address } = keyring.createFromUri(phrase);

    setAddress(keyring.encodeAddress(address, ss58Format));
    setPhrase(phrase);
  };
  const _onChangeSS58Format = ({ currentTarget: { value } }: React.SyntheticEvent): void => {
github polkadot-js / ui / packages / example-react / src / index.tsx View on Github external
useEffect((): void => {
    address && setAddress(keyring.encodeAddress(address, ss58Format));
  }, [address, ss58Format]);