Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wallet history details #1054

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 69 additions & 8 deletions mobile/lib/features/wallet/wallet_history_item.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import 'package:flutter/material.dart';
import 'package:get_10101/common/amount_text.dart';
import 'package:get_10101/common/domain/model.dart';
import 'package:get_10101/features/wallet/domain/payment_flow.dart';
import 'package:get_10101/features/wallet/domain/wallet_history.dart';
import 'package:intl/intl.dart';
import 'package:timeago/timeago.dart' as timeago;

class WalletHistoryItem extends StatelessWidget {
final WalletHistoryItemData data;
static final dateFormat = DateFormat("yyyy-MM-dd HH:mm:ss");

const WalletHistoryItem({super.key, required this.data});

Expand Down Expand Up @@ -52,20 +55,17 @@ class WalletHistoryItem extends StatelessWidget {
String title = () {
switch (data.type) {
case WalletHistoryItemDataType.lightning:
return data.paymentHash ?? "";
case WalletHistoryItemDataType.onChain:
return data.txid ?? "";
return "Payment";
case WalletHistoryItemDataType.trade:
final orderId = data.orderId!.substring(0, 8);
switch (data.flow) {
case PaymentFlow.inbound:
return "Closed position with order $orderId";
return "Closed position";
case PaymentFlow.outbound:
return "Opened position with order $orderId";
return "Opened position";
}
case WalletHistoryItemDataType.orderMatchingFee:
final orderId = data.orderId!.substring(0, 8);
return "Matching fee for $orderId";
return "Matching fee";
}
}();

Expand Down Expand Up @@ -98,10 +98,13 @@ class WalletHistoryItem extends StatelessWidget {
}
}();

var amountFormatter = NumberFormat.compact(locale: "en_IN");
var amountFormatter = NumberFormat.compact(locale: "en_UK");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓Is the locale choice important and/or deliberate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a small chore fix which I could extract. It's just weird that we use en_IN, and since Indian English has got lakh and other ways to abbreviate numbers I thought it could be slightly dangerous too


return Card(
child: ListTile(
onTap: () async {
await showDialog(context: context, builder: (ctx) => showItemDetails(title, ctx));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓What does showDialog do and where does it come from? I'm curious because I think our code is just showItemDetails, so this must be some kind of pattern.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a flutter function to show the dialogue as a modal: https://api.flutter.dev/flutter/material/showDialog.html

},
leading: Stack(children: [
Container(
padding: const EdgeInsets.only(bottom: 20.0),
Expand Down Expand Up @@ -153,4 +156,62 @@ class WalletHistoryItem extends StatelessWidget {
)),
);
}

Widget showItemDetails(String title, BuildContext context) {
var [label, id] = () {
switch (data.type) {
case WalletHistoryItemDataType.lightning:
return ["Payment hash", data.paymentHash ?? ""];
case WalletHistoryItemDataType.onChain:
return ["Transaction id", data.txid ?? ""];
case WalletHistoryItemDataType.trade:
case WalletHistoryItemDataType.orderMatchingFee:
final orderId = data.orderId!.substring(0, 8);
return ["Order", orderId];
}
}();

int directionMultiplier = () {
switch (data.flow) {
case PaymentFlow.inbound:
return 1;
case PaymentFlow.outbound:
return -1;
}
}();

return AlertDialog(
title: Text(title),
content: Column(
mainAxisSize: MainAxisSize.min,
children: [
HistoryDetail(label: label, value: id),
HistoryDetail(
label: "Amount", value: formatSats(Amount(data.amount.sats * directionMultiplier))),
HistoryDetail(label: "Date and time", value: dateFormat.format(data.timestamp)),
],
),
);
}
}

class HistoryDetail extends StatelessWidget {
final String label;
final String value;

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

@override
Widget build(BuildContext context) {
return Padding(
padding: const EdgeInsets.symmetric(vertical: 8.0),
child: Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Text(label, style: const TextStyle(fontWeight: FontWeight.bold)),
),
Flexible(child: Text(value)),
]),
);
}
}