Skip to content

Commit

Permalink
create mempool helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbabeck committed Oct 18, 2023
1 parent 00fda81 commit 3f0521f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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<String>(
future: ServiceInjector().blockexplorer,
future: mempoolHelper.blockexplorer,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
final blockexplorer = snapshot.data!;
Expand All @@ -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!,
),
],
Expand All @@ -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!,
),
]
Expand Down
7 changes: 4 additions & 3 deletions lib/routes/subswap/swap/widgets/inprogress_swap.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 0 additions & 11 deletions lib/services/injector.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -78,14 +77,4 @@ class ServiceInjector {
Preferences get preferences {
return _preferences ??= Preferences();
}

Future<String> get blockexplorer async {
String? blockexplorer = await _preferences?.getMempoolSpaceUrl();

if (blockexplorer == null) {
final config = await Config.instance();
blockexplorer = config.defaultMempoolUrl;
}
return blockexplorer;
}
}
17 changes: 17 additions & 0 deletions lib/utils/mempool_helper.dart
Original file line number Diff line number Diff line change
@@ -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<String> get blockexplorer async {
String? blockexplorer = await ServiceInjector().preferences.getMempoolSpaceUrl();
if (blockexplorer == null) {
final config = await Config.instance();
blockexplorer = config.defaultMempoolUrl;
}
return blockexplorer;
}
}

0 comments on commit 3f0521f

Please sign in to comment.