diff --git a/lib/monero/get_height_by_date.dart b/lib/monero/get_height_by_date.dart index 3f5f87623..5393d2a32 100644 --- a/lib/monero/get_height_by_date.dart +++ b/lib/monero/get_height_by_date.dart @@ -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; + 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(); + 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; } diff --git a/lib/src/widgets/blockchain_height_widget.dart b/lib/src/widgets/blockchain_height_widget.dart index 384700839..f8b22b5c4 100644 --- a/lib/src/widgets/blockchain_height_widget.dart +++ b/lib/src/widgets/blockchain_height_widget.dart @@ -92,7 +92,7 @@ class BlockchainHeightState extends State { 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) {