More split between history view and model
This commit is contained in:
parent
267a3e0ba1
commit
82a17df414
|
@ -1,5 +1,6 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:sentry/sentry.dart' as sentry;
|
import 'package:sentry/sentry.dart' as sentry;
|
||||||
import 'package:qrscan/qrscan.dart' as scanner;
|
import 'package:qrscan/qrscan.dart' as scanner;
|
||||||
|
@ -10,6 +11,9 @@ class HistoryProvider with ChangeNotifier {
|
||||||
String pubkey = '';
|
String pubkey = '';
|
||||||
HistoryProvider(this.pubkey);
|
HistoryProvider(this.pubkey);
|
||||||
final TextEditingController _outputPubkey = new TextEditingController();
|
final TextEditingController _outputPubkey = new TextEditingController();
|
||||||
|
bool isTheEnd = false;
|
||||||
|
List transBC;
|
||||||
|
|
||||||
// String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug
|
// String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug
|
||||||
|
|
||||||
Future scan() async {
|
Future scan() async {
|
||||||
|
@ -105,6 +109,44 @@ class HistoryProvider with ChangeNotifier {
|
||||||
return transBC;
|
return transBC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FetchMoreOptions checkQueryResult(result, opts) {
|
||||||
|
final List<dynamic> blockchainTX =
|
||||||
|
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
|
||||||
|
|
||||||
|
final Map pageInfo = result.data['txsHistoryBc']['both']['pageInfo'];
|
||||||
|
|
||||||
|
final String fetchMoreCursor = pageInfo['endCursor'];
|
||||||
|
|
||||||
|
if (fetchMoreCursor != null) {
|
||||||
|
opts = FetchMoreOptions(
|
||||||
|
variables: {'cursor': fetchMoreCursor},
|
||||||
|
updateQuery: (previousResultData, fetchMoreResultData) {
|
||||||
|
final List<dynamic> repos = [
|
||||||
|
...previousResultData['txsHistoryBc']['both']['edges']
|
||||||
|
as List<dynamic>,
|
||||||
|
...fetchMoreResultData['txsHistoryBc']['both']['edges']
|
||||||
|
as List<dynamic>
|
||||||
|
];
|
||||||
|
|
||||||
|
fetchMoreResultData['txsHistoryBc']['both']['edges'] = repos;
|
||||||
|
return fetchMoreResultData;
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
print(
|
||||||
|
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
|
||||||
|
if (fetchMoreCursor != null) {
|
||||||
|
transBC = parseHistory(blockchainTX);
|
||||||
|
isTheEnd = false;
|
||||||
|
} else {
|
||||||
|
print("###### DEBUG H - Début de l'historique");
|
||||||
|
isTheEnd = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return opts;
|
||||||
|
}
|
||||||
|
|
||||||
void resetdHistory() {
|
void resetdHistory() {
|
||||||
this._outputPubkey.text = '';
|
this._outputPubkey.text = '';
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
|
@ -14,8 +14,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
ScrollController scrollController = ScrollController();
|
ScrollController scrollController = ScrollController();
|
||||||
final nRepositories = 20;
|
final nRepositories = 20;
|
||||||
// HistoryProvider _historyProvider;
|
// HistoryProvider _historyProvider;
|
||||||
bool isTheEnd = false;
|
|
||||||
List _transBC;
|
|
||||||
final _formKey = GlobalKey<FormState>();
|
final _formKey = GlobalKey<FormState>();
|
||||||
FocusNode _pubkeyFocus = FocusNode();
|
FocusNode _pubkeyFocus = FocusNode();
|
||||||
|
|
||||||
|
@ -114,45 +112,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
return const Text('Aucune donnée à afficher.');
|
return const Text('Aucune donnée à afficher.');
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<dynamic> blockchainTX =
|
|
||||||
(result.data['txsHistoryBc']['both']['edges'] as List<dynamic>);
|
|
||||||
|
|
||||||
final Map pageInfo =
|
|
||||||
result.data['txsHistoryBc']['both']['pageInfo'];
|
|
||||||
|
|
||||||
final String fetchMoreCursor = pageInfo['endCursor'];
|
|
||||||
|
|
||||||
final num balance = _historyProvider
|
final num balance = _historyProvider
|
||||||
.removeDecimalZero(result.data['balance']['amount'] / 100);
|
.removeDecimalZero(result.data['balance']['amount'] / 100);
|
||||||
|
|
||||||
if (fetchMoreCursor != null) {
|
opts = _historyProvider.checkQueryResult(result, opts);
|
||||||
opts = FetchMoreOptions(
|
|
||||||
variables: {'cursor': fetchMoreCursor},
|
|
||||||
updateQuery: (previousResultData, fetchMoreResultData) {
|
|
||||||
final List<dynamic> repos = [
|
|
||||||
...previousResultData['txsHistoryBc']['both']['edges']
|
|
||||||
as List<dynamic>,
|
|
||||||
...fetchMoreResultData['txsHistoryBc']['both']['edges']
|
|
||||||
as List<dynamic>
|
|
||||||
];
|
|
||||||
|
|
||||||
fetchMoreResultData['txsHistoryBc']['both']['edges'] = repos;
|
|
||||||
return fetchMoreResultData;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
print(
|
|
||||||
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
|
|
||||||
if (fetchMoreCursor != null) {
|
|
||||||
_transBC = _historyProvider.parseHistory(blockchainTX);
|
|
||||||
isTheEnd = false;
|
|
||||||
} else {
|
|
||||||
print("###### DEBUG H - Début de l'historique");
|
|
||||||
isTheEnd = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// _historyProvider.resetdHistory();
|
|
||||||
|
|
||||||
// Build history list
|
// Build history list
|
||||||
return NotificationListener(
|
return NotificationListener(
|
||||||
|
@ -191,7 +154,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
indent: 0,
|
indent: 0,
|
||||||
endIndent: 0,
|
endIndent: 0,
|
||||||
),
|
),
|
||||||
_transBC == null
|
_historyProvider.transBC == null
|
||||||
? Text('Aucune transaction à afficher.')
|
? Text('Aucune transaction à afficher.')
|
||||||
: loopTransactions(context, result),
|
: loopTransactions(context, result),
|
||||||
],
|
],
|
||||||
|
@ -214,7 +177,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
||||||
|
|
||||||
return Column(children: <Widget>[
|
return Column(children: <Widget>[
|
||||||
for (var repository in _transBC)
|
for (var repository in _historyProvider.transBC)
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
padding: const EdgeInsets.symmetric(horizontal: 8.0),
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
|
@ -249,7 +212,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
CircularProgressIndicator(),
|
CircularProgressIndicator(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (isTheEnd)
|
if (_historyProvider.isTheEnd)
|
||||||
Column(children: <Widget>[
|
Column(children: <Widget>[
|
||||||
SizedBox(height: 15),
|
SizedBox(height: 15),
|
||||||
Text("Début de l'historique.",
|
Text("Début de l'historique.",
|
||||||
|
|
Loading…
Reference in New Issue