diff --git a/snippets/react-native/buy_btc.ts b/snippets/react-native/buy_btc.ts index 75bc3f3f..023f4b38 100644 --- a/snippets/react-native/buy_btc.ts +++ b/snippets/react-native/buy_btc.ts @@ -1,12 +1,12 @@ import { - buyBitcoin, - BuyBitcoinProvider -} from "@breeztech/react-native-breez-sdk" + buyBitcoin, + BuyBitcoinProvider +} from '@breeztech/react-native-breez-sdk' const exampleBuyBtc = async () => { - // ANCHOR: buy-btc - const buyBitcoinResponse = await buyBitcoin({ - provider: BuyBitcoinProvider.MOONPAY - }) - // ANCHOR_END: buy-btc + // ANCHOR: buy-btc + const buyBitcoinResponse = await buyBitcoin({ + provider: BuyBitcoinProvider.MOONPAY + }) + // ANCHOR_END: buy-btc } diff --git a/snippets/react-native/connecting_lsp.ts b/snippets/react-native/connecting_lsp.ts index 1a39ad26..094a05ae 100644 --- a/snippets/react-native/connecting_lsp.ts +++ b/snippets/react-native/connecting_lsp.ts @@ -1,15 +1,15 @@ -import { connectLsp, lspId, lspInfo } from "@breeztech/react-native-breez-sdk" +import { connectLsp, lspId, lspInfo } from '@breeztech/react-native-breez-sdk' const exampleAutoConnect = async () => { - // ANCHOR: get-lsp-info - const id = await lspId() - const info = await lspInfo() - // ANCHOR_END: get-lsp-info + // ANCHOR: get-lsp-info + const id = await lspId() + const info = await lspInfo() + // ANCHOR_END: get-lsp-info } const exampleManualConnect = async () => { - // ANCHOR: connect-lsp - const id = "your selected lsp id" - await connectLsp(id) - // ANCHOR_END: connect-lsp + // ANCHOR: connect-lsp + const id = 'your selected lsp id' + await connectLsp(id) + // ANCHOR_END: connect-lsp } diff --git a/snippets/react-native/fiat_currencies.ts b/snippets/react-native/fiat_currencies.ts index 141bf8cf..5ed40eaa 100644 --- a/snippets/react-native/fiat_currencies.ts +++ b/snippets/react-native/fiat_currencies.ts @@ -1,22 +1,22 @@ import { - listFiatCurrencies, - fetchFiatRates -} from "@breeztech/react-native-breez-sdk" + listFiatCurrencies, + fetchFiatRates +} from '@breeztech/react-native-breez-sdk' const exampleListCurrencies = async () => { - // ANCHOR: list-fiat-currencies - const fiatCurrencies = await listFiatCurrencies() - // ANCHOR_END: list-fiat-currencies + // ANCHOR: list-fiat-currencies + const fiatCurrencies = await listFiatCurrencies() + // ANCHOR_END: list-fiat-currencies } const exampleFetchRates = async () => { - // ANCHOR: fetch-fiat-rates - const fiatRates = await fetchFiatRates() - // ANCHOR_END: fetch-fiat-rates + // ANCHOR: fetch-fiat-rates + const fiatRates = await fetchFiatRates() + // ANCHOR_END: fetch-fiat-rates } const exampleListCurrenciesAndRates = async () => { - // ANCHOR: get-fiat-currencies-and-rates - // TODO - // ANCHOR_END: get-fiat-currencies-and-rates + // ANCHOR: get-fiat-currencies-and-rates + // TODO + // ANCHOR_END: get-fiat-currencies-and-rates } diff --git a/snippets/react-native/getting_started.ts b/snippets/react-native/getting_started.ts index 9f269a99..52a08dc4 100644 --- a/snippets/react-native/getting_started.ts +++ b/snippets/react-native/getting_started.ts @@ -1,47 +1,47 @@ import { - BreezEvent, - connect, - defaultConfig, - EnvironmentType, - mnemonicToSeed, - NodeConfig, - NodeConfigVariant, - nodeInfo -} from "@breeztech/react-native-breez-sdk" + type BreezEvent, + connect, + defaultConfig, + EnvironmentType, + mnemonicToSeed, + type NodeConfig, + NodeConfigVariant, + nodeInfo +} from '@breeztech/react-native-breez-sdk' const exampleGettingStarted = async () => { - // ANCHOR: init-sdk - // SDK events listener - const onBreezEvent = (e: BreezEvent) => { - console.log(`Received event ${e.type}`) - } + // ANCHOR: init-sdk + // SDK events listener + const onBreezEvent = (e: BreezEvent) => { + console.log(`Received event ${e.type}`) + } - // Create the default config - const seed = await mnemonicToSeed("") - const inviteCode = "" - const apiKey = "" - const nodeConfig: NodeConfig = { - type: NodeConfigVariant.GREENLIGHT, - config: { - inviteCode - } + // Create the default config + const seed = await mnemonicToSeed('') + const inviteCode = '' + const apiKey = '' + const nodeConfig: NodeConfig = { + type: NodeConfigVariant.GREENLIGHT, + config: { + inviteCode } + } - const config = await defaultConfig( - EnvironmentType.PRODUCTION, - apiKey, - nodeConfig - ) + const config = await defaultConfig( + EnvironmentType.PRODUCTION, + apiKey, + nodeConfig + ) - // Connect to the Breez SDK make it ready for use - await connect(config, seed, onBreezEvent) - // ANCHOR_END: init-sdk + // Connect to the Breez SDK make it ready for use + await connect(config, seed, onBreezEvent) + // ANCHOR_END: init-sdk } const exampleFetchNodeInfo = async () => { - // ANCHOR: fetch-balance - const nodeState = await nodeInfo() - const balanceLn = nodeState.channelsBalanceMsat - const balanceOnchain = nodeState.onchainBalanceMsat - // ANCHOR_END: fetch-balance + // ANCHOR: fetch-balance + const nodeState = await nodeInfo() + const balanceLn = nodeState.channelsBalanceMsat + const balanceOnchain = nodeState.onchainBalanceMsat + // ANCHOR_END: fetch-balance } diff --git a/snippets/react-native/list_payments.ts b/snippets/react-native/list_payments.ts index 9f36687e..b9bea08d 100644 --- a/snippets/react-native/list_payments.ts +++ b/snippets/react-native/list_payments.ts @@ -1,20 +1,20 @@ import { - listPayments, - PaymentTypeFilter -} from "@breeztech/react-native-breez-sdk" + listPayments, + PaymentTypeFilter +} from '@breeztech/react-native-breez-sdk' const exampleListPayments = async () => { - // ANCHOR: list-payments - const payments = listPayments({ filter: PaymentTypeFilter.ALL }) - // ANCHOR_END: list-payments + // ANCHOR: list-payments + const payments = listPayments({ filter: PaymentTypeFilter.ALL }) + // ANCHOR_END: list-payments } const exampleListPaymentsFiltered = async () => { - // ANCHOR: list-payments-filtered - const payments = listPayments({ - filter: PaymentTypeFilter.SENT, - fromTimestamp: 1696880000, - includeFailures: true - }) - // ANCHOR_END: list-payments-filtered + // ANCHOR: list-payments-filtered + const payments = listPayments({ + filter: PaymentTypeFilter.SENT, + fromTimestamp: 1696880000, + includeFailures: true + }) + // ANCHOR_END: list-payments-filtered } diff --git a/snippets/react-native/lnurl_auth.ts b/snippets/react-native/lnurl_auth.ts index a4d5bd2d..e6ed41a2 100644 --- a/snippets/react-native/lnurl_auth.ts +++ b/snippets/react-native/lnurl_auth.ts @@ -1,25 +1,25 @@ import { - InputTypeVariant, - lnurlAuth, - LnUrlCallbackStatusVariant, - parseInput -} from "@breeztech/react-native-breez-sdk" + InputTypeVariant, + lnurlAuth, + LnUrlCallbackStatusVariant, + parseInput +} from '@breeztech/react-native-breez-sdk' const exampleLnurlAuth = async () => { - // ANCHOR: lnurl-auth - // Endpoint can also be of the form: - // keyauth://domain.com/auth?key=val - const lnurlAuthUrl = - "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu" + // ANCHOR: lnurl-auth + // Endpoint can also be of the form: + // keyauth://domain.com/auth?key=val + const lnurlAuthUrl = + 'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu' - const input = await parseInput(lnurlAuthUrl) - if (input.type === InputTypeVariant.LN_URL_AUTH) { - const result = await lnurlAuth(input.data) - if (result.type === LnUrlCallbackStatusVariant.OK) { - console.log("Successfully authenticated") - } else { - console.log("Failed to authenticate") - } + const input = await parseInput(lnurlAuthUrl) + if (input.type === InputTypeVariant.LN_URL_AUTH) { + const result = await lnurlAuth(input.data) + if (result.type === LnUrlCallbackStatusVariant.OK) { + console.log('Successfully authenticated') + } else { + console.log('Failed to authenticate') } - // ANCHOR_END: lnurl-auth + } + // ANCHOR_END: lnurl-auth } diff --git a/snippets/react-native/lnurl_pay.ts b/snippets/react-native/lnurl_pay.ts index ad4210a4..ea959de1 100644 --- a/snippets/react-native/lnurl_pay.ts +++ b/snippets/react-native/lnurl_pay.ts @@ -1,24 +1,24 @@ import { - InputTypeVariant, - parseInput, - payLnurl -} from "@breeztech/react-native-breez-sdk" + InputTypeVariant, + parseInput, + payLnurl +} from '@breeztech/react-native-breez-sdk' const exampleLnurlPay = async () => { - // ANCHOR: lnurl-pay - // Endpoint can also be of the - // lnurlp://domain.com/lnurl-pay?key=val - // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf - const lnurlPayUrl = "lightning@address.com" + // ANCHOR: lnurl-pay + // Endpoint can also be of the + // lnurlp://domain.com/lnurl-pay?key=val + // lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf + const lnurlPayUrl = 'lightning@address.com' - const input = await parseInput(lnurlPayUrl) - if (input.type === InputTypeVariant.LN_URL_PAY) { - const amountMsat = input.data.minSendable - const lnUrlPayResult = await payLnurl({ - data: input.data, - amountMsat, - comment: "comment" - }) - } - // ANCHOR_END: lnurl-pay + const input = await parseInput(lnurlPayUrl) + if (input.type === InputTypeVariant.LN_URL_PAY) { + const amountMsat = input.data.minSendable + const lnUrlPayResult = await payLnurl({ + data: input.data, + amountMsat, + comment: 'comment' + }) + } + // ANCHOR_END: lnurl-pay } diff --git a/snippets/react-native/lnurl_withdraw.ts b/snippets/react-native/lnurl_withdraw.ts index 9e657700..52028d68 100644 --- a/snippets/react-native/lnurl_withdraw.ts +++ b/snippets/react-native/lnurl_withdraw.ts @@ -1,24 +1,24 @@ import { - InputTypeVariant, - parseInput, - withdrawLnurl -} from "@breeztech/react-native-breez-sdk" + InputTypeVariant, + parseInput, + withdrawLnurl +} from '@breeztech/react-native-breez-sdk' const exampleLnurlWithdraw = async () => { - // ANCHOR: lnurl-withdraw - // Endpoint can also be of the form: - // lnurlw://domain.com/lnurl-withdraw?key=val - const lnurlWithdrawUrl = - "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk" + // ANCHOR: lnurl-withdraw + // Endpoint can also be of the form: + // lnurlw://domain.com/lnurl-withdraw?key=val + const lnurlWithdrawUrl = + 'lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk' - const input = await parseInput(lnurlWithdrawUrl) - if (input.type === InputTypeVariant.LN_URL_WITHDRAW) { - const amountMsat = input.data.minWithdrawable - const lnUrlWithdrawResult = await withdrawLnurl({ - data: input.data, - amountMsat, - description: "comment" - }) - } - // ANCHOR_END: lnurl-withdraw + const input = await parseInput(lnurlWithdrawUrl) + if (input.type === InputTypeVariant.LN_URL_WITHDRAW) { + const amountMsat = input.data.minWithdrawable + const lnUrlWithdrawResult = await withdrawLnurl({ + data: input.data, + amountMsat, + description: 'comment' + }) + } + // ANCHOR_END: lnurl-withdraw } diff --git a/snippets/react-native/receive_onchain.ts b/snippets/react-native/receive_onchain.ts index 6fc4621b..37ad498d 100644 --- a/snippets/react-native/receive_onchain.ts +++ b/snippets/react-native/receive_onchain.ts @@ -1,52 +1,52 @@ import { - inProgressSwap, - listRefundables, - openChannelFee, - receiveOnchain, - refund -} from "@breeztech/react-native-breez-sdk" + inProgressSwap, + listRefundables, + openChannelFee, + receiveOnchain, + refund +} from '@breeztech/react-native-breez-sdk' const exampleReceiveOnchain = async () => { - // ANCHOR: generate-receive-onchain-address - const swapInfo = await receiveOnchain({}) + // ANCHOR: generate-receive-onchain-address + const swapInfo = await receiveOnchain({}) - // Send your funds to the below bitcoin address - const address = swapInfo.bitcoinAddress - // ANCHOR_END: generate-receive-onchain-address + // Send your funds to the below bitcoin address + const address = swapInfo.bitcoinAddress + // ANCHOR_END: generate-receive-onchain-address } const exampleInProgressSwap = async () => { - // ANCHOR: in-progress-swap - const swapInfo = await inProgressSwap() - // ANCHOR_END: in-progress-swap + // ANCHOR: in-progress-swap + const swapInfo = await inProgressSwap() + // ANCHOR_END: in-progress-swap } const exampleListRefundables = async () => { - // ANCHOR: list-refundables - const refundables = await listRefundables() - // ANCHOR_END: list-refundables + // ANCHOR: list-refundables + const refundables = await listRefundables() + // ANCHOR_END: list-refundables } const exampleRefund = async () => { - // ANCHOR: execute-refund - const refundables = await listRefundables() - const toAddress = "..." - const satPerVbyte = 5 - - const refundResponse = await refund({ - swapAddress: refundables[0].bitcoinAddress, - toAddress, - satPerVbyte - }) - // ANCHOR_END: execute-refund + // ANCHOR: execute-refund + const refundables = await listRefundables() + const toAddress = '...' + const satPerVbyte = 5 + + const refundResponse = await refund({ + swapAddress: refundables[0].bitcoinAddress, + toAddress, + satPerVbyte + }) + // ANCHOR_END: execute-refund } const exampleOpenChannelFee = async () => { - // ANCHOR: get-channel-opening-fees - const amountMsat = 10000 + // ANCHOR: get-channel-opening-fees + const amountMsat = 10000 - const openChannelFeeResponse = await openChannelFee({ - amountMsat: amountMsat - }) - // ANCHOR_END: get-channel-opening-fees + const openChannelFeeResponse = await openChannelFee({ + amountMsat + }) + // ANCHOR_END: get-channel-opening-fees } diff --git a/snippets/react-native/receive_payment.ts b/snippets/react-native/receive_payment.ts index 75c1010c..3675c2b9 100644 --- a/snippets/react-native/receive_payment.ts +++ b/snippets/react-native/receive_payment.ts @@ -1,10 +1,10 @@ -import { receivePayment } from "@breeztech/react-native-breez-sdk" +import { receivePayment } from '@breeztech/react-native-breez-sdk' const exampleReceiveLightningPayment = async () => { - // ANCHOR: receive-payment - const invoice = await receivePayment({ - amountMsat: 3000000, - description: "Invoice for 3000 sats" - }) - // ANCHOR_END: receive-payment + // ANCHOR: receive-payment + const invoice = await receivePayment({ + amountMsat: 3000000, + description: 'Invoice for 3000 sats' + }) + // ANCHOR_END: receive-payment } diff --git a/snippets/react-native/send_onchain.ts b/snippets/react-native/send_onchain.ts index 7a4a0d64..32205af6 100644 --- a/snippets/react-native/send_onchain.ts +++ b/snippets/react-native/send_onchain.ts @@ -1,49 +1,49 @@ import { - ReverseSwapPairInfo, - fetchReverseSwapFees, - inProgressReverseSwaps, - sendOnchain -} from "@breeztech/react-native-breez-sdk" + type ReverseSwapPairInfo, + fetchReverseSwapFees, + inProgressReverseSwaps, + sendOnchain +} from '@breeztech/react-native-breez-sdk' const exampleFetchReverseSwapFees = async () => { - // ANCHOR: estimate-current-reverse-swap-total-fees - const currentFees = await fetchReverseSwapFees({ sendAmountSat: 50000 }) + // ANCHOR: estimate-current-reverse-swap-total-fees + const currentFees = await fetchReverseSwapFees({ sendAmountSat: 50000 }) - console.log( + console.log( `Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}` - ) - // ANCHOR_END: estimate-current-reverse-swap-total-fees + ) + // ANCHOR_END: estimate-current-reverse-swap-total-fees } const exampleListCurrentFees = (currentFees: ReverseSwapPairInfo) => { - // ANCHOR: get-current-reverse-swap-min-max - console.log(`Minimum amount, in sats: ${currentFees.min}`) - console.log(`Maximum amount, in sats: ${currentFees.max}`) - // ANCHOR_END: get-current-reverse-swap-min-max + // ANCHOR: get-current-reverse-swap-min-max + console.log(`Minimum amount, in sats: ${currentFees.min}`) + console.log(`Maximum amount, in sats: ${currentFees.max}`) + // ANCHOR_END: get-current-reverse-swap-min-max } const exampleSendOnchain = async (currentFees: ReverseSwapPairInfo) => { - // ANCHOR: start-reverse-swap - const onchainRecipientAddress = "bc1.." - const amountSat = currentFees.min - const satPerVbyte = 5 + // ANCHOR: start-reverse-swap + const onchainRecipientAddress = 'bc1..' + const amountSat = currentFees.min + const satPerVbyte = 5 - const reverseSwapInfo = await sendOnchain({ - amountSat, - onchainRecipientAddress, - pairHash: currentFees.feesHash, - satPerVbyte - }) - // ANCHOR_END: start-reverse-swap + const reverseSwapInfo = await sendOnchain({ + amountSat, + onchainRecipientAddress, + pairHash: currentFees.feesHash, + satPerVbyte + }) + // ANCHOR_END: start-reverse-swap } const exampleInProgressReverseSwaps = async () => { - // ANCHOR: check-reverse-swaps-status - const swaps = await inProgressReverseSwaps() - for (const swap of swaps) { - console.log( + // ANCHOR: check-reverse-swaps-status + const swaps = await inProgressReverseSwaps() + for (const swap of swaps) { + console.log( `Reverse swap ${swap.id} in progress, status is ${swap.status}` - ) - } - // ANCHOR_END: check-reverse-swaps-status + ) + } + // ANCHOR_END: check-reverse-swaps-status } diff --git a/snippets/react-native/send_payment.ts b/snippets/react-native/send_payment.ts index 2a86cbe7..f99631d6 100644 --- a/snippets/react-native/send_payment.ts +++ b/snippets/react-native/send_payment.ts @@ -1,10 +1,10 @@ -import { sendPayment } from "@breeztech/react-native-breez-sdk" +import { sendPayment } from '@breeztech/react-native-breez-sdk' -const exampleSendLightningPayment = async () => { - // ANCHOR: send-payment - // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount. - // The amountMsat is required in case an amount is not specified in the bolt11 invoice'. - const amountMsat = 3000000 - const response = await sendPayment({bolt11, amountMsat}) - // ANCHOR_END: send-payment +const exampleSendLightningPayment = async (bolt11: string) => { + // ANCHOR: send-payment + // The `amountMsat` param is optional and should only passed if the bolt11 doesn't specify an amount. + // The amountMsat is required in case an amount is not specified in the bolt11 invoice'. + const amountMsat = 3000000 + const response = await sendPayment({ bolt11, amountMsat }) + // ANCHOR_END: send-payment } diff --git a/snippets/react-native/send_spontaneous_payment.ts b/snippets/react-native/send_spontaneous_payment.ts index de6999a3..bdfcbc24 100644 --- a/snippets/react-native/send_spontaneous_payment.ts +++ b/snippets/react-native/send_spontaneous_payment.ts @@ -1,12 +1,12 @@ -import { sendSpontaneousPayment } from "@breeztech/react-native-breez-sdk" +import { sendSpontaneousPayment } from '@breeztech/react-native-breez-sdk' const exampleSendSpontaneousPayment = async () => { - // ANCHOR: send-spontaneous-payment - const nodeId = "..." + // ANCHOR: send-spontaneous-payment + const nodeId = '...' - const sendPaymentResponse = await sendSpontaneousPayment({ - nodeId, - amountMsat: 3000000 - }) - // ANCHOR_END: send-spontaneous-payment + const sendPaymentResponse = await sendSpontaneousPayment({ + nodeId, + amountMsat: 3000000 + }) + // ANCHOR_END: send-spontaneous-payment } diff --git a/snippets/react-native/static_channel_backup.ts b/snippets/react-native/static_channel_backup.ts index 5f819ba8..90734ae2 100644 --- a/snippets/react-native/static_channel_backup.ts +++ b/snippets/react-native/static_channel_backup.ts @@ -1,7 +1,7 @@ -import { staticBackup } from "@breeztech/react-native-breez-sdk" +import { staticBackup } from '@breeztech/react-native-breez-sdk' const exampleStaticBackup = async () => { - // ANCHOR: static-channel-backup - let backupData = await staticBackup({ workingDir: "" }) - // ANCHOR_END: static-channel-backup + // ANCHOR: static-channel-backup + const backupData = await staticBackup({ workingDir: '' }) + // ANCHOR_END: static-channel-backup }