Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit aa2bc86

Browse files
authored
Merge pull request #191 from Bitcoin-com/docs/badger-react-0.2
badger-react doc update for 0.2.0
2 parents 4019c82 + 87df150 commit aa2bc86

4 files changed

Lines changed: 92 additions & 29 deletions

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
Bitcoin.com’s developer plaform is based on the popular BITBOX javascript framework. Offering utility methods for Mnemonics, HDNodes, ECPairs, Crypto, Address conversion, Transactions and much more.
88

9+
### Badger
10+
11+
Integrate Bitcoin Cash (BCH) into your next app with ease. Helpers, tools, and SDK's to help connect your website to the Badger wallet.
12+
913
### REST
1014

1115
The BCH JSON RPC over HTTP including a fully documented and interactive GUI which developers can use to test their ideas and confirm their code is making proper API calls.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"name": "developer.bitcoin.com",
33
"description": "Bitcoin.com developer resources and documentation",
4-
"version": "3.4.0",
4+
"version": "3.4.1",
55
"author": "Peter <peter@bitcoin.com> and Gabriel Cardona <gabriel@bitcoin.com>",
66
"dependencies": {
7-
"badger-components-react": "^0.1.3",
7+
"badger-components-react": "^0.2.0",
88
"gatsby": "^2.0.118",
99
"gatsby-image": "^2.0.29",
1010
"gatsby-plugin-flow": "^1.0.2",

src/data/docs/badger/badger-components-react.md

Lines changed: 57 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ A set of React components and helpers to integrate Bitcoin Cash (BCH) and the Ba
1313

1414
### Install Components
1515

16-
Start by installing the `badger-components-react` library and it's 3 peer depenencies, `react`, `react-dom` and `styled-components`
16+
Start by installing the `badger-components-react` library and it's 3 peer dependencies, `react`, `react-dom` and `styled-components`
1717

1818
```bash
1919
Install library
@@ -27,20 +27,35 @@ $ npm install --save styled-components react react-dom
2727

2828
The library comes with some ready-to-use Badger components, `BadgerBadge` and `BadgerButton`, with more coming soon. These components are can be added quickly to any React projects. If you require a different solution then continue reading to learn how to create custom Badger integrations using `BadgerBase`.
2929

30-
#### Badger Button
30+
#### Base props
3131

32-
Simple Badger Button to display the price in local currency, satoshi amount, and have an optional message. Supports the following props
32+
These props are required or supported by all components which build upon `BadgerBase`.
3333

3434
- `to: BCH Address` - Required - Bitcoin Cash address to send BCH to
35-
- `price: number` - Required - Price in chosen currency, will be turned into satoshis
35+
- `price: number` - Optional - Price in chosen fiat currency, will be turned into the satoshis equivalent
36+
- `amount: number` - Optional - Price in chosen ticker, currently only BCH
37+
<spacer></spacer>
3638
- `currency: string` - Default `USD` - [ISO Country Code](https://en.wikipedia.org/wiki/ISO_4217) to charge in
37-
- `showSatoshis: boolean` Default `true` - Show the value in BCH Satoshis below the button
38-
- `border: boolean` - Default `true` - Border around button and text
39-
- `opReturn: string[]` - Optional - OP_RETURN message
40-
- `text: string` - Optional - Text between the button and border
39+
- `ticker: string` - Default `BCH` - Ticker to send, currently only BCH
40+
<spacer></spacer>
41+
- `opReturn: string[]` - Optional - OP_RETURN message when paid with Badger
42+
- `isRepeatable` - Optional - Payment can be done multiple times in a single visit
43+
- `repeatTimeout` - Optional - How many milliseconds until button reverts to a fresh state
44+
- `watchAddress` - Optional - Go to confirmed if address receives any payment, best if used with unique payment codes
45+
<spacer></spacer>
4146
- `successFn: Function` - Optional -Callback function when payment is successful
4247
- `failFn: Function` - Optional - Callback function when payment fails or is cancelled
4348

49+
#### Badger Button
50+
51+
Simple Badger Button to display the price in local currency, satoshi amount, and have an optional message. Supports the following props
52+
53+
- All props from Base Props
54+
- `showSatoshis: boolean` Default `true` - Show the value in BCH Satoshis below the button
55+
- `showBorder: boolean` - Default `false` - Border around button and text
56+
- `showQR: boolean` - Default `false` - Show a QR code attached to the button
57+
- `text: string` - Optional - Text between the button and border
58+
4459
<spacer></spacer>
4560
<badger-button to="bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g" price="0.001" currency="CAD" text="Badger Button"></badger-button>
4661

@@ -49,21 +64,31 @@ Simple Badger Button to display the price in local currency, satoshi amount, and
4964
A slightly larger display of payment details.
5065
Supports the following props.
5166

52-
- `to: BCH Address` - Required - Bitcoin Cash address to send BCH to
53-
- `price: number` - Required - Price in chosen currency, will be turned into satoshis
54-
- `currency: string` - Default `USD` - [ISO Country Code](https://en.wikipedia.org/wiki/ISO_4217) to charge in
67+
- All from Base Props
5568
- `showSatoshis: boolean` Default `true` - Show the value in BCH Satoshis below the button
5669
- `showBrand: boolean` Default `true` - Show the branding text
57-
- `border: boolean` - Default `true` - Border around button and text
70+
- `showBorder: boolean` - Default `true` - Border around button and text
71+
- `showQR: boolean` - Default `true` - Show a QR code attached to the button
5872
- `text: string` - Default `Payment Total` - Text between the button and border
5973
- `tag: string` - Default `Badger Pay` - Text on the button
60-
- `opReturn: string[]` - Optional - OP_RETURN message
61-
- `successFn: Function` - Optional - Callback function when payment is successful
62-
- `failFn: Function` - Optional - Callback function when payment fails or is cancelled
6374

6475
<spacer></spacer>
6576
<badger-badge to="bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g" price="0.001" currency="USD" text="Badger Badger"></badger-button>
6677

78+
#### Price in fiat or BCH
79+
80+
Provide `price` for fiat, and `amount` for BCH
81+
82+
```jsx
83+
// Price in fiat, currency defaults to USD
84+
<BadgerBadge to="bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g" currency="CAD" price={0.01} />
85+
86+
// Price in BCH, ticker defaults to BCH
87+
<BadgerBadge to="bitcoincash:pp8skudq3x5hzw8ew7vzsw8tn4k8wxsqsv0lt0mf3g" ticker="BCH" amount={0.001} />
88+
```
89+
90+
#### Price in BCH
91+
6792
#### Code Examples
6893

6994
```js
@@ -119,19 +144,28 @@ The library contains a Higher Order Component (HOC) `BadgerBase` which contains
119144
Components wrapped in `BadgerBase` support the following props
120145

121146
- `to: BCH Address` - Required - Bitcoin Cash address to send BCH to
122-
- `price: number` - Required - Price in chosen currency, will be turned into satoshis
147+
- `price: number` - Optional - Price in chosen fiat currency, will be turned into the satoshis equivalent
148+
- `amount: number` - Optional - Price in chosen ticker, currently only BCH
149+
<spacer></spacer>
123150
- `currency: string` - Default `USD` - [ISO Country Code](https://en.wikipedia.org/wiki/ISO_4217) to charge in
124-
- `opReturn: string[]` - Optional - OP_RETURN message to send with transaction
151+
- `ticker: string` - Default `BCH` - Ticker to send, currently only BCH
152+
<spacer></spacer>
153+
- `opReturn: string[]` - Optional - OP_RETURN message when paid with Badger
154+
- `isRepeatable` - Optional - Payment can be done multiple times in a single visit
155+
- `repeatTimeout` - Optional - How many milliseconds until button reverts to a fresh state
156+
- `watchAddress` - Optional - Go to confirmed if address receives any payment, best if used with unique payment codes
157+
<spacer></spacer>
158+
- `successFn: Function` - Optional -Callback function when payment is successful
159+
- `failFn: Function` - Optional - Callback function when payment fails or is cancelled
125160

126-
And get the following props added to them for use in custom integration component
161+
And get the following props added to them for use in the custom integration component
127162

128163
- `handleClick: Function` - Call this to start the Badger transaction
129164
- `step: string` - State of the Badger transaction. One of `fresh`, `pending`, `complete`, `login`, `install`
130-
- `satoshiDisplay: string` - Transaction value in satoshis, converted from the price and currency every minute
131165

132166
```js
133167
import React from 'react'
134-
import { BadgerBase } from 'badger-react-components'
168+
import { BadgerBase, formatSatoshis } from 'badger-react-components'
135169

136170
import styled from 'styled-components'
137171

@@ -144,12 +178,12 @@ const CoolButton = styled.button`
144178
const MyButton extends React.Component {
145179
render() {
146180
// Props from higher order component
147-
const {handleClick, to, price, currency, satoshiDisplay, step} = this.props;
181+
const {handleClick, to, price, currency, satoshis, step} = this.props;
148182
return (
149183
<div>
150184
<h3>Donate {price}{currency} to {to}</h3>
151-
<h4>Satoshis: {satoshiDisplay}</h4>
152-
<CoolButton onClick={handleClick}>Custom looking button with render</CoolButton>
185+
<h4>Satoshis: {formatSatoshis(satoshiDisplay)}</h4>
186+
<CoolButton onClick={handleClick}>Custom button render</CoolButton>
153187
</div>
154188
)
155189
}

yarn.lock

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1616,10 +1616,13 @@ backo2@1.0.2:
16161616
resolved "https://registry.yarnpkg.com/backo2/-/backo2-1.0.2.tgz#31ab1ac8b129363463e35b3ebb69f4dfcfba7947"
16171617
integrity sha1-MasayLEpNjRj41s+u2n038+6eUc=
16181618

1619-
badger-components-react@^0.1.3:
1620-
version "0.1.3"
1621-
resolved "https://registry.yarnpkg.com/badger-components-react/-/badger-components-react-0.1.3.tgz#98aaf9567c1d1e3446bd7623e27d3a7c095b3fae"
1622-
integrity sha512-wZw403Tc2Gw4XT2w3lVGJg+H2rd4hlbXDz+Ee1RXU0JRK6CdcRX2UCshhB3DTRtdr0w2Bdy8GSsN0bsq4VWTrQ==
1619+
badger-components-react@^0.2.0:
1620+
version "0.2.0"
1621+
resolved "https://registry.yarnpkg.com/badger-components-react/-/badger-components-react-0.2.0.tgz#164b37b90b8bd770a46079a7194d711407cffedd"
1622+
integrity sha512-XoW7Pz1VGvXiAxRbUNdrCZfdTHr+9GLY9usFnB+Rtp5A6A/qnIbA6y5P8AdLlUaXw16NO2sr8vtcdzL5Hzj9xA==
1623+
dependencies:
1624+
lodash "^4.17.11"
1625+
qrcode.react "^0.9.2"
16231626

16241627
bail@^1.0.0:
16251628
version "1.0.3"
@@ -9366,6 +9369,15 @@ prop-types@^15.5.4, prop-types@^15.6.1, prop-types@^15.6.2:
93669369
object-assign "^4.1.1"
93679370
react-is "^16.8.1"
93689371

9372+
prop-types@^15.6.0:
9373+
version "15.7.2"
9374+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
9375+
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
9376+
dependencies:
9377+
loose-envify "^1.4.0"
9378+
object-assign "^4.1.1"
9379+
react-is "^16.8.1"
9380+
93699381
property-information@^4.0.0:
93709382
version "4.2.0"
93719383
resolved "https://registry.yarnpkg.com/property-information/-/property-information-4.2.0.tgz#f0e66e07cbd6fed31d96844d958d153ad3eb486e"
@@ -9473,6 +9485,19 @@ q@^1.1.2:
94739485
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7"
94749486
integrity sha1-fjL3W0E4EpHQRhHxvxQQmsAGUdc=
94759487

9488+
qr.js@0.0.0:
9489+
version "0.0.0"
9490+
resolved "https://registry.yarnpkg.com/qr.js/-/qr.js-0.0.0.tgz#cace86386f59a0db8050fa90d9b6b0e88a1e364f"
9491+
integrity sha1-ys6GOG9ZoNuAUPqQ2baw6IoeNk8=
9492+
9493+
qrcode.react@^0.9.2:
9494+
version "0.9.3"
9495+
resolved "https://registry.yarnpkg.com/qrcode.react/-/qrcode.react-0.9.3.tgz#91de1287912bdc5ccfb3b091737b828d6ced60c5"
9496+
integrity sha512-gGd30Ez7cmrKxyN2M3nueaNLk/f9J7NDRgaD5fVgxGpPLsYGWMn9UQ+XnDpv95cfszTQTdaf4QGLNMf3xU0hmw==
9497+
dependencies:
9498+
prop-types "^15.6.0"
9499+
qr.js "0.0.0"
9500+
94769501
qs@6.5.2, qs@~6.5.2:
94779502
version "6.5.2"
94789503
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"

0 commit comments

Comments
 (0)