add support for scanning bip21 qr (#755)
This commit is contained in:
parent
c58d3c778a
commit
f915b2b8b3
@ -29,6 +29,7 @@ import { useField } from 'formik'
|
|||||||
import { useToast } from '../components/toast'
|
import { useToast } from '../components/toast'
|
||||||
import { WalletLimitBanner } from '../components/banners'
|
import { WalletLimitBanner } from '../components/banners'
|
||||||
import Plug from '../svgs/plug.svg'
|
import Plug from '../svgs/plug.svg'
|
||||||
|
import { decode } from 'bolt11'
|
||||||
|
|
||||||
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
|
export const getServerSideProps = getGetServerSideProps({ authRequired: true })
|
||||||
|
|
||||||
@ -279,7 +280,13 @@ function InvoiceScanner ({ fieldName }) {
|
|||||||
return (
|
return (
|
||||||
<QrScanner
|
<QrScanner
|
||||||
onDecode={(result) => {
|
onDecode={(result) => {
|
||||||
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()
|
onClose()
|
||||||
}}
|
}}
|
||||||
onError={(error) => {
|
onError={(error) => {
|
||||||
@ -288,6 +295,7 @@ function InvoiceScanner ({ fieldName }) {
|
|||||||
} else {
|
} else {
|
||||||
toaster.danger(error?.message || error?.toString?.())
|
toaster.danger(error?.message || error?.toString?.())
|
||||||
}
|
}
|
||||||
|
onClose()
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user