mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 21:04:53 +00:00
CAKE-168 | fixed blockheight calculation by date; changed getHeightByDate method; changed first date in the date picker to 1 of May, 2014
This commit is contained in:
parent
37d3bf3fa9
commit
70467b1fe7
2 changed files with 18 additions and 23 deletions
|
@ -85,34 +85,29 @@ final dates = {
|
|||
"2020-11": 2221803
|
||||
};
|
||||
|
||||
final heightCoefficient = 0.7;
|
||||
|
||||
int getHeigthByDate({DateTime date}) {
|
||||
final raw = '${date.year}' + '-' + '${date.month}';
|
||||
var endHeight = dates[raw] ?? 0;
|
||||
int preLastYear = date.year;
|
||||
int preLastMonth = date.month - 1;
|
||||
final lastHeight = dates.values.last;
|
||||
int startHeight;
|
||||
int endHeight;
|
||||
int height;
|
||||
|
||||
if (endHeight <= 0) {
|
||||
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
|
||||
startHeight = dates.values.toList()[dates.length - 2];
|
||||
endHeight = dates.values.toList()[dates.length - 1];
|
||||
final preLastDate =
|
||||
dateFormat.parse(dates.keys.elementAt(dates.keys.length - 2));
|
||||
preLastYear = preLastDate.year;
|
||||
preLastMonth = preLastDate.month;
|
||||
final heightPerDay = (endHeight - startHeight) / 31;
|
||||
final daysHeight = (heightCoefficient * date.day * heightPerDay).round();
|
||||
height = endHeight + daysHeight;
|
||||
} else {
|
||||
preLastYear = date.year;
|
||||
preLastMonth = date.month - 1;
|
||||
}
|
||||
|
||||
if (preLastMonth <= 0) {
|
||||
preLastMonth = 12;
|
||||
preLastYear -= 1;
|
||||
}
|
||||
|
||||
final startRaw = '$preLastYear' + '-' + '$preLastMonth';
|
||||
final startHeight = dates[startRaw];
|
||||
final diff = endHeight - startHeight;
|
||||
final heightPerDay = diff / 30;
|
||||
startHeight = dates[raw];
|
||||
final index = dates.values.toList().indexOf(startHeight);
|
||||
endHeight = dates.values.toList()[index + 1];
|
||||
final heightPerDay = (endHeight - startHeight) / 31;
|
||||
final daysHeight = date.day * heightPerDay.round();
|
||||
final height = endHeight + daysHeight;
|
||||
height = startHeight + daysHeight;
|
||||
}
|
||||
|
||||
return height;
|
||||
}
|
||||
|
|
|
@ -92,7 +92,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
|||
final date = await getDate(
|
||||
context: context,
|
||||
initialDate: now.subtract(Duration(days: 1)),
|
||||
firstDate: DateTime(2014, DateTime.april),
|
||||
firstDate: DateTime(2014, DateTime.may),
|
||||
lastDate: now);
|
||||
|
||||
if (date != null) {
|
||||
|
|
Loading…
Reference in a new issue