Skip to content

Commit

Permalink
feat: add mempool.space link to on-chain transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Restioson committed Sep 8, 2023
1 parent 19b481e commit d430ea4
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 7 deletions.
54 changes: 48 additions & 6 deletions mobile/lib/features/wallet/wallet_history_item.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get_10101/bridge_generated/bridge_definitions.dart' as bridge;
import 'package:get_10101/common/amount_text.dart';
import 'package:get_10101/common/domain/model.dart';
import 'package:get_10101/common/middle_ellipsised_text.dart';
Expand All @@ -9,7 +10,9 @@ import 'package:get_10101/features/wallet/domain/payment_flow.dart';
import 'package:get_10101/features/wallet/domain/wallet_history.dart';
import 'package:get_10101/features/wallet/wallet_theme.dart';
import 'package:intl/intl.dart';
import 'package:provider/provider.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:url_launcher/url_launcher.dart';

abstract class WalletHistoryItem extends StatelessWidget {
abstract final WalletHistoryItemData data;
Expand Down Expand Up @@ -148,7 +151,7 @@ abstract class WalletHistoryItem extends StatelessWidget {
)),
HistoryDetail(
label: "When",
displayValue: timeago.format(data.timestamp),
displayWidget: Text(timeago.format(data.timestamp)),
value: dateFormat.format(data.timestamp)),
...getDetails(),
];
Expand Down Expand Up @@ -177,9 +180,9 @@ abstract class WalletHistoryItem extends StatelessWidget {
class HistoryDetail extends StatelessWidget {
final String label;
final String value;
final String? displayValue;
final Widget? displayWidget;

const HistoryDetail({super.key, required this.label, required this.value, this.displayValue});
const HistoryDetail({super.key, required this.label, required this.value, this.displayWidget});

@override
Widget build(BuildContext context) {
Expand All @@ -192,7 +195,7 @@ class HistoryDetail extends StatelessWidget {
),
Expanded(
child: Row(mainAxisAlignment: MainAxisAlignment.end, children: [
Expanded(child: MiddleEllipsisedText(displayValue ?? value)),
Expanded(child: displayWidget ?? MiddleEllipsisedText(value)),
IconButton(
padding: EdgeInsets.zero,
onPressed: () {
Expand All @@ -217,6 +220,41 @@ IconData iconForFlow(PaymentFlow flow) {
}
}

class TransactionIdText extends StatelessWidget {
final String txId;

const TransactionIdText(this.txId, {super.key});

@override
Widget build(BuildContext context) {
final bridge.Config config = context.read<bridge.Config>();

List<String> network = switch (config.network) {
"signet" => ["signet"],
"testnet" => ["testnet"],
_ => [],
};

return Row(
children: [
Expanded(child: MiddleEllipsisedText(txId)),
IconButton(
padding: EdgeInsets.zero,
onPressed: () => launchUrl(Uri(
scheme: 'https',
host: 'mempool.space',
pathSegments: [
...network,
'tx',
txId
],
)),
icon: const Icon(Icons.open_in_new, size: 18))
],
);
}
}

class LightningPaymentHistoryItem extends WalletHistoryItem {
@override
final LightningPaymentData data;
Expand Down Expand Up @@ -331,7 +369,11 @@ class JitChannelOpenFeeHistoryItem extends WalletHistoryItem {

@override
List<Widget> getDetails() {
return [HistoryDetail(label: "Funding transaction ID", value: data.txid)];
return [HistoryDetail(
label: "Funding transaction ID",
displayWidget: TransactionIdText(data.txid),
value: data.txid
)];
}

@override
Expand All @@ -358,7 +400,7 @@ class OnChainPaymentHistoryItem extends WalletHistoryItem {
@override
List<Widget> getDetails() {
final details = [
HistoryDetail(label: "Transaction ID", value: data.txid),
HistoryDetail(label: "Transaction ID", value: data.txid, displayWidget: TransactionIdText(data.txid)),
HistoryDetail(label: "Confirmations", value: data.confirmations.toString()),
Visibility(
visible: data.fee != null,
Expand Down
2 changes: 2 additions & 0 deletions mobile/macos/Flutter/GeneratedPluginRegistrant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import package_info_plus
import path_provider_foundation
import share_plus
import shared_preferences_foundation
import url_launcher_macos

func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
FLTFirebaseCorePlugin.register(with: registry.registrar(forPlugin: "FLTFirebaseCorePlugin"))
Expand All @@ -21,4 +22,5 @@ func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))
SharePlusMacosPlugin.register(with: registry.registrar(forPlugin: "SharePlusMacosPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
}
34 changes: 33 additions & 1 deletion mobile/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,30 @@ packages:
url: "https://pub.dev"
source: hosted
version: "2.2.2"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
sha256: "47e208a6711459d813ba18af120d9663c20bdf6985d6ad39fe165d2538378d27"
url: "https://pub.dev"
source: hosted
version: "6.1.14"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
sha256: b04af59516ab45762b2ca6da40fa830d72d0f6045cd97744450b73493fa76330
url: "https://pub.dev"
source: hosted
version: "6.1.0"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
sha256: "7c65021d5dee51813d652357bc65b8dd4a6177082a9966bc8ba6ee477baa795f"
url: "https://pub.dev"
source: hosted
version: "6.1.5"
url_launcher_linux:
dependency: transitive
description:
Expand All @@ -1149,6 +1173,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.5"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
sha256: b55486791f666e62e0e8ff825e58a023fd6b1f71c49926483f1128d3bbd8fe88
url: "https://pub.dev"
source: hosted
version: "3.0.7"
url_launcher_platform_interface:
dependency: transitive
description:
Expand Down Expand Up @@ -1311,4 +1343,4 @@ packages:
version: "2.1.1"
sdks:
dart: ">=3.1.0-185.0.dev <4.0.0"
flutter: ">=3.7.0"
flutter: ">=3.10.0"
1 change: 1 addition & 0 deletions mobile/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies:
firebase_core: ^2.15.0
firebase_messaging: ^14.6.5
flutter_local_notifications: ^15.1.0+1
url_launcher: ^6.1.14
dependency_overrides:
intl: ^0.18.0
dev_dependencies:
Expand Down

0 comments on commit d430ea4

Please sign in to comment.