npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@digix/react-trezor-container

v1.1.9

Published

React Component that implements [Trezor Connect](https://github.com/trezor/connect)

Downloads

5

Readme

React Trezor Container

React Component that implements Trezor Connect

Features

  • Public Address retrieval
    • Returns an HD wallet that allows you to retrieve public addresses based ond the provided path
  • Transactions
    • signTransaction
    • sigMessage
    • getAddress
  • getAddresses option for pulling addresses based on the specified path (defaults to first account if not provided)
  • expect option for validating address
  • onReady event handler for triggering actions

Example

  • Getting addresses
  import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Table, Message } from 'semantic-ui-react';

import TrezorContainer from '@digix/react-trezor-container';

import TrezorAddressList from './trezor_keystore_address_list';
import TrezorKeystoreAddressItem from './trezor_keystore_address_item';

export default class TrezorKeystoreCreationForm extends Component {
  constructor(props) {
    super(props);
    this.renderItem = this.renderItem.bind(this);
    this.handleItemChange = this.handleItemChange.bind(this);
    this.renderContainer = this.renderContainer.bind(this);
  }
  handleItemChange(e) {
    const { name, value } = e;
    const { enabled } = value;
    const addresses = (this.props.formData || {}).addresses || {};
    if (!enabled && addresses) {
      delete addresses[name];
      this.props.formChange({ name: 'addresses', value: { ...addresses } });
    } else {
      const update = {
        networks: (addresses[name] || {}).networks || this.props.formData.networks,
        tokens: (addresses[name] || {}).tokens || this.props.formData.tokens,
        ...value,
      };
      this.props.formChange({ name: 'addresses', value: { ...addresses, [name]: { ...addresses[name], ...update } } });
    }
  }

  renderContainer({ renderItems }) {
    const count = Object.values(this.props.formData.addresses || {}).filter(a => a.enabled).length;
    return (
      <Table>
        <Table.Header>
          <Table.Row>
            <Table.HeaderCell>Select addresses to enable</Table.HeaderCell>
            <Table.HeaderCell textAlign="right" colSpan={100}>
              {count} enabled
            </Table.HeaderCell>
          </Table.Row>
        </Table.Header>
        <Table.Body>{renderItems()}</Table.Body>
      </Table>
    );
  }
  renderError({ error }) {
    return <Message icon="warning sign" negative header="Trezor Error" content={`${error}`} />;
  }
  renderItem(item) {
    if (!item.address) {
      return (
        <Table.Row disabled key={item.kdPath}>
          <Table.Cell colSpan={100}>Getting Address Info...</Table.Cell>
        </Table.Row>
      );
    }
    const data = ((this.props.formData || {}).addresses || {})[item.kdPath] || {};
    return <TrezorKeystoreAddressItem key={item.kdPath} {...item} data={data} onChange={this.handleItemChange} />;
  }
  render() {
    const { renderContainer, renderItem } = this;
    // return <TrezorAddressList {...this.props} {...{ renderContainer, renderItem }} />;
    return (
      <TrezorContainer
        renderError={this.renderError}
        renderLoading={() => (
          <Message
            icon="info circle"
            info
            header="Connecting to Trezor"
            content="Please follow instructions on the Trezor Popup window to continue."
          />
        )}
        getAddresses={props => <TrezorAddressList {...props} {...{ renderContainer, renderItem }} />}
      />
    );
  }
}

TrezorKeystoreCreationForm.propTypes = {
  formData: PropTypes.object.isRequired,
  formChange: PropTypes.func.isRequired,
};
  • Signing Transaction
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Message } from 'semantic-ui-react';
import TrezorContainer from '@digix/react-trezor-container';

export default class TrezorKeystoreTransactionSigner extends Component {
  constructor(props) {
    super(props);
    this.handleSign = this.handleSign.bind(this);
    this.state = { signed: false };
  }
  handleSign({ signTransaction }) {
    const { txData, address, hideTxSigningModal } = this.props;
    const { kdPath } = address;
    signTransaction(kdPath, txData, hideTxSigningModal)
      .then((signedTx) => {
        this.setState({ signed: true });
        hideTxSigningModal({ signedTx });
      })
      .catch(error => this.setState({ error }));
  }
  renderError() {
    const { error } = this.state;
    return <Message icon="warning sign" negative header={'Trezor Transaction'} content={error} />;
  }
  render() {
    const { kdPath, address } = this.props.address;
    const { error } = this.state;
    if (error) {
      return this.renderError();
    }
    const { signed } = this.state;
    return (
      <TrezorContainer
        expect={{ kdPath, address }}
        onReady={this.handleSign}
        signed={signed}
        renderReady={() => (
          <Message
            icon="check"
            positive
            header={'Ready to Sign Transaction'}
            content="Trezor Popup window is loading. Please follow instructions from the popup and your Trezor Wallet to continue."
          />
        )}
      />
    );
  }
}

TrezorKeystoreTransactionSigner.propTypes = {
  hideTxSigningModal: PropTypes.func.isRequired,
  address: PropTypes.object.isRequired,
  txData: PropTypes.object.isRequired,
};

TODO

  • Bitcoin support