How to use the @polkadot/ui-keyring.saveAddress 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 / AddressRow.tsx View on Github external
protected saveName = (): void => {
    const { address, name } = this.state;
    const trimmedName = name.trim();
    const meta = {
      name: trimmedName,
      whenEdited: Date.now()
    };

    // Save only if the name was changed or if it's no empty.
    if (trimmedName && address) {
      try {
        const currentKeyring = keyring.getPair(address);

        currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
      } catch (error) {
        keyring.saveAddress(address, meta);
      }
    }

    this.setState({ isEditingName: false });
  }
github polkadot-js / apps / packages / app-address-book / src / Creator.tsx View on Github external
onCommit = (): void => {
    const { basePath, onStatusChange, t } = this.props;
    const { address, isAddressExisting, name, tags } = this.state;

    const status = {
      action: 'create'
    } as ActionStatus;

    try {
      keyring.saveAddress(address, { name, tags });

      status.account = address;
      status.status = address ? 'success' : 'error';
      status.message = isAddressExisting
        ? t('address edited')
        : t('address created');

      InputAddress.setLastValue('address', address);
    } catch (error) {
      status.status = 'error';
      status.message = error.message;
    }

    onStatusChange(status);

    if (status.status !== 'error') {
github polkadot-js / apps / packages / app-address-book / src / modals / Create.tsx View on Github external
const _onCommit = (): void => {
    const status = { action: 'create' } as ActionStatus;

    if (!isValid) {
      return;
    }

    try {
      keyring.saveAddress(address, { name: name.trim(), genesisHash: keyring.genesisHash, tags: [] });

      status.account = address;
      status.status = address ? 'success' : 'error';
      status.message = isAddressExisting
        ? t('address edited')
        : t('address created');

      InputAddress.setLastValue('address', address);
    } catch (error) {
      status.status = 'error';
      status.message = error.message;
    }

    onStatusChange(status);
    onClose();
  };
github polkadot-js / apps / packages / app-accounts / src / Account.tsx View on Github external
const _saveTags = (): void => {
    toggleEditTags();

    const meta = { tags, whenEdited: Date.now() };

    if (address) {
      try {
        const currentKeyring = keyring.getPair(address);

        currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
      } catch (error) {
        keyring.saveAddress(address, meta);
      }
    }
  };
  const _onForget = (): void => {
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);
  };
github polkadot-js / apps / packages / ui-app / src / AddressSummary.tsx View on Github external
protected saveTags = () => {
    const { address, tags } = this.state;
    const meta = {
      tags,
      whenEdited: Date.now()
    };

    if (address) {
      try {
        const currentKeyring = keyring.getPair(address);

        currentKeyring && keyring.saveAccountMeta(currentKeyring, meta);
      } catch (error) {
        keyring.saveAddress(address, meta);
      }

      this.setState({ isEditingTags: false });
    }
  }
github polkadot-js / apps / packages / app-address-book / src / Editor.tsx View on Github external
onCommit = (): void => {
    const { onStatusChange, t } = this.props;
    const { current, editedName, tags } = this.state;

    if (!current) {
      return;
    }

    const status = {
      account: current.address(),
      action: 'edit'
    } as ActionStatus;

    try {
      keyring.saveAddress(current.address(), {
        name: editedName,
        tags,
        whenEdited: Date.now()
      });

      status.status = current.getMeta().name === editedName ? 'success' : 'error';
      status.message = t('address edited');
    } catch (error) {
      status.status = 'error';
      status.message = error.message;
    }

    onStatusChange(status);
  }