diff --git a/lib/models/history.dart b/lib/models/history.dart index b058519..4a28d04 100644 --- a/lib/models/history.dart +++ b/lib/models/history.dart @@ -1,5 +1,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:sentry/sentry.dart' as sentry; import 'package:qrscan/qrscan.dart' as scanner; @@ -10,6 +11,9 @@ class HistoryProvider with ChangeNotifier { String pubkey = ''; HistoryProvider(this.pubkey); final TextEditingController _outputPubkey = new TextEditingController(); + bool isTheEnd = false; + List transBC; + // String pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'; // For debug Future scan() async { @@ -105,6 +109,44 @@ class HistoryProvider with ChangeNotifier { return transBC; } + FetchMoreOptions checkQueryResult(result, opts) { + final List blockchainTX = + (result.data['txsHistoryBc']['both']['edges'] as List); + + 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 repos = [ + ...previousResultData['txsHistoryBc']['both']['edges'] + as List, + ...fetchMoreResultData['txsHistoryBc']['both']['edges'] + as List + ]; + + 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() { this._outputPubkey.text = ''; notifyListeners(); diff --git a/lib/screens/history.dart b/lib/screens/history.dart index 9bc1248..f3ed4b5 100644 --- a/lib/screens/history.dart +++ b/lib/screens/history.dart @@ -14,8 +14,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ScrollController scrollController = ScrollController(); final nRepositories = 20; // HistoryProvider _historyProvider; - bool isTheEnd = false; - List _transBC; final _formKey = GlobalKey(); FocusNode _pubkeyFocus = FocusNode(); @@ -114,45 +112,10 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { return const Text('Aucune donnée à afficher.'); } - final List blockchainTX = - (result.data['txsHistoryBc']['both']['edges'] as List); - - final Map pageInfo = - result.data['txsHistoryBc']['both']['pageInfo']; - - final String fetchMoreCursor = pageInfo['endCursor']; - final num balance = _historyProvider .removeDecimalZero(result.data['balance']['amount'] / 100); - if (fetchMoreCursor != null) { - opts = FetchMoreOptions( - variables: {'cursor': fetchMoreCursor}, - updateQuery: (previousResultData, fetchMoreResultData) { - final List repos = [ - ...previousResultData['txsHistoryBc']['both']['edges'] - as List, - ...fetchMoreResultData['txsHistoryBc']['both']['edges'] - as List - ]; - - 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(); + opts = _historyProvider.checkQueryResult(result, opts); // Build history list return NotificationListener( @@ -191,7 +154,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { indent: 0, endIndent: 0, ), - _transBC == null + _historyProvider.transBC == null ? Text('Aucune transaction à afficher.') : loopTransactions(context, result), ], @@ -214,7 +177,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { HistoryProvider _historyProvider = Provider.of(context); return Column(children: [ - for (var repository in _transBC) + for (var repository in _historyProvider.transBC) Padding( padding: const EdgeInsets.symmetric(horizontal: 8.0), child: ListTile( @@ -249,7 +212,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { CircularProgressIndicator(), ], ), - if (isTheEnd) + if (_historyProvider.isTheEnd) Column(children: [ SizedBox(height: 15), Text("Début de l'historique.",