mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2026-01-06 15:44:24 +01:00
Add config to flutter example (#274)
This commit is contained in:
@@ -4,6 +4,7 @@ import 'package:flutter_breez_liquid_example/routes/connect/connect_page.dart';
|
||||
import 'package:flutter_breez_liquid_example/routes/home/home_page.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/credentials_manager.dart';
|
||||
import 'package:flutter_breez_liquid_example/services/keychain.dart';
|
||||
import 'package:flutter_breez_liquid_example/utils/config.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
void main() async {
|
||||
@@ -20,13 +21,12 @@ void main() async {
|
||||
|
||||
Future<BindingLiquidSdk> reconnect({
|
||||
required String mnemonic,
|
||||
Network network = Network.liquid,
|
||||
Network network = Network.mainnet,
|
||||
}) async {
|
||||
final dataDir = await getApplicationDocumentsDirectory();
|
||||
final config = await getConfig(network: network);
|
||||
final req = ConnectRequest(
|
||||
config: config,
|
||||
mnemonic: mnemonic,
|
||||
dataDir: dataDir.path,
|
||||
network: network,
|
||||
);
|
||||
return await connect(req: req);
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ 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/credentials_manager.dart';
|
||||
import 'package:flutter_breez_liquid_example/utils/config.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class ConnectPage extends StatefulWidget {
|
||||
@@ -95,13 +96,12 @@ class _ConnectPageState extends State<ConnectPage> {
|
||||
|
||||
Future<BindingLiquidSdk> initializeWallet({
|
||||
required String mnemonic,
|
||||
Network network = Network.liquid,
|
||||
Network network = Network.mainnet,
|
||||
}) async {
|
||||
final dataDir = await getApplicationDocumentsDirectory();
|
||||
final config = await getConfig(network: network);
|
||||
final req = ConnectRequest(
|
||||
config: config,
|
||||
mnemonic: mnemonic,
|
||||
dataDir: dataDir.path,
|
||||
network: network,
|
||||
);
|
||||
return await connect(req: req);
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ class _SendPaymentDialogState extends State<SendPaymentDialog> {
|
||||
try {
|
||||
setState(() => paymentInProgress = true);
|
||||
SendPaymentResponse resp = await widget.liquidSdk.sendPayment(req: sendPaymentReq!);
|
||||
debugPrint("Paid ${resp.txid}");
|
||||
debugPrint("Paid ${resp.payment.txId}");
|
||||
if (context.mounted) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
33
packages/flutter/example/lib/utils/config.dart
Normal file
33
packages/flutter/example/lib/utils/config.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_breez_liquid/flutter_breez_liquid.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
Future<Config> getConfig({
|
||||
Network network = Network.mainnet,
|
||||
}) async {
|
||||
debugPrint("Getting default SDK config for network: $network");
|
||||
final defaultConf = defaultConfig(network: network);
|
||||
debugPrint("Getting SDK config");
|
||||
final workingDir = await getApplicationDocumentsDirectory();
|
||||
return defaultConf.copyWith(
|
||||
workingDir: workingDir.path,
|
||||
);
|
||||
}
|
||||
|
||||
extension ConfigCopyWith on Config {
|
||||
Config copyWith({
|
||||
String? boltzUrl,
|
||||
String? electrumUrl,
|
||||
String? workingDir,
|
||||
Network? network,
|
||||
BigInt? paymentTimeoutSec,
|
||||
}) {
|
||||
return Config(
|
||||
boltzUrl: boltzUrl ?? this.boltzUrl,
|
||||
electrumUrl: electrumUrl ?? this.electrumUrl,
|
||||
workingDir: workingDir ?? this.workingDir,
|
||||
network: network ?? this.network,
|
||||
paymentTimeoutSec: paymentTimeoutSec ?? this.paymentTimeoutSec,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user