mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-19 14:04:22 +01:00
feat: add `PrepareSendRequest` object fix: rename to `claim_tx_feerate` fix: fix reverse submarine test feat: improve prepare_send and prepare_receive interfaces fix: use v2 to broadcast lowball tx feat: finalize prepare_send and prepare_receive feat: remove manual BTC pair from response fix: remove `pair_hash` from PrepareReceive rebasing updating Cargo.lock fix: update lbtc pair method names fixing bindings fix: re-add uniffi_macros add comment to elements dependency fix: switch back to v1 fee calculation fix: revert to v1 pair hash fix: simplify migrations fix: rename `FeesExpired` to `InvalidOrExpiredFees` Log error when list_ongoing_swaps() fails Log swap ID when list_ongoing_swaps() succeeds Migrations: add missing ongoing_receive_swaps field Clarify swap type (reverse vs submarine) in logs
187 lines
6.8 KiB
Dart
187 lines
6.8 KiB
Dart
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
await initialize();
|
|
await initializeWallet();
|
|
runApp(const MyApp());
|
|
}
|
|
|
|
const String mnemonic = "";
|
|
|
|
Future initializeWallet() async {
|
|
assert(mnemonic.isNotEmpty, "Please enter your mnemonic.");
|
|
final dataDir = await getApplicationDocumentsDirectory();
|
|
final req = ConnectRequest(
|
|
mnemonic: mnemonic,
|
|
dataDir: dataDir.path,
|
|
network: Network.liquid,
|
|
);
|
|
await connect(req: req);
|
|
}
|
|
|
|
class MyApp extends StatefulWidget {
|
|
const MyApp({super.key});
|
|
|
|
@override
|
|
State<MyApp> createState() => _MyAppState();
|
|
}
|
|
|
|
class _MyAppState extends State<MyApp> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return MaterialApp(
|
|
home: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('Breez Liquid Native Packages'),
|
|
),
|
|
body: Padding(
|
|
padding: const EdgeInsets.all(10),
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
children: [
|
|
FutureBuilder<GetInfoResponse>(
|
|
future: getInfo(
|
|
req: const GetInfoRequest(
|
|
withScan: true,
|
|
),
|
|
),
|
|
initialData: null,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return Text('Error: ${snapshot.error}');
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
return const Text('Loading...');
|
|
}
|
|
|
|
if (snapshot.requireData.balanceSat.isNaN) {
|
|
return const Text('No balance.');
|
|
}
|
|
final walletInfo = snapshot.data!;
|
|
|
|
return Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Text(
|
|
"Balance",
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(vertical: 32.0),
|
|
child: Center(
|
|
child: Text(
|
|
"${walletInfo.balanceSat} sats",
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text(
|
|
"pubKey: ${walletInfo.pubkey}",
|
|
style: Theme.of(context).textTheme.bodySmall,
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
const SizedBox(height: 16.0),
|
|
FutureBuilder<PrepareReceiveResponse>(
|
|
future: prepareReceivePayment(
|
|
req: const PrepareReceiveRequest(payerAmountSat: 1000),
|
|
),
|
|
initialData: null,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return Text('Error: ${snapshot.error}');
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
return const Text('Loading...');
|
|
}
|
|
|
|
final prepareReceiveResponse = snapshot.data!;
|
|
|
|
return Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16.0),
|
|
child: Text(
|
|
"Preparing a receive payment of 1000 sats",
|
|
style: Theme.of(context).textTheme.headlineSmall,
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text(
|
|
"Payer Amount: ${prepareReceiveResponse.payerAmountSat} (in sats)"),
|
|
),
|
|
ListTile(
|
|
title: Text(
|
|
"Fees: ${prepareReceiveResponse.feesSat} (in sats)"),
|
|
),
|
|
const SizedBox(height: 16.0),
|
|
FutureBuilder<ReceivePaymentResponse>(
|
|
future: receivePayment(req: prepareReceiveResponse),
|
|
initialData: null,
|
|
builder: (context, snapshot) {
|
|
if (snapshot.hasError) {
|
|
return Text('Error: ${snapshot.error}');
|
|
}
|
|
|
|
if (!snapshot.hasData) {
|
|
return const Text('Loading...');
|
|
}
|
|
|
|
if (snapshot.requireData.id.isEmpty) {
|
|
return const Text('Missing invoice id');
|
|
}
|
|
|
|
final receivePaymentResponse = snapshot.data!;
|
|
debugPrint(
|
|
"Invoice ID: ${receivePaymentResponse.id}");
|
|
debugPrint(
|
|
"Invoice: ${receivePaymentResponse.invoice}");
|
|
|
|
return Column(
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
horizontal: 16.0),
|
|
child: Text(
|
|
"Invoice for receive payment of 1000 sats",
|
|
style: Theme.of(context)
|
|
.textTheme
|
|
.headlineSmall,
|
|
),
|
|
),
|
|
ListTile(
|
|
title: Text(
|
|
"Invoice ID: ${receivePaymentResponse.id}"),
|
|
),
|
|
ListTile(
|
|
title: Text(
|
|
"Invoice: ${receivePaymentResponse.invoice}"),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
}
|