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
|
"2020-11": 2221803
|
||||||
};
|
};
|
||||||
|
|
||||||
|
final heightCoefficient = 0.7;
|
||||||
|
|
||||||
int getHeigthByDate({DateTime date}) {
|
int getHeigthByDate({DateTime date}) {
|
||||||
final raw = '${date.year}' + '-' + '${date.month}';
|
final raw = '${date.year}' + '-' + '${date.month}';
|
||||||
var endHeight = dates[raw] ?? 0;
|
final lastHeight = dates.values.last;
|
||||||
int preLastYear = date.year;
|
int startHeight;
|
||||||
int preLastMonth = date.month - 1;
|
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];
|
endHeight = dates.values.toList()[dates.length - 1];
|
||||||
final preLastDate =
|
final heightPerDay = (endHeight - startHeight) / 31;
|
||||||
dateFormat.parse(dates.keys.elementAt(dates.keys.length - 2));
|
final daysHeight = (heightCoefficient * date.day * heightPerDay).round();
|
||||||
preLastYear = preLastDate.year;
|
height = endHeight + daysHeight;
|
||||||
preLastMonth = preLastDate.month;
|
|
||||||
} else {
|
} else {
|
||||||
preLastYear = date.year;
|
startHeight = dates[raw];
|
||||||
preLastMonth = date.month - 1;
|
final index = dates.values.toList().indexOf(startHeight);
|
||||||
|
endHeight = dates.values.toList()[index + 1];
|
||||||
|
final heightPerDay = (endHeight - startHeight) / 31;
|
||||||
|
final daysHeight = date.day * heightPerDay.round();
|
||||||
|
height = startHeight + daysHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (preLastMonth <= 0) {
|
|
||||||
preLastMonth = 12;
|
|
||||||
preLastYear -= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
final startRaw = '$preLastYear' + '-' + '$preLastMonth';
|
|
||||||
final startHeight = dates[startRaw];
|
|
||||||
final diff = endHeight - startHeight;
|
|
||||||
final heightPerDay = diff / 30;
|
|
||||||
final daysHeight = date.day * heightPerDay.round();
|
|
||||||
final height = endHeight + daysHeight;
|
|
||||||
|
|
||||||
return height;
|
return height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ class BlockchainHeightState extends State<BlockchainHeightWidget> {
|
||||||
final date = await getDate(
|
final date = await getDate(
|
||||||
context: context,
|
context: context,
|
||||||
initialDate: now.subtract(Duration(days: 1)),
|
initialDate: now.subtract(Duration(days: 1)),
|
||||||
firstDate: DateTime(2014, DateTime.april),
|
firstDate: DateTime(2014, DateTime.may),
|
||||||
lastDate: now);
|
lastDate: now);
|
||||||
|
|
||||||
if (date != null) {
|
if (date != null) {
|
||||||
|
|
Loading…
Reference in a new issue