-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
281 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import 'package:get_10101/common/model.dart'; | ||
|
||
class Payment { | ||
final String address; | ||
final int amount; | ||
final int fee; | ||
|
||
const Payment({required this.address, required this.amount, required this.fee}); | ||
} | ||
|
||
enum PaymentFlow { outbound, inbound } | ||
|
||
class OnChainPayment { | ||
final PaymentFlow flow; | ||
final Amount amount; | ||
final DateTime timestamp; | ||
final String txid; | ||
final int confirmations; | ||
final Amount? fee; | ||
|
||
const OnChainPayment( | ||
{required this.flow, | ||
required this.amount, | ||
required this.timestamp, | ||
required this.txid, | ||
required this.confirmations, | ||
this.fee}); | ||
|
||
factory OnChainPayment.fromJson(Map<String, dynamic> json) { | ||
return switch (json) { | ||
{ | ||
"flow": String flow, | ||
"amount": int amount, | ||
"timestamp": int timestamp, | ||
"txid": String txid, | ||
"confirmations": int confirmations, | ||
"fee": int fee | ||
} => | ||
OnChainPayment( | ||
flow: flow == 'inbound' ? PaymentFlow.inbound : PaymentFlow.outbound, | ||
amount: Amount(amount), | ||
timestamp: DateTime.fromMillisecondsSinceEpoch(timestamp * 1000), | ||
txid: txid, | ||
confirmations: confirmations, | ||
fee: Amount(fee)), | ||
_ => throw const FormatException('Failed to load history.'), | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:flutter/gestures.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/common/payment.dart'; | ||
import 'package:get_10101/wallet/onchain_payment_history_item.dart'; | ||
import 'package:get_10101/wallet/wallet_service.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
class HistoryScreen extends StatefulWidget { | ||
const HistoryScreen({super.key}); | ||
|
||
@override | ||
State<HistoryScreen> createState() => _HistoryScreenState(); | ||
} | ||
|
||
class _HistoryScreenState extends State<HistoryScreen> { | ||
List<OnChainPayment> history = []; | ||
|
||
@override | ||
void initState() { | ||
super.initState(); | ||
context | ||
.read<WalletService>() | ||
.getOnChainPaymentHistory() | ||
.then((value) => setState(() => history = value)); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Container( | ||
padding: const EdgeInsets.only(top: 25), | ||
child: Row( | ||
crossAxisAlignment: CrossAxisAlignment.start, | ||
children: [ | ||
Expanded( | ||
child: ScrollConfiguration( | ||
behavior: ScrollConfiguration.of(context).copyWith( | ||
dragDevices: PointerDeviceKind.values.toSet(), | ||
), | ||
child: SingleChildScrollView( | ||
physics: const AlwaysScrollableScrollPhysics(), | ||
child: Column( | ||
children: history.map((item) => OnChainPaymentHistoryItem(data: item)).toList(), | ||
), | ||
), | ||
), | ||
), | ||
], | ||
)); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
webapp/frontend/lib/wallet/onchain_payment_history_item.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:get_10101/common/payment.dart'; | ||
import 'package:intl/intl.dart'; | ||
import 'package:timeago/timeago.dart' as timeago; | ||
|
||
class OnChainPaymentHistoryItem extends StatelessWidget { | ||
final OnChainPayment data; | ||
|
||
const OnChainPaymentHistoryItem({super.key, required this.data}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
final statusIcon = switch (data.confirmations) { | ||
>= 3 => const Icon(Icons.check_circle, color: Colors.green, size: 18), | ||
_ => const Icon(Icons.pending, size: 18) | ||
}; | ||
|
||
String sign = data.flow == PaymentFlow.inbound ? "+" : "-"; | ||
Color color = data.flow == PaymentFlow.inbound ? Colors.green.shade600 : Colors.red.shade600; | ||
final flowIcon = data.flow == PaymentFlow.inbound ? Icons.arrow_downward : Icons.arrow_upward; | ||
|
||
var amountFormatter = NumberFormat.compact(locale: "en_UK"); | ||
|
||
return Column( | ||
children: [ | ||
Card( | ||
color: Colors.transparent, | ||
margin: const EdgeInsets.all(0), | ||
elevation: 0, | ||
child: ListTile( | ||
onTap: () async { | ||
// todo | ||
}, | ||
leading: Stack(children: [ | ||
Container( | ||
padding: const EdgeInsets.only(bottom: 20.0), | ||
child: SizedBox(height: 18, width: 18, child: statusIcon), | ||
), | ||
Container( | ||
padding: const EdgeInsets.only(left: 5.0, top: 10.0), | ||
child: SizedBox(height: 30, width: 30, child: Icon(flowIcon, size: 30))), | ||
]), | ||
title: RichText( | ||
overflow: TextOverflow.ellipsis, | ||
text: TextSpan( | ||
style: DefaultTextStyle.of(context).style, | ||
children: const <TextSpan>[ | ||
TextSpan(text: "Payment"), | ||
], | ||
), | ||
), | ||
subtitle: RichText( | ||
textWidthBasis: TextWidthBasis.longestLine, | ||
text: TextSpan(style: DefaultTextStyle.of(context).style, children: <TextSpan>[ | ||
TextSpan( | ||
text: timeago.format(data.timestamp), | ||
style: const TextStyle(color: Colors.grey)), | ||
])), | ||
trailing: Padding( | ||
padding: const EdgeInsets.only(top: 11.0, bottom: 5.0), | ||
child: Column( | ||
mainAxisAlignment: MainAxisAlignment.spaceBetween, | ||
crossAxisAlignment: CrossAxisAlignment.end, | ||
children: [ | ||
RichText( | ||
text: TextSpan( | ||
style: DefaultTextStyle.of(context).style, | ||
children: <InlineSpan>[ | ||
TextSpan( | ||
text: "$sign${amountFormatter.format(data.amount.sats)} sats", | ||
style: TextStyle( | ||
color: color, | ||
fontFamily: "Courier", | ||
fontSize: 14, | ||
fontWeight: FontWeight.bold)) | ||
]), | ||
), | ||
RichText( | ||
text: TextSpan( | ||
style: DefaultTextStyle.of(context).style, | ||
children: const <TextSpan>[ | ||
TextSpan(text: "on-chain", style: TextStyle(color: Colors.grey)), | ||
])), | ||
], | ||
), | ||
)), | ||
), | ||
const Divider(height: 0, thickness: 0.5, indent: 10, endIndent: 10) | ||
], | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters