Skip to content
Snippets Groups Projects
Commit 267a3e0b authored by poka's avatar poka
Browse files

Improve few things ...

parent 45aa28ab
No related branches found
No related tags found
No related merge requests found
[ [
"https://g1.librelois.fr/gva" "https://g1.librelois.fr/gva",
] "http://localhost:30901/gva"
\ No newline at end of file ]
import 'dart:io'; import 'dart:io';
import 'package:shared_preferences/shared_preferences.dart';
Directory appPath; Directory appPath;
Directory walletsDirectory; Directory walletsDirectory;
String appVersion; String appVersion;
SharedPreferences prefs;
...@@ -12,6 +12,7 @@ import 'package:graphql_flutter/graphql_flutter.dart'; ...@@ -12,6 +12,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:sentry_flutter/sentry_flutter.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:shared_preferences/shared_preferences.dart';
final bool enableSentry = true; final bool enableSentry = true;
...@@ -24,11 +25,12 @@ Future<void> main() async { ...@@ -24,11 +25,12 @@ Future<void> main() async {
HomeProvider _homeProvider = HomeProvider(); HomeProvider _homeProvider = HomeProvider();
await _homeProvider.getAppPath(); await _homeProvider.getAppPath();
appVersion = await _homeProvider.getAppVersion(); appVersion = await _homeProvider.getAppVersion();
prefs = await SharedPreferences.getInstance();
String randomEndpoint; // = await getRandomEndpoint(); String randomEndpoint; // = await getRandomEndpoint();
int i = 0; int i = 0;
do { do {
if (i >= 3) { if (i >= 5) {
print('NO VALID ENDPOINT FOUND !'); print('NO VALID ENDPOINT FOUND !');
break; break;
} }
......
...@@ -42,8 +42,8 @@ class GenerateWalletsProvider with ChangeNotifier { ...@@ -42,8 +42,8 @@ class GenerateWalletsProvider with ChangeNotifier {
} }
await walletNameDirectory.create(); await walletNameDirectory.create();
walletFile.writeAsString('${wallet.dewif}'); await walletFile.writeAsString('${wallet.dewif}');
walletPubkey.writeAsString('${wallet.publicKey}'); await walletPubkey.writeAsString('${wallet.publicKey}');
Navigator.pop(context, true); Navigator.pop(context, true);
Navigator.pop(context, wallet.publicKey); Navigator.pop(context, wallet.publicKey);
......
...@@ -3,6 +3,8 @@ import 'package:flutter/material.dart'; ...@@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart'; import 'package:permission_handler/permission_handler.dart';
import 'package:sentry/sentry.dart' as sentry; import 'package:sentry/sentry.dart' as sentry;
import 'package:qrscan/qrscan.dart' as scanner; import 'package:qrscan/qrscan.dart' as scanner;
import 'dart:math';
import 'package:intl/intl.dart';
class HistoryProvider with ChangeNotifier { class HistoryProvider with ChangeNotifier {
String pubkey = ''; String pubkey = '';
...@@ -56,6 +58,63 @@ class HistoryProvider with ChangeNotifier { ...@@ -56,6 +58,63 @@ class HistoryProvider with ChangeNotifier {
return ''; return '';
} }
List parseHistory(txs) {
var transBC = [];
int i = 0;
final currentBase = 0;
double currentUD = 10.54;
for (final trans in txs) {
var direction = trans['direction'];
final transaction = trans['node'];
var output = transaction['outputs'][0];
transBC.add(i);
transBC[i] = [];
final dateBrut = DateTime.fromMillisecondsSinceEpoch(
transaction['writtenTime'] * 1000);
final DateFormat formatter = DateFormat('dd-MM-yy\nHH:mm');
final date = formatter.format(dateBrut);
transBC[i].add(transaction['writtenTime']);
transBC[i].add(date);
// print(
// "DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}");
int amountBrut = int.parse(output.split(':')[0]);
final base = int.parse(output.split(':')[1]);
final int applyBase = base - currentBase;
final num amount =
removeDecimalZero(amountBrut * pow(10, applyBase) / 100);
num amountUD = amount / currentUD;
if (direction == "RECEIVED") {
transBC[i].add(transaction['issuers'][0]);
transBC[i].add(amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2));
} else if (direction == "SENT") {
final outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transBC[i].add(outPubkey);
transBC[i].add('- ' + amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2));
}
transBC[i].add(transaction['comment']);
i++;
}
// transBC.sort((b, a) => Comparable.compare(a[0], b[0]));
return transBC;
}
void resetdHistory() {
this._outputPubkey.text = '';
notifyListeners();
}
num removeDecimalZero(double n) {
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
return num.parse(result);
}
// num getBalance(_pubkey) { // num getBalance(_pubkey) {
// getBalance(_pubkey); // getBalance(_pubkey);
// } // }
......
...@@ -34,7 +34,11 @@ class HomeProvider with ChangeNotifier { ...@@ -34,7 +34,11 @@ class HomeProvider with ChangeNotifier {
// print(_json); // print(_json);
// final _list = _json[]; // final _list = _json[];
final _listEndpoints = ['https://g1.librelois.fr/gva']; // final _listEndpoints = ['https://g1.librelois.fr/gva'];
final _listEndpoints = [
'https://g1.librelois.fr/gva',
'https://duniter-gva.axiom-team.fr/gva'
];
final _endpoint = getRandomElement(_listEndpoints); final _endpoint = getRandomElement(_listEndpoints);
print('ENDPOINT: ' + _endpoint); print('ENDPOINT: ' + _endpoint);
......
...@@ -37,7 +37,8 @@ class MyWalletsProvider with ChangeNotifier { ...@@ -37,7 +37,8 @@ class MyWalletsProvider with ChangeNotifier {
.listSync(recursive: false, followLinks: false) .listSync(recursive: false, followLinks: false)
.forEach((wallet) { .forEach((wallet) {
String _name = wallet.path.split('/').last; String _name = wallet.path.split('/').last;
String _pubkey = File(wallet.path + '/pubkey').readAsLinesSync()[0]; List _pubkeyList = File(wallet.path + '/pubkey').readAsLinesSync();
String _pubkey = _pubkeyList[0];
print("$_name: $_pubkey"); print("$_name: $_pubkey");
listWallets[_name] = _pubkey; listWallets[_name] = _pubkey;
// i++; // i++;
......
import 'dart:math';
import 'package:intl/intl.dart';
num removeDecimalZero(double n) {
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
return num.parse(result);
}
List parseHistory(txs) {
var transBC = [];
int i = 0;
final currentBase = 0;
double currentUD = 10.54;
for (final trans in txs) {
var direction = trans['direction'];
final transaction = trans['node'];
var output = transaction['outputs'][0];
transBC.add(i);
transBC[i] = [];
final dateBrut =
DateTime.fromMillisecondsSinceEpoch(transaction['writtenTime'] * 1000);
final DateFormat formatter = DateFormat('dd-MM-yy\nHH:mm');
final date = formatter.format(dateBrut);
transBC[i].add(transaction['writtenTime']);
transBC[i].add(date);
print(
"DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}");
int amountBrut = int.parse(output.split(':')[0]);
final base = int.parse(output.split(':')[1]);
final int applyBase = base - currentBase;
final num amount = removeDecimalZero(amountBrut * pow(10, applyBase) / 100);
num amountUD = amount / currentUD;
if (direction == "RECEIVED") {
transBC[i].add(transaction['issuers'][0]);
transBC[i].add(amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2));
} else if (direction == "SENT") {
final outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transBC[i].add(outPubkey);
transBC[i].add(amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2));
}
transBC[i].add(transaction['comment']);
i++;
}
// transBC.sort((b, a) => Comparable.compare(a[0], b[0]));
return transBC;
}
File moved
import 'package:gecko/models/parsingGVA.dart'; import 'package:flutter/services.dart';
import 'package:gecko/models/query.dart'; import 'package:gecko/models/queries.dart';
import 'package:gecko/models/history.dart'; import 'package:gecko/models/history.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
...@@ -16,6 +16,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -16,6 +16,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
// HistoryProvider _historyProvider; // HistoryProvider _historyProvider;
bool isTheEnd = false; bool isTheEnd = false;
List _transBC; List _transBC;
final _formKey = GlobalKey<FormState>();
FocusNode _pubkeyFocus = FocusNode();
FetchMore fetchMore; FetchMore fetchMore;
FetchMoreOptions opts; FetchMoreOptions opts;
...@@ -47,6 +49,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -47,6 +49,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
body: Column(children: <Widget>[ body: Column(children: <Widget>[
SizedBox(height: 8), SizedBox(height: 8),
TextField( TextField(
autofocus: false,
focusNode: _pubkeyFocus,
// Entrée de la pubkey // Entrée de la pubkey
onChanged: (text) { onChanged: (text) {
print("Clé tappxé: $text"); print("Clé tappxé: $text");
...@@ -72,6 +76,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -72,6 +76,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
} }
historyQuery(context) { historyQuery(context) {
_pubkeyFocus.unfocus();
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context); HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
return Expanded( return Expanded(
child: Column( child: Column(
...@@ -117,8 +122,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -117,8 +122,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
final String fetchMoreCursor = pageInfo['endCursor']; final String fetchMoreCursor = pageInfo['endCursor'];
final num balance = final num balance = _historyProvider
removeDecimalZero(result.data['balance']['amount'] / 100); .removeDecimalZero(result.data['balance']['amount'] / 100);
if (fetchMoreCursor != null) { if (fetchMoreCursor != null) {
opts = FetchMoreOptions( opts = FetchMoreOptions(
...@@ -140,77 +145,55 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -140,77 +145,55 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
print( print(
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######"); "###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
if (fetchMoreCursor != null) { if (fetchMoreCursor != null) {
_transBC = parseHistory(blockchainTX); _transBC = _historyProvider.parseHistory(blockchainTX);
isTheEnd = false; isTheEnd = false;
} else { } else {
print("###### DEBUG H - Début de l'historique"); print("###### DEBUG H - Début de l'historique");
isTheEnd = true; isTheEnd = true;
} }
// _historyProvider.resetdHistory();
// Build history list // Build history list
return NotificationListener( return NotificationListener(
child: Expanded( child: Expanded(
child: ListView( child: ListView(
controller: scrollController, controller: scrollController,
children: <Widget>[ children: <Widget>[
SizedBox(height: 7), SizedBox(height: 15),
if (_historyProvider.pubkey != '') if (_historyProvider.pubkey != '')
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Container(width: 32.0, height: 0.0), Container(width: 70.0, height: 0.0),
Text(balance.toString() + ' Ğ1', Text(balance.toString() + ' Ğ1',
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: TextStyle(fontSize: 30.0)), style: TextStyle(fontSize: 30.0)),
Container( Container(
padding: const EdgeInsets.only(right: 80), padding: const EdgeInsets.only(right: 15),
child: Text("Payer")), child: IconButton(
icon: Icon(Icons.payments),
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return paymentPopup(context);
});
},
iconSize: 30,
color: Color(0xFFB16E16)))
]), ]),
SizedBox(height: 12), SizedBox(height: 15),
for (var repository in _transBC) const Divider(
Padding( color: Colors.grey,
padding: const EdgeInsets.symmetric(horizontal: 8.0), height: 5,
child: ListTile( thickness: 0.5,
contentPadding: const EdgeInsets.all(5.0), indent: 0,
leading: Text(repository[1].toString(), endIndent: 0,
style: TextStyle( ),
fontSize: 12, _transBC == null
color: Colors.grey[800], ? Text('Aucune transaction à afficher.')
fontWeight: FontWeight.w700), : loopTransactions(context, result),
textAlign: TextAlign.center),
title: Text(repository[5],
style: TextStyle(fontSize: 14.0),
textAlign: TextAlign.center),
subtitle: Text(
truncate(repository[2], 20,
omission: "...",
position: TruncatePosition.end),
style: TextStyle(fontSize: 11.0),
textAlign: TextAlign.center),
trailing: Text("${repository[3]} Ğ1",
style: TextStyle(fontSize: 14.0),
textAlign: TextAlign.justify),
dense: true,
isThreeLine: false,
onTap: () {
// this._outputPubkey.text = repository[2];
_historyProvider.isPubkey(repository[2]);
})),
if (result.isLoading)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
],
),
if (isTheEnd)
Column(children: <Widget>[
SizedBox(height: 15),
Text("Début de l'historique.",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20)),
SizedBox(height: 15)
])
], ],
)), )),
onNotification: (t) { onNotification: (t) {
...@@ -227,8 +210,103 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier { ...@@ -227,8 +210,103 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
)); ));
} }
num removeDecimalZero(double n) { Widget loopTransactions(context, result) {
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1); HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
return num.parse(result);
return Column(children: <Widget>[
for (var repository in _transBC)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 8.0),
child: ListTile(
contentPadding: const EdgeInsets.all(5.0),
leading: Text(repository[1].toString(),
style: TextStyle(
fontSize: 12,
color: Colors.grey[800],
fontWeight: FontWeight.w700),
textAlign: TextAlign.center),
title: Text(repository[5],
style: TextStyle(fontSize: 14.0),
textAlign: TextAlign.center),
subtitle: Text(
truncate(repository[2], 20,
omission: "...", position: TruncatePosition.end),
style: TextStyle(fontSize: 11.0),
textAlign: TextAlign.center),
trailing: Text("${repository[3]} Ğ1",
style: TextStyle(fontSize: 14.0),
textAlign: TextAlign.justify),
dense: true,
isThreeLine: false,
onTap: () {
// this._outputPubkey.text = repository[2];
_historyProvider.isPubkey(repository[2]);
})),
if (result.isLoading)
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
CircularProgressIndicator(),
],
),
if (isTheEnd)
Column(children: <Widget>[
SizedBox(height: 15),
Text("Début de l'historique.",
textAlign: TextAlign.center, style: TextStyle(fontSize: 20)),
SizedBox(height: 15)
])
]);
}
Widget paymentPopup(context) {
return AlertDialog(
content: Stack(
overflow: Overflow.visible,
children: <Widget>[
Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text('À:'),
Padding(
padding: EdgeInsets.all(8.0),
child: Text(this._outputPubkey.text,
textAlign: TextAlign.center,
style:
TextStyle(fontSize: 15, fontWeight: FontWeight.w500)),
),
SizedBox(height: 20),
Text('Montant (Ğ1):'),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
textAlign: TextAlign.center,
autofocus: true,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d*)'))
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
child: Text("Payer"),
color: Color(0xffFFD68E),
onPressed: () {
if (_formKey.currentState.validate()) {
_formKey.currentState.save();
}
},
),
)
],
),
),
],
),
);
} }
} }
...@@ -492,6 +492,48 @@ packages: ...@@ -492,6 +492,48 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "4.0.1" version: "4.0.1"
shared_preferences:
dependency: "direct main"
description:
name: shared_preferences
url: "https://pub.dartlang.org"
source: hosted
version: "0.5.12+4"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2+4"
shared_preferences_macos:
dependency: transitive
description:
name: shared_preferences_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.1+11"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2+7"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.2+2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
......
...@@ -30,6 +30,7 @@ dependencies: ...@@ -30,6 +30,7 @@ dependencies:
super_tooltip: ^0.9.6 super_tooltip: ^0.9.6
package_info: ^0.4.3+2 package_info: ^0.4.3+2
printing: ^4.0.0 printing: ^4.0.0
shared_preferences: ^0.5.12+4
flutter_icons: flutter_icons:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment