How to use the @hathor/wallet-lib.tokens function in @hathor/wallet-lib

To help you get started, we’ve selected a few @hathor/wallet-lib 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 HathorNetwork / hathor-wallet / src / screens / SendTokens.js View on Github external
send = () => {
    $('#pinModal').modal('toggle');
    const isValid = this.validateData();
    if (!isValid) return;
    let data = this.getData();
    if (!data) return;
    data.tokens = hathorLib.tokens.filterTokens(this.state.txTokens, hathorLib.constants.HATHOR_TOKEN_CONFIG).map((token) => token.uid);
    this.setState({ errorMessage: '', loading: true });
    try {
      const promise = hathorLib.transaction.sendTransaction(data, this.state.pin);
      promise.then(() => {
        // Must update the shared address, in case we have used one for the change
        wallet.updateSharedAddress();
        this.props.history.push('/wallet/');
      }, (message) => {
        this.setState({ errorMessage: message, loading: false });
      });
    } catch(e) {
      if (e instanceof hathorLib.errors.AddressError || e instanceof hathorLib.errors.OutputValueError) {
        this.setState({ errorMessage: e.message, loading: false });
      } else {
        // Unhandled error
        throw e;
github HathorNetwork / hathor-wallet / src / screens / CreateToken.js View on Github external
createToken = () => {
    $('#pinModal').modal('hide');
    if (!this.formValid()) {
      return;
    }
    this.setState({ errorMessage: '', loading: true });
    // Get the address to send the created tokens
    let address = '';
    if (this.refs.autoselectAddress.checked) {
      address = hathorLib.wallet.getAddressToUse();
    } else {
      address = this.refs.address.value;
    }

    const retPromise = hathorLib.tokens.createToken(
      address,
      this.refs.shortName.value,
      this.refs.symbol.value,
      wallet.decimalToInteger(this.state.amount),
      this.state.pin
    );
    retPromise.then((token) => {
      // Update redux with added token
      tokens.saveTokenRedux(token.uid);
      // Must update the shared address, in case we have used one for the change
      wallet.updateSharedAddress();
      this.showAlert(token);
    }, (e) => {
      this.setState({ loading: false, errorMessage: e.message });
    });
  }
github HathorNetwork / hathor-wallet / src / utils / wallet.js View on Github external
reloadData() {
    store.dispatch(loadingAddresses(true));

    this.cleanWalletRedux();

    // Cleaning redux and leaving only tokens data
    const dataToken = hathorLib.tokens.getTokens();
    store.dispatch(reloadData({
      historyTransactions: {},
      tokens: dataToken,
    }));

    // Load history from new server
    const promise = hathorLib.wallet.reloadData();
    promise.then(() => {
      this.afterLoadAddressHistory();
    });
    return promise;
  },
github HathorNetwork / hathor-wallet / src / components / ModalUnregisteredTokenInfo.js View on Github external
register = (e) => {
    if (!this.state.token) return;

    e.preventDefault();

    const isValid = this.form.current.checkValidity();
    this.setState({ formValidated: true, errorMessage: '' });
    if (isValid) {
      const configurationString = hathorLib.tokens.getConfigurationString(this.state.token.uid, this.state.token.name, this.state.token.symbol);

      const promise = hathorLib.tokens.validateTokenToAddByConfigurationString(configurationString, null);
      promise.then((tokenData) => {
        tokens.addToken(tokenData.uid, tokenData.name, tokenData.symbol);
        $('#unregisteredTokenInfoModal').modal('hide');
        this.props.tokenRegistered(this.state.token);
      }, (e) => {
        this.setState({ errorMessage: e.message });
      });
    }
  }
github HathorNetwork / hathor-wallet / src / screens / CreateToken.js View on Github external
showAlert = (token) => {
    this.setState({ name: token.name, configurationString: hathorLib.tokens.getConfigurationString(token.uid, token.name, token.symbol) }, () => {
      $('#alertModal').modal('show');
    });
  }
github HathorNetwork / hathor-wallet / src / components / tokens / TokenMint.js View on Github external
executeMint = (pin) => {
    const amountValue = this.amount.current.value*(10**hathorLib.constants.DECIMAL_PLACES);
    const output = this.props.mintOutputs[0];
    const address = this.chooseAddress.current.checked ? hathorLib.wallet.getAddressToUse() : this.address.current.value;
    const promise = hathorLib.tokens.mintTokens(
      output.tx_id,
      output.index,
      output.decoded.address,
      this.props.token.uid,
      address,
      amountValue,
      pin,
      {
        createAnotherMint: this.createAnother.current.checked
      }
    );
    return { promise, message: `${hathorLib.helpers.prettyValue(amountValue)} ${this.props.token.symbol} minted!` };
  }
github HathorNetwork / hathor-wallet / src / utils / tokens.js View on Github external
addToken(uid, name, symbol) {
    const tokens = hathorLib.tokens.addToken(uid, name, symbol);
    store.dispatch(newTokens({tokens, uid: uid}));
  },
github HathorNetwork / hathor-wallet / src / screens / CreateToken.js View on Github external
<p>Your token has been successfully created!</p>
          <p>You can share the following configuration string with other people to let them use your brand new token.</p>
          <p>Remember to <strong>make a backup</strong> of this configuration string.</p>
          <p><strong>{this.state.configurationString}</strong></p>
        
      )
    }

    return (
      <div>
        
        <h3>Create Token</h3>
        <p>Here you will create a new customized token. After the creation, you will be able to send this new token to other addresses.</p>
        <p>Custom tokens share the address space with all other tokens, including HTR. This means that you can send and receive tokens using any valid address.</p>
        <p>Remember to make a backup of your new token's configuration string. You will need to send it to other people to allow them to use your new token.</p>
        <p>When creating and minting tokens, a <strong>deposit of {hathorLib.tokens.getDepositPercentage() * 100}%</strong> in HTR is required. If these tokens are later melted, this HTR deposit will be returned. Read more about it <a href="https://gitlab.com/HathorNetwork/rfcs/blob/master/text/0011-token-deposit.md" rel="noopener noreferrer">here</a>.</p>
        <hr>
        <form id="formCreateToken">
          <div>
            <div>
              <label>Short name</label>
              <input type="text" placeholder="MyCoin" required="">
            </div>
            <div>
              <label>Symbol</label>
              <input pattern="\w{1,5}" type="text" placeholder="MYC (max 5 characters)" required="">
            </div>
          </div>
          <div>
            <div>
              <label>Amount</label>
              </div></div></form></div>
github HathorNetwork / hathor-wallet / src / components / tokens / TokenDelegate.js View on Github external
executeDelegate = (pin) => {
    const output = this.props.authorityOutputs[0];
    const type = this.props.action === 'delegate-mint' ? 'Mint' : 'Melt';
    const promise = hathorLib.tokens.delegateAuthority(output.tx_id, output.index, output.decoded.address, this.props.token.uid, this.delegateAddress.current.value, this.delegateCreateAnother.current.checked, type.toLowerCase(), pin);
    return { promise, message: `${type} output delegated!`};
  }
github HathorNetwork / hathor-wallet / src / components / ModalUnregisteredTokenInfo.js View on Github external
register = (e) => {
    if (!this.state.token) return;

    e.preventDefault();

    const isValid = this.form.current.checkValidity();
    this.setState({ formValidated: true, errorMessage: '' });
    if (isValid) {
      const configurationString = hathorLib.tokens.getConfigurationString(this.state.token.uid, this.state.token.name, this.state.token.symbol);

      const promise = hathorLib.tokens.validateTokenToAddByConfigurationString(configurationString, null);
      promise.then((tokenData) => {
        tokens.addToken(tokenData.uid, tokenData.name, tokenData.symbol);
        $('#unregisteredTokenInfoModal').modal('hide');
        this.props.tokenRegistered(this.state.token);
      }, (e) => {
        this.setState({ errorMessage: e.message });
      });
    }
  }