Skip to content

Commit

Permalink
feat: paycode also working
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev committed Jul 13, 2023
1 parent fc80868 commit 08d96f4
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/screens/receive-bitcoin-screen/payment/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Invoice, GetFullUriInput } from "./index.types"
const prefixByType = {
[Invoice.OnChain]: "bitcoin:",
[Invoice.Lightning]: "lightning:",
[Invoice.PayCode]: "paycode:",
[Invoice.PayCode]: "",
}

export const getPaymentRequestFullUri = ({
Expand Down
2 changes: 2 additions & 0 deletions app/screens/receive-bitcoin-screen/payment/index.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ type BasePaymentRequestCreationData<T extends WalletCurrency> = {
// Can use paycode (if username is set)
canUsePaycode: boolean
username?: string
posUrl: string

network: Network
}
Expand All @@ -133,6 +134,7 @@ export type BaseCreatePaymentRequestCreationDataParams<T extends WalletCurrency>
bitcoinWalletDescriptor: BtcWalletDescriptor
convertMoneyAmount: ConvertMoneyAmount
username?: string
posUrl: string
receivingWalletDescriptor?: WalletDescriptor<T>
memo?: string
unitOfAccountAmount?: MoneyAmount<WalletOrDisplayCurrency>
Expand Down
20 changes: 17 additions & 3 deletions app/screens/receive-bitcoin-screen/payment/payment-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { decodeInvoiceString, Network as NetworkLibGaloy } from "@galoymoney/client"
import { BtcMoneyAmount } from "@app/types/amounts"
import { getPaymentRequestFullUri } from "./helpers"
import { bech32 } from "bech32"

export const createPaymentRequest = (
params: CreatePaymentRequestParams,
Expand Down Expand Up @@ -196,13 +197,26 @@ export const createPaymentRequest = (

// Paycode
} else if (pr.type === Invoice.PayCode && pr.username) {
const getFullUriFn: GetFullUriFn = ({ uppercase, prefix }) =>
getPaymentRequestFullUri({
const getFullUriFn: GetFullUriFn = ({ uppercase, prefix }) => {
const lnurl = bech32.encode(
"lnurl",
bech32.toWords(
Buffer.from(`${pr.posUrl}/.well-known/lnurlp/${pr.username}`, "utf8"),
),
1500,
)

const webURL = `${pr.posUrl}/${pr.username}`

const qrCodeURL = (webURL + "?lightning=" + lnurl).toUpperCase()

return getPaymentRequestFullUri({
type: Invoice.PayCode,
input: pr.username || "",
input: qrCodeURL,
uppercase,
prefix,
})
}

info = {
data: {
Expand Down
1 change: 1 addition & 0 deletions app/screens/receive-bitcoin-screen/qr-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const QRView: React.FC<Props> = ({
const getQrLogo = () => {
if (type === Invoice.OnChain) return Logo
if (type === Invoice.Lightning) return Logo
if (type === Invoice.PayCode) return Logo
return null
}

Expand Down
2 changes: 1 addition & 1 deletion app/screens/receive-bitcoin-screen/receive-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const ReceiveScreen = () => {
}
}, [request?.type])

if (!request) return <Text>Loading</Text>
if (!request) return <></>
const {
type,
setType,
Expand Down
10 changes: 9 additions & 1 deletion app/screens/receive-bitcoin-screen/use-receive-bitcoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from "@app/graphql/generated"
import { createPaymentRequestCreationData } from "./payment/payment-request-creation-data"

import { usePriceConversion } from "@app/hooks"
import { useAppConfig, usePriceConversion } from "@app/hooks"
import Clipboard from "@react-native-clipboard/clipboard"
import { gql } from "@apollo/client"
import { useIsAuthed } from "@app/graphql/is-authed-context"
Expand Down Expand Up @@ -155,6 +155,10 @@ export const useReceiveBitcoin = () => {

const username = data?.me?.username

const appConfig = useAppConfig().appConfig
const posUrl = appConfig.galoyInstance.posUrl
const lnAddressHostname = appConfig.galoyInstance.lnAddressHostname

const { convertMoneyAmount: _convertMoneyAmount } = usePriceConversion()

// Initialize Payment Request
Expand All @@ -165,6 +169,7 @@ export const useReceiveBitcoin = () => {
defaultWallet &&
bitcoinWallet &&
username !== null &&
posUrl &&
data?.globals?.network
) {
const defaultWalletDescriptor = {
Expand All @@ -183,6 +188,7 @@ export const useReceiveBitcoin = () => {
bitcoinWalletDescriptor,
convertMoneyAmount: _convertMoneyAmount,
username,
posUrl,
network: data.globals?.network,
}
setPRCD(createPaymentRequestCreationData(initialPRParams))
Expand Down Expand Up @@ -386,6 +392,8 @@ export const useReceiveBitcoin = () => {
0,
6,
)}......${pr.info.data.address.slice(-6)}`
} else if (prcd.type === "PayCode" && pr?.info?.data?.invoiceType === "PayCode") {
extraDetails = `${pr.info.data.username}@${lnAddressHostname}`
}

return {
Expand Down

0 comments on commit 08d96f4

Please sign in to comment.