Skip to content

Commit

Permalink
Upgrade breez sdk and update sdk methods (#312)
Browse files Browse the repository at this point in the history
* upgrade breez sdk and update sdk methods

* update breez sdk methods in modal-nfc and useBreezPayment

* clean up

* upgradre min ios version to 13
  • Loading branch information
Nodirbek75 authored Dec 30, 2024
1 parent 6fa261f commit 04fc499
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 125 deletions.
71 changes: 0 additions & 71 deletions app/appTest.tsx

This file was deleted.

17 changes: 8 additions & 9 deletions app/components/modal-nfc/modal-nfc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
LnUrlPayResultVariant,
lnurlPay,
parse,
prepareLnurlPay,
} from "@breeztech/react-native-breez-sdk-liquid"

export const ModalNfc: React.FC<{
Expand Down Expand Up @@ -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 = "<comment>"
const optionalPaymentLabel = "<label>"
const optionalValidateSuccessActionUrl = true
const lnUrlPayResult = await lnurlPay({
const prepareResponse = await prepareLnurlPay({
data: input.data,
amountMsat,
comment: optionalComment,
paymentLabel: optionalPaymentLabel,
validateSuccessActionUrl: optionalValidateSuccessActionUrl,
amountMsat: input.data.minSendable,
validateSuccessActionUrl: true,
})

const lnUrlPayResult = await lnurlPay({
prepareResponse,
})

console.log(lnUrlPayResult)
Expand Down
22 changes: 12 additions & 10 deletions app/hooks/useBreezPayments.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as sdk from "@breeztech/react-native-breez-sdk-liquid"
import { TransactionFragment } from "@app/graphql/generated"

export const formatPaymentsBreezSDK = (
txid: unknown,
Expand All @@ -8,26 +7,26 @@ export const formatPaymentsBreezSDK = (
) => {
const response: sdk.Payment[] = payments
const responseTx = response.find((tx) => tx.txId === txid)
let tx: TransactionFragment = {} as TransactionFragment
let tx: any = {}
if (responseTx) {
const amountSat = responseTx.amountSat
// round up to 2 decimal places
const moneyAmount = (convertedAmount / 100).toString()
const transformedData: TransactionFragment = {
// Map fields from response to fields of TransactionFragment, e.g.,
const transformedData = {
id: responseTx.txId || "",
direction: responseTx.paymentType === "receive" ? "RECEIVE" : "SEND",
status:
(responseTx.status === sdk.PaymentState.PENDING ? "PENDING" : "SUCCESS") ||
"FAILURE",
memo: responseTx.description,
status: responseTx.status.toUpperCase(),
memo: responseTx.details.description,
settlementAmount: amountSat,
settlementCurrency: "BTC",
settlementDisplayAmount: moneyAmount,
settlementDisplayCurrency: "USD",
settlementVia: {
__typename: "SettlementViaLn",
paymentSecret: responseTx.preimage,
paymentSecret:
responseTx.details.type === sdk.PaymentDetailsVariant.LIGHTNING
? responseTx.details.preimage
: "",
},
createdAt: responseTx.timestamp,
settlementFee: responseTx.feesSat,
Expand All @@ -41,7 +40,10 @@ export const formatPaymentsBreezSDK = (
},
initiationVia: {
__typename: "InitiationViaLn",
paymentHash: responseTx.bolt11 || "",
paymentHash:
responseTx.details.type === sdk.PaymentDetailsVariant.LIGHTNING
? responseTx.details.paymentHash || ""
: "",
},
__typename: "Transaction",
}
Expand Down
8 changes: 8 additions & 0 deletions app/i18n/i18n-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,10 @@ type RootTranslation = {
* S​e​l​e​c​t​ ​W​a​l​l​e​t
*/
selectWallet: string
/**
* S​e​l​e​c​t​ ​W​a​l​l​e​t
*/
cantReceiveZeroSats: string
}
RedeemBitcoinScreen: {
/**
Expand Down Expand Up @@ -6262,6 +6266,10 @@ export type TranslationFunctions = {
* Select Wallet
*/
selectWallet: () => LocalizedString
/**
* S​e​l​e​c​t​ ​W​a​l​l​e​t
*/
cantReceiveZeroSats: () => LocalizedString
}
RedeemBitcoinScreen: {
/**
Expand Down
6 changes: 2 additions & 4 deletions app/screens/transaction-history/BTCTransactionHistory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Screen } from "@app/components/screen"
import { BreezTransactionItem } from "@app/components/transaction-item/breez-transaction-item"

// graphql
import { TransactionFragment, WalletCurrency } from "@app/graphql/generated"
import { WalletCurrency } from "@app/graphql/generated"
import { groupTransactionsByDate } from "@app/graphql/transactions"

// Breez SDK
Expand Down Expand Up @@ -38,9 +38,7 @@ export const BTCTransactionHistory: React.FC = () => {
const [refreshing, setRefreshing] = useState(false)
const [fetchingMore, setFetchingMore] = useState(false)
const [breezLoading, setBreezLoading] = useState(false)
const [txsList, setTxsList] = useState<TransactionFragment[]>(
persistentState.btcTransactions || [],
)
const [txsList, setTxsList] = useState<any[]>(persistentState.btcTransactions || [])

useEffect(() => {
fetchPaymentsBreez(0)
Expand Down
44 changes: 32 additions & 12 deletions app/utils/breez-sdk-liquid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -83,7 +86,7 @@ const retry = <T>(fn: () => Promise<T>, 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) {
Expand Down Expand Up @@ -151,19 +154,27 @@ export const fetchBreezFee = async (
if (paymentType === "lightning" && !!invoice) {
const response = await prepareSendPayment({
destination: invoice,
amountSat: receiverAmountSat,
})
return { fee: response.feesSat, err: null }
} else if (paymentType === "onchain" && !!receiverAmountSat) {
const response = await preparePayOnchain({
receiverAmountSat,
amount: { type: PayAmountVariant.RECEIVER, amountSat: receiverAmountSat },
})
return { fee: response.totalFeesSat, err: null }
} else if ((paymentType === "intraledger" || paymentType === "lnurl") && !!invoice) {
// const response = await parse(invoice)
// console.log(">>>>>>>>>>>.", response)

return { fee: null, err: "Failed to get fee" }
return response.totalFeesSat
} 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 { fee: null, err: "Wrong payment type" }
}
Expand Down Expand Up @@ -263,7 +274,10 @@ export const sendOnchainBreezSDK = async (
): Promise<SendPaymentResponse> => {
try {
const prepareResponse = await preparePayOnchain({
receiverAmountSat: amountSat,
amount: {
type: PayAmountVariant.RECEIVER,
amountSat,
},
})

// Check if the fees are acceptable before proceeding
Expand All @@ -289,12 +303,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")
Expand All @@ -314,11 +332,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 }
Expand Down
4 changes: 2 additions & 2 deletions ios/LNFlash.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@
INFOPLIST_FILE = LNFlash/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Flash;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.2.6;
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -497,7 +497,7 @@
INFOPLIST_FILE = LNFlash/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = Flash;
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.finance";
IPHONEOS_DEPLOYMENT_TARGET = 12.0;
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
LD_RUNPATH_SEARCH_PATHS = "$(inherited)";
MARKETING_VERSION = 0.2.6;
OTHER_LDFLAGS = (
Expand Down
2 changes: 1 addition & 1 deletion ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
use_modular_headers!

platform :ios, min_ios_version_supported
platform :ios, '13.0'
prepare_react_native_project!
# If you are using a `react-native-flipper` your iOS build will fail when `NO_FLIPPER=1` is set.
# because `react-native-flipper` depends on (FlipperKit,...) that will be excluded
Expand Down
22 changes: 11 additions & 11 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ PODS:
- GoogleUtilities/UserDefaults (~> 7.13)
- PromisesObjC (~> 2.3)
- boost (1.76.0)
- breez_sdk_liquid (0.3.0):
- BreezSDKLiquid (= 0.3.0)
- breez_sdk_liquid (0.5.1):
- BreezSDKLiquid (= 0.5.1)
- React-Core
- breez_sdk_liquidFFI (0.3.0)
- BreezSDKLiquid (0.3.0):
- breez_sdk_liquidFFI (= 0.3.0)
- breez_sdk_liquidFFI (0.5.1)
- BreezSDKLiquid (0.5.1):
- breez_sdk_liquidFFI (= 0.5.1)
- BVLinearGradient (2.8.3):
- React-Core
- DoubleConversion (1.1.6)
Expand Down Expand Up @@ -153,7 +153,7 @@ PODS:
- nanopb/encode (= 2.30909.1)
- nanopb/decode (2.30909.1)
- nanopb/encode (2.30909.1)
- OpenSSL-Universal (3.3.1000)
- OpenSSL-Universal (3.3.2000)
- PromisesObjC (2.4.0)
- PromisesSwift (2.4.0):
- PromisesObjC (= 2.4.0)
Expand Down Expand Up @@ -1040,9 +1040,9 @@ EXTERNAL SOURCES:
SPEC CHECKSUMS:
AppCheckCore: 9feb4300caa596a36416cde10674dc5bec1e022e
boost: 57d2868c099736d80fcd648bf211b4431e51a558
breez_sdk_liquid: c19bb2739da6c57c4b9605fe4f8f89a03725e376
breez_sdk_liquidFFI: c85c235fb8177538d63f7902f86ff994bdc622a6
BreezSDKLiquid: 68dca0e9ba38647692f4950468f602ca756b5cd8
breez_sdk_liquid: 8528aefaa995706819939f420f869bc1d90bd5c5
breez_sdk_liquidFFI: 60003088e92e35cf6fc5a8686883b346023a26d1
BreezSDKLiquid: 2895e61f32ed200952104575a56e937b0a787df8
BVLinearGradient: 880f91a7854faff2df62518f0281afb1c60d49a3
DoubleConversion: 5189b271737e1565bdce30deb4a08d647e3f5f54
FBLazyVector: 5fbbff1d7734827299274638deb8ba3024f6c597
Expand Down Expand Up @@ -1070,7 +1070,7 @@ SPEC CHECKSUMS:
hermes-engine: 9180d43df05c1ed658a87cc733dc3044cf90c00a
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
nanopb: d4d75c12cd1316f4a64e3c6963f879ecd4b5e0d5
OpenSSL-Universal: 57f92a826947ee3183556bf5e22d7dff8d55f834
OpenSSL-Universal: b60a3702c9fea8b3145549d421fdb018e53ab7b4
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
Expand Down Expand Up @@ -1161,6 +1161,6 @@ SPEC CHECKSUMS:
Yoga: 4c3aa327e4a6a23eeacd71f61c81df1bcdf677d5
ZXingObjC: 8898711ab495761b2dbbdec76d90164a6d7e14c5

PODFILE CHECKSUM: 9e8bcc2e44fb66d8e9088a950dd1fd43100d442b
PODFILE CHECKSUM: 59de119b61d210af59849d66e2fb77a74d9922c8

COCOAPODS: 1.15.2
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading

0 comments on commit 04fc499

Please sign in to comment.