From 00fda81d33885901f794943f9709ffe95ac9bd0c Mon Sep 17 00:00:00 2001 From: ruben beck Date: Wed, 18 Oct 2023 11:30:24 +0200 Subject: [PATCH] add blockexplorer to ServiceInjector --- .../closed_channel_payment_details.dart | 16 +++++----- .../subswap/swap/widgets/inprogress_swap.dart | 29 +++++++++++++------ .../in_progress/reverse_swap_in_progress.dart | 7 ++--- lib/services/injector.dart | 11 +++++++ 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/lib/routes/home/widgets/payments_list/dialog/closed_channel_payment_details.dart b/lib/routes/home/widgets/payments_list/dialog/closed_channel_payment_details.dart index 7c9d3bd60..4cd5545ea 100644 --- a/lib/routes/home/widgets/payments_list/dialog/closed_channel_payment_details.dart +++ b/lib/routes/home/widgets/payments_list/dialog/closed_channel_payment_details.dart @@ -1,8 +1,8 @@ import 'package:breez_sdk/bridge_generated.dart' as sdk; import 'package:breez_translations/breez_translations_locales.dart'; -import 'package:c_breez/config.dart'; import 'package:c_breez/models/payment_minutiae.dart'; import 'package:c_breez/routes/home/widgets/payments_list/dialog/tx_widget.dart'; +import 'package:c_breez/services/injector.dart'; import 'package:c_breez/widgets/loader.dart'; import 'package:flutter/material.dart'; @@ -18,11 +18,11 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { Widget build(BuildContext context) { final themeData = Theme.of(context); final texts = context.texts(); - return FutureBuilder( - future: Config.instance(), - builder: (BuildContext context, AsyncSnapshot snapshot) { + return FutureBuilder( + future: ServiceInjector().blockexplorer, + builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { - final blockExplorer = snapshot.data!.defaultMempoolUrl; + final blockexplorer = snapshot.data!; if (paymentMinutiae.status == sdk.PaymentStatus.Complete) { return Column( mainAxisSize: MainAxisSize.min, @@ -36,7 +36,7 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { if (paymentMinutiae.paymentType == sdk.PaymentType.ClosedChannel && paymentMinutiae.closingTxid != null) ...[ TxWidget( - txURL: "$blockExplorer/tx/${paymentMinutiae.closingTxid!}", + txURL: "$blockexplorer/tx/${paymentMinutiae.closingTxid!}", txID: paymentMinutiae.closingTxid!, ), ], @@ -58,13 +58,13 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { ), if (paymentMinutiae.fundingTxid != null) ...[ TxWidget( - txURL: "$blockExplorer/tx/${paymentMinutiae.fundingTxid!}", + txURL: "$blockexplorer/tx/${paymentMinutiae.fundingTxid!}", txID: paymentMinutiae.fundingTxid!, ), ], if (paymentMinutiae.closingTxid != null) ...[ TxWidget( - txURL: "$blockExplorer/tx/${paymentMinutiae.closingTxid!}", + txURL: "$blockexplorer/tx/${paymentMinutiae.closingTxid!}", txID: paymentMinutiae.closingTxid!, ), ] diff --git a/lib/routes/subswap/swap/widgets/inprogress_swap.dart b/lib/routes/subswap/swap/widgets/inprogress_swap.dart index 8d7debd01..36e93a7be 100644 --- a/lib/routes/subswap/swap/widgets/inprogress_swap.dart +++ b/lib/routes/subswap/swap/widgets/inprogress_swap.dart @@ -3,6 +3,7 @@ import 'package:breez_translations/breez_translations_locales.dart'; import 'package:c_breez/services/injector.dart'; import 'package:c_breez/widgets/flushbar.dart'; import 'package:c_breez/widgets/link_launcher.dart'; +import 'package:c_breez/widgets/loader.dart'; import 'package:flutter/material.dart'; class SwapInprogress extends StatelessWidget { @@ -49,15 +50,25 @@ class _TxLink extends StatelessWidget { Widget build(BuildContext context) { final text = context.texts(); - return LinkLauncher( - linkName: txid, - linkAddress: "https://blockstream.info/tx/$txid", - onCopy: () { - ServiceInjector().device.setClipboardText(txid); - showFlushbar( - context, - message: text.add_funds_transaction_id_copied, - duration: const Duration(seconds: 3), + return FutureBuilder( + future: ServiceInjector().blockexplorer, + builder: (context, snapshot) { + if (snapshot.connectionState != ConnectionState.done) { + return const Loader(); + } + final blockexplorer = snapshot.data!; + + return LinkLauncher( + linkName: txid, + linkAddress: "$blockexplorer/tx/$txid", + onCopy: () { + ServiceInjector().device.setClipboardText(txid); + showFlushbar( + context, + message: text.add_funds_transaction_id_copied, + duration: const Duration(seconds: 3), + ); + }, ); }, ); diff --git a/lib/routes/withdraw/reverse_swap/in_progress/reverse_swap_in_progress.dart b/lib/routes/withdraw/reverse_swap/in_progress/reverse_swap_in_progress.dart index 3f5f9e3a6..4836b97ab 100644 --- a/lib/routes/withdraw/reverse_swap/in_progress/reverse_swap_in_progress.dart +++ b/lib/routes/withdraw/reverse_swap/in_progress/reverse_swap_in_progress.dart @@ -1,6 +1,5 @@ import 'package:breez_sdk/bridge_generated.dart' as sdk; import 'package:breez_translations/breez_translations_locales.dart'; -import 'package:c_breez/config.dart'; import 'package:c_breez/services/injector.dart'; import 'package:c_breez/widgets/flushbar.dart'; import 'package:c_breez/widgets/link_launcher.dart'; @@ -48,17 +47,17 @@ class _TxLink extends StatelessWidget { final text = context.texts(); return FutureBuilder( - future: Config.instance(), + future: ServiceInjector().blockexplorer, builder: (context, snapshot) { if (snapshot.connectionState != ConnectionState.done) { return const Loader(); } - final blockExplorer = snapshot.data!.defaultMempoolUrl; + final blockexplorer = snapshot.data!; return LinkLauncher( linkName: txid, - linkAddress: "$blockExplorer/tx/$txid", + linkAddress: "$blockexplorer/tx/$txid", onCopy: () { ServiceInjector().device.setClipboardText(txid); showFlushbar( diff --git a/lib/services/injector.dart b/lib/services/injector.dart index 079d306c2..74890f97f 100644 --- a/lib/services/injector.dart +++ b/lib/services/injector.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:breez_sdk/breez_sdk.dart'; +import 'package:c_breez/config.dart'; import 'package:c_breez/services/breez_server.dart'; import 'package:c_breez/services/deep_links.dart'; import 'package:c_breez/services/device.dart'; @@ -77,4 +78,14 @@ class ServiceInjector { Preferences get preferences { return _preferences ??= Preferences(); } + + Future get blockexplorer async { + String? blockexplorer = await _preferences?.getMempoolSpaceUrl(); + + if (blockexplorer == null) { + final config = await Config.instance(); + blockexplorer = config.defaultMempoolUrl; + } + return blockexplorer; + } }