mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-17 13:54:20 +01:00
Add React Native snippets
This commit is contained in:
49
snippets/react-native/send_onchain.ts
Normal file
49
snippets/react-native/send_onchain.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {
|
||||
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 })
|
||||
|
||||
console.log(
|
||||
`Total estimated fees for reverse swap: ${currentFees.totalEstimatedFees}`
|
||||
)
|
||||
// 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
|
||||
}
|
||||
|
||||
const exampleSendOnchain = async (currentFees: ReverseSwapPairInfo) => {
|
||||
// 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 exampleInProgressReverseSwaps = async () => {
|
||||
// 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
|
||||
}
|
||||
Reference in New Issue
Block a user