From 31b93cdce516738ab2ea9771187e46f7b73a810d Mon Sep 17 00:00:00 2001 From: nodirbek75 Date: Wed, 11 Dec 2024 15:58:51 +0500 Subject: [PATCH 1/4] upgrade breez sdk and update sdk methods --- app/utils/breez-sdk-liquid/index.ts | 41 ++++++++++++++++++++++------- package.json | 2 +- yarn.lock | 8 +++--- 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/app/utils/breez-sdk-liquid/index.ts b/app/utils/breez-sdk-liquid/index.ts index faab4f5ad0..3e04009fb1 100644 --- a/app/utils/breez-sdk-liquid/index.ts +++ b/app/utils/breez-sdk-liquid/index.ts @@ -29,7 +29,10 @@ import { LnUrlWithdrawResultVariant, PaymentMethod, ReceivePaymentResponse, + prepareLnurlPay, + PayAmountVariant, } from "@breeztech/react-native-breez-sdk-liquid" +import { API_KEY } from "@env" export const KEYCHAIN_MNEMONIC_KEY = "mnemonic_key" @@ -83,7 +86,7 @@ const retry = (fn: () => Promise, ms = 15000, maxRetries = 3) => const connectToSDK = async () => { try { const mnemonic = await getMnemonic() - const config = await defaultConfig(LiquidNetwork.MAINNET) + const config = await defaultConfig(LiquidNetwork.MAINNET, API_KEY) await connect({ mnemonic, config }) } catch (error) { @@ -147,22 +150,31 @@ export const fetchBreezFee = async ( invoice?: string, receiverAmountSat?: number, ) => { + console.log(">>>>>>>>???????????", receiverAmountSat) try { if (paymentType === "lightning" && !!invoice) { const response = await prepareSendPayment({ destination: invoice, - amountSat: receiverAmountSat, }) return response.feesSat } else if (paymentType === "onchain" && !!receiverAmountSat) { const response = await preparePayOnchain({ - receiverAmountSat, + amount: { type: PayAmountVariant.RECEIVER, amountSat: receiverAmountSat }, }) return response.totalFeesSat - } else if ((paymentType === "intraledger" || paymentType === "lnurl") && !!invoice) { - // const response = await parse(invoice) - // console.log(">>>>>>>>>>>.", response) - + } else if ( + (paymentType === "intraledger" || paymentType === "lnurl") && + !!invoice && + !!receiverAmountSat + ) { + const input = await parse(invoice) + if (input.type === InputTypeVariant.LN_URL_PAY) { + const prepareResponse = await prepareLnurlPay({ + data: input.data, + amountMsat: receiverAmountSat * 1000, + }) + return prepareResponse.feesSat + } return null } else { return null @@ -264,7 +276,10 @@ export const sendOnchainBreezSDK = async ( ): Promise => { try { const prepareResponse = await preparePayOnchain({ - receiverAmountSat: amountSat, + amount: { + type: PayAmountVariant.RECEIVER, + amountSat, + }, }) // Check if the fees are acceptable before proceeding @@ -290,12 +305,16 @@ export const payLnurlBreezSDK = async ( try { const input = await parse(lnurl) if (input.type === InputTypeVariant.LN_URL_PAY) { - const lnUrlPayResult = await lnurlPay({ + const prepareResponse = await prepareLnurlPay({ data: input.data, amountMsat: amountSat * 1000, validateSuccessActionUrl: true, }) + const lnUrlPayResult = await lnurlPay({ + prepareResponse, + }) + if (lnUrlPayResult.type === LnUrlPayResultVariant.PAY_ERROR) { console.log("Error paying lnurl: ", lnUrlPayResult.data.reason) console.log("Reporting issue to Breez SDK") @@ -315,11 +334,13 @@ export const onRedeem = async (lnurl: string, defaultDescription: string) => { const input = await parse(lnurl) if (input.type === InputTypeVariant.LN_URL_PAY) { - const lnUrlPayResult = await lnurlPay({ + const prepareResponse = await prepareLnurlPay({ data: input.data, amountMsat: input.data.minSendable, validateSuccessActionUrl: true, }) + const lnUrlPayResult = await lnurlPay({ prepareResponse }) + console.log("LNURL PAY>>>>>>>>", lnUrlPayResult) if (lnUrlPayResult.type === LnUrlPayResultVariant.ENDPOINT_SUCCESS) { return { success: true, error: undefined } diff --git a/package.json b/package.json index 65f33961e0..0b6425408f 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,7 @@ "dependencies": { "@apollo/client": "3.9.0-alpha.5", "@bitcoinerlab/secp256k1": "^1.0.5", - "@breeztech/react-native-breez-sdk-liquid": "^0.3.0", + "@breeztech/react-native-breez-sdk-liquid": "^0.5.1", "@flash/client": "git+https://github.com/lnflash/flash-client.git", "@flyerhq/react-native-chat-ui": "^1.4.3", "@flyerhq/react-native-link-preview": "^1.6.0", diff --git a/yarn.lock b/yarn.lock index 53e7ac69c0..7bba627f16 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1402,10 +1402,10 @@ "@noble/hashes" "^1.1.5" "@noble/secp256k1" "^1.7.1" -"@breeztech/react-native-breez-sdk-liquid@^0.3.0": - version "0.3.0" - resolved "https://registry.yarnpkg.com/@breeztech/react-native-breez-sdk-liquid/-/react-native-breez-sdk-liquid-0.3.0.tgz#bf12948a962664a02f86062a1150dfb0f434d3e1" - integrity sha512-dFST33/KSxS7a0zH88b4i0dyZcrcMmcWyB8RId2eay8tDc8HaGo84G+nQISRua+AwpilCHS9cGHAPL3vuqDynA== +"@breeztech/react-native-breez-sdk-liquid@^0.5.1": + version "0.5.1" + resolved "https://registry.npmjs.org/@breeztech/react-native-breez-sdk-liquid/-/react-native-breez-sdk-liquid-0.5.1.tgz#e6c893b887b33e414b6b5d3503cb6e441e5ca7dd" + integrity sha512-1ZvcTE+ahEb79aMJXQjL1dvNCJyaTNtjOMcsFs2ivSD59/1efp5fpgJ0J7WUK/1ESJdxJeXXGXJoAB7TnNrFOg== "@callstack/react-theme-provider@3.0.3": version "3.0.3" From 7940d2d470732d0e7da7551cd2d22313381d5a7a Mon Sep 17 00:00:00 2001 From: nodirbek75 Date: Wed, 11 Dec 2024 16:12:19 +0500 Subject: [PATCH 2/4] update breez sdk methods in modal-nfc and useBreezPayment --- app/components/modal-nfc/modal-nfc.tsx | 17 ++++++++--------- app/hooks/useBreezPayments.ts | 22 ++++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/app/components/modal-nfc/modal-nfc.tsx b/app/components/modal-nfc/modal-nfc.tsx index 0a604727c7..d7c5369697 100644 --- a/app/components/modal-nfc/modal-nfc.tsx +++ b/app/components/modal-nfc/modal-nfc.tsx @@ -30,6 +30,7 @@ import { LnUrlPayResultVariant, lnurlPay, parse, + prepareLnurlPay, } from "@breeztech/react-native-breez-sdk-liquid" export const ModalNfc: React.FC<{ @@ -180,16 +181,14 @@ export const ModalNfc: React.FC<{ try { const input = await parse(lnurl) if (input.type === InputTypeVariant.LN_URL_PAY) { - const amountMsat = input.data.minSendable - const optionalComment = "" - const optionalPaymentLabel = "