refacto: getDateDelimiter() logic
This commit is contained in:
parent
21a56bbc96
commit
5b04c5b19e
|
@ -254,59 +254,51 @@ Future<QueryResult> _execQuery(
|
||||||
}
|
}
|
||||||
|
|
||||||
Map computeHistoryView(repository, String address) {
|
Map computeHistoryView(repository, String address) {
|
||||||
bool isTody = false;
|
|
||||||
bool isYesterday = false;
|
|
||||||
bool isThisWeek = false;
|
|
||||||
bool isMigrationTime = false;
|
|
||||||
bool isChangeOwnerkeyTime = false;
|
|
||||||
String? dateDelimiter;
|
|
||||||
DateTime now = DateTime.now();
|
|
||||||
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
final bool isUdUnit = configBox.get('isUdUnit') ?? false;
|
||||||
|
|
||||||
late double amount;
|
late double amount;
|
||||||
late String finalAmount;
|
late String finalAmount;
|
||||||
DateTime date = repository[0];
|
final DateTime date = repository[0];
|
||||||
String dateForm;
|
|
||||||
bool isDelimiter = true;
|
|
||||||
|
|
||||||
if ({4, 10, 11, 12}.contains(date.month)) {
|
final dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, {
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 3)}";
|
1,
|
||||||
} else if ({1, 2, 7, 9}.contains(date.month)) {
|
2,
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]!.substring(0, 4)}";
|
7,
|
||||||
} else {
|
9
|
||||||
dateForm = "${date.day} ${monthsInYear[date.month]}";
|
}.contains(date.month) ? 4 : 3)}";
|
||||||
|
|
||||||
|
DateTime normalizeDate(DateTime inputDate) {
|
||||||
|
return DateTime(inputDate.year, inputDate.month, inputDate.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
final transactionDate = DateTime(date.year, date.month, date.day);
|
String getDateDelimiter() {
|
||||||
final todayDate = DateTime(now.year, now.month, now.day);
|
DateTime now = DateTime.now();
|
||||||
final yesterdayDate = DateTime(now.year, now.month, now.day - 1);
|
final transactionDate = normalizeDate(date.toLocal());
|
||||||
|
final todayDate = normalizeDate(now);
|
||||||
|
final yesterdayDate = normalizeDate(now.subtract(const Duration(days: 1)));
|
||||||
|
final isSameWeek = weekNumber(transactionDate) == weekNumber(now) &&
|
||||||
|
transactionDate.year == now.year;
|
||||||
|
final isTodayOrYesterday =
|
||||||
|
transactionDate == todayDate || transactionDate == yesterdayDate;
|
||||||
|
|
||||||
if (transactionDate == todayDate && !isTody) {
|
if (transactionDate == todayDate) {
|
||||||
dateDelimiter = "today".tr();
|
return "today".tr();
|
||||||
isTody = true;
|
} else if (transactionDate == yesterdayDate) {
|
||||||
} else if (transactionDate == yesterdayDate && !isYesterday) {
|
return "yesterday".tr();
|
||||||
dateDelimiter = "yesterday".tr();
|
} else if (isSameWeek && !isTodayOrYesterday) {
|
||||||
isYesterday = true;
|
return "thisWeek".tr();
|
||||||
} else if (weekNumber(date) == weekNumber(now) &&
|
} else if (!isSameWeek && !isTodayOrYesterday) {
|
||||||
date.year == now.year &&
|
if (transactionDate.year == now.year) {
|
||||||
transactionDate != yesterdayDate &&
|
return monthsInYear[transactionDate.month]!;
|
||||||
transactionDate != todayDate &&
|
} else {
|
||||||
!isThisWeek) {
|
return "${monthsInYear[transactionDate.month]} ${transactionDate.year}";
|
||||||
dateDelimiter = "thisWeek".tr();
|
}
|
||||||
isThisWeek = true;
|
|
||||||
} else if (dateDelimiter != "${monthsInYear[date.month]} ${date.year}" &&
|
|
||||||
transactionDate != todayDate &&
|
|
||||||
transactionDate != yesterdayDate &&
|
|
||||||
!(weekNumber(date) == weekNumber(now) && date.year == now.year)) {
|
|
||||||
if (date.year == now.year) {
|
|
||||||
dateDelimiter = monthsInYear[date.month];
|
|
||||||
} else {
|
} else {
|
||||||
dateDelimiter = "${monthsInYear[date.month]} ${date.year}";
|
return '';
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
isDelimiter = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final dateDelimiter = getDateDelimiter();
|
||||||
|
|
||||||
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
amount = repository[4] == 'RECEIVED' ? repository[3] : repository[3] * -1;
|
||||||
|
|
||||||
if (isUdUnit) {
|
if (isUdUnit) {
|
||||||
|
@ -316,30 +308,20 @@ Map computeHistoryView(repository, String address) {
|
||||||
finalAmount = '$amount $currencyName';
|
finalAmount = '$amount $currencyName';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (startBlockchainInitialized && date.compareTo(startBlockchainTime) < 0) {
|
bool isMigrationTime =
|
||||||
isMigrationTime = true;
|
startBlockchainInitialized && date.compareTo(startBlockchainTime) < 0;
|
||||||
} else {
|
|
||||||
isMigrationTime = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: Migration date and transaction migration doesn't match, add this event to v2s indexer.
|
//TODO: Migration date and transaction migration doesn't match, add this event to v2s indexer.
|
||||||
|
|
||||||
// log.d('debug date transaction: $date');
|
// log.d('debug date transaction: $date');
|
||||||
// log.d('debug date identity migration: ${sub.oldOwnerKeys[address]?[1]}');
|
// log.d('debug date identity migration: ${sub.oldOwnerKeys[address]?[1]}');
|
||||||
// if (date.compareTo(sub.oldOwnerKeys[address]?[1] ?? DateTime(2000)) < 0) {
|
// isChangeOwnerkeyTime = date.compareTo(sub.oldOwnerKeys[address]?[1] ?? DateTime(2000)) < 0;
|
||||||
// log.d('taaaaaaaaa: GOOOO');
|
|
||||||
// isChangeOwnerkeyTime = true;
|
|
||||||
// } else {
|
|
||||||
// isChangeOwnerkeyTime = false;
|
|
||||||
// }
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'finalAmount': finalAmount,
|
'finalAmount': finalAmount,
|
||||||
'isMigrationTime': isMigrationTime,
|
'isMigrationTime': isMigrationTime,
|
||||||
'dateDelimiter': dateDelimiter ?? '',
|
'dateDelimiter': dateDelimiter,
|
||||||
'isDelimiter': isDelimiter,
|
|
||||||
'dateForm': dateForm,
|
'dateForm': dateForm,
|
||||||
'isChangeOwnerkeyTime': isChangeOwnerkeyTime
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue