diff --git a/api/resolvers/wallet.js b/api/resolvers/wallet.js index 7259ceeb..07915631 100644 --- a/api/resolvers/wallet.js +++ b/api/resolvers/wallet.js @@ -290,7 +290,7 @@ export default { if (payer) { payer = { ...payer, - identifier: payer.identifier ? me.name : undefined + identifier: payer.identifier ? `${me.name}@stacker.news` : undefined } payer = Object.fromEntries( Object.entries(payer).filter(([, value]) => !!value) @@ -305,10 +305,10 @@ export default { callback.searchParams.append('comment', comment) } - let encodedPayerData = '' + let stringifiedPayerData = '' if (payer && Object.entries(payer).length) { - encodedPayerData = encodeURIComponent(JSON.stringify(payer)) - callback.searchParams.append('payerdata', encodedPayerData) + stringifiedPayerData = JSON.stringify(payer) + callback.searchParams.append('payerdata', stringifiedPayerData) } // call callback with amount and conditionally comment @@ -320,7 +320,7 @@ export default { // decode invoice try { const decoded = await decodePaymentRequest({ lnd, request: res.pr }) - if (decoded.description_hash !== lnurlPayDescriptionHash(`${options.metadata}${encodedPayerData}`)) { + if (decoded.description_hash !== lnurlPayDescriptionHash(`${options.metadata}${stringifiedPayerData}`)) { throw new Error('description hash does not match') } if (!decoded.mtokens || BigInt(decoded.mtokens) !== BigInt(milliamount)) { diff --git a/package-lock.json b/package-lock.json index 16f12a70..c4562a35 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36,6 +36,7 @@ "graphql-type-json": "^0.3.2", "jose1": "npm:jose@^1.27.2", "ln-service": "^56.11.0", + "lodash.debounce": "^4.0.8", "mathjs": "^11.9.1", "mdast-util-find-and-replace": "^3.0.0", "mdast-util-from-markdown": "^2.0.0", diff --git a/package.json b/package.json index af34d1df..3fcb7907 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "graphql-type-json": "^0.3.2", "jose1": "npm:jose@^1.27.2", "ln-service": "^56.11.0", + "lodash.debounce": "^4.0.8", "mathjs": "^11.9.1", "mdast-util-find-and-replace": "^3.0.0", "mdast-util-from-markdown": "^2.0.0", diff --git a/pages/api/lnurlp/[username]/pay.js b/pages/api/lnurlp/[username]/pay.js index 7efe6af3..ed2513d8 100644 --- a/pages/api/lnurlp/[username]/pay.js +++ b/pages/api/lnurlp/[username]/pay.js @@ -50,7 +50,7 @@ export default async ({ query: { username, amount, nostr, comment, payerdata: pa let parsedPayerData if (payerData) { try { - parsedPayerData = JSON.parse(decodeURIComponent(payerData)) + parsedPayerData = JSON.parse(payerData) } catch (err) { console.error('failed to parse payerdata', err) return res.status(400).json({ status: 'ERROR', reason: 'Invalid JSON supplied for payerdata parameter' }) diff --git a/pages/wallet.js b/pages/wallet.js index 7ea3111b..d011c212 100644 --- a/pages/wallet.js +++ b/pages/wallet.js @@ -8,7 +8,7 @@ import { CenterLayout } from '../components/layout' import InputGroup from 'react-bootstrap/InputGroup' import { WithdrawlSkeleton } from './withdrawals/[id]' import { useMe } from '../components/me' -import { useEffect, useState } from 'react' +import { useCallback, useEffect, useState } from 'react' import { requestProvider } from 'webln' import Alert from 'react-bootstrap/Alert' import { CREATE_WITHDRAWL, SEND_TO_LNADDR } from '../fragments/wallet' @@ -21,6 +21,7 @@ import styles from '../components/user-header.module.css' import HiddenWalletSummary from '../components/hidden-wallet-summary' import AccordianItem from '../components/accordian-item' import { lnAddrOptions } from '../lib/lnurl' +import debounce from 'lodash.debounce' export const getServerSideProps = getGetServerSideProps({ authRequired: true }) @@ -300,7 +301,7 @@ export function LnAddrWithdrawal () { const [addrOptions, setAddrOptions] = useState(defaultOptions) const [formSchema, setFormSchema] = useState(lnAddrSchema()) - const onAddrChange = async (formik, e) => { + const onAddrChange = useCallback(debounce(async (formik, e) => { let options try { options = await lnAddrOptions(e.target.value) @@ -312,7 +313,7 @@ export function LnAddrWithdrawal () { setAddrOptions(options) setFormSchema(lnAddrSchema(options)) - } + }, 500), [lnAddrOptions, lnAddrSchema]) return ( <>