diff --git a/lib/bloc/account/account_bloc.dart b/lib/bloc/account/account_bloc.dart index c3eef2b95..d12a5f6de 100644 --- a/lib/bloc/account/account_bloc.dart +++ b/lib/bloc/account/account_bloc.dart @@ -296,6 +296,11 @@ class AccountBloc extends Cubit with HydratedMixin { return _credentialsManager.exportCredentials(); } + void exportStaticChannelBackup() async { + _log.v("exportStaticChannelBackup"); + return _credentialsManager.exportStaticChannelBackup(); + } + void recursiveFolderCopySync(String path1, String path2) { _log.v("recursiveFolderCopySync: $path1, $path2"); Directory dir1 = Directory(path1); diff --git a/lib/bloc/account/credentials_manager.dart b/lib/bloc/account/credentials_manager.dart index 90233e309..118fed138 100644 --- a/lib/bloc/account/credentials_manager.dart +++ b/lib/bloc/account/credentials_manager.dart @@ -1,8 +1,12 @@ import 'dart:io'; +import 'package:breez_sdk/bridge_generated.dart'; +import 'package:c_breez/services/injector.dart'; import 'package:c_breez/services/keychain.dart'; +import 'package:c_breez/widgets/flushbar.dart'; import 'package:fimber/fimber.dart'; import 'package:path_provider/path_provider.dart'; +import 'package:share_plus/share_plus.dart'; class CredentialsManager { final _log = FimberLog("CredentialsManager"); @@ -50,4 +54,27 @@ class CredentialsManager { throw e.toString(); } } + + void exportStaticChannelBackup() async { + try { + const name = "static_backup"; + final breezLib = ServiceInjector().breezSDK; + + Directory tempDir = await getTemporaryDirectory(); + + tempDir = await tempDir.createTemp(name); + final staticBakcup = + await breezLib.staticBackup(request: StaticBackupRequest(workingDir: tempDir.path)); + if (staticBakcup.backup != null) { + final backup = staticBakcup.backup!.join(); + String filePath = '${tempDir.path}/$name.db'; + File file = File(filePath); + await file.writeAsString(backup, flush: true); + final xFile = XFile(filePath); + Share.shareXFiles([xFile]); + } + } catch (e) { + rethrow; + } + } } diff --git a/lib/routes/dev/developers_view.dart b/lib/routes/dev/developers_view.dart index e918343eb..4921201b6 100644 --- a/lib/routes/dev/developers_view.dart +++ b/lib/routes/dev/developers_view.dart @@ -4,8 +4,10 @@ import 'package:archive/archive_io.dart'; import 'package:c_breez/bloc/account/account_bloc.dart'; import 'package:c_breez/logger.dart'; import 'package:c_breez/routes/dev/command_line_interface.dart'; +import 'package:c_breez/routes/dev/static_backup.dart'; import 'package:c_breez/routes/ui_test/ui_test_page.dart'; import 'package:c_breez/widgets/back_button.dart' as back_button; +import 'package:c_breez/widgets/flushbar.dart'; import 'package:c_breez/widgets/route.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; @@ -72,6 +74,8 @@ class DevelopersView extends StatelessWidget { icon: Icons.share, function: (_) => shareLog(), ), + Choice( + title: "Export static backup", icon: Icons.charging_station, function: _exportStaticBackup) ] .map((choice) => PopupMenuItem( value: choice, @@ -109,4 +113,10 @@ class DevelopersView extends StatelessWidget { final zipFile = XFile(zipFilePath); Share.shareXFiles([zipFile]); } + + void _exportStaticBackup(BuildContext context) async { + final accBloc = context.read(); + + accBloc.exportStaticChannelBackup(); + } }