diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 05fb9bb..674eb76 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -26,6 +26,7 @@ import 'package:http/http.dart' as http; import 'package:flutter/foundation.dart'; import '../config.dart'; +import '../helper.dart'; int rpcID = 0; @@ -68,8 +69,7 @@ Future rpcString(String method, {String field}) async { final _result = json.decode(response.body)['result']; final _field = field == null ? _result : _result[field]; - final JsonEncoder encoder = new JsonEncoder.withIndent(' '); - return encoder.convert(_field); + return pretty(_field); } } @@ -180,8 +180,7 @@ Future rpcOtherString(String method, {String field}) async { final _body= json.decode(response.body); final _field = field == null ? _body: _body[field]; - final JsonEncoder encoder = new JsonEncoder.withIndent(' '); - return encoder.convert(_field); + return pretty(_field); } } diff --git a/cyberwow/lib/helper.dart b/cyberwow/lib/helper.dart new file mode 100644 index 0000000..bf03074 --- /dev/null +++ b/cyberwow/lib/helper.dart @@ -0,0 +1,27 @@ +/* + +Copyright 2019 fuwa + +This file is part of CyberWOW. + +CyberWOW is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +CyberWOW is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with CyberWOW. If not, see . + +*/ + +import 'dart:convert'; + +String pretty(dynamic x) { + final JsonEncoder encoder = new JsonEncoder.withIndent(' '); + return encoder.convert(x); +} diff --git a/cyberwow/lib/state.dart b/cyberwow/lib/state.dart index d3aa102..b903072 100644 --- a/cyberwow/lib/state.dart +++ b/cyberwow/lib/state.dart @@ -200,7 +200,7 @@ class SyncedState extends HookedState { String getInfo = 'getInfo'; String syncInfo = 'syncInfo'; String getConnections = 'getConnections'; - String getTransactionPool = 'getTransactionPool'; + List getTransactionPool = []; SyncedState(f, s, this.stdout, this.processOutput) : super (f, s); @@ -232,9 +232,9 @@ class SyncedState extends HookedState { getConnections = await rpc.getConnectionsString(); // getTransactionPool = await rpc.getTransactionPoolString(); - final getTransactionPool = await rpc.getTransactionPoolSimple(); + getTransactionPool = await rpc.getTransactionPoolSimple(); - log.fine('getTransactionPool: $getTransactionPool'); + // log.fine('getTransactionPool: $getTransactionPool'); syncState(); } } diff --git a/cyberwow/lib/widget/synced.dart b/cyberwow/lib/widget/synced.dart index aca7d39..9a4adc4 100644 --- a/cyberwow/lib/widget/synced.dart +++ b/cyberwow/lib/widget/synced.dart @@ -23,6 +23,7 @@ import 'package:flutter/material.dart'; import '../state.dart'; import '../config.dart'; +import '../helper.dart'; Widget summary(SyncedState state) { return Container @@ -157,18 +158,19 @@ Widget rpcView(String title, String body) { Widget getInfo(SyncedState state) => rpcView('info', state.getInfo); Widget getConnections(SyncedState state) => rpcView('connections', state.getConnections); Widget syncInfo(SyncedState state) => rpcView('sync info', state.syncInfo); -Widget getTransactionPool(SyncedState state) => rpcView('transaction pool', state.getTransactionPool); +Widget getTransactionPool(SyncedState state) => + rpcView('transaction pool', pretty(state.getTransactionPool)); Widget pageView (SyncedState state, PageController controller) { return PageView ( controller: controller, children: [ + getTransactionPool(state), summary(state), getInfo(state), getConnections(state), // syncInfo(state), - // getTransactionPool(state), ], ); }