mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-21 16:04:27 +01:00
Add Liquid SDK Event & Log stream handlers to example app (#305)
Update example app * Use defaultConfig on ConnectRequest * Update feesSat as non-null * Use payment & walletInfo streams from BreezLiquidSDK
This commit is contained in:
@@ -3,13 +3,14 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/connect/restore_page.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/home_page.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/breez_liquid_sdk.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/credentials_manager.dart';
|
||||
import 'package:flutter_breez_liquid_example/utils/config.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class ConnectPage extends StatefulWidget {
|
||||
final BreezLiquidSDK liquidSDK;
|
||||
final CredentialsManager credentialsManager;
|
||||
const ConnectPage({super.key, required this.credentialsManager});
|
||||
const ConnectPage({super.key, required this.liquidSDK, required this.credentialsManager});
|
||||
|
||||
@override
|
||||
State<ConnectPage> createState() => _ConnectPageState();
|
||||
@@ -84,7 +85,7 @@ class _ConnectPageState extends State<ConnectPage> {
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (BuildContext context) => HomePage(
|
||||
liquidSDK: liquidSDK,
|
||||
liquidSDK: widget.liquidSDK,
|
||||
credentialsManager: widget.credentialsManager,
|
||||
),
|
||||
),
|
||||
@@ -103,6 +104,6 @@ class _ConnectPageState extends State<ConnectPage> {
|
||||
config: config,
|
||||
mnemonic: mnemonic,
|
||||
);
|
||||
return await connect(req: req);
|
||||
return await widget.liquidSDK.connect(req: req);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/widgets/balance.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/widgets/bottom_app_bar.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/widgets/drawer.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/widgets/payment_list/payment_list.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/widgets/qr_scan_action_button.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/breez_liquid_sdk.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/credentials_manager.dart';
|
||||
|
||||
class HomePage extends StatefulWidget {
|
||||
final CredentialsManager credentialsManager;
|
||||
final BindingLiquidSdk liquidSDK;
|
||||
final BreezLiquidSDK liquidSDK;
|
||||
|
||||
const HomePage({super.key, required this.credentialsManager, required this.liquidSDK});
|
||||
|
||||
@@ -20,26 +20,6 @@ class HomePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _HomePageState extends State<HomePage> {
|
||||
Stream<GetInfoResponse> walletInfoStream() async* {
|
||||
debugPrint("Initialized walletInfoStream");
|
||||
yield await widget.liquidSDK.getInfo();
|
||||
while (true) {
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
yield await widget.liquidSDK.getInfo();
|
||||
debugPrint("Refreshed wallet info");
|
||||
}
|
||||
}
|
||||
|
||||
Stream<List<Payment>> paymentsStream() async* {
|
||||
debugPrint("Initialized paymentsStream");
|
||||
yield await widget.liquidSDK.listPayments();
|
||||
while (true) {
|
||||
await Future.delayed(const Duration(seconds: 10));
|
||||
yield await widget.liquidSDK.listPayments();
|
||||
debugPrint("Refreshed payments");
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
@@ -70,13 +50,13 @@ class _HomePageState extends State<HomePage> {
|
||||
Container(
|
||||
height: constraints.maxHeight * 0.3,
|
||||
color: Colors.white,
|
||||
child: Balance(walletInfoStream: walletInfoStream().asBroadcastStream()),
|
||||
child: Balance(walletInfoStream: widget.liquidSDK.walletInfoStream),
|
||||
),
|
||||
Container(
|
||||
height: constraints.maxHeight * 0.7,
|
||||
color: Colors.white,
|
||||
child: PaymentList(
|
||||
paymentsStream: paymentsStream().asBroadcastStream(),
|
||||
paymentsStream: widget.liquidSDK.paymentsStream,
|
||||
onRefresh: () async => await _sync(),
|
||||
),
|
||||
),
|
||||
@@ -84,12 +64,13 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
},
|
||||
),
|
||||
drawer: HomePageDrawer(liquidSDK: widget.liquidSDK, credentialsManager: widget.credentialsManager),
|
||||
floatingActionButton: QrActionButton(liquidSDK: widget.liquidSDK),
|
||||
drawer: HomePageDrawer(
|
||||
liquidSDK: widget.liquidSDK.wallet!, credentialsManager: widget.credentialsManager),
|
||||
floatingActionButton: QrActionButton(liquidSDK: widget.liquidSDK.wallet!),
|
||||
floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
|
||||
bottomNavigationBar: HomePageBottomAppBar(
|
||||
liquidSDK: widget.liquidSDK,
|
||||
paymentsStream: paymentsStream().asBroadcastStream(),
|
||||
liquidSDK: widget.liquidSDK.wallet!,
|
||||
paymentsStream: widget.liquidSDK.paymentsStream,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -98,7 +79,7 @@ class _HomePageState extends State<HomePage> {
|
||||
Future<void> _sync() async {
|
||||
try {
|
||||
debugPrint("Syncing wallet.");
|
||||
await widget.liquidSDK.sync();
|
||||
await widget.liquidSDK.wallet!.sync();
|
||||
debugPrint("Wallet synced!");
|
||||
} on Exception catch (e) {
|
||||
final errMsg = "Failed to sync wallet. $e";
|
||||
|
||||
@@ -49,7 +49,7 @@ class HomePageBottomAppBar extends StatelessWidget {
|
||||
context: context,
|
||||
builder: (context) => ReceivePaymentDialog(
|
||||
liquidSDK: liquidSDK,
|
||||
paymentsStream: paymentsStream.asBroadcastStream(),
|
||||
paymentsStream: paymentsStream,
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -62,7 +62,7 @@ class PaymentItem extends StatelessWidget {
|
||||
"${item.paymentType == PaymentType.send ? "-" : "+"}${item.amountSat} sats",
|
||||
style: Theme.of(context).textTheme.bodyLarge,
|
||||
),
|
||||
if (item.feesSat != null) ...[
|
||||
if (item.feesSat != BigInt.zero) ...[
|
||||
Text("FEE: ${item.paymentType == PaymentType.receive ? "-" : ""}${item.feesSat} sats"),
|
||||
]
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user