From 7201b162b4bfb8e0b3b8c78c34a6a50e1cc18369 Mon Sep 17 00:00:00 2001 From: benalleng Date: Mon, 15 Jan 2024 23:29:13 -0500 Subject: [PATCH] add support for scanning bip21 qr --- pages/wallet.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pages/wallet.js b/pages/wallet.js index 6f9845fbe..9bf716268 100644 --- a/pages/wallet.js +++ b/pages/wallet.js @@ -29,6 +29,7 @@ import { useField } from 'formik' import { useToast } from '../components/toast' import { WalletLimitBanner } from '../components/banners' import Plug from '../svgs/plug.svg' +import { decode } from 'bolt11' export const getServerSideProps = getGetServerSideProps({ authRequired: true }) @@ -279,7 +280,13 @@ function InvoiceScanner ({ fieldName }) { return ( { - helpers.setValue(result.replace(/^lightning:/, '').toLowerCase()) + if (result.split('lightning=')[1]) { + helpers.setValue(result.split('lightning=')[1].split(/[&?]/)[0].toLowerCase()) + } else if (decode(result.replace(/^lightning:/, ''))) { + helpers.setValue(result.replace(/^lightning:/, '').toLowerCase()) + } else { + throw new Error('Not a proper lightning payment request') + } onClose() }} onError={(error) => { @@ -288,6 +295,7 @@ function InvoiceScanner ({ fieldName }) { } else { toaster.danger(error?.message || error?.toString?.()) } + onClose() }} /> )