0.1.0 • Published 6 years ago

phantom-qrcode v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

npm.io

PHANTOM QR Code

A web component to generate QR codes for PHANTOM payments.

Built With Stencil

Install

Script tag

  • @todo put dist version on cdn server

Node Modules

  • Run npm install phantom-qrcode --save
  • Put this script tag <script src='node_modules/phantom-qrcode/dist/phantomqrcode.js'></script> in the head of your index.html

In a stencil-starter app

  • Run npm install phantom-qrcode --save
  • Add { name: 'phantom-qrcode' } to your collections.

Usage

Insert the element in your code and enter your custom properties:

<phantom-qrcode address="DE6os4N86ef9bba6kVGurqxmhpBHKctoxY" amount="20.3"></phantom-qrcode>

Examples

<body>
<phantom-qrcode address="DE6os4N86ef9bba6kVGurqxmhpBHKctoxY" amount="10.5" vendor-field="Hello%Phantom!" size="200" show-logo="true">
<script>
  document.querySelector('phantom-qrcode').getURI();
  // => phantom:DE6os4N86ef9bba6kVGurqxmhpBHKctoxY?amount=10.5&vendorField=Hello%20Phantom!
</script>
</body>

Generate this QR code:

Properties

This package complies with the specifications described in AIP-13.

AttributeDescriptionTypeRequired
addressPhantom recipient address encoded in Base58.StringYes
amountAmount in PHANTOM (Ẕ) or DPHANTOM (DẔ).NumberNo
labelRecipient label string.StringNo
sizeSize of the QR code (pixels)NumberNo
show-logoDisplay the PHANTOM logo in QR codeBooleanNo
vendor-fieldVendor field string (encoded URI).StringNo

Methods

You can interact with the component data using the methods below:

getURI()

Format the properties entered to the PHANTOM URI scheme.

document.querySelector('phantom-qrcode').getURI();
// => phantom:DE6os4N86ef9bba6kVGurqxmhpBHKctoxY?amount=20.3

getDataURL([mime])

Generates a base64 encoded data URI for the QR code.

document.querySelector('phantom-qrcode').getDataURL();
// => data:image/png;base64,iVBORw0KGgoAAAANSUhE...n6ofvMC4I9AAAAAElFTkSuQmCC

validateURI(uri)

Validate an URI string.

const uri = 'phantom:DE6os4N86ef9bba6kVGurqxmhpBHKctoxY?amount=10.5';
document.querySelector('phantom-qrcode').validateURI(uri);
// => ["phantom:DE6os4N86ef9bba6kVGurqxmhpBHKctoxY?amount=10.5", "DE6os4N86ef9bba6kVGurqxmhpBHKctoxY", "?amount=10.5"]

deserializeURI(uri)

Deserialize the URI scheme to a JSON object.

const uri = 'phantom:DE6os4N86ef9bba6kVGurqxmhpBHKctoxY?amount=10.5&vendorField=Hello%20Phantom!';
document.querySelector('phantom-qrcode').deserializeURI(uri);
// => { address: 'DE6os4N86ef9bba6kVGurqxmhpBHKctoxY', amount: 10.5, label: null, vendorField: 'Hello Phantom!' }

fromObject(obj)

Instantiate a URI from an Object.

const obj = { address: DE6os4N86ef9bba6kVGurqxmhpBHKctoxY, amount: 10.5 };
const element = document.querySelector('phantom-qrcode').fromObject(obj);
// => <phantom-qrcode address="DE6os4N86ef9bba6kVGurqxmhpBHKctoxY" amount="10.5">

Security

If you discover a security vulnerability within this project, please send an e-mail to security@phantom.org. All security vulnerabilities will be promptly addressed.

Authors

License

PHANTOM QRCode is licensed under the MIT License - see the LICENSE file for details.