From 0719737967edb28f00c3439aea0a1ca3547cba00 Mon Sep 17 00:00:00 2001 From: fuwa Date: Tue, 23 Jul 2019 11:06:46 +0800 Subject: [PATCH] clean up connections page --- cyberwow/lib/controller/rpc.dart | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cyberwow/lib/controller/rpc.dart b/cyberwow/lib/controller/rpc.dart index 0d0e572..0e6e70e 100644 --- a/cyberwow/lib/controller/rpc.dart +++ b/cyberwow/lib/controller/rpc.dart @@ -57,7 +57,7 @@ Future rpc(String method) async { return response; } -Future rpcString(String method) async { +Future rpcString(String method, {String field}) async { var response = await rpc(method); if (response == null) return ''; @@ -66,9 +66,10 @@ Future rpcString(String method) async { return ''; } else { final _result = json.decode(response.body)['result']; + final _field = field == null ? _result : _result[field]; final JsonEncoder encoder = new JsonEncoder.withIndent(' '); - return encoder.convert(_result); + return encoder.convert(_field); } } @@ -88,7 +89,7 @@ Future rpcOther(String method) async { return response; } -Future rpcOtherString(String method) async { +Future rpcOtherString(String method, {String field}) async { var response = await rpcOther(method); if (response == null) return ''; @@ -96,10 +97,11 @@ Future rpcOtherString(String method) async { if (response.statusCode != 200) { return ''; } else { - final _result = json.decode(response.body); + final _body= json.decode(response.body); + final _field = field == null ? _body: _body[field]; final JsonEncoder encoder = new JsonEncoder.withIndent(' '); - return encoder.convert(_result); + return encoder.convert(_field); } } @@ -206,5 +208,5 @@ Future incomingConnectionsCount() async { // } -Future getConnectionsString() async => rpcString('get_connections'); +Future getConnectionsString() async => rpcString('get_connections', field: 'connections'); Future getTransactionPoolString() async => rpcOtherString('get_transaction_pool');