From 557d60a7c69074a2c642b0f70c10b02483e2c91a Mon Sep 17 00:00:00 2001 From: fuwa Date: Wed, 27 Nov 2019 19:56:21 +0800 Subject: [PATCH] simplify height in peers --- cyberwow/lib/controller/rpc/rpc2View.dart | 4 ++-- cyberwow/lib/controller/rpc/rpcView.dart | 25 ++++++++++++++++++++++- cyberwow/lib/state.dart | 9 +++++--- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/cyberwow/lib/controller/rpc/rpc2View.dart b/cyberwow/lib/controller/rpc/rpc2View.dart index 6d16f51..3c6884f 100644 --- a/cyberwow/lib/controller/rpc/rpc2View.dart +++ b/cyberwow/lib/controller/rpc/rpc2View.dart @@ -25,7 +25,7 @@ import 'package:intl/intl.dart'; import '../../config.dart' as config; -Map rpcTxView(x) { +Map rpcTxView(Map x) { const _remove = [ 'tx_blob', @@ -105,7 +105,7 @@ Map rpcTxView(x) { .toList(); final _sortedTx = { - for (var k in keys) k: _tx[k] + for (final k in keys) k: _tx[k] }; return _sortedTx; diff --git a/cyberwow/lib/controller/rpc/rpcView.dart b/cyberwow/lib/controller/rpc/rpcView.dart index b4c5ae5..64c5964 100644 --- a/cyberwow/lib/controller/rpc/rpcView.dart +++ b/cyberwow/lib/controller/rpc/rpcView.dart @@ -98,7 +98,7 @@ Map rpcPeerView(Map x) { .toList(); final _sortedConn = { - for (var k in keys) k: _conn[k] + for (final k in keys) k: _conn[k] }; final _cleanupConn = _sortedConn..removeWhere @@ -109,3 +109,26 @@ Map rpcPeerView(Map x) { return _cleanupConn; } +Map simpleHeight(int height, Map x) { + return x.map + ( + (k, v) { + if (k == 'height') { + if (v < height) { + return MapEntry('height', '- ${height - v}'); + } + + else if (v == height) { + return MapEntry('height', '✓'); + } + + else { + return MapEntry('height', '+ ${v - height}'); + } + } + else { + return MapEntry(k, v); + } + } + ); +} diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index 3c82cc7..13da4fb 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -36,6 +36,7 @@ import 'controller/daemon.dart' as daemon; import 'controller/refresh.dart' as refresh; import 'config.dart' as config; import 'logging.dart'; +import 'controller/rpc/rpcView.dart'; abstract class AppState { T use @@ -236,8 +237,8 @@ class SyncedState extends HookedState { bool userExit = false; bool connected = true; Map getInfo = {}; - List getConnections = []; - List getTransactionPool = []; + List> getConnections = []; + List> getTransactionPool = []; int pageIndex; String syncInfo = 'syncInfo'; PageController pageController; @@ -299,7 +300,9 @@ class SyncedState extends HookedState { height = await rpc.height(); connected = await daemon.isConnected(); getInfo = await rpc.getInfoSimple(); - getConnections = await rpc.getConnectionsSimple(); + final _getConnections = await rpc.getConnectionsSimple(); + getConnections = _getConnections.map((x) => simpleHeight(height, x)).toList(); + // getTransactionPool = await rpc.getTransactionPoolString(); getTransactionPool = await rpc.getTransactionPoolSimple();