Add random endpoint choossing in main; WIP: Add commented code for wallet list refresh; Add TODO

This commit is contained in:
poka 2021-01-11 19:13:28 +01:00
parent 2b053226a7
commit a1f2b92d5b
6 changed files with 71 additions and 12 deletions

View File

@ -0,0 +1,3 @@
[
"https://g1.librelois.fr/gva"
]

View File

@ -4,31 +4,84 @@ import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart' as http;
// import 'package:flutter/services.dart' show rootBundle;
import 'dart:math';
// import 'dart:convert';
// void main() => runApp(Gecko());
final bool enableSentry = true;
// Future<String> getJsonEndpoints() {
// return rootBundle.loadString('config/gva_endpoints.json');
// }
T getRandomElement<T>(List<T> list) {
final random = new Random();
var i = random.nextInt(list.length);
return list[i];
}
Future<String> getRandomEndpoint() async {
// TODO: Improve implemention of getRandomEndpoint() with JSON and error handling
// final _json = json.decode(await getJsonEndpoints());
// print('JSON !! :');
// print(_json);
// final _list = _json[];
final _list = ['https://g1.librelois.fr/gva'];
final _endpoint = getRandomElement(_list);
print('ENDPOINT: ' + _endpoint);
// http.post(_endpoint);
final response = await http.post(_endpoint);
if (response.statusCode != 200) {
print('Endpoint statutcode: ' + response.statusCode.toString());
// _endpoint = getRandomElement(_list);
return 'HS';
}
return _endpoint;
}
Future<void> main() async {
String randomEndpoint; // = await getRandomEndpoint();
int i = 0;
do {
print(i);
if (i >= 3) {
print('NO VALID ENDPOINT FOUND !');
break;
}
if (i != 0) {
await Future.delayed(Duration(milliseconds: 500));
}
randomEndpoint = await getRandomEndpoint();
i++;
} while (randomEndpoint == 'HS');
if (kReleaseMode && enableSentry) {
await SentryFlutter.init(
(options) {
options.dsn =
'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110';
},
appRunner: () => runApp(Gecko()),
appRunner: () => runApp(Gecko(randomEndpoint)),
);
} else {
print('Debug mode enabled: No sentry alerte');
runApp(Gecko());
runApp(Gecko(randomEndpoint));
}
}
class Gecko extends StatelessWidget {
Gecko(this.randomEndpoint);
final String randomEndpoint;
@override
Widget build(BuildContext context) {
final _httpLink = HttpLink(
// 'http://192.168.1.91:10060/gva',
'https://g1.librelois.fr/gva',
randomEndpoint,
);
final _client = ValueNotifier(

View File

@ -14,7 +14,7 @@ class GenerateWalletScreen extends StatefulWidget {
}
class GenerateWalletState extends State<GenerateWalletScreen> {
GlobalKey<MyWalletState> _keyWallets = GlobalKey();
GlobalKey<MyWalletState> _keyMyWallets = GlobalKey();
GlobalKey<ValidStoreWalletState> _keyValidWallets = GlobalKey();
void initState() {
super.initState();
@ -102,7 +102,7 @@ class GenerateWalletState extends State<GenerateWalletScreen> {
if (fSnapshot.hasData)
return Visibility(
visible: fSnapshot.data,
child: MyWalletsScreen(keyWallets: _keyWallets));
child: MyWalletsScreen(keyMyWallets: _keyMyWallets));
return Center(child: CircularProgressIndicator());
}),
SizedBox(height: 8),
@ -164,7 +164,7 @@ class GenerateWalletState extends State<GenerateWalletScreen> {
fontSize: 30.0,
color: Colors.black,
fontWeight: FontWeight.bold)),
SizedBox(height: 12),
SizedBox(height: 20),
// Expanded(child: Align(alignment: Alignment.bottomCenter)),
new RaisedButton(
color: Color(0xffFFD68E),
@ -192,12 +192,12 @@ class GenerateWalletState extends State<GenerateWalletScreen> {
// setState(() {});
// getAllWalletsNames();
// checkIfWalletExist('tata');
// _keyWallets.currentState.getAllWalletsNames();
// _keyMyWallets.currentState.getAllWalletsNames();
}
}));
}
: null,
child: Text('Enregistrer ce wallet',
child: Text('Enregistrer ce portefeuille',
style: TextStyle(fontSize: 20))),
SizedBox(height: 20)
]),
@ -219,7 +219,8 @@ class GenerateWalletState extends State<GenerateWalletScreen> {
final bool _isExist = await checkIfWalletExist('tata');
print('The wallet exist in resetWalletState(): ' + _isExist.toString());
// initState();
// _keyWallets.currentState.setState(() {});
// _keyMyWallets.currentState.setState(() {});
// _keyMyWallets.currentState.initAppDirectory();
setState(() {
// getAllWalletsNames();
// this.walletIsGenerated = true;

View File

@ -9,7 +9,7 @@ import 'package:path_provider/path_provider.dart';
import 'package:pin_code_fields/pin_code_fields.dart';
class MyWalletsScreen extends StatefulWidget {
const MyWalletsScreen({Key keyWallets}) : super(key: keyWallets);
const MyWalletsScreen({Key keyMyWallets}) : super(key: keyMyWallets);
@override
MyWalletState createState() => MyWalletState();
}

View File

@ -227,7 +227,7 @@ packages:
source: hosted
version: "1.4.4+1"
http:
dependency: transitive
dependency: "direct main"
description:
name: http
url: "https://pub.dartlang.org"

View File

@ -26,6 +26,7 @@ dependencies:
sentry_flutter: ^4.0.1
path_provider: ^1.6.24
pin_code_fields: ^6.0.2
http: ^0.12.2
flutter_icons:
@ -44,3 +45,4 @@ flutter:
assets:
- images/
- config/