anza-xyz / solana-pay

A new standard for decentralized payments.
https://solanapay.com
Apache License 2.0
1.29k stars 450 forks source link

createQR(url) function error #146

Closed a-creation closed 2 years ago

a-creation commented 2 years ago

After following documentation specification for using the createQR(url), createQR errors: ReferenceError: Can't find variable: document.

const url = encodeURL({ recipient, amount, splToken, reference, label, message, memo }); const qrCode = createQR(url);

IMG_3E2F189ED4B7-1

jordaaash commented 2 years ago

This isn't a bug with the library. You're using it inside React Native, and that QR code library depends on the DOM.

a-creation commented 2 years ago

@jordansexton What is the best practice to generate this QR code within React Native?

jordaaash commented 2 years ago

I couldn't tell you specifically :)

But it's just a URL string that's being encoded, so any QR code library that works natively or without requiring the DOM should be good.

samheutmaker commented 2 years ago

@a-creation A little late, but here is a good QR Code library for react-native.

Example:

import React from 'react';
import QRCode from 'react-native-qrcode-svg';
import { encodeURL } from '@solana/pay';

const MyComponent: React.FC = () => {
  const url = 'https://...'; // Your url here
  const encoded = encodeURL({ link: new URL(url) });

  return (
    <QRCode
      value={encoded.toString()}
      size={300}
    />
  );
};