Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add delete network graph in settings #1744

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Feat: Add delete network graph in settings

## [1.7.2] - 2023-12-13

- Feat: Receive USD-P via Lightning
Expand Down
9 changes: 9 additions & 0 deletions mobile/lib/common/routes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/global_keys.dart';
import 'package:get_10101/common/settings/channel_screen.dart';
import 'package:get_10101/common/settings/delete_network_graph.dart';
import 'package:get_10101/common/status_screen.dart';
import 'package:get_10101/features/wallet/domain/destination.dart';
import 'package:get_10101/features/wallet/send/send_lightning_screen.dart';
Expand Down Expand Up @@ -117,6 +118,14 @@ GoRouter createRoutes() {
return const StatusScreen();
},
),
GoRoute(
path: DeleteNetworkGraphScreen.subRouteName,
// Use root navigator so the screen overlays the application shell
parentNavigatorKey: rootNavigatorKey,
builder: (BuildContext context, GoRouterState state) {
return const DeleteNetworkGraphScreen();
},
),
GoRoute(
path: CollabCloseScreen.subRouteName,
// Use root navigator so the screen overlays the application shell
Expand Down
113 changes: 113 additions & 0 deletions mobile/lib/common/settings/delete_network_graph.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/color.dart';
import 'package:get_10101/common/custom_app_bar.dart';
import 'package:get_10101/common/settings/settings_screen.dart';
import 'package:get_10101/common/snack_bar.dart';
import 'package:get_10101/ffi.dart' as rust;

class DeleteNetworkGraphScreen extends StatefulWidget {
static const route = "${SettingsScreen.route}/$subRouteName";
static const subRouteName = "deletenetworkgraph";

const DeleteNetworkGraphScreen({super.key});

@override
State<DeleteNetworkGraphScreen> createState() => _DeleteNetworkGraphScreenState();
}

class _DeleteNetworkGraphScreenState extends State<DeleteNetworkGraphScreen> {
bool deletedNetworkGraph = false;

@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
padding: const EdgeInsets.only(top: 20, left: 10, right: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const TenTenOneAppBar(title: "Delete Network Graph"),
Container(
margin: const EdgeInsets.all(10),
child: Column(
children: [
const SizedBox(
height: 20,
),
const Text(
"If you are having troubles sending a payment, it may help to delete and recreate you network graph.",
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w400),
),
const SizedBox(height: 30),
Visibility(
visible: deletedNetworkGraph,
replacement: OutlinedButton(
onPressed: () {
final messenger = ScaffoldMessenger.of(context);
try {
rust.api.deleteNetworkGraph();
setState(() => deletedNetworkGraph = true);
showSnackBar(messenger, "Successfully deleted network graph");
} catch (e) {
showSnackBar(
messenger, "Failed to delete network graph. Error: $e");
}
},
style: ButtonStyle(
fixedSize: MaterialStateProperty.all(const Size(double.infinity, 50)),
iconSize: MaterialStateProperty.all<double>(20.0),
elevation: MaterialStateProperty.all<double>(0),
// this reduces the shade
side: MaterialStateProperty.all(
const BorderSide(width: 1.0, color: tenTenOnePurple)),
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(
const EdgeInsets.fromLTRB(20, 12, 20, 12),
),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
backgroundColor: MaterialStateProperty.all<Color>(Colors.transparent),
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.delete),
SizedBox(width: 10),
Text("Delete Network Graph")
])),
child: Container(
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
decoration: BoxDecoration(
border: Border.all(color: tenTenOnePurple),
color: Colors.white,
borderRadius: BorderRadius.circular(10)),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Icon(
Icons.info_outline,
color: tenTenOnePurple.shade800,
size: 22,
),
const SizedBox(width: 10),
const Text(
"Restart the app to recreate your\nnetwork graph.",
softWrap: true,
overflow: TextOverflow.ellipsis,
maxLines: 4,
),
],
))),
],
),
)
],
),
),
),
);
}
}
6 changes: 6 additions & 0 deletions mobile/lib/common/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:get_10101/common/service_status_notifier.dart';
import 'package:get_10101/common/settings/app_info_screen.dart';
import 'package:get_10101/common/settings/channel_screen.dart';
import 'package:get_10101/common/settings/collab_close_screen.dart';
import 'package:get_10101/common/settings/delete_network_graph.dart';
import 'package:get_10101/common/settings/force_close_screen.dart';
import 'package:get_10101/common/settings/share_logs_screen.dart';
import 'package:get_10101/common/snack_bar.dart';
Expand Down Expand Up @@ -214,6 +215,11 @@ class _SettingsScreenState extends State<SettingsScreen> {
color: Colors.white, borderRadius: BorderRadius.circular(10)),
child: Column(
children: [
SettingsClickable(
icon: Icons.delete,
title: "Delete Network Graph",
callBackFunc: () =>
GoRouter.of(context).push(DeleteNetworkGraphScreen.route)),
SettingsClickable(
icon: Icons.close,
title: "Close Channel",
Expand Down
17 changes: 17 additions & 0 deletions mobile/native/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use crate::trade::order::api::Order;
use crate::trade::position;
use crate::trade::position::api::Position;
use crate::trade::users;
use anyhow::anyhow;
use anyhow::ensure;
use anyhow::Context;
use anyhow::Result;
Expand All @@ -30,6 +31,10 @@ use commons::OrderbookRequest;
use flutter_rust_bridge::frb;
use flutter_rust_bridge::StreamSink;
use flutter_rust_bridge::SyncReturn;
use lightning::util::persist::KVStore;
use lightning::util::persist::NETWORK_GRAPH_PERSISTENCE_KEY;
use lightning::util::persist::NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE;
use lightning::util::persist::NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE;
use ln_dlc_node::channel::UserChannelId;
use rust_decimal::prelude::FromPrimitive;
use rust_decimal::Decimal;
Expand Down Expand Up @@ -241,6 +246,18 @@ pub async fn get_positions() -> Result<Vec<Position>> {
Ok(positions)
}

pub fn delete_network_graph() -> Result<()> {
crate::state::get_storage()
.ln_storage
.remove(
NETWORK_GRAPH_PERSISTENCE_PRIMARY_NAMESPACE,
NETWORK_GRAPH_PERSISTENCE_SECONDARY_NAMESPACE,
NETWORK_GRAPH_PERSISTENCE_KEY,
false,
)
.map_err(|e| anyhow!("{e:#}"))
}

pub fn subscribe(stream: StreamSink<event::api::Event>) {
tracing::debug!("Subscribing flutter to event hub");
event::subscribe(FlutterSubscriber::new(stream))
Expand Down
Loading