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 4cd5545ea..664067b24 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 @@ -2,7 +2,7 @@ import 'package:breez_sdk/bridge_generated.dart' as sdk; import 'package:breez_translations/breez_translations_locales.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/utils/mempool_helper.dart'; import 'package:c_breez/widgets/loader.dart'; import 'package:flutter/material.dart'; @@ -18,8 +18,9 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { Widget build(BuildContext context) { final themeData = Theme.of(context); final texts = context.texts(); + final mempoolHelper = MempoolHelper(); return FutureBuilder( - future: ServiceInjector().blockexplorer, + future: mempoolHelper.blockexplorer, builder: (BuildContext context, AsyncSnapshot snapshot) { if (snapshot.hasData) { final blockexplorer = snapshot.data!; @@ -36,7 +37,8 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { if (paymentMinutiae.paymentType == sdk.PaymentType.ClosedChannel && paymentMinutiae.closingTxid != null) ...[ TxWidget( - txURL: "$blockexplorer/tx/${paymentMinutiae.closingTxid!}", + txURL: mempoolHelper.formatTransactionUrl( + txid: paymentMinutiae.closingTxid!, blockexplorer: blockexplorer), txID: paymentMinutiae.closingTxid!, ), ], @@ -58,13 +60,15 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget { ), if (paymentMinutiae.fundingTxid != null) ...[ TxWidget( - txURL: "$blockexplorer/tx/${paymentMinutiae.fundingTxid!}", + txURL: mempoolHelper.formatTransactionUrl( + txid: paymentMinutiae.fundingTxid!, blockexplorer: blockexplorer), txID: paymentMinutiae.fundingTxid!, ), ], if (paymentMinutiae.closingTxid != null) ...[ TxWidget( - txURL: "$blockexplorer/tx/${paymentMinutiae.closingTxid!}", + txURL: mempoolHelper.formatTransactionUrl( + txid: paymentMinutiae.closingTxid!, blockexplorer: blockexplorer), txID: paymentMinutiae.closingTxid!, ), ] diff --git a/lib/routes/subswap/swap/widgets/inprogress_swap.dart b/lib/routes/subswap/swap/widgets/inprogress_swap.dart index 36e93a7be..d8180de47 100644 --- a/lib/routes/subswap/swap/widgets/inprogress_swap.dart +++ b/lib/routes/subswap/swap/widgets/inprogress_swap.dart @@ -1,6 +1,7 @@ import 'package:breez_sdk/bridge_generated.dart'; import 'package:breez_translations/breez_translations_locales.dart'; import 'package:c_breez/services/injector.dart'; +import 'package:c_breez/utils/mempool_helper.dart'; import 'package:c_breez/widgets/flushbar.dart'; import 'package:c_breez/widgets/link_launcher.dart'; import 'package:c_breez/widgets/loader.dart'; @@ -49,9 +50,9 @@ class _TxLink extends StatelessWidget { @override Widget build(BuildContext context) { final text = context.texts(); - + final mempoolExplorer = MempoolHelper(); return FutureBuilder( - future: ServiceInjector().blockexplorer, + future: mempoolExplorer.blockexplorer, builder: (context, snapshot) { if (snapshot.connectionState != ConnectionState.done) { return const Loader(); @@ -60,7 +61,7 @@ class _TxLink extends StatelessWidget { return LinkLauncher( linkName: txid, - linkAddress: "$blockexplorer/tx/$txid", + linkAddress: mempoolExplorer.formatTransactionUrl(txid: txid, blockexplorer: blockexplorer), onCopy: () { ServiceInjector().device.setClipboardText(txid); showFlushbar( 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 4836b97ab..d49b78951 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,7 @@ import 'package:breez_sdk/bridge_generated.dart' as sdk; import 'package:breez_translations/breez_translations_locales.dart'; import 'package:c_breez/services/injector.dart'; +import 'package:c_breez/utils/mempool_helper.dart'; import 'package:c_breez/widgets/flushbar.dart'; import 'package:c_breez/widgets/link_launcher.dart'; import 'package:c_breez/widgets/loader.dart'; @@ -45,19 +46,20 @@ class _TxLink extends StatelessWidget { @override Widget build(BuildContext context) { final text = context.texts(); + final mempoolHelper = MempoolHelper(); return FutureBuilder( - future: ServiceInjector().blockexplorer, + future: MempoolHelper().blockexplorer, builder: (context, snapshot) { if (snapshot.connectionState != ConnectionState.done) { return const Loader(); } - final blockexplorer = snapshot.data!; + final transactionUrl = mempoolHelper.formatTransactionUrl(blockexplorer: snapshot.data!, txid: txid); return LinkLauncher( linkName: txid, - linkAddress: "$blockexplorer/tx/$txid", + linkAddress: transactionUrl, onCopy: () { ServiceInjector().device.setClipboardText(txid); showFlushbar( diff --git a/lib/services/injector.dart b/lib/services/injector.dart index 74890f97f..079d306c2 100644 --- a/lib/services/injector.dart +++ b/lib/services/injector.dart @@ -1,7 +1,6 @@ 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'; @@ -78,14 +77,4 @@ 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; - } } diff --git a/lib/utils/mempool_helper.dart b/lib/utils/mempool_helper.dart new file mode 100644 index 000000000..37953ba75 --- /dev/null +++ b/lib/utils/mempool_helper.dart @@ -0,0 +1,17 @@ +import 'package:c_breez/config.dart'; +import 'package:c_breez/services/injector.dart'; + +class MempoolHelper { + String formatTransactionUrl({required String txid, required String blockexplorer}) { + return "$blockexplorer/tx/$txid"; + } + + Future get blockexplorer async { + String? blockexplorer = await ServiceInjector().preferences.getMempoolSpaceUrl(); + if (blockexplorer == null) { + final config = await Config.instance(); + blockexplorer = config.defaultMempoolUrl; + } + return blockexplorer; + } +}