How to use the @polkadot/ui-keyring.decodeAddress 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-signer / src / Modal.tsx View on Github external
function extractExternal (accountId?: AccountId | string | null): { isExternal: boolean; isHardware: boolean; hardwareType?: string } {
  if (!accountId) {
    return { isExternal: false, isHardware: false };
  }

  let publicKey;

  try {
    publicKey = keyring.decodeAddress(accountId);
  } catch (error) {
    console.error(error);

    return { isExternal: false, isHardware: false };
  }

  const pair = keyring.getPair(publicKey);

  return {
    isExternal: !!pair.meta.isExternal,
    isHardware: !!pair.meta.isHardware,
    hardwareType: pair.meta.hardwareType
  };
}
github polkadot-js / apps / packages / react-signer / src / Modal.tsx View on Github external
private unlockAccount (accountId: string, password?: string): string | null {
    let publicKey;

    try {
      publicKey = keyring.decodeAddress(accountId);
    } catch (error) {
      console.error(error);

      return 'unable to decode address';
    }

    const pair = keyring.getPair(publicKey);

    if (!pair.isLocked || pair.meta.isInjected || pair.meta.isExternal) {
      return null;
    }

    try {
      pair.decodePkcs8(password);
    } catch (error) {
      console.error(error);
github polkadot-js / apps / packages / react-params / src / Param / Account.tsx View on Github external
return (value?: string | null): void => {
    let isValid = false;

    if (value) {
      try {
        keyring.decodeAddress(value);

        isValid = true;
      } catch (err) {
        console.error(err);
      }
    }

    onChange && onChange({
      isValid,
      value
    });
  };
}
github polkadot-js / apps / packages / app-transfer / src / Transfer.tsx View on Github external
private renderAddress (accountId: string | null, media: 'large' | 'medium') {
    if (!accountId) {
      return null;
    }

    try {
      keyring.decodeAddress(accountId);
    } catch (err) {
      return null;
    }

    return (
      <div>
        
      </div>
    );
  }
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) {
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) {