2022-06-14 21:55:33 +02:00
|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:io';
|
2022-06-18 01:50:06 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2022-11-30 05:22:37 +01:00
|
|
|
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:gecko/globals.dart';
|
2022-08-14 22:16:46 +02:00
|
|
|
import 'package:gecko/models/g1_wallets_list.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:gecko/models/queries_indexer.dart';
|
|
|
|
import 'package:gecko/models/wallet_data.dart';
|
2022-08-23 00:25:16 +02:00
|
|
|
import 'package:gecko/models/widgets_keys.dart';
|
2022-06-15 01:14:23 +02:00
|
|
|
import 'package:gecko/providers/cesium_plus.dart';
|
|
|
|
import 'package:gecko/providers/substrate_sdk.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:gecko/providers/wallet_options.dart';
|
2022-06-15 01:14:23 +02:00
|
|
|
import 'package:gecko/providers/wallets_profiles.dart';
|
|
|
|
import 'package:gecko/screens/wallet_view.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
import 'package:graphql_flutter/graphql_flutter.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
2022-07-22 22:08:41 +02:00
|
|
|
import 'package:truncate/truncate.dart';
|
2022-06-14 21:55:33 +02:00
|
|
|
|
|
|
|
class DuniterIndexer with ChangeNotifier {
|
|
|
|
Map<String, String?> walletNameIndexer = {};
|
2022-06-16 19:45:34 +02:00
|
|
|
String? fetchMoreCursor;
|
2022-06-16 02:43:30 +02:00
|
|
|
Map? pageInfo;
|
2022-06-16 19:45:34 +02:00
|
|
|
int nPage = 1;
|
|
|
|
int nRepositories = 20;
|
|
|
|
List? transBC;
|
2022-07-16 21:03:40 +02:00
|
|
|
List listIndexerEndpoints = [];
|
|
|
|
bool isLoadingIndexer = false;
|
2022-06-14 21:55:33 +02:00
|
|
|
|
|
|
|
void reload() {
|
|
|
|
notifyListeners();
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:03:40 +02:00
|
|
|
Future<bool> checkIndexerEndpoint(String endpoint) async {
|
|
|
|
isLoadingIndexer = true;
|
|
|
|
notifyListeners();
|
2022-08-06 02:22:41 +02:00
|
|
|
final client = HttpClient();
|
|
|
|
client.connectionTimeout = const Duration(milliseconds: 4000);
|
2022-07-16 21:03:40 +02:00
|
|
|
try {
|
2022-08-06 02:22:41 +02:00
|
|
|
final request = await client.postUrl(Uri.parse('$endpoint/v1/graphql'));
|
2022-07-16 21:03:40 +02:00
|
|
|
final response = await request.close();
|
|
|
|
if (response.statusCode != 200) {
|
2022-06-14 21:55:33 +02:00
|
|
|
log.d('INDEXER IS OFFILINE');
|
|
|
|
indexerEndpoint = '';
|
2022-07-16 21:03:40 +02:00
|
|
|
isLoadingIndexer = false;
|
|
|
|
notifyListeners();
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
indexerEndpoint = endpoint;
|
|
|
|
await configBox.put('indexerEndpoint', endpoint);
|
|
|
|
// await configBox.put('customEndpoint', endpoint);
|
|
|
|
isLoadingIndexer = false;
|
|
|
|
notifyListeners();
|
|
|
|
final cache = HiveStore();
|
|
|
|
cache.reset();
|
|
|
|
return true;
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|
2022-07-16 21:03:40 +02:00
|
|
|
} catch (e) {
|
|
|
|
log.d('INDEXER IS OFFILINE');
|
|
|
|
indexerEndpoint = '';
|
|
|
|
isLoadingIndexer = false;
|
|
|
|
notifyListeners();
|
|
|
|
return false;
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:03:40 +02:00
|
|
|
// Future checkIndexerEndpointBackground() async {
|
|
|
|
// final oldEndpoint = indexerEndpoint;
|
|
|
|
// while (true) {
|
|
|
|
// await Future.delayed(const Duration(seconds: 30));
|
|
|
|
// final isValid = await checkIndexerEndpoint(oldEndpoint);
|
|
|
|
// if (!isValid) {
|
|
|
|
// log.d('INDEXER IS OFFILINE');
|
|
|
|
// indexerEndpoint = '';
|
|
|
|
// } else {
|
|
|
|
// // log.d('Indexer is online');
|
|
|
|
// indexerEndpoint = oldEndpoint;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2022-06-14 21:55:33 +02:00
|
|
|
Future<String> getValidIndexerEndpoint() async {
|
2022-07-16 21:03:40 +02:00
|
|
|
// await configBox.delete('indexerEndpoint');
|
|
|
|
|
|
|
|
listIndexerEndpoints = await rootBundle
|
2022-06-14 21:55:33 +02:00
|
|
|
.loadString('config/indexer_endpoints.json')
|
|
|
|
.then((jsonStr) => jsonDecode(jsonStr));
|
|
|
|
// _listEndpoints.shuffle();
|
|
|
|
|
2022-07-16 21:03:40 +02:00
|
|
|
log.d(listIndexerEndpoints);
|
2022-07-16 21:22:12 +02:00
|
|
|
listIndexerEndpoints.add('Personnalisé');
|
2022-07-16 21:03:40 +02:00
|
|
|
|
|
|
|
if (configBox.containsKey('customIndexer')) {
|
2022-07-16 21:22:12 +02:00
|
|
|
return configBox.get('customIndexer');
|
|
|
|
// listIndexerEndpoints.insert(0, configBox.get('customIndexer'));
|
2022-07-16 21:03:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (configBox.containsKey('indexerEndpoint')) {
|
|
|
|
if (await checkIndexerEndpoint(configBox.get('indexerEndpoint'))) {
|
|
|
|
return configBox.get('indexerEndpoint');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-14 21:55:33 +02:00
|
|
|
int i = 0;
|
|
|
|
// String _endpoint = '';
|
2022-08-06 02:22:41 +02:00
|
|
|
int statusCode = 0;
|
2022-06-14 21:55:33 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final client = HttpClient();
|
|
|
|
client.connectionTimeout = const Duration(milliseconds: 3000);
|
2022-06-14 21:55:33 +02:00
|
|
|
|
|
|
|
do {
|
2022-08-15 17:31:17 +02:00
|
|
|
int listLenght = listIndexerEndpoints.length - 1;
|
2022-06-14 21:55:33 +02:00
|
|
|
if (i >= listLenght) {
|
|
|
|
log.e('NO VALID INDEXER ENDPOINT FOUND');
|
|
|
|
indexerEndpoint = '';
|
|
|
|
break;
|
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d('${i + 1}n indexer endpoint try: ${listIndexerEndpoints[i]}');
|
2022-06-14 21:55:33 +02:00
|
|
|
|
|
|
|
if (i != 0) {
|
|
|
|
await Future.delayed(const Duration(milliseconds: 300));
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2022-07-16 21:03:40 +02:00
|
|
|
String endpointPath = '${listIndexerEndpoints[i]}/v1/graphql';
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final request = await client.postUrl(Uri.parse(endpointPath));
|
2022-06-14 21:55:33 +02:00
|
|
|
final response = await request.close();
|
|
|
|
|
2022-07-16 21:03:40 +02:00
|
|
|
indexerEndpoint = listIndexerEndpoints[i];
|
|
|
|
await configBox.put('indexerEndpoint', listIndexerEndpoints[i]);
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
statusCode = response.statusCode;
|
2022-06-14 21:55:33 +02:00
|
|
|
i++;
|
|
|
|
} on TimeoutException catch (_) {
|
|
|
|
log.e('This endpoint is timeout, next');
|
2022-08-06 02:22:41 +02:00
|
|
|
statusCode = 50;
|
2022-06-14 21:55:33 +02:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
} on SocketException catch (_) {
|
|
|
|
log.e('This endpoint is a bad endpoint, next');
|
2022-08-06 02:22:41 +02:00
|
|
|
statusCode = 70;
|
2022-06-14 21:55:33 +02:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
} on Exception {
|
|
|
|
log.e('Unknown error');
|
2022-08-06 02:22:41 +02:00
|
|
|
statusCode = 60;
|
2022-06-14 21:55:33 +02:00
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
} while (statusCode != 200);
|
2022-06-14 21:55:33 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
log.i('INDEXER: $indexerEndpoint');
|
2022-06-14 21:55:33 +02:00
|
|
|
return indexerEndpoint;
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget getNameByAddress(BuildContext context, String address,
|
|
|
|
[WalletData? wallet,
|
|
|
|
double size = 20,
|
|
|
|
bool canEdit = false,
|
2022-08-06 02:22:41 +02:00
|
|
|
Color color = Colors.black,
|
2022-06-14 21:55:33 +02:00
|
|
|
FontWeight fontWeight = FontWeight.w400,
|
|
|
|
FontStyle fontStyle = FontStyle.italic]) {
|
2022-11-30 05:42:08 +01:00
|
|
|
final walletOptions =
|
2022-06-14 21:55:33 +02:00
|
|
|
Provider.of<WalletOptionsProvider>(context, listen: false);
|
|
|
|
if (indexerEndpoint == '') {
|
|
|
|
if (wallet == null) {
|
|
|
|
return const SizedBox();
|
|
|
|
} else {
|
|
|
|
if (canEdit) {
|
2022-08-06 02:22:41 +02:00
|
|
|
return walletOptions.walletName(context, wallet, size, color);
|
2022-06-14 21:55:33 +02:00
|
|
|
} else {
|
2022-08-06 02:22:41 +02:00
|
|
|
return walletOptions.walletNameController(context, wallet, size);
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-06 02:22:41 +02:00
|
|
|
final httpLink = HttpLink(
|
2022-06-16 19:45:34 +02:00
|
|
|
'$indexerEndpoint/v1/graphql',
|
|
|
|
);
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final client = ValueNotifier(
|
2022-06-16 19:45:34 +02:00
|
|
|
GraphQLClient(
|
|
|
|
cache: GraphQLCache(store: HiveStore()),
|
2022-08-06 02:22:41 +02:00
|
|
|
link: httpLink,
|
2022-06-16 19:45:34 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
return GraphQLProvider(
|
2022-08-06 02:22:41 +02:00
|
|
|
client: client,
|
2022-06-16 19:45:34 +02:00
|
|
|
child: Query(
|
|
|
|
options: QueryOptions(
|
|
|
|
document: gql(
|
|
|
|
getNameByAddressQ), // this is the query string you just created
|
|
|
|
variables: {
|
|
|
|
'address': address,
|
|
|
|
},
|
|
|
|
// pollInterval: const Duration(seconds: 10),
|
|
|
|
),
|
|
|
|
builder: (QueryResult result,
|
|
|
|
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
|
|
|
if (result.hasException) {
|
|
|
|
return Text(result.exception.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.isLoading) {
|
|
|
|
return const Text('Loading');
|
|
|
|
}
|
2022-06-14 21:55:33 +02:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
walletNameIndexer[address] =
|
|
|
|
result.data?['account_by_pk']?['identity']?['name'];
|
|
|
|
|
2022-08-14 22:16:46 +02:00
|
|
|
g1WalletsBox.put(
|
|
|
|
address,
|
|
|
|
G1WalletsList(
|
2022-09-12 11:22:26 +02:00
|
|
|
address: address, username: walletNameIndexer[address]));
|
2022-08-14 22:16:46 +02:00
|
|
|
|
|
|
|
// log.d(g1WalletsBox.toMap().values.first.username);
|
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
if (walletNameIndexer[address] == null) {
|
|
|
|
if (wallet == null) {
|
|
|
|
return const SizedBox();
|
2022-06-14 21:55:33 +02:00
|
|
|
} else {
|
2022-06-16 19:45:34 +02:00
|
|
|
if (canEdit) {
|
2022-08-06 02:22:41 +02:00
|
|
|
return walletOptions.walletName(context, wallet, size, color);
|
2022-06-16 19:45:34 +02:00
|
|
|
} else {
|
2022-08-06 02:22:41 +02:00
|
|
|
return walletOptions.walletNameController(
|
2022-06-16 19:45:34 +02:00
|
|
|
context, wallet, size);
|
|
|
|
}
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|
|
|
|
}
|
2022-06-16 19:45:34 +02:00
|
|
|
|
|
|
|
return Text(
|
2022-08-06 02:22:41 +02:00
|
|
|
color == Colors.grey[700]!
|
2022-06-16 19:45:34 +02:00
|
|
|
? '(${walletNameIndexer[address]!})'
|
2022-07-22 22:08:41 +02:00
|
|
|
: truncate(walletNameIndexer[address]!, 20),
|
2022-06-16 19:45:34 +02:00
|
|
|
style: TextStyle(
|
|
|
|
fontSize: size,
|
2022-08-06 02:22:41 +02:00
|
|
|
color: color,
|
2022-06-16 19:45:34 +02:00
|
|
|
fontWeight: fontWeight,
|
|
|
|
fontStyle: fontStyle,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|
2022-06-15 01:14:23 +02:00
|
|
|
|
|
|
|
Widget searchIdentity(BuildContext context, String name) {
|
|
|
|
// WalletOptionsProvider _walletOptions =
|
|
|
|
// Provider.of<WalletOptionsProvider>(context, listen: false);
|
2022-11-30 05:42:08 +01:00
|
|
|
final cesiumPlusProvider =
|
2022-06-15 01:14:23 +02:00
|
|
|
Provider.of<CesiumPlusProvider>(context, listen: false);
|
2022-08-06 02:22:41 +02:00
|
|
|
WalletsProfilesProvider walletsProfiles =
|
2022-06-15 01:14:23 +02:00
|
|
|
Provider.of<WalletsProfilesProvider>(context, listen: false);
|
|
|
|
if (indexerEndpoint == '') {
|
|
|
|
return const Text('Aucun résultat');
|
|
|
|
}
|
|
|
|
|
2022-07-16 21:03:40 +02:00
|
|
|
log.d(indexerEndpoint);
|
2022-08-06 02:22:41 +02:00
|
|
|
final httpLink = HttpLink(
|
2022-06-16 19:45:34 +02:00
|
|
|
'$indexerEndpoint/v1/graphql',
|
|
|
|
);
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
final client = ValueNotifier(
|
2022-06-16 19:45:34 +02:00
|
|
|
GraphQLClient(
|
2022-07-16 21:03:40 +02:00
|
|
|
cache: GraphQLCache(
|
|
|
|
store: HiveStore()), // GraphQLCache(store: HiveStore())
|
2022-08-06 02:22:41 +02:00
|
|
|
link: httpLink,
|
2022-06-16 19:45:34 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
return GraphQLProvider(
|
2022-08-06 02:22:41 +02:00
|
|
|
client: client,
|
2022-06-16 19:45:34 +02:00
|
|
|
child: Query(
|
|
|
|
options: QueryOptions(
|
|
|
|
document: gql(
|
|
|
|
searchAddressByNameQ), // this is the query string you just created
|
|
|
|
variables: {
|
|
|
|
'name': name,
|
|
|
|
},
|
|
|
|
// pollInterval: const Duration(seconds: 10),
|
|
|
|
),
|
|
|
|
builder: (QueryResult result,
|
|
|
|
{VoidCallback? refetch, FetchMore? fetchMore}) {
|
|
|
|
if (result.hasException) {
|
|
|
|
return Text(result.exception.toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result.isLoading) {
|
2022-06-18 01:50:06 +02:00
|
|
|
return Text('loading'.tr());
|
2022-06-16 19:45:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
final List identities = result.data?['search_identity'] ?? [];
|
|
|
|
|
|
|
|
if (identities.isEmpty) {
|
2022-06-18 01:50:06 +02:00
|
|
|
return Text('noResult'.tr());
|
2022-06-16 19:45:34 +02:00
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
double avatarSize = 55;
|
2022-06-16 19:45:34 +02:00
|
|
|
return Expanded(
|
|
|
|
child: ListView(children: <Widget>[
|
|
|
|
for (Map profile in identities)
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 5),
|
|
|
|
child: ListTile(
|
2022-11-27 01:59:58 +01:00
|
|
|
key: keySearchResult(profile['pubkey']),
|
2022-06-16 19:45:34 +02:00
|
|
|
horizontalTitleGap: 40,
|
|
|
|
contentPadding: const EdgeInsets.all(5),
|
2022-08-06 02:22:41 +02:00
|
|
|
leading: cesiumPlusProvider.defaultAvatar(avatarSize),
|
2022-06-16 19:45:34 +02:00
|
|
|
title: Row(children: <Widget>[
|
2022-11-27 01:59:58 +01:00
|
|
|
Text(getShortPubkey(profile['pubkey']),
|
2022-06-16 19:45:34 +02:00
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
fontFamily: 'Monospace',
|
|
|
|
fontWeight: FontWeight.w500),
|
|
|
|
textAlign: TextAlign.center),
|
|
|
|
]),
|
2022-09-11 13:14:52 +02:00
|
|
|
trailing: SizedBox(
|
|
|
|
width: 110,
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
|
|
children: [
|
|
|
|
Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: [
|
2022-11-27 01:59:58 +01:00
|
|
|
balance(context, profile['pubkey'], 16),
|
2022-09-11 13:14:52 +02:00
|
|
|
]),
|
|
|
|
]),
|
|
|
|
),
|
2022-06-16 19:45:34 +02:00
|
|
|
subtitle: Row(children: <Widget>[
|
|
|
|
Text(profile['name'] ?? '',
|
|
|
|
style: const TextStyle(
|
|
|
|
fontSize: 18, fontWeight: FontWeight.w500),
|
|
|
|
textAlign: TextAlign.center),
|
|
|
|
]),
|
|
|
|
dense: false,
|
|
|
|
isThreeLine: false,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(builder: (context) {
|
2022-11-27 01:59:58 +01:00
|
|
|
walletsProfiles.address = profile['pubkey'];
|
2022-06-16 19:45:34 +02:00
|
|
|
return WalletViewScreen(
|
2022-11-27 01:59:58 +01:00
|
|
|
address: profile['pubkey'],
|
2022-06-16 19:45:34 +02:00
|
|
|
username: g1WalletsBox
|
2022-11-27 01:59:58 +01:00
|
|
|
.get(profile['pubkey'])
|
2022-06-16 19:45:34 +02:00
|
|
|
?.id
|
|
|
|
?.username,
|
2022-11-27 01:59:58 +01:00
|
|
|
avatar:
|
|
|
|
g1WalletsBox.get(profile['pubkey'])?.avatar,
|
2022-06-16 19:45:34 +02:00
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
);
|
|
|
|
}),
|
|
|
|
);
|
2022-06-15 01:14:23 +02:00
|
|
|
}
|
2022-06-16 02:43:30 +02:00
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
List parseHistory(blockchainTX, pubkey) {
|
2022-06-16 19:45:34 +02:00
|
|
|
var transBC = [];
|
|
|
|
int i = 0;
|
2022-06-16 02:43:30 +02:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
for (final trans in blockchainTX) {
|
|
|
|
final transaction = trans['node'];
|
|
|
|
final direction =
|
2022-11-27 01:59:58 +01:00
|
|
|
transaction['issuer_pubkey'] != pubkey ? 'RECEIVED' : 'SENT';
|
2022-06-16 02:43:30 +02:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
transBC.add(i);
|
|
|
|
transBC[i] = [];
|
|
|
|
transBC[i].add(DateTime.parse(transaction['created_at']));
|
|
|
|
final int amountBrut = transaction['amount'];
|
2022-09-11 13:14:52 +02:00
|
|
|
final double amount = removeDecimalZero(amountBrut / 100);
|
2022-06-16 19:45:34 +02:00
|
|
|
if (direction == "RECEIVED") {
|
2022-11-27 01:59:58 +01:00
|
|
|
transBC[i].add(transaction['issuer_pubkey']);
|
2022-06-16 19:45:34 +02:00
|
|
|
transBC[i].add(transaction['issuer']['identity']?['name'] ?? '');
|
|
|
|
} else if (direction == "SENT") {
|
2022-11-27 01:59:58 +01:00
|
|
|
transBC[i].add(transaction['receiver_pubkey']);
|
2022-06-16 19:45:34 +02:00
|
|
|
transBC[i].add(transaction['receiver']['identity']?['name'] ?? '');
|
|
|
|
}
|
2022-09-11 13:14:52 +02:00
|
|
|
transBC[i].add(amount);
|
|
|
|
transBC[i].add(direction);
|
2022-06-16 19:45:34 +02:00
|
|
|
// transBC[i].add(''); //transaction comment
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return transBC;
|
|
|
|
}
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
FetchMoreOptions? checkQueryResult(result, opts, pubkey) {
|
2022-06-16 19:45:34 +02:00
|
|
|
final List<dynamic>? blockchainTX =
|
|
|
|
(result.data['transaction_connection']['edges'] as List<dynamic>?);
|
|
|
|
// final List<dynamic> mempoolTX =
|
|
|
|
// (result.data['txsHistoryMp']['receiving'] as List<dynamic>);
|
|
|
|
|
|
|
|
pageInfo = result.data['transaction_connection']['pageInfo'];
|
|
|
|
fetchMoreCursor = pageInfo!['endCursor'];
|
|
|
|
if (fetchMoreCursor == null) nPage = 1;
|
|
|
|
|
|
|
|
log.d(fetchMoreCursor);
|
|
|
|
|
|
|
|
if (nPage == 1) {
|
|
|
|
nRepositories = 40;
|
|
|
|
} else if (nPage == 2) {
|
|
|
|
nRepositories = 100;
|
|
|
|
}
|
|
|
|
// nRepositories = 10;
|
|
|
|
nPage++;
|
|
|
|
|
|
|
|
if (fetchMoreCursor != null) {
|
|
|
|
opts = FetchMoreOptions(
|
|
|
|
variables: {'cursor': fetchMoreCursor, 'number': nRepositories},
|
|
|
|
updateQuery: (previousResultData, fetchMoreResultData) {
|
|
|
|
final List<dynamic> repos = [
|
|
|
|
...previousResultData!['transaction_connection']['edges']
|
|
|
|
as List<dynamic>,
|
|
|
|
...fetchMoreResultData!['transaction_connection']['edges']
|
|
|
|
as List<dynamic>
|
|
|
|
];
|
|
|
|
|
2022-08-06 02:22:41 +02:00
|
|
|
log.d('repos: $previousResultData');
|
|
|
|
log.d('repos: $fetchMoreResultData');
|
|
|
|
log.d('repos: $repos');
|
2022-06-16 19:45:34 +02:00
|
|
|
|
|
|
|
fetchMoreResultData['transaction_connection']['edges'] = repos;
|
|
|
|
return fetchMoreResultData;
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
log.d(
|
|
|
|
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
|
|
|
|
if (fetchMoreCursor != null) {
|
2022-08-06 02:22:41 +02:00
|
|
|
transBC = parseHistory(blockchainTX, pubkey);
|
2022-06-16 19:45:34 +02:00
|
|
|
} else {
|
|
|
|
log.i("###### DEBUG H - Début de l'historique");
|
|
|
|
}
|
|
|
|
|
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
2022-09-11 13:14:52 +02:00
|
|
|
double removeDecimalZero(double n) {
|
2022-06-16 19:45:34 +02:00
|
|
|
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 2);
|
2022-09-11 13:14:52 +02:00
|
|
|
return double.parse(result);
|
2022-06-16 19:45:34 +02:00
|
|
|
}
|
2022-06-16 02:43:30 +02:00
|
|
|
|
2022-06-16 19:45:34 +02:00
|
|
|
// checkHistoryResult(
|
|
|
|
// QueryResult<Object?> result, FetchMoreOptions options, String address) {}
|
2022-06-14 21:55:33 +02:00
|
|
|
}
|