-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from goldcaddy77/feat/qrcode-component
feat(qr-code): adds QR code component
- Loading branch information
Showing
10 changed files
with
148 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { storiesOf } from '@storybook/react'; | ||
import * as React from 'react'; | ||
|
||
import { ReblocksQRCode } from './ReblocksQRCode'; | ||
|
||
import { ACCOUNT_ID } from '../../lib/'; | ||
|
||
storiesOf('ReblocksQRCode', module) | ||
.add('Default', () => { | ||
return <ReblocksQRCode accountId={ACCOUNT_ID} />; | ||
}) | ||
.add('Default with Address', () => { | ||
return <ReblocksQRCode accountId={ACCOUNT_ID} showUrl={true} />; | ||
}) | ||
.add('With Amount', () => { | ||
return <ReblocksQRCode accountId={ACCOUNT_ID} amount={1000} showUrl={true} />; | ||
}) | ||
.add('With Amount and Label', () => { | ||
return ( | ||
<ReblocksQRCode accountId={ACCOUNT_ID} amount={1000} label="For a good time" showUrl={true} /> | ||
); | ||
}) | ||
.add('Amount, Label and Message', () => { | ||
return ( | ||
<ReblocksQRCode | ||
accountId={ACCOUNT_ID} | ||
amount={1000} | ||
label="For a good time" | ||
message="I'm a message" | ||
showUrl={true} | ||
/> | ||
); | ||
}) | ||
.add('RaiBlocks Purple', () => { | ||
return <ReblocksQRCode accountId={ACCOUNT_ID} fgColor="#8c43d5" />; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as QRCode from 'qrcode.react'; | ||
import * as queryString from 'query-string'; | ||
import * as React from 'react'; | ||
|
||
export interface OptionalProps { | ||
amount?: number; | ||
bgColor?: string; | ||
fgColor?: string; | ||
label?: string; | ||
message?: string; | ||
size?: number; | ||
showUrl?: boolean; | ||
} | ||
|
||
export interface Props extends OptionalProps { | ||
accountId: string; | ||
} | ||
|
||
const ReblocksQRCode: React.StatelessComponent<Props> = (props): JSX.Element => { | ||
const { accountId, amount, label, message, showUrl, ...otherProps } = props; | ||
let address = `xrb:${accountId}`; | ||
|
||
const params: OptionalProps = {}; | ||
if (amount) { | ||
params.amount = amount; | ||
} | ||
if (label) { | ||
params.label = label; | ||
} | ||
if (message) { | ||
params.message = message; | ||
} | ||
|
||
const qs = queryString.stringify(params); | ||
address = qs ? `${address}?${qs}` : address; | ||
|
||
const qrComponent = <QRCode value={`${address}${qs}`} {...otherProps} />; | ||
|
||
if (showUrl) { | ||
return ( | ||
<div> | ||
{qrComponent} | ||
<div>{address}</div> | ||
</div> | ||
); | ||
} | ||
|
||
return qrComponent; | ||
}; | ||
|
||
ReblocksQRCode.defaultProps = { | ||
bgColor: '#FFFFFF', | ||
fgColor: '#000000', | ||
showUrl: false, | ||
size: 128 | ||
}; | ||
|
||
export { ReblocksQRCode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { PaymentResponse, ReblocksPayment } from './components/ReblocksPayment/ReblocksPayment'; | ||
export { ReblocksFiatConversion } from './components/ReblocksFiatConversion/ReblocksFiatConversion'; | ||
export { ReblocksQRCode } from './components/ReblocksQRCode/ReblocksQRCode'; | ||
|
||
export * from './lib'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -334,6 +334,16 @@ | |
version "15.5.2" | ||
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.5.2.tgz#3c6b8dceb2906cc87fe4358e809f9d20c8d59be1" | ||
|
||
"@types/qrcode.react@^0.6.2": | ||
version "0.6.2" | ||
resolved "https://registry.yarnpkg.com/@types/qrcode.react/-/qrcode.react-0.6.2.tgz#c3c09a1f01c8f1378b2dc9cde27a15cc1529cf19" | ||
dependencies: | ||
"@types/react" "*" | ||
|
||
"@types/query-string@^5.0.1": | ||
version "5.0.1" | ||
resolved "https://registry.yarnpkg.com/@types/query-string/-/query-string-5.0.1.tgz#6cb41c724cb1644d56c2d1dae7c7b204e706b39e" | ||
|
||
"@types/react-select@^1.1.0": | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/@types/react-select/-/react-select-1.1.0.tgz#b3ddf7a58f033f69d3c47c825587a54fec1629c6" | ||
|
@@ -7303,6 +7313,17 @@ q@^1.1.2, q@^1.4.1: | |
version "1.5.1" | ||
resolved "https://registry.yarnpkg.com/q/-/q-1.5.1.tgz#7e32f75b41381291d04611f1bf14109ac00651d7" | ||
|
||
[email protected]: | ||
version "0.0.0" | ||
resolved "https://registry.yarnpkg.com/qr.js/-/qr.js-0.0.0.tgz#cace86386f59a0db8050fa90d9b6b0e88a1e364f" | ||
|
||
qrcode.react@^0.7.2: | ||
version "0.7.2" | ||
resolved "https://registry.yarnpkg.com/qrcode.react/-/qrcode.react-0.7.2.tgz#72a5718fd56baafe15c2c153fe436628d83aa286" | ||
dependencies: | ||
prop-types "^15.5.8" | ||
qr.js "0.0.0" | ||
|
||
[email protected], qs@^6.5.1, qs@~6.5.1: | ||
version "6.5.1" | ||
resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" | ||
|