cake_wallet/lib/view_model/lightning_view_model.dart

53 lines
1.6 KiB
Dart
Raw Normal View History

2024-02-14 17:34:52 +00:00
import 'dart:async';
import 'package:breez_sdk/breez_sdk.dart';
import 'package:breez_sdk/bridge_generated.dart';
import 'package:mobx/mobx.dart';
part 'lightning_view_model.g.dart';
class LightningViewModel = LightningViewModelBase with _$LightningViewModel;
abstract class LightningViewModelBase with Store {
LightningViewModelBase() {}
// @observable
// ExecutionState state;
2024-02-14 18:21:37 +00:00
Future<List<String>> receiveOnchain() async {
final sdk = await BreezSDK();
ReceiveOnchainRequest req = const ReceiveOnchainRequest();
SwapInfo swapInfo = await sdk.receiveOnchain(req: req);
print(swapInfo.bitcoinAddress);
print("Minimum amount allowed to deposit in sats: ${swapInfo.minAllowedDeposit}");
print("Maximum amount allowed to deposit in sats: ${swapInfo.maxAllowedDeposit}");
return [
swapInfo.bitcoinAddress,
swapInfo.minAllowedDeposit.toString(),
swapInfo.maxAllowedDeposit.toString()
];
}
2024-02-14 17:34:52 +00:00
2024-02-14 18:21:37 +00:00
Future<String> createInvoice({required String amount, String? description}) async {
final sdk = await BreezSDK();
final req = ReceivePaymentRequest(
2024-02-16 20:37:08 +00:00
amountMsat: (double.parse(amount) * 100000000).round(),
2024-02-14 18:21:37 +00:00
description: description ?? '',
);
final res = await sdk.receivePayment(req: req);
return res.lnInvoice.bolt11;
}
2024-02-14 17:34:52 +00:00
2024-02-14 18:21:37 +00:00
Future<List<String>> invoiceLimits() async {
final sdk = await BreezSDK();
final req = ReceivePaymentRequest(
2024-02-26 18:01:39 +00:00
amountMsat: 3000000,
description: "limits",
2024-02-14 18:21:37 +00:00
);
2024-02-22 03:03:19 +00:00
final res = await sdk.receivePayment(req: req);
2024-02-26 18:01:39 +00:00
int min = (res.openingFeeMsat ?? 2500000);
int max = 1000000000;
return [min.toString(), max.toString()];
2024-02-14 17:34:52 +00:00
}
}