hypercore-one / syrius

MIT License
0 stars 0 forks source link

Fix realtime statistics refresh #9

Closed KingGorrin closed 1 year ago

KingGorrin commented 1 year ago

What?

The RealtimeStatistics widget periodically fetches data on each new momentum, but does not update the RealtimeTxsChart widget with the newly retrived data. The new data is only loaded when navigating from another tab.

Why?

The RealtimeTxsChart widget generates the Znn and Qsr spots data when the widget is initialized in the initState method.

@override
void initState() {
  super.initState();
  _znnSpots = _generateZnnSpots();
  _qsrSpots = _generateQsrSpots();
}

This method is only called once when the widget is created. When the stream is updated, the widget gets rebuild but does not generate new spots.

How?

The RealtimeTxsChart widget must generate the Znn and Qsr spots data whenever the widget configuration changes by overriding the didUpdateWidget method.

@override
void didUpdateWidget(RealtimeTxsChart oldWidget) {
  _znnSpots = _generateZnnSpots();
  _qsrSpots = _generateQsrSpots();
  super.didUpdateWidget(oldWidget);
}

Anything else?

This PR depends on PR https://github.com/zenon-network/syrius/pull/7; otherwise no chart will be displayed.

georgezgeorgez commented 1 year ago

I'm not super familiar with flutter so just dropping this as reference for anyone else in the same boat https://api.flutter.dev/flutter/widgets/State/didUpdateWidget.html