From dcf00e1aab63916d834a62502c5ca641b475c3f7 Mon Sep 17 00:00:00 2001 From: Sandipan Dey Date: Thu, 13 Jul 2023 13:03:41 +0530 Subject: [PATCH] feat: paycode await --- .../payment/payment-request.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/app/screens/receive-bitcoin-screen/payment/payment-request.ts b/app/screens/receive-bitcoin-screen/payment/payment-request.ts index d9aef7d25a..b7e295b887 100644 --- a/app/screens/receive-bitcoin-screen/payment/payment-request.ts +++ b/app/screens/receive-bitcoin-screen/payment/payment-request.ts @@ -197,26 +197,32 @@ export const createPaymentRequest = ( // Paycode } else if (pr.type === Invoice.PayCode && pr.username) { - const getFullUriFn: GetFullUriFn = ({ uppercase, prefix }) => { - const lnurl = bech32.encode( - "lnurl", - bech32.toWords( - Buffer.from(`${pr.posUrl}/.well-known/lnurlp/${pr.username}`, "utf8"), + const lnurl = await new Promise((resolve) => { + resolve( + bech32.encode( + "lnurl", + bech32.toWords( + Buffer.from(`${pr.posUrl}/.well-known/lnurlp/${pr.username}`, "utf8"), + ), + 1500, ), - 1500, ) + }) - const webURL = `${pr.posUrl}/${pr.username}` + // To make the page render at loading state + // (otherwise jittery becoz encode takes ~10ms on slower phones) + await new Promise((r) => setTimeout(r, 500)) - const qrCodeURL = (webURL + "?lightning=" + lnurl).toUpperCase() + const webURL = `${pr.posUrl}/${pr.username}` + const qrCodeURL = (webURL + "?lightning=" + lnurl).toUpperCase() - return getPaymentRequestFullUri({ + const getFullUriFn: GetFullUriFn = ({ uppercase, prefix }) => + getPaymentRequestFullUri({ type: Invoice.PayCode, input: qrCodeURL, uppercase, prefix, }) - } info = { data: {