JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q45673F
  • License MIT

nOS API bindings and types

Package Exports

  • @nosplatform/api-functions

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@nosplatform/api-functions) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@nosplatform/api-functions

nOS API bindings and types


installation

npm i --save @nosplatform/api-functions
yarn add @nosplatform/api-functions

Usage in react

Wrap your component with the higher-order components to provide fallbacks when running outside the context of the nOS client. Specify propTypes provided by this package.

import React from 'react';
import { compose } from 'recompose';
import { injectNOS, injectAssets, nosProps, assetProps } from "@nosplatform/api-functions/lib/react";

class ShowBalance extends React.Component {
  static propTypes = {
    nos: nosProps.isRequired,
    assets: assetProps.isRequired
  }

  render() {
    return (
      <button type="button" onClick={this.handleClick}>
        Show NEO Balance
      </button>
    );
  }

  async handleClick = () => {
    const { nos, assets } = this.props;
    const balance = await nos.getBalance({ asset: assets.NEO });
    console.log('NEO Balance:', balance);
  }
};

export default compose(
  injectNOS,
  injectAssets
)(ShowBalance);

In addition to automatically providing the NOS API function as a prop to your React component, the api-functions package also provides the opportunity to specify a fallback implementation. This is especially useful for building in the context of another browser if not wanting to use the nOS client for any reason.

const balance = await nos.getBalance({ asset: assets.NEO }, () => '23');
console.log('NEO Balance:', balance);  // NEO Balance: 23