mirror of
https://github.com/aljazceru/breez-sdk-docs.git
synced 2025-12-18 14:24:19 +01:00
Merge remote-tracking branch 'origin/dart-examples-lsp-fiat-fee' into python-examples
This commit is contained in:
@@ -290,12 +290,30 @@ result, err := sdkServices.Refund(refundable.BitcoinAddress, destinationAddress,
|
||||
<div slot="title">Dart</div>
|
||||
<section>
|
||||
|
||||
To calculate fees, you'll need to detect if channel opening fees are needed first and then calculate the fee for the amount you'll be receiving.
|
||||
|
||||
```dart
|
||||
int calculateChannelOpeningFee(int amountSats) {
|
||||
int calculateChannelOpeningFee(int amountSats) async {
|
||||
bool isChannelOpeningFeeNeeded = await isChannelOpeningFeeNeeded(amountSats);
|
||||
return isChannelOpeningFeeNeeded ? calculateFeesForAmount(amountSats) : 0;
|
||||
}
|
||||
```
|
||||
|
||||
How to detect if open channel fees are needed.
|
||||
|
||||
```dart
|
||||
bool isChannelOpeningFeeNeeded(int amountSats) async {
|
||||
NodeState? nodeState = await getNodeState();
|
||||
int liquidity = nodeState.inboundLiquidityMsats ~/ 1000;
|
||||
// Check if we need to open channel
|
||||
if(amountSats >= liquidity) {
|
||||
return amountSats >= liquidity;
|
||||
}
|
||||
```
|
||||
|
||||
How to calculate the fee for a specific amount.
|
||||
|
||||
```dart
|
||||
int calculateFeesForAmount(int amountSats) async {
|
||||
// We need to open channel so we are calculating the fees for the LSP
|
||||
String? lspId = await getLspId();
|
||||
LSPInformation? lspInformation = await fetchLspInfo(lspId!);
|
||||
@@ -309,7 +327,6 @@ int calculateChannelOpeningFee(int amountSats) {
|
||||
int channelFeesMsat = (amountSats * setupFee ~/ 100);
|
||||
// If the proportional fee is smaller than minimum fees, minimum fees is selected.
|
||||
return max(channelFeesMsat, minFee);
|
||||
}
|
||||
}
|
||||
```
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user