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

@rossconsulting/hedera-react-micropayment-plugin

v0.2.0

Published

@rossconsulting/hedera-react-micropayment-plugin React component

Downloads

2

Readme

Hedera React Micropayments Widget

A React component to facilitate Hedera micropayments via the Hedera Chrome extension.

What is Hedera Hashgraph?

Hedera is a decentralized public network that utiltizes the Hashgraph consensus algorithm to overcome the traditional limitations of blockchain and allow one to create next era of fast, fair, and secure applications.

Including the widget in your project

npm install @rossconsulting/hedera-react-micropayment-plugin

And import the component, and its optional provided styling, as follows:

import HederaMicropayment from '@rossconsulting/hedera-react-micropayment-plugin'
import '@rossconsulting/hedera-react-micropayment-plugin/css/index.css'

Usage

The widget injects a payWithHedera function as a prop to the component that it wraps.

payWithHedera is called with the payment details, a success callback and a failure callback.

Do note that the payment is handled in a new page (default pathname [origin]/hedera-process-payment) which self closes once done.

Configuring the widget

The widget must wrap your main component as it will handle the rendering for the popup page. The widget requires only the maximumAmount prop to ask for expense approval from the user. An optional popupPath can be supplied - this is used by the popup page to process payment. The popupPath route must be controlled by the widget only.

HederaMicropayment can only have one child.

<HederaMicropayment maximumAmount="100000" popupPath="/hedera-process-payment">
  <App/>
</HederaMicropayment>

Once this is done, you will have 2 methods available as props in your application:

  • payWithHedera
  • askForApproval (available but implementation not complete)

payWithHedera (amount, recipient, memo, productId, successCallback, failureCallback)

  • amount: Amount to be paid in tinybars
  • recipient: Hedera account number of the recipient. (0.0.xxxx)
  • memo: Memo to be included in the transaction
  • productId: ID for product/service bought
  • successCallback: Callback for success scenario.
  • failureCallback: Callback for failure scenario. A reasonCode (string) is passed as parameter to this function.

Example call:

this.props.payWithHedera(amount, "0.0.1742", "Hello Future!", "future007",
  () => {
    console.log('success callback!');
    this.setState({
      ...
    });
  },
  (reasonCode) => {
    console.log('failure callback!', reason);
    this.setState({
      ...
    });
  });

Failure Reason Code:

  • BLOCKED_POPUP: Popup was blocked by the browser.
  • CANNOT_CONFIRM_PAYMENT: User canceled/closed popup unexpectedly.
  • NO_ACCOUNT: User is not currently logged in the Chrome widget.
  • INSUFFICIENT_AMOUNT: Either insufficient amount in the user's wallet or the user didn't approve that payment amount.

askForApproval(maxAmount)

Not implemented yet - Use to ask the user for a new maximum amount threshold.

detectPlugin()

A function is also available in HederaMicropayment to check for the Hedera Chrome Brower Extension. It returns a Promise.

import {detectPlugin} from 'HederaMicropayment';

detectPlugin().then(r => {
  this.setState({hasPlugin: true});
}).catch(e => {
  this.setState({hasPlugin: false});
});

Contributing to this Project

We welcome participation from all developers!

For instructions on how to contribute to this repo, please review the Contributing Guide.

License Information

Licensed under Apache License,Version 2.0 – see LICENSE in this repo or apache.org/licenses/LICENSE-2.0.

Installation of tooling

  1. Install phantomjs yourself via your OS package manager, since it fails via NPM dependency
  2. Install nwb with sudo npm i -g --unsafe-perm nwb
  3. Now you can run the npm commands in package.json (e.g. npm run build)

TODOs

  1. How to bundle images (hbar-icon-white.png) with this module?