CAKE-168 | fixed blockheight calculation by date; changed getHeightByDate method; changed first date in the date picker to 1 of May, 2014
OleksandrSobol committed
Nov 12, 2020 at 17:46 UTC
70467b1fe7ebca93b7ab1a5c381ef31af1ae91f7
2 files changed
+18
-23
lib/monero/get_height_by_date.dart
+17
-22
@@ -85,34 +85,29 @@ final dates = {
85
"2020-11": 2221803
86
};
87
88
+final heightCoefficient = 0.7;
89
+
90
int getHeigthByDate({DateTime date}) {
91
final raw = '${date.year}' + '-' + '${date.month}';
90
- var endHeight = dates[raw] ?? 0;
91
- int preLastYear = date.year;
92
- int preLastMonth = date.month - 1;
92
+ final lastHeight = dates.values.last;
93
+ int startHeight;
94
+ int endHeight;
95
+ int height;
96
94
- if (endHeight <= 0) {
97
+ if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
98
+ startHeight = dates.values.toList()[dates.length - 2];
99
endHeight = dates.values.toList()[dates.length - 1];
96
- final preLastDate =
97
- dateFormat.parse(dates.keys.elementAt(dates.keys.length - 2));
98
- preLastYear = preLastDate.year;
99
- preLastMonth = preLastDate.month;
100
+ final heightPerDay = (endHeight - startHeight) / 31;
101
+ final daysHeight = (heightCoefficient * date.day * heightPerDay).round();
102
+ height = endHeight + daysHeight;
103
} else {
101
- preLastYear = date.year;
102
- preLastMonth = date.month - 1;
103
- }
104
-
105
- if (preLastMonth <= 0) {
106
- preLastMonth = 12;
107
- preLastYear -= 1;
104
+ startHeight = dates[raw];
105
+ final index = dates.values.toList().indexOf(startHeight);
106
+ endHeight = dates.values.toList()[index + 1];
107
+ final heightPerDay = (endHeight - startHeight) / 31;
108
+ final daysHeight = date.day * heightPerDay.round();
109
+ height = startHeight + daysHeight;
110
}
111
110
- final startRaw = '$preLastYear' + '-' + '$preLastMonth';
111
- final startHeight = dates[startRaw];
112
- final diff = endHeight - startHeight;
113
- final heightPerDay = diff / 30;
114
- final daysHeight = date.day * heightPerDay.round();
115
- final height = endHeight + daysHeight;
116
-
112
return height;
113
}
lib/src/widgets/blockchain_height_widget.dart
+1
-1
@@ -92,7 +92,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
92
final date = await getDate(
93
context: context,
94
initialDate: now.subtract(Duration(days: 1)),
95
- firstDate: DateTime(2014, DateTime.april),
95
+ firstDate: DateTime(2014, DateTime.may),
96
lastDate: now);
97
98
if (date != null) {