0.1.11 • Published 3 years ago

react-native-webln v0.1.11

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

react-native-webln

Library for handling all the boilerplate needed for supporting WebLN in a react-native-webview, so you can focus on actually implementing all the features of WebLN in your app or wallet.

Just plug and play.

Getting Started

To use this library you also need to install react-native-webview. If you want Typescript typings, you need to install webln.

# Install react-native-webln and its peer dependencies
npm install --save react-native-webln react-native-webview

# If you want Typescript definitions
npm install --save-dev webln

or if you prefer Yarn.

# Install react-native-webln and its peer dependencies
yarn add react-native-webln react-native-webview

# If you want Typescript definitions
yarn add --dev webln

Example

import { injectJs, postMessageHandler } from "react-native-webln";

const WebLNBrowser = () => {
  const webview = useRef<WebView>();
  const [jsInjected, setJsInjected] = useState(false);

  return (
    <WebView
      ref={webview}
      source={{ uri: "https://webln-capable-site.com" }}
      onLoadStart={() => setJsInjected(false)}
      onLoadProgress={(e) => {
        if (!jsInjected && e.nativeEvent.progress > 0.75) {
          webview.current.injectJavaScript(injectJs());
          setJsInjected(true);
        }
      }}
      onMessage={onMessageHandler(webview, {
        enable: async () => { /* Your implementation goes here */ },
        getInfo: async () => { /* Your implementation goes here */ },
        makeInvoice: async (args) => { /* Your implementation goes here */ },
        sendPayment: async (paymentRequestStr) => { /* Your implementation goes here */ },
        signMessage: async (message) => { /* Your implementation goes here */ },
        verifyMessage: async (signature, message) => { /* Your implementation goes here */ },

        // Non-WebLN
        // Called when an a-tag containing a `lightning:` uri is found on a page
        foundInvoice: async (paymentRequestStr) => { /* Your implementation goes here */ }
      })}
      style={{ width: "100%", height: "100%", flex: 1 }}
    />
  )
}

License

MIT

0.1.11

3 years ago

0.1.10

4 years ago

0.1.9

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago

0.1.0

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.3

4 years ago

1.0.0

4 years ago