Add React Native snippets

This commit is contained in:
Ross Savage
2023-10-24 22:38:52 +02:00
parent cd3e85d92a
commit 07b55775cf
32 changed files with 4227 additions and 199 deletions

View File

@@ -50,11 +50,7 @@ try {
<section>
```typescript
try {
let buyBitcoinResponse = await buyBitcoin({provider: BuyBitcoinProvider.MOONPAY})
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/buy_btc.ts:buy-btc}}
```
</section>

View File

@@ -45,12 +45,7 @@ try {
<section>
```typescript
try {
const lspId = await lspId()
const lspInfo = await lspInfo()
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/connecting_lsp.ts:get-lsp-info}}
```
</section>
@@ -149,11 +144,7 @@ try {
<section>
```typescript
try {
await connectLsp(lspId)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/connecting_lsp.ts:connect-lsp}}
```
</section>

View File

@@ -27,11 +27,7 @@ try {
<section>
```typescript
try {
const fiatCurrencyList = await listFiatCurrencies()
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/fiat_currencies.ts:list-fiat-currencies}}
```
</section>
@@ -112,11 +108,7 @@ try {
<section>
```typescript
try {
const fiatRatesMap = await fetchFiatRates()
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/fiat_currencies.ts:fetch-fiat-rates}}
```
</section>
@@ -217,7 +209,7 @@ fun fiatCurrenciesAndRate(): Map<FiatCurrency, Rate> = try {
<section>
```typescript
// TODO
{{#include ../../snippets/react-native/fiat_currencies.ts:get-fiat-currencies-and-rates}}
```
</section>

View File

@@ -113,32 +113,7 @@ try {
<section>
```typescript
// SDK events listener
const onBreezEvent = (event: BreezEvent) => {
console.log(`received event ${event.type}`)
})
// Create the default config
const seed = await mnemonicToSeed("<mnemonic words>")
const inviteCode = "<invite code>"
const apiKey = "<api key>"
const nodeConfig : NodeConfig = {
type: NodeConfigVariant.GREENLIGHT,
config: {
inviteCode: inviteCode
}
}
let config = await defaultConfig(EnvironmentType.PRODUCTION, apiKey, nodeConfig)
// Customize the config object according to your needs
config.workingDir = "path to an existing directory"
try {
// Connect to the Breez SDK make it ready for use
const sdkServices = await connect(config, seed, onBreezEvent)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/getting_started.ts:init-sdk}}
```
</section>
@@ -332,13 +307,7 @@ try {
<section>
```typescript
try {
const nodeInfo = await nodeInfo();
const lnBalance = nodeInfo.channelsBalanceMsat;
const onchainBalance = nodeInfo.onchainBalanceMsat;
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/getting_started.ts:fetch-balance}}
```
</section>

View File

@@ -39,11 +39,7 @@ try {
<section>
```typescript
try {
const payments = await listPayments({filter: PaymentTypeFilter.ALL})
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/list_payments.ts:list-payments}}
```
</section>
@@ -143,15 +139,7 @@ try {
<section>
```typescript
try {
const payments = await listPayments({
filter: PaymentTypeFilter.SENT,
fromTimestamp: 1696880000,
includeFailures: true
})
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/list_payments.ts:list-payments-filtered}}
```
</section>

View File

@@ -61,23 +61,7 @@ try {
<section>
```typescript
// Endpoint can also be of the form:
// keyauth://domain.com/auth?key=val
let lnurlAuthUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttvdankjm3lw3skw0tvdankjm3xdvcn6vtp8q6n2dfsx5mrjwtrxdjnqvtzv56rzcnyv3jrxv3sxqmkyenrvv6kve3exv6nqdtyv43nqcmzvdsnvdrzx33rsenxx5unqc3cxgeqgntfgu"
try {
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 authanticated")
} else {
console.log("Failed to authenticate")
}
}
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/lnurl_auth.ts:lnurl-auth}}
```
</section>

View File

@@ -57,20 +57,7 @@ try {
<section>
```typescript
// Endpoint can also be of the form:
// lnurlp://domain.com/lnurl-pay?key=val
// lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4excttsv9un7um9wdekjmmw84jxywf5x43rvv35xgmr2enrxanr2cfcvsmnwe3jxcukvde48qukgdec89snwde3vfjxvepjxpjnjvtpxd3kvdnxx5crxwpjvyunsephsz36jf
let lnurlPayUrl = "lightning@address.com"
try {
const input = await parseInput(lnurlPayUrl)
if (input.type === InputTypeVariant.LN_URL_PAY) {
const amountSats = input.data.minSendable
const result = await payLnurl(input.data, amountSats, "comment")
}
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/lnurl_pay.ts:lnurl-pay}}
```
</section>

View File

@@ -59,19 +59,7 @@ try {
<section>
```typescript
// Endpoint can also be of the form:
// lnurlw://domain.com/lnurl-withdraw?key=val
let lnurlWithdrawUrl = "lnurl1dp68gurn8ghj7mr0vdskc6r0wd6z7mrww4exctthd96xserjv9mn7um9wdekjmmw843xxwpexdnxzen9vgunsvfexq6rvdecx93rgdmyxcuxverrvcursenpxvukzv3c8qunsdecx33nzwpnvg6ryc3hv93nzvecxgcxgwp3h33lxk"
try {
const input = await parseInput(lnurlWithdrawUrl)
if (input.type === InputTypeVariant.LN_URL_WITHDRAW) {
const amountSats = input.data.minWithdrawable
const result = await withdrawLnurl(input.data, amountSats, "comment")
}
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/lnurl_withdraw.ts:lnurl-withdraw}}
```
</section>

View File

@@ -47,14 +47,7 @@ try {
<section>
```typescript
try {
const swapInfo = await receiveOnchain({})
// Send your funds to the below bitcoin address
const address = swapInfo.bitcoinAddress
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/receive_onchain.ts:generate-receive-onchain-address}}
```
</section>
@@ -159,11 +152,7 @@ try {
<section>
```typescript
try {
const swapInfo = await inProgressSwap()
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/receive_onchain.ts:in-progress-swap}}
```
</section>
@@ -260,11 +249,7 @@ try {
<section>
```typescript
try {
const refundables = await listRefundables()
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/receive_onchain.ts:list-refundables}}
```
</section>
@@ -365,13 +350,7 @@ try {
<section>
```typescript
const destinationAddress = "..."
const satPerVbyte = <refund tx fee rate>
try {
const result = await refund(refundable.bitcoinAddress, destinationAddress, satPerVbyte)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/receive_onchain.ts:execute-refund}}
```
</section>
@@ -483,12 +462,7 @@ do {
<section>
```typescript
const amountMsat = <amount msat>
try {
const channelFees = await openChannelFee({amountMsat: amountMsat})
} catch (error) {
// handle error
}
{{#include ../../snippets/react-native/receive_onchain.ts:get-channel-opening-fees}}
```
</section>

View File

@@ -46,14 +46,7 @@ try {
<section>
```typescript
try {
const invoice = await receivePayment({
amountSats: 3000,
description: "Invoice for 3000 sats"
})
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/receive_payment.ts:receive-payment}}
```
</section>

View File

@@ -45,13 +45,7 @@ try {
<section>
```typescript
try {
const currentFees = await fetchReverseSwapFees({sendAmountSat: 50000})
console.log(`Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}`)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/send_onchain.ts:estimate-current-reverse-swap-total-fees}}
```
</section>
@@ -155,8 +149,7 @@ Log.v("Breez", "Maximum amount, in sats: ${fees.max}")
<section>
```typescript
console.log(`Minimum amount, in sats: ${currentFees.min}`)
console.log(`Maximum amount, in sats: ${currentFees.max}`)
{{#include ../../snippets/react-native/send_onchain.ts:get-current-reverse-swap-min-max}}
```
</section>
@@ -246,14 +239,7 @@ try {
<section>
```typescript
const destinationAddress = "bc1.."
const amountSat = currentFees.min
const satPerVbyte = <fee rate>
try {
const reverseSwapInfo = await sendOnchain(amountSat, destinationAddress, currentFees.feesHash, satPerVbyte)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/send_onchain.ts:start-reverse-swap}}
```
</section>
@@ -369,14 +355,7 @@ for (rs in sdk.inProgressReverseSwaps()) {
<section>
```typescript
try {
const swaps = await inProgressReverseSwaps()
for (const swap of swaps) {
console.log(`Reverse swap ${swap.id} in progress, status is ${swap.status}`)
}
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/send_onchain.ts:check-reverse-swaps-status}}
```
</section>

View File

@@ -43,12 +43,7 @@ try {
<section>
```typescript
const bolt11 = "..."
try {
const payment = await sendPayment(bolt11, 3000)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/send_payment.ts:send-payment}}
```
</section>

View File

@@ -41,12 +41,7 @@ try {
<section>
```typescript
const nodeId = "..."
try {
const payment = await sendSpontaneousPayment(nodeId, 3000)
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/send_spontaneous_payment.ts:send-spontaneous-payment}}
```
</section>

View File

@@ -47,11 +47,7 @@ try {
<section>
```typescript
try {
let backupData = await staticBackup({workingDir: "<working directory>"})
} catch (error) {
console.log(error)
}
{{#include ../../snippets/react-native/static_channel_backup.ts:static-channel-backup}}
```
</section>