Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unified QR scanning #755

Merged
merged 1 commit into from
Jan 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion pages/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 })

Expand Down Expand Up @@ -279,7 +280,13 @@ function InvoiceScanner ({ fieldName }) {
return (
<QrScanner
onDecode={(result) => {
helpers.setValue(result.replace(/^lightning:/, '').toLowerCase())
if (result.split('lightning=')[1]) {
helpers.setValue(result.split('lightning=')[1].split(/[&?]/)[0].toLowerCase())
huumn marked this conversation as resolved.
Show resolved Hide resolved
} 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) => {
Expand All @@ -288,6 +295,7 @@ function InvoiceScanner ({ fieldName }) {
} else {
toaster.danger(error?.message || error?.toString?.())
}
onClose()
huumn marked this conversation as resolved.
Show resolved Hide resolved
}}
/>
)
Expand Down