Disconnect completly GVA and Cs+

This commit is contained in:
poka 2022-05-30 15:32:00 +02:00
parent 7bef4a9cd3
commit 1a6dfdd617
10 changed files with 272 additions and 385 deletions

View File

@ -15,7 +15,6 @@ Directory? appPath;
late String appVersion;
late SharedPreferences prefs;
late String endPointGVA;
const int pinLength = 5;
const String appLang = 'english';

View File

@ -36,7 +36,6 @@ import 'package:flutter/material.dart';
import 'package:gecko/screens/myWallets/wallets_home.dart';
import 'package:gecko/screens/search.dart';
import 'package:gecko/screens/search_result.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:hive_flutter/hive_flutter.dart';
import 'package:provider/provider.dart';
import 'package:flutter/foundation.dart';
@ -73,26 +72,9 @@ Future<void> main() async {
await Hive.deleteBoxFromDisk('g1WalletsBox');
g1WalletsBox = await Hive.openBox<G1WalletsList>("g1WalletsBox");
// keystoreBox = await Hive.openBox("keystoreBox");
// g1WalletsBox.clear();
// final HiveStore _store =
// await HiveStore.open(path: '${appPath.path}/gqlCache');
// Get a valid GVA endpoint
endPointGVA = 'https://g1.librelois.fr/gva';
// endPointGVA = 'https://duniter-g1.p2p.legal/gva';
await _homeProvider.getValidEndpoints();
// log.d(await configBox.get('endpoint'));
// if (endPointGVA == 'HS') {
// _homeProvider.playSound('faché', 0.8);
// } else {
// _homeProvider.playSound('start', 0.2);
// }
HttpOverrides.global = MyHttpOverrides();
if (kReleaseMode && enableSentry) {
@ -109,7 +91,7 @@ Future<void> main() async {
await SentryFlutter.init((options) {
options.dsn =
'https://c09587b46eaa42e8b9fda28d838ed180@o496840.ingest.sentry.io/5572110';
}, appRunner: () => runApp(Gecko(endPointGVA)));
}, appRunner: () => runApp(const Gecko()));
// runZoned<Future<void>>(
// () async {
@ -126,30 +108,17 @@ Future<void> main() async {
} else {
print('Debug mode enabled: No sentry alerte');
runApp(Gecko(endPointGVA));
runApp(const Gecko());
}
}
class Gecko extends StatelessWidget {
const Gecko(this.randomEndpoint, {Key? key}) : super(key: key);
final String? randomEndpoint;
const Gecko({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
final _httpLink = HttpLink(
randomEndpoint!,
);
final _client = ValueNotifier(
GraphQLClient(
cache: GraphQLCache(),
link: _httpLink,
),
);
// HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
// HistoryProvider('').snackNode(context);
return MultiProvider(
providers: [
// Provider(create: (context) => HistoryProvider()),
@ -163,44 +132,41 @@ class Gecko extends StatelessWidget {
ChangeNotifierProvider(create: (_) => CesiumPlusProvider()),
ChangeNotifierProvider(create: (_) => SubstrateSdk())
],
child: GraphQLProvider(
client: _client,
child: MaterialApp(
builder: (context, widget) => ResponsiveWrapper.builder(
BouncingScrollWrapper.builder(context, widget!),
maxWidth: 1200,
minWidth: 480,
defaultScale: true,
breakpoints: [
const ResponsiveBreakpoint.resize(480, name: MOBILE),
const ResponsiveBreakpoint.autoScale(800, name: TABLET),
const ResponsiveBreakpoint.resize(1000, name: DESKTOP),
],
background: Container(color: backgroundColor)),
title: 'Ğecko',
theme: ThemeData(
appBarTheme: const AppBarTheme(
color: Color(0xffFFD58D),
foregroundColor: Color(0xFF000000),
),
primaryColor: const Color(0xffFFD58D),
textTheme: const TextTheme(
bodyText1: TextStyle(fontSize: 16),
bodyText2: TextStyle(fontSize: 18),
).apply(
bodyColor: const Color(0xFF000000),
),
colorScheme:
ColorScheme.fromSwatch().copyWith(secondary: Colors.grey[850]),
child: MaterialApp(
builder: (context, widget) => ResponsiveWrapper.builder(
BouncingScrollWrapper.builder(context, widget!),
maxWidth: 1200,
minWidth: 480,
defaultScale: true,
breakpoints: [
const ResponsiveBreakpoint.resize(480, name: MOBILE),
const ResponsiveBreakpoint.autoScale(800, name: TABLET),
const ResponsiveBreakpoint.resize(1000, name: DESKTOP),
],
background: Container(color: backgroundColor)),
title: 'Ğecko',
theme: ThemeData(
appBarTheme: const AppBarTheme(
color: Color(0xffFFD58D),
foregroundColor: Color(0xFF000000),
),
home: const HomeScreen(),
initialRoute: "/",
routes: {
'/mywallets': (context) => const WalletsHome(),
'/search': (context) => const SearchScreen(),
'/searchResult': (context) => const SearchResultScreen(),
},
primaryColor: const Color(0xffFFD58D),
textTheme: const TextTheme(
bodyText1: TextStyle(fontSize: 16),
bodyText2: TextStyle(fontSize: 18),
).apply(
bodyColor: const Color(0xFF000000),
),
colorScheme:
ColorScheme.fromSwatch().copyWith(secondary: Colors.grey[850]),
),
home: const HomeScreen(),
initialRoute: "/",
routes: {
'/mywallets': (context) => const WalletsHome(),
'/search': (context) => const SearchScreen(),
'/searchResult': (context) => const SearchResultScreen(),
},
),
);
}

View File

@ -1,95 +0,0 @@
const String getHistory = r'''
query ($pubkey: String!, $number: Int!, $cursor: String) {
txsHistoryBc(
script: $pubkey
pagination: { pageSize: $number, ord: DESC, cursor: $cursor }
) {
both {
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
edges {
direction
node {
currency
issuers
outputs
comment
writtenTime
}
}
}
}
txsHistoryMp(pubkey: $pubkey) {
receiving {
currency
issuers
comment
outputs
}
sending {
currency
issuers
comment
outputs
}
}
currentUd {
amount
base
}
balance(script: $pubkey) {
amount
base
}
}
''';
const String getBalance = r'''
query ($pubkey: String!) {
balance(script: $pubkey) {
amount
base
}
currentUd {
amount
base
}
}
''';
const String getWallets = r'''
query ($number: Int!, $cursor: String) {
wallets(pagination: {ord: ASC, pageSize: $number, cursor: $cursor}) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
script
balance {
amount
base
}
idty {
isMember
username
}
}
}
}
}
''';
const String getId = r'''
query ($pubkey: PubKeyGva!) {
idty(pubkey: $pubkey) {
isMember
username
}
}
''';

View File

@ -14,66 +14,78 @@ class SearchProvider with ChangeNotifier {
notifyListeners();
}
Future<List> searchBlockchain() async {
searchResult.clear();
int searchTime = DateTime.now().millisecondsSinceEpoch;
WalletsProfilesProvider _walletProfiles = WalletsProfilesProvider('pubkey');
// Future<List> searchBlockchain() async {
// searchResult.clear();
// int searchTime = DateTime.now().millisecondsSinceEpoch;
// WalletsProfilesProvider _walletProfiles = WalletsProfilesProvider('pubkey');
if (cacheTime + cacheDuring <= searchTime) {
g1WalletsBox.clear();
// final url = Uri.parse('https://g1-stats.axiom-team.fr/data/forbes.json');
// final response = await http.get(url);
// if (cacheTime + cacheDuring <= searchTime) {
// g1WalletsBox.clear();
// // final url = Uri.parse('https://g1-stats.axiom-team.fr/data/forbes.json');
// // final response = await http.get(url);
var dio = Dio();
late Response response;
try {
response = await dio.get(
'https://g1-stats.axiom-team.fr/data/forbes.json',
options: Options(
sendTimeout: 5000,
receiveTimeout: 10000,
),
);
// response = await http.post((Uri.parse(queryOptions[0])),
// body: queryOptions[1], headers: queryOptions[2]);
} catch (e) {
log.e(e);
}
// var dio = Dio();
// late Response response;
// try {
// response = await dio.get(
// 'https://g1-stats.axiom-team.fr/data/forbes.json',
// options: Options(
// sendTimeout: 5000,
// receiveTimeout: 10000,
// ),
// );
// // response = await http.post((Uri.parse(queryOptions[0])),
// // body: queryOptions[1], headers: queryOptions[2]);
// } catch (e) {
// log.e(e);
// }
List<G1WalletsList> _listWallets = _parseG1Wallets(response.data)!;
Map<String?, G1WalletsList> _mapWallets = {
for (var e in _listWallets) e.pubkey: e
};
// List<G1WalletsList> _listWallets = _parseG1Wallets(response.data)!;
// Map<String?, G1WalletsList> _mapWallets = {
// for (var e in _listWallets) e.pubkey: e
// };
await g1WalletsBox.putAll(_mapWallets);
cacheTime = DateTime.now().millisecondsSinceEpoch;
// await g1WalletsBox.putAll(_mapWallets);
// cacheTime = DateTime.now().millisecondsSinceEpoch;
// }
// g1WalletsBox.toMap().forEach((key, value) {
// if ((value.id != null &&
// value.id!.username != null &&
// value.id!.username!
// .toLowerCase()
// .contains(searchController.text)) ||
// value.pubkey!.contains(searchController.text)) {
// searchResult.add(value);
// return;
// }
// });
// if (searchResult.isEmpty &&
// _walletProfiles.isPubkey(searchController.text)) {
// searchResult = [G1WalletsList(pubkey: searchController.text)];
// }
// return searchResult;
// }
Future<List<G1WalletsList>> searchAddress() async {
final WalletsProfilesProvider _walletProfiles =
WalletsProfilesProvider('pubkey');
if (_walletProfiles.isAddress(searchController.text)) {
G1WalletsList _wallet = G1WalletsList(pubkey: searchController.text);
return [_wallet];
} else {
return [];
}
g1WalletsBox.toMap().forEach((key, value) {
if ((value.id != null &&
value.id!.username != null &&
value.id!.username!
.toLowerCase()
.contains(searchController.text)) ||
value.pubkey!.contains(searchController.text)) {
searchResult.add(value);
return;
}
});
if (searchResult.isEmpty &&
_walletProfiles.isPubkey(searchController.text)) {
searchResult = [G1WalletsList(pubkey: searchController.text)];
}
return searchResult;
}
}
List<G1WalletsList>? _parseG1Wallets(var responseBody) {
final parsed = responseBody.cast<Map<String, dynamic>>();
// List<G1WalletsList>? _parseG1Wallets(var responseBody) {
// final parsed = responseBody.cast<Map<String, dynamic>>();
return parsed
.map<G1WalletsList>((json) => G1WalletsList.fromJson(json))
.toList();
}
// return parsed
// .map<G1WalletsList>((json) => G1WalletsList.fromJson(json))
// .toList();
// }

View File

@ -11,9 +11,9 @@ import 'dart:math';
import 'package:intl/intl.dart';
class WalletsProfilesProvider with ChangeNotifier {
WalletsProfilesProvider(this.pubkey);
WalletsProfilesProvider(this.address);
String? pubkey = '';
String? address = '';
String pubkeyShort = '';
List? transBC;
String? fetchMoreCursor;
@ -38,7 +38,7 @@ class WalletsProfilesProvider with ChangeNotifier {
log.e(e);
return 'false';
}
if (barcode != null && isPubkey(barcode)) {
if (barcode != null && isAddress(barcode)) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
@ -70,19 +70,19 @@ class WalletsProfilesProvider with ChangeNotifier {
// return result;
// }
bool isPubkey(pubkey) {
bool isAddress(address) {
final RegExp regExp = RegExp(
r'^[a-zA-Z0-9]+$',
caseSensitive: false,
multiLine: false,
);
if (regExp.hasMatch(pubkey) == true &&
pubkey.length > 42 &&
pubkey.length < 50) {
log.d("C'est une pubkey !");
if (regExp.hasMatch(address) == true &&
address.length > 47 &&
address.length < 50) {
log.d("C'est une adresse !");
this.pubkey = pubkey;
this.address = address;
return true;
} else {

View File

@ -1,7 +1,6 @@
import 'package:flutter/services.dart';
import 'package:gecko/globals.dart';
import 'package:gecko/providers/cesium_plus.dart';
import 'package:gecko/models/queries.dart';
import 'package:gecko/providers/substrate_sdk.dart';
import 'package:gecko/providers/wallets_profiles.dart';
import 'package:flutter/material.dart';
@ -65,7 +64,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
children: <Widget>[
Query(
options: QueryOptions(
document: gql(getHistory),
document: gql('getHistory'),
variables: <String, dynamic>{
'pubkey': pubkey,
'number': 10,
@ -419,7 +418,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
if (username == null)
Query(
options: QueryOptions(
document: gql(getId),
document: gql('getId'),
variables: {
'pubkey': pubkey,
},

View File

@ -240,10 +240,10 @@ class UnlockingWallet extends StatelessWidget {
listen: false);
final acc = _sub.getCurrentWallet();
log.d(
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.pubkey!}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin");
"fromAddress: ${acc.address!},destAddress: ${_walletViewProvider.address!}, amount: ${double.parse(_walletViewProvider.payAmount.text)}, password: $_pin");
_sub.pay(
fromAddress: acc.address!,
destAddress: _walletViewProvider.pubkey!,
destAddress: _walletViewProvider.address!,
amount:
double.parse(_walletViewProvider.payAmount.text),
password: _pin.toUpperCase());
@ -260,7 +260,7 @@ class UnlockingWallet extends StatelessWidget {
listen: false);
final acc = _sub.getCurrentWallet();
_sub.certify(acc.address!, _pin.toUpperCase(),
_walletViewProvider.pubkey!);
_walletViewProvider.address!);
Navigator.push(
context,

View File

@ -43,153 +43,159 @@ class SearchResultScreen extends StatelessWidget {
body: SafeArea(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child:
Column(crossAxisAlignment: CrossAxisAlignment.start, children: <
Widget>[
const SizedBox(height: 30),
RichText(
text: TextSpan(
style: TextStyle(
fontSize: 18,
color: Colors.grey[700],
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
const SizedBox(height: 30),
RichText(
text: TextSpan(
style: TextStyle(
fontSize: 18,
color: Colors.grey[700],
),
children: <TextSpan>[
const TextSpan(
text: "Résultats pour ",
),
TextSpan(
text: '"${_searchProvider.searchController.text}"',
style: const TextStyle(fontStyle: FontStyle.italic),
),
],
),
),
children: <TextSpan>[
const TextSpan(
text: "Résultats pour ",
),
TextSpan(
text: '"${_searchProvider.searchController.text}"',
style: const TextStyle(fontStyle: FontStyle.italic),
),
],
),
),
const SizedBox(height: 40),
Text(
'Dans la blockchain $currencyName',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 20),
FutureBuilder(
future: _searchProvider.searchBlockchain(),
builder: (context, AsyncSnapshot<List?> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in snapshot.data ?? [])
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: Key('searchResult${keyID++}'),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading: g1WalletsBox
.get(g1Wallet.pubkey)
?.avatar !=
null
? ClipOval(
child: g1WalletsBox
.get(g1Wallet.pubkey)!
.avatar)
: FutureBuilder(
future: _cesiumPlusProvider.getAvatar(
g1Wallet.pubkey, _avatarSize),
builder: (BuildContext context,
AsyncSnapshot<Image?> _avatar) {
if (_avatar.connectionState !=
ConnectionState.done ||
_avatar.hasError) {
return Stack(children: [
_cesiumPlusProvider
.defaultAvatar(_avatarSize),
Positioned(
top: 8,
right: 0,
width: 12,
height: 12,
child: CircularProgressIndicator(
strokeWidth: 1,
color: orangeC,
),
),
]);
}
if (_avatar.hasData) {
final _w =
g1WalletsBox.get(g1Wallet.pubkey);
if (_w != null) {
_w.avatar = _avatar.data;
}
return ClipOval(child: _avatar.data);
} else {
g1WalletsBox
.get(g1Wallet.pubkey)!
.avatar =
_cesiumPlusProvider
.defaultAvatar(_avatarSize);
return _cesiumPlusProvider
.defaultAvatar(_avatarSize);
}
}),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.pubkey!),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
balance(context, g1Wallet.pubkey!, 16)
]),
subtitle: Row(children: <Widget>[
Text(g1Wallet.id?.username ?? '',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
_walletsProfilesClass.pubkey =
g1Wallet.pubkey;
return WalletViewScreen(
pubkey: g1Wallet.pubkey,
username: g1WalletsBox
.get(g1Wallet.pubkey)
?.id
?.username,
avatar: g1WalletsBox
.get(g1Wallet.pubkey)
?.avatar,
);
}),
);
}),
),
]),
);
}
return Center(
heightFactor: 5,
child: CircularProgressIndicator(
strokeWidth: 3,
backgroundColor: yellowC,
color: orangeC,
),
);
},
),
// Text(
// _searchProvider.searchResult.toString(),
// )
]),
const SizedBox(height: 40),
Text(
'Dans la blockchain $currencyName',
style: const TextStyle(fontSize: 20),
),
const SizedBox(height: 20),
FutureBuilder(
future: _searchProvider.searchAddress(),
builder: (context, AsyncSnapshot<List?> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
log.d(snapshot.data);
if (snapshot.data?.isEmpty ?? true) {
return const Text('Aucun résultat');
} else {
return Expanded(
child: ListView(children: <Widget>[
for (G1WalletsList g1Wallet in snapshot.data ?? [])
Padding(
padding:
const EdgeInsets.symmetric(horizontal: 5),
child: ListTile(
key: Key('searchResult${keyID++}'),
horizontalTitleGap: 40,
contentPadding: const EdgeInsets.all(5),
leading:
// g1WalletsBox.get(g1Wallet.pubkey)
// ?.avatar !=
// null
// ?
_cesiumPlusProvider
.defaultAvatar(_avatarSize),
// : FutureBuilder(
// future: _cesiumPlusProvider.getAvatar(
// g1Wallet.pubkey, _avatarSize),
// builder: (BuildContext context,
// AsyncSnapshot<Image?> _avatar) {
// if (_avatar.connectionState !=
// ConnectionState.done ||
// _avatar.hasError) {
// return Stack(children: [
// _cesiumPlusProvider
// .defaultAvatar(_avatarSize),
// Positioned(
// top: 8,
// right: 0,
// width: 12,
// height: 12,
// child: CircularProgressIndicator(
// strokeWidth: 1,
// color: orangeC,
// ),
// ),
// ]);
// }
// if (_avatar.hasData) {
// final _w =
// g1WalletsBox.get(g1Wallet.pubkey);
// if (_w != null) {
// _w.avatar = _avatar.data;
// }
// return ClipOval(child: _avatar.data);
// } else {
// g1WalletsBox
// .get(g1Wallet.pubkey)!
// .avatar =
// _cesiumPlusProvider
// .defaultAvatar(_avatarSize);
// return _cesiumPlusProvider
// .defaultAvatar(_avatarSize);
// }
// }),
title: Row(children: <Widget>[
Text(getShortPubkey(g1Wallet.pubkey!),
style: const TextStyle(
fontSize: 18,
fontFamily: 'Monospace',
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
trailing: Column(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
balance(context, g1Wallet.pubkey!, 16)
]),
subtitle: Row(children: <Widget>[
Text(g1Wallet.id?.username ?? '',
style: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w500),
textAlign: TextAlign.center),
]),
dense: false,
isThreeLine: false,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) {
_walletsProfilesClass.address =
g1Wallet.pubkey;
return WalletViewScreen(
pubkey: g1Wallet.pubkey,
username: g1WalletsBox
.get(g1Wallet.pubkey)
?.id
?.username,
avatar: g1WalletsBox
.get(g1Wallet.pubkey)
?.avatar,
);
}),
);
}),
),
]),
);
}
}
return Center(
heightFactor: 5,
child: CircularProgressIndicator(
strokeWidth: 3,
backgroundColor: yellowC,
color: orangeC,
),
);
},
),
// Text(
// _searchProvider.searchResult.toString(),
// )
]),
),
),
);

View File

@ -28,10 +28,10 @@ class TransactionInProgress extends StatelessWidget {
// Map jsonResult;
final _result = _sub.transactionStatus;
log.d(_walletViewProvider.pubkey!);
log.d(_walletViewProvider.address!);
final from = _myWalletProvider.getDefaultWallet()!.name!;
final to = getShortPubkey(_walletViewProvider.pubkey!);
final to = getShortPubkey(_walletViewProvider.address!);
final amount = _walletViewProvider.payAmount.text;
String _actionName = '';

View File

@ -29,7 +29,7 @@ class WalletViewScreen extends StatelessWidget {
Provider.of<WalletsProfilesProvider>(context, listen: false);
CesiumPlusProvider _cesiumPlusProvider =
Provider.of<CesiumPlusProvider>(context, listen: false);
_walletViewProvider.pubkey = pubkey!;
_walletViewProvider.address = pubkey!;
SubstrateSdk _sub = Provider.of<SubstrateSdk>(context, listen: false);
HomeProvider _homeProvider =
Provider.of<HomeProvider>(context, listen: false);
@ -278,7 +278,7 @@ class WalletViewScreen extends StatelessWidget {
double.parse(_walletViewProvider.payAmount.text) <=
double.parse(
balanceCache[defaultWallet.address]!.split(' ')[0]) &&
_walletViewProvider.pubkey != defaultWallet.address) {
_walletViewProvider.address != defaultWallet.address) {
canValidate = true;
} else {
canValidate = false;