From 62f29769ec89d1796d7920eba899de6adf34b148 Mon Sep 17 00:00:00 2001 From: owczaro Date: Sun, 14 Nov 2021 14:40:26 +0100 Subject: [PATCH] Add datetime field to transactions --- .../account_history_response_item.dart | 9 ++ .../account_history_response_item.g.dart | 2 + lib/ui/home_page.dart | 139 ++++++++++-------- 3 files changed, 88 insertions(+), 62 deletions(-) diff --git a/lib/network/model/response/account_history_response_item.dart b/lib/network/model/response/account_history_response_item.dart index 0aee856..630769d 100644 --- a/lib/network/model/response/account_history_response_item.dart +++ b/lib/network/model/response/account_history_response_item.dart @@ -1,3 +1,4 @@ +import 'package:intl/intl.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:kalium_wallet_flutter/service_locator.dart'; @@ -25,6 +26,9 @@ class AccountHistoryResponseItem { @JsonKey(name: 'height', fromJson: _toInt) int height; + @JsonKey(name: 'local_timestamp', fromJson: _toInt) + int localTimestamp; + @JsonKey(ignore: true) bool confirmed; @@ -34,6 +38,7 @@ class AccountHistoryResponseItem { String amount, String hash, int height, + int localTimestamp, this.confirmed, }) { this.type = type; @@ -41,6 +46,7 @@ class AccountHistoryResponseItem { this.amount = amount; this.hash = hash; this.height = height; + this.localTimestamp = localTimestamp; } String getShortString() { @@ -58,6 +64,9 @@ class AccountHistoryResponseItem { return NumberUtil.getRawAsUsableString(amount); } + String get date => DateFormat().format(DateTime.fromMillisecondsSinceEpoch( + int.parse(localTimestamp.toString().padRight(13, '0')))); + factory AccountHistoryResponseItem.fromJson(Map json) => _$AccountHistoryResponseItemFromJson(json); Map toJson() => _$AccountHistoryResponseItemToJson(this); diff --git a/lib/network/model/response/account_history_response_item.g.dart b/lib/network/model/response/account_history_response_item.g.dart index 89292b7..a8434b0 100644 --- a/lib/network/model/response/account_history_response_item.g.dart +++ b/lib/network/model/response/account_history_response_item.g.dart @@ -14,6 +14,7 @@ AccountHistoryResponseItem _$AccountHistoryResponseItemFromJson( amount: json['amount'] as String, hash: json['hash'] as String, height: _toInt(json['height'] as String), + localTimestamp: _toInt(json['local_timestamp'] as String), ); } @@ -25,4 +26,5 @@ Map _$AccountHistoryResponseItemToJson( 'amount': instance.amount, 'hash': instance.hash, 'height': instance.height, + 'local_timestamp': instance.localTimestamp, }; diff --git a/lib/ui/home_page.dart b/lib/ui/home_page.dart index 1f11126..345387b 100644 --- a/lib/ui/home_page.dart +++ b/lib/ui/home_page.dart @@ -965,79 +965,94 @@ class _AppHomePageState extends State child: Padding( padding: const EdgeInsets.symmetric( vertical: 14.0, horizontal: 20.0), - child: Row( + child: Column( mainAxisAlignment: MainAxisAlignment.spaceBetween, - children: [ + children: [ + Padding( + padding: EdgeInsetsDirectional.only(bottom: 8.0), + child: Text( + item.date, + textAlign: TextAlign.end, + style: AppStyles.textStyleTransactionAddress(context), + ), + ), Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Row( + children: [ + Container( + margin: EdgeInsetsDirectional.only(end: 16.0), + child: Icon(icon, color: iconColor, size: 20)), + Container( + width: MediaQuery.of(context).size.width / 4, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + text, + textAlign: TextAlign.start, + style: AppStyles.textStyleTransactionType( + context), + ), + RichText( + textAlign: TextAlign.start, + text: TextSpan( + text: '', + children: [ + TextSpan( + text: item.getFormattedAmount(), + style: AppStyles + .textStyleTransactionAmount( + context), + ), + TextSpan( + text: " BAN", + style: AppStyles + .textStyleTransactionUnit( + context), + ), + ], + ), + ), + ], + ), + ), + ], + ), Container( - margin: EdgeInsetsDirectional.only(end: 16.0), - child: Icon(icon, color: iconColor, size: 20)), - Container( - width: MediaQuery.of(context).size.width / 4, + width: MediaQuery.of(context).size.width / 2.4, child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ + crossAxisAlignment: CrossAxisAlignment.end, + children: [ Text( - text, - textAlign: TextAlign.start, - style: - AppStyles.textStyleTransactionType(context), - ), - RichText( - textAlign: TextAlign.start, - text: TextSpan( - text: '', - children: [ - TextSpan( - text: item.getFormattedAmount(), - style: - AppStyles.textStyleTransactionAmount( - context), - ), - TextSpan( - text: " BAN", - style: AppStyles.textStyleTransactionUnit( - context), - ), - ], - ), + displayName, + textAlign: TextAlign.end, + style: AppStyles.textStyleTransactionAddress( + context), ), + + // TRANSACTION STATE TAG + (item.confirmed != null && !item.confirmed) || + (currentConfHeight != null && + currentConfHeight > -1 && + item.height != null && + item.height > currentConfHeight) + ? Container( + margin: EdgeInsetsDirectional.only( + top: 4, + ), + child: TransactionStateTag( + transactionState: + TransactionStateOptions + .UNCONFIRMED), + ) + : SizedBox() ], ), ), ], - ), - Container( - width: MediaQuery.of(context).size.width / 2.4, - child: Column( - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - Text( - displayName, - textAlign: TextAlign.end, - style: - AppStyles.textStyleTransactionAddress(context), - ), - - // TRANSACTION STATE TAG - (item.confirmed != null && !item.confirmed) || - (currentConfHeight != null && - currentConfHeight > -1 && - item.height != null && - item.height > currentConfHeight) - ? Container( - margin: EdgeInsetsDirectional.only( - top: 4, - ), - child: TransactionStateTag( - transactionState: - TransactionStateOptions.UNCONFIRMED), - ) - : SizedBox() - ], - ), - ), + ) ], ), ),