-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: update balance docs * feat: add payInvoiceSync to lightning service * feat: add createInvoice, payInvoice docs pages * feat: add timeout param to waitForReceive * feat: improve lightning docs * chore: add changesets
- Loading branch information
1 parent
9468ef5
commit 21f94f9
Showing
8 changed files
with
198 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@fedimint/core-web': patch | ||
--- | ||
|
||
Added optional timeout parameter to lightning.waitForReceive() | ||
Added lightning.waitForSend() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
docs/core/FedimintWallet/LightningService/createInvoice.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# Receive Lightning | ||
|
||
### `lightning.createInvoice()` | ||
|
||
Create a Lightning Invoice for a given amount. Returns a `CreateBolt11Response` object containing details about the created invoice. | ||
|
||
You can use `subscribeLnReceive` to track the payment status and `waitForReceive` to wait for the payment to be received. | ||
|
||
```ts twoslash | ||
// @esModuleInterop | ||
import { FedimintWallet } from '@fedimint/core-web' | ||
import type { LnReceiveState } from '@fedimint/core-web' | ||
|
||
const wallet = new FedimintWallet() | ||
wallet.open() | ||
|
||
const { operation_id, invoice } = await wallet.lightning.createInvoice( // [!code focus] | ||
10_000, // msats // [!code focus] | ||
'This is an invoice description', // [!code focus] | ||
) // [!code focus] | ||
|
||
console.log(operation_id) // operation id for the invoice | ||
console.log(invoice) // bolt11 invoice | ||
|
||
const unsubscribe = wallet.lightning.subscribeLnReceive( // [!code focus] | ||
operation_id, // [!code focus] | ||
(state: LnReceiveState) => console.log(state), // [!code focus] | ||
(error: string) => console.error(error), // [!code focus] | ||
) // [!code focus] | ||
|
||
// ...Cleanup Later | ||
unsubscribe() | ||
|
||
try { | ||
const timeoutMs = 10000 | ||
await wallet.lightning.waitForReceive(operation_id, timeoutMs) // [!code focus] | ||
console.log('Payment Received!') | ||
} catch (error) { | ||
console.error(error) // Timeout waiting for payment | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# Send Lightning | ||
|
||
### `lightning.payInvoiceSync(invoice: string)` | ||
|
||
Helper function to pay an invoice and resolve when the payment is confirmed or fails. | ||
|
||
```ts twoslash | ||
// @esModuleInterop | ||
import { FedimintWallet } from '@fedimint/core-web' | ||
|
||
const wallet = new FedimintWallet() | ||
wallet.open() | ||
|
||
const result = await wallet.lightning.payInvoiceSync( // [!code focus] | ||
'lnbc...', // bolt11 invoice // [!code focus] | ||
) // [!code focus] | ||
|
||
if (result.success) { | ||
console.log(result.data.preimage) // preimage of the settled payment | ||
console.log(result.data.feeMsats) // fee paid in msats | ||
} | ||
``` | ||
|
||
### `lightning.payInvoice(invoice: string)` | ||
|
||
Attempt to pay a lightning invoice. Returns an `OutgoingLightningPayment` object containing details about the in-flight payment. | ||
|
||
You can use `subscribeLnPay` to track the payment status and `waitForPay` to wait for the payment to be confirmed or fail. | ||
|
||
```ts twoslash | ||
// @esModuleInterop | ||
import { FedimintWallet } from '@fedimint/core-web' | ||
import type { LnPayState } from '@fedimint/core-web' | ||
|
||
const wallet = new FedimintWallet() | ||
wallet.open() | ||
|
||
const { contract_id, fee } = await wallet.lightning.payInvoice( // [!code focus] | ||
'lnbc...', // bolt11 invoice // [!code focus] | ||
) // [!code focus] | ||
|
||
console.log(contract_id) // in flight lightning payment id | ||
|
||
const unsubscribe = wallet.lightning.subscribeLnPay( // [!code focus] | ||
contract_id, // [!code focus] | ||
(state: LnPayState) => console.log(state), // State of the payment // [!code focus] | ||
(error: string) => console.error(error), // [!code focus] | ||
) | ||
|
||
// ...Cleanup Later | ||
unsubscribe() | ||
|
||
const result = await wallet.lightning.waitForPay(contract_id) // [!code focus] | ||
|
||
if (result.success) { | ||
console.log(result.data.preimage) // preimage of the settled payment | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters