mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-11-17 01:37:40 +00:00
Merge pull request #99 from cake-tech/CAKE-291-rescan-restore-from-date-issue
CAKE-291 | fixed bug in the get_height_by_date.dart
This commit is contained in:
commit
f93d10face
1 changed files with 23 additions and 16 deletions
|
@ -85,28 +85,35 @@ final dates = {
|
|||
"2020-11": 2220000
|
||||
};
|
||||
|
||||
final heightCoefficient = 0.7;
|
||||
|
||||
int getHeigthByDate({DateTime date}) {
|
||||
final raw = '${date.year}' + '-' + '${date.month}';
|
||||
final lastHeight = dates.values.last;
|
||||
int startHeight;
|
||||
int endHeight;
|
||||
int height;
|
||||
int height = 0;
|
||||
|
||||
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
|
||||
startHeight = dates.values.toList()[dates.length - 2];
|
||||
endHeight = dates.values.toList()[dates.length - 1];
|
||||
final heightPerDay = (endHeight - startHeight) / 31;
|
||||
final daysHeight = (heightCoefficient * (date.day - 1) * heightPerDay).round();
|
||||
height = endHeight + daysHeight;
|
||||
} else {
|
||||
startHeight = dates[raw];
|
||||
final index = dates.values.toList().indexOf(startHeight);
|
||||
endHeight = dates.values.toList()[index + 1];
|
||||
final heightPerDay = ((endHeight - startHeight) / 31).round();
|
||||
final daysHeight = (date.day - 1) * heightPerDay;
|
||||
height = startHeight + daysHeight - heightPerDay;
|
||||
try {
|
||||
if ((dates[raw] == null)||(dates[raw] == lastHeight)) {
|
||||
startHeight = dates.values.toList()[dates.length - 2];
|
||||
endHeight = dates.values.toList()[dates.length - 1];
|
||||
final heightPerDay = (endHeight - startHeight) / 31;
|
||||
final endDateRaw = dates.keys.toList()[dates.length - 1].split('-');
|
||||
final endYear = int.parse(endDateRaw[0]);
|
||||
final endMonth = int.parse(endDateRaw[1]);
|
||||
final endDate = DateTime(endYear, endMonth);
|
||||
final differenceInDays = date.difference(endDate).inDays;
|
||||
final daysHeight = (differenceInDays * heightPerDay).round();
|
||||
height = endHeight + daysHeight;
|
||||
} else {
|
||||
startHeight = dates[raw];
|
||||
final index = dates.values.toList().indexOf(startHeight);
|
||||
endHeight = dates.values.toList()[index + 1];
|
||||
final heightPerDay = ((endHeight - startHeight) / 31).round();
|
||||
final daysHeight = (date.day - 1) * heightPerDay;
|
||||
height = startHeight + daysHeight - heightPerDay;
|
||||
}
|
||||
} catch (e) {
|
||||
print(e.toString());
|
||||
}
|
||||
|
||||
return height;
|
||||
|
|
Loading…
Reference in a new issue