npm.io
0.1.0 • Published 7 years ago

phantom-qrcode

Licence
MIT
Version
0.1.0
Deps
3
Size
7 kB
Vulns
0
Weekly
0

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.

Attribute Description Type Required
address Phantom recipient address encoded in Base58. String Yes
amount Amount in PHANTOM (Ẕ) or DPHANTOM (DẔ). Number No
label Recipient label string. String No
size Size of the QR code (pixels) Number No
show-logo Display the PHANTOM logo in QR code Boolean No
vendor-field Vendor field string (encoded URI). String No

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.