WIP: Use GVA directly to get wallets list for search. To many request due to big number of gql pages, ban IP.
This commit is contained in:
parent
48a04866b5
commit
5726547f2f
|
@ -50,31 +50,53 @@ class SearchProvider with ChangeNotifier {
|
|||
|
||||
if (cacheTime + cacheDuring <= searchTime) {
|
||||
g1WalletsBox.clear();
|
||||
final url = Uri.parse(
|
||||
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
|
||||
final response = await http.get(url);
|
||||
// log.d(response.body);
|
||||
// final url = Uri.parse(
|
||||
// 'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
|
||||
// final response = await http.get(url);
|
||||
// // log.d(response.body);
|
||||
|
||||
G1WalletsListLive _jsonResponse =
|
||||
G1WalletsListLive.fromJson(json.decode(response.body));
|
||||
// G1WalletsListLive _jsonResponse =
|
||||
// G1WalletsListLive.fromJson(json.decode(response.body));
|
||||
|
||||
while (_jsonResponse.data.wallets.pageInfo.hasNextPage) {
|
||||
var cursor = _jsonResponse.data.wallets.pageInfo.endCursor;
|
||||
final url = Uri.parse(
|
||||
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
|
||||
final response = await http.get(url);
|
||||
}
|
||||
String cursor = '';
|
||||
Uri url;
|
||||
http.Response response;
|
||||
G1WalletsListLive _jsonResponse;
|
||||
List<G1WalletsListLive> _jsonResponseComplete = [];
|
||||
|
||||
await configBox.put('g1WalletCache', _jsonResponse);
|
||||
do {
|
||||
if (cursor == '') {
|
||||
url = Uri.parse(
|
||||
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
|
||||
} else {
|
||||
url = Uri.parse(
|
||||
'https://g1.librelois.fr/gva?query={%20wallets(pagination:%20{%20cursor:%20"$cursor",%20ord:%20ASC,%20pageSize:%20999%20})%20{%20pageInfo%20{%20hasNextPage%20endCursor%20}%20edges%20{%20node%20{%20script%20balance%20{%20amount%20base%20}%20idty%20{%20isMember%20username%20}%20}%20}%20}%20}');
|
||||
}
|
||||
response = await http.get(url);
|
||||
_jsonResponse = G1WalletsListLive.fromJson(json.decode(response.body));
|
||||
|
||||
try {
|
||||
cursor = _jsonResponse.data.wallets.pageInfo.endCursor;
|
||||
} catch (e) {
|
||||
log.e(_jsonResponse.toString() + e);
|
||||
}
|
||||
_jsonResponseComplete.add(_jsonResponse);
|
||||
log.d('yoyoyo');
|
||||
log.d(_jsonResponse.data.wallets.pageInfo.endCursor);
|
||||
} while (_jsonResponse.data.wallets.pageInfo.hasNextPage);
|
||||
|
||||
await configBox.put('g1WalletCache', _jsonResponseComplete);
|
||||
cacheTime = DateTime.now().millisecondsSinceEpoch;
|
||||
}
|
||||
|
||||
for (var value in configBox.get('g1WalletCache').data.wallets.edges) {
|
||||
if ((value.node.idty != null &&
|
||||
value.node.idty.username != null &&
|
||||
value.node.idty.username.contains(searchController.text)) ||
|
||||
value.node.script.contains(searchController.text)) {
|
||||
searchResult.add(value);
|
||||
for (var page in configBox.get('g1WalletCache')) {
|
||||
for (var value in page.data.wallets.edges) {
|
||||
if ((value.node.idty != null &&
|
||||
value.node.idty.username != null &&
|
||||
value.node.idty.username.contains(searchController.text)) ||
|
||||
value.node.script.contains(searchController.text)) {
|
||||
searchResult.add(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:gecko/globals.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:gecko/models/cesium_plus.dart';
|
||||
import 'package:gecko/models/g1_wallets_list.dart';
|
||||
import 'package:gecko/models/g1_wallets_list_live.dart';
|
||||
import 'package:gecko/models/history.dart';
|
||||
import 'package:gecko/models/search.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
@ -65,13 +66,13 @@ class SearchResultScreen extends StatelessWidget {
|
|||
),
|
||||
const SizedBox(height: 20),
|
||||
FutureBuilder(
|
||||
future: _searchProvider.searchBlockchain(),
|
||||
future: _searchProvider.searchBlockchainLive(),
|
||||
// initialData: const [],
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
return Expanded(
|
||||
child: ListView(children: <Widget>[
|
||||
for (G1WalletsList g1Wallet in snapshot.data)
|
||||
for (Edges g1Wallet in snapshot.data)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 5),
|
||||
child: ListTile(
|
||||
|
@ -79,7 +80,7 @@ class SearchResultScreen extends StatelessWidget {
|
|||
contentPadding: const EdgeInsets.all(5),
|
||||
leading: FutureBuilder(
|
||||
future: _cesiumPlusProvider
|
||||
.getAvatar(g1Wallet.pubkey),
|
||||
.getAvatar(g1Wallet.node.script),
|
||||
initialData: [
|
||||
File(appPath.path + '/default_avatar.png')
|
||||
],
|
||||
|
@ -110,21 +111,24 @@ class SearchResultScreen extends StatelessWidget {
|
|||
height: avatarsSize);
|
||||
}),
|
||||
title: Text(
|
||||
_historyClass.getShortPubkey(g1Wallet.pubkey),
|
||||
_historyClass
|
||||
.getShortPubkey(g1Wallet.node.script),
|
||||
style: const TextStyle(
|
||||
fontSize: 15.0, fontFamily: 'Monospace'),
|
||||
textAlign: TextAlign.center),
|
||||
subtitle: Text(g1Wallet?.id?.username ?? '',
|
||||
subtitle: Text(
|
||||
g1Wallet?.node?.idty?.username ?? '',
|
||||
style: const TextStyle(fontSize: 12.0),
|
||||
textAlign: TextAlign.center),
|
||||
trailing: Text("${g1Wallet.balance} Ğ1",
|
||||
trailing: Text(
|
||||
"${g1Wallet.node.balance.amount} Ğ1",
|
||||
style: const TextStyle(fontSize: 14.0),
|
||||
textAlign: TextAlign.justify),
|
||||
dense: false,
|
||||
isThreeLine: false,
|
||||
onTap: () {
|
||||
_historyClass.isPubkey(
|
||||
context, g1Wallet.pubkey);
|
||||
context, g1Wallet.node.script);
|
||||
}),
|
||||
),
|
||||
]),
|
||||
|
|
Loading…
Reference in New Issue