Giter VIP home page Giter VIP logo

badger-components-react's Introduction

Build on Bitcoin Cash (BCH)

A set of React components and helpers to integrate Bitcoin Cash (BCH) and SLP tokens into your app with ease. Integrates with the Badger wallet.

Get Started

Install Component

$ npm install --save badger-components-react

Install Peer Dependencies

This library depends on the following three peer dependencies

  • styled-components ^4.0.0
  • react ^16.3.0
  • react-dom ^16.3.0
$ npm install --save styled-components react react-dom

Add to React Project

import React from 'react'
import { BadgerButton, BadgerBadge } from 'badger-components-react'

const Example = (props) => {

  // eatBCH bitcoin cash address
  const toAddress = 'bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g'

  // Random SLP address
  const toSLPAddress = 'simpleledger:qq6qcjt6xlkeqzdwkhdvfyl2q2d2wafkgg8phzcqez'

  // tokenId
  const nakamotoID = 'df808a41672a0a0ae6475b44f272a107bc9961b90f29dc918d71301f24fe92fb'

  return (
    <>
      {/* Minimal Examples */}
      <BadgerBadge to={toAddress} price={0.5} currency='USD' />
      <BadgerButton to={toAddress} price={1} currency='JPY' />

      {/* Price in bch */}
      <BadgerBadge to={toAddress} amount={0.01} coinType='BCH' />
      <BadgerButton to={toAddress} amount={0.0001} coinType='BCH' />

      {/* Price in SLP tokens - NAKAMOTO in this example */}
      <BadgerBadge to={toSLPAddress} amount={5.01} coinType='SLP' tokenId={nakamotoID} />
      <BadgerButton to={toSLPAddress} amount={2.0001} coinType='SLP' tokenId={nakamotoID} />

      {/* More Complex Examples, pricing in fiat */}
      <BadgerBadge
        price={0.001} // Price in currency
        currency='CAD' // Currency to convert from
        to='bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g' // Payment address
        opReturn={["0x6d02", "Hello badger-components-react"]}
        tag='Badger Pay' // Text on button
        text='Payment Total' // Text at top of badge

        showBrand// Show link to badger website
        showAmount // Show BCH satoshi amount
        showQR // Intent to show QR if transaction is URI encodeable

        successFn={() => console.log('Payment success callback')}
        failFn={() => console.warn('Payment failed or cancelled callback')}
      />

      <BadgerButton
        price={0.003}
        currency='USD'
        to='bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g'
        opReturn={["0x6d02", "Hello badger-components-react"]}
        text='Badger Pay'
        showAmount
        showBorder
        showQR
        successFn={() => console.log('success example function called')}
        failFn={() => console.log('fail example function called')}
      />

      {/* Pricing in BCH */}
      <BadgerBadge
        amount={0.001} // Amount in crypto
        coinType='BCH' // Defaults to BCH
        to='bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g' // Payment address

        isRepeatable // Reset to fresh state after a few seconds
        repeatTimeout={4000} // time in ms to reset button after payment
        watchAddress // Watch all payments to address
      />
    </>
  )
};

export default Example

Create a Custom Badger Button / Integration

import React from 'react'
import { BadgerBase, formatAmount } from 'badger-react-components'

import styled from 'styled-components'

const CoolButton = styled.button`
  background-color: rebeccapurple;
  color: lime;
  border-radius: 24px;
`

const MyButton extends React.Component {
  render() {
    // Props from higher order component
    const {
      handleClick,
      to,
      step,

      price,
      currency,

      coinType,
      coinDecimals,
      coinSymbol,
      amount,

      showQR,

      isRepeatable,
      repeatTimeout,
      watchAddress,
      } = this.props;

    return (
      <div>
        <h3>Donate {price}{currency} to {to}</h3>
        <h4>Satoshis: {formatAmount(amount, coinDecimals)}</h4>
        <CoolButton onClick={handleClick}>Custom looking button with render</CoolButton>
      </div>
    )
  }
}

// Wrap with BadgerBase higher order component
export default BadgerBase(MyButton);

Control Step from app

When accepting payments, the state of the payment should be handled by the backend of your application. As such, you can pass in stepControlled with the values of fresh, pending or complete to indicate which part of the payment the user is on.

Development with Storybook

To develop additions to this project, run the local storybook development server with

Setup

 $ npm install -g flow-bin
 $ npm i
 $ npm run storybook

Navigate to http://localhost:9001 to view your stories. They automatically update as you develop โœจ.

Storybook will pick up stories from the stories.js file in each components folder.

To build a static version of storybook for deployment

 $ npm run build-storybook
 Deploy contents of  `/storybook-static`

badger-components-react's People

Contributors

iiamboss avatar nickfujita avatar spicypete avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

badger-components-react's Issues

External Control

For complex applications which accept payments, the state of the payment should be validated and provided from the backend.

This issue is to add a property such as buttonState which will override the internal button step state.

Testing coverage

As these components API is gaining stability, it's time ensure the important code is tested correctly, especially for when additional people contribute to the projects.

Aiming for 75%+ testing coverage.

Documentation Update

Documentation

Add documentation to developer.bitcoin.com on how to use, customize and create your own Badger integrations using our supplied components, as well as our Higher Order Components.

Usage

  • Install
  • Use a Badger Button - Embed example
  • Use a BadgerBadge - Embed example
  • Options
    • List props with descriptions - link to storybook page to try them out
  • Limitations
    • Outline what they do, and what they can't do (Should use a server side to verify payments), these buttons assist, but are visual when it comes to security.
  • Showcase
    • Examples of pages using parts of the library

Send SLP tokens

Enable the react component to send SLP tokens using Badger.
Improve the UI to indicate the sending amount is in SLP tokens.

Along with this change should also enable sending an absolute amount of satoshis instead of converting from real world equivalents

SLP - Display enhancements

When building SLP token payments, it needs to be very clear which token one is sending.

  • Show Symbol
  • Show name
  • Show correct decimal formatting.

0.2.0 Documentation update

Update documentation on developer.bitcoin.com for 0.2.0

Topics to update

  • Repeatable payments
  • Absolute BCH amounts
  • SLP if it makes it in this release
  • QR Codes and URI
    • Watch all for payments
    • controlled step from app.

Send BCH absolute amounts

Issue

Currently can only send amounts of BCH converted from their fiat currency equivalents.

Solution

Allow users to use props ticker/amount in addition of currency/price.
When ticker is used, create payments of an absolute amount.
When currency is used, create payments of BCH converted from price

Remove styled-components dependency

As amazing as styled-components are, not everyone uses it.
As such, having it as a requirement to use these components is adding un-needed package size bloat.

Since the core of these components is the BadgerBase higher-order-component, we should keep the size as minimal as possible.
If we want to build complex components using styled-components we may create a separate package for those in the future.

Images broken on Safari

Summary

  • Images not rendering properly on Safari.
  • Makes it unusable on iOS devices, and some versions of desktop Safari

Error surfacing

These components need advanced error surfacing so users understand why the Badges are not working as they expect.
The component requires certain combinations of properties to work as intended, so when they are setup in an incompatible way, there should be a clear message with steps to correct them.

Repeatable Payments

Problem

Some use-cases, require the same button to be re-useable multiple times in a single visit.

Solution

  • Add an optional prop to revert the state of the button to fresh after a payment is made
  • Update documentation
  • Update stories

Custom Color support

Custom Color Support

  • Ability to either pass in N colors to use within the Button.
  • To decide: Theme the button and BCH logo as well?
  • Pass in colors OR a theme object compatible with styled-components

Colors to consider

  • Background
  • Foreground
  • Brand - 500 and 700
    • Button fresh
    • Border
  • Pending - 500 and 700
    • Button pending
  • Success - 500 and 700
  • Button success

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.