Improve few things ...
This commit is contained in:
parent
45aa28ab70
commit
267a3e0ba1
|
@ -1,3 +1,4 @@
|
|||
[
|
||||
"https://g1.librelois.fr/gva"
|
||||
]
|
||||
"https://g1.librelois.fr/gva",
|
||||
"http://localhost:30901/gva"
|
||||
]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import 'dart:io';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
Directory appPath;
|
||||
Directory walletsDirectory;
|
||||
String appVersion;
|
||||
SharedPreferences prefs;
|
||||
|
|
|
@ -12,6 +12,7 @@ import 'package:graphql_flutter/graphql_flutter.dart';
|
|||
import 'package:provider/provider.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
final bool enableSentry = true;
|
||||
|
||||
|
@ -24,11 +25,12 @@ Future<void> main() async {
|
|||
HomeProvider _homeProvider = HomeProvider();
|
||||
await _homeProvider.getAppPath();
|
||||
appVersion = await _homeProvider.getAppVersion();
|
||||
prefs = await SharedPreferences.getInstance();
|
||||
|
||||
String randomEndpoint; // = await getRandomEndpoint();
|
||||
int i = 0;
|
||||
do {
|
||||
if (i >= 3) {
|
||||
if (i >= 5) {
|
||||
print('NO VALID ENDPOINT FOUND !');
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -42,8 +42,8 @@ class GenerateWalletsProvider with ChangeNotifier {
|
|||
}
|
||||
|
||||
await walletNameDirectory.create();
|
||||
walletFile.writeAsString('${wallet.dewif}');
|
||||
walletPubkey.writeAsString('${wallet.publicKey}');
|
||||
await walletFile.writeAsString('${wallet.dewif}');
|
||||
await walletPubkey.writeAsString('${wallet.publicKey}');
|
||||
|
||||
Navigator.pop(context, true);
|
||||
Navigator.pop(context, wallet.publicKey);
|
||||
|
|
|
@ -3,6 +3,8 @@ import 'package:flutter/material.dart';
|
|||
import 'package:permission_handler/permission_handler.dart';
|
||||
import 'package:sentry/sentry.dart' as sentry;
|
||||
import 'package:qrscan/qrscan.dart' as scanner;
|
||||
import 'dart:math';
|
||||
import 'package:intl/intl.dart';
|
||||
|
||||
class HistoryProvider with ChangeNotifier {
|
||||
String pubkey = '';
|
||||
|
@ -56,6 +58,63 @@ class HistoryProvider with ChangeNotifier {
|
|||
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) {
|
||||
// getBalance(_pubkey);
|
||||
// }
|
||||
|
|
|
@ -34,7 +34,11 @@ class HomeProvider with ChangeNotifier {
|
|||
// print(_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);
|
||||
print('ENDPOINT: ' + _endpoint);
|
||||
|
||||
|
|
|
@ -37,7 +37,8 @@ class MyWalletsProvider with ChangeNotifier {
|
|||
.listSync(recursive: false, followLinks: false)
|
||||
.forEach((wallet) {
|
||||
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");
|
||||
listWallets[_name] = _pubkey;
|
||||
// i++;
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
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;
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import 'package:gecko/models/parsingGVA.dart';
|
||||
import 'package:gecko/models/query.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:gecko/models/queries.dart';
|
||||
import 'package:gecko/models/history.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
@ -16,6 +16,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
// HistoryProvider _historyProvider;
|
||||
bool isTheEnd = false;
|
||||
List _transBC;
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
FocusNode _pubkeyFocus = FocusNode();
|
||||
|
||||
FetchMore fetchMore;
|
||||
FetchMoreOptions opts;
|
||||
|
@ -47,6 +49,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
body: Column(children: <Widget>[
|
||||
SizedBox(height: 8),
|
||||
TextField(
|
||||
autofocus: false,
|
||||
focusNode: _pubkeyFocus,
|
||||
// Entrée de la pubkey
|
||||
onChanged: (text) {
|
||||
print("Clé tappxé: $text");
|
||||
|
@ -72,6 +76,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
}
|
||||
|
||||
historyQuery(context) {
|
||||
_pubkeyFocus.unfocus();
|
||||
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
||||
return Expanded(
|
||||
child: Column(
|
||||
|
@ -117,8 +122,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
|
||||
final String fetchMoreCursor = pageInfo['endCursor'];
|
||||
|
||||
final num balance =
|
||||
removeDecimalZero(result.data['balance']['amount'] / 100);
|
||||
final num balance = _historyProvider
|
||||
.removeDecimalZero(result.data['balance']['amount'] / 100);
|
||||
|
||||
if (fetchMoreCursor != null) {
|
||||
opts = FetchMoreOptions(
|
||||
|
@ -140,77 +145,55 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
print(
|
||||
"###### DEBUG H Parse blockchainTX list. Cursor: $fetchMoreCursor ######");
|
||||
if (fetchMoreCursor != null) {
|
||||
_transBC = parseHistory(blockchainTX);
|
||||
_transBC = _historyProvider.parseHistory(blockchainTX);
|
||||
isTheEnd = false;
|
||||
} else {
|
||||
print("###### DEBUG H - Début de l'historique");
|
||||
isTheEnd = true;
|
||||
}
|
||||
|
||||
// _historyProvider.resetdHistory();
|
||||
|
||||
// Build history list
|
||||
return NotificationListener(
|
||||
child: Expanded(
|
||||
child: ListView(
|
||||
controller: scrollController,
|
||||
children: <Widget>[
|
||||
SizedBox(height: 7),
|
||||
SizedBox(height: 15),
|
||||
if (_historyProvider.pubkey != '')
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Container(width: 32.0, height: 0.0),
|
||||
Container(width: 70.0, height: 0.0),
|
||||
Text(balance.toString() + ' Ğ1',
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: 30.0)),
|
||||
Container(
|
||||
padding: const EdgeInsets.only(right: 80),
|
||||
child: Text("Payer")),
|
||||
padding: const EdgeInsets.only(right: 15),
|
||||
child: IconButton(
|
||||
icon: Icon(Icons.payments),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return paymentPopup(context);
|
||||
});
|
||||
},
|
||||
iconSize: 30,
|
||||
color: Color(0xFFB16E16)))
|
||||
]),
|
||||
SizedBox(height: 12),
|
||||
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)
|
||||
])
|
||||
SizedBox(height: 15),
|
||||
const Divider(
|
||||
color: Colors.grey,
|
||||
height: 5,
|
||||
thickness: 0.5,
|
||||
indent: 0,
|
||||
endIndent: 0,
|
||||
),
|
||||
_transBC == null
|
||||
? Text('Aucune transaction à afficher.')
|
||||
: loopTransactions(context, result),
|
||||
],
|
||||
)),
|
||||
onNotification: (t) {
|
||||
|
@ -227,8 +210,103 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
|||
));
|
||||
}
|
||||
|
||||
num removeDecimalZero(double n) {
|
||||
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
|
||||
return num.parse(result);
|
||||
Widget loopTransactions(context, result) {
|
||||
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
|
||||
|
||||
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();
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
42
pubspec.lock
42
pubspec.lock
|
@ -492,6 +492,48 @@ packages:
|
|||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
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:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
|
|
@ -30,6 +30,7 @@ dependencies:
|
|||
super_tooltip: ^0.9.6
|
||||
package_info: ^0.4.3+2
|
||||
printing: ^4.0.0
|
||||
shared_preferences: ^0.5.12+4
|
||||
|
||||
|
||||
flutter_icons:
|
||||
|
|
Loading…
Reference in New Issue