add pretty helper

pull/2/head
fuwa 5 years ago
parent a68d49d80c
commit 3d44b3a734

@ -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<String> 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<String> 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);
}
}

@ -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 <https://www.gnu.org/licenses/>.
*/
import 'dart:convert';
String pretty(dynamic x) {
final JsonEncoder encoder = new JsonEncoder.withIndent(' ');
return encoder.convert(x);
}

@ -200,7 +200,7 @@ class SyncedState extends HookedState {
String getInfo = 'getInfo';
String syncInfo = 'syncInfo';
String getConnections = 'getConnections';
String getTransactionPool = 'getTransactionPool';
List<dynamic> 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();
}
}

@ -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),
],
);
}