Skip to content

Commit

Permalink
add blockexplorer to ServiceInjector
Browse files Browse the repository at this point in the history
  • Loading branch information
ubbabeck committed Oct 18, 2023
1 parent ee18e49 commit 3ede527
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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';

Expand All @@ -18,11 +19,11 @@ class ClosedChannelPaymentDetailsWidget extends StatelessWidget {
Widget build(BuildContext context) {
final themeData = Theme.of(context);
final texts = context.texts();
return FutureBuilder<Config>(
future: Config.instance(),
builder: (BuildContext context, AsyncSnapshot<Config> snapshot) {
return FutureBuilder<String>(
future: ServiceInjector().blockexplorer,
builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
if (snapshot.hasData) {
final blockExplorer = snapshot.data!.defaultMempoolUrl;
final blockexplorer = snapshot.data!;
if (paymentMinutiae.status == sdk.PaymentStatus.Complete) {
return Column(
mainAxisSize: MainAxisSize.min,
Expand All @@ -36,7 +37,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!,
),
],
Expand All @@ -58,13 +59,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!,
),
]
Expand Down
29 changes: 20 additions & 9 deletions lib/routes/subswap/swap/widgets/inprogress_swap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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),
);
},
);
},
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,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(
Expand Down
12 changes: 12 additions & 0 deletions lib/services/injector.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -31,6 +32,7 @@ class ServiceInjector {
KeyChain? _keychain;
Client? _client;
Preferences? _preferences;
Config? _config;

factory ServiceInjector() {
return _injector ?? _singleton;
Expand Down Expand Up @@ -77,4 +79,14 @@ 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;
}
}

0 comments on commit 3ede527

Please sign in to comment.