Merge branch 'UXProfiles'

This commit is contained in:
poka 2021-02-17 01:15:02 +01:00
commit 70fbce3621
7 changed files with 285 additions and 159 deletions

View File

@ -7,15 +7,21 @@ 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 'dart:math';
import 'package:intl/intl.dart'; import 'package:intl/intl.dart';
import 'package:truncate/truncate.dart';
import 'package:crypto/crypto.dart';
import 'package:fast_base58/fast_base58.dart';
class HistoryProvider with ChangeNotifier { class HistoryProvider with ChangeNotifier {
String pubkey = ''; String pubkey = '';
String pubkeyShort = '';
HistoryProvider(this.pubkey); HistoryProvider(this.pubkey);
final TextEditingController outputPubkey = TextEditingController(); final TextEditingController outputPubkey = TextEditingController();
List transBC; List transBC;
bool isFirstBuild = true; bool isFirstBuild = true;
String fetchMoreCursor; String fetchMoreCursor;
Map pageInfo; Map pageInfo;
bool isHistoryScreen = false;
String historySwitchButtun = "Voir l'historique";
Future scan() async { Future scan() async {
await Permission.camera.request(); await Permission.camera.request();
@ -54,7 +60,13 @@ class HistoryProvider with ChangeNotifier {
print("C'est une pubkey !!!"); print("C'est une pubkey !!!");
this.pubkey = pubkey; this.pubkey = pubkey;
getShortPubkey(pubkey);
this.outputPubkey.text = pubkey; this.outputPubkey.text = pubkey;
print(pubkeyShort);
isHistoryScreen = false;
historySwitchButtun = "Voir l'historique";
notifyListeners(); notifyListeners();
return pubkey; return pubkey;
@ -63,6 +75,22 @@ class HistoryProvider with ChangeNotifier {
return ''; return '';
} }
String getShortPubkey(String pubkey) {
List<int> pubkeyByte = Base58Decode(pubkey);
Digest pubkeyS256 = sha256.convert(sha256.convert(pubkeyByte).bytes);
String pubkeyCheksum = Base58Encode(pubkeyS256.bytes);
String pubkeyChecksumShort = truncate(pubkeyCheksum, 3,
omission: "", position: TruncatePosition.end);
pubkeyShort = truncate(pubkey, 5,
omission: String.fromCharCode(0x2026),
position: TruncatePosition.end) +
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
':$pubkeyChecksumShort';
return pubkeyShort;
}
// Pi: D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU // For debug // Pi: D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU // For debug
// Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn // Boris: JE6mkuzSpT3ePciCPRTpuMT9fqPUVVLJz2618d33p7tn
// Matograine portefeuille: 9p5nHsES6xujFR7pw2yGy4PLKKHgWsMvsDHaHF64Uj25. // Matograine portefeuille: 9p5nHsES6xujFR7pw2yGy4PLKKHgWsMvsDHaHF64Uj25.
@ -111,11 +139,13 @@ class HistoryProvider with ChangeNotifier {
num amountUD = amount / currentUD; num amountUD = amount / currentUD;
if (direction == "RECEIVED") { if (direction == "RECEIVED") {
transBC[i].add(transaction['issuers'][0]); transBC[i].add(transaction['issuers'][0]);
transBC[i].add(getShortPubkey(transaction['issuers'][0]));
transBC[i].add(amount.toString()); transBC[i].add(amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2)); transBC[i].add(amountUD.toStringAsFixed(2));
} else if (direction == "SENT") { } else if (direction == "SENT") {
final outPubkey = output.split("SIG(")[1].replaceAll(')', ''); final outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transBC[i].add(outPubkey); transBC[i].add(outPubkey);
transBC[i].add(getShortPubkey(outPubkey));
transBC[i].add('- ' + amount.toString()); transBC[i].add('- ' + amount.toString());
transBC[i].add(amountUD.toStringAsFixed(2)); transBC[i].add(amountUD.toStringAsFixed(2));
} }
@ -190,6 +220,24 @@ class HistoryProvider with ChangeNotifier {
return num.parse(result); return num.parse(result);
} }
snackCopyKey(context) {
final snackBar = SnackBar(
content:
Text("Cette clé publique a été copié dans votre presse-papier."),
duration: Duration(seconds: 2));
Scaffold.of(context).showSnackBar(snackBar);
}
void switchProfileView() {
isHistoryScreen = !isHistoryScreen;
if (isHistoryScreen) {
historySwitchButtun = "Payer";
} else {
historySwitchButtun = "Voir l'historique";
}
notifyListeners();
}
// num getBalance(_pubkey) { // num getBalance(_pubkey) {
// getBalance(_pubkey); // getBalance(_pubkey);
// } // }

View File

@ -11,6 +11,10 @@ import 'package:path_provider/path_provider.dart';
class HomeProvider with ChangeNotifier { class HomeProvider with ChangeNotifier {
int _currentIndex = 0; int _currentIndex = 0;
bool isSearching;
Icon searchIcon = Icon(Icons.search);
final TextEditingController searchQuery = new TextEditingController();
Widget appBarTitle = Text('Ğecko', style: TextStyle(color: Colors.grey[850]));
get currentIndex => _currentIndex; get currentIndex => _currentIndex;
@ -101,8 +105,25 @@ class HomeProvider with ChangeNotifier {
} }
T getRandomElement<T>(List<T> list) { T getRandomElement<T>(List<T> list) {
final random = new Random(); final random = Random();
var i = random.nextInt(list.length); var i = random.nextInt(list.length);
return list[i]; return list[i];
} }
void handleSearchStart() {
isSearching = true;
notifyListeners();
}
void handleSearchEnd() {
searchIcon = Icon(
Icons.search,
color: Colors.grey[850],
);
appBarTitle = Text('Ğecko', style: TextStyle(color: Colors.grey[850]));
isSearching = false;
searchQuery.clear();
notifyListeners();
}
} }

View File

@ -10,7 +10,6 @@ import 'package:flutter/foundation.dart';
import 'dart:ui'; import 'dart:ui';
import 'package:graphql_flutter/graphql_flutter.dart'; import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:truncate/truncate.dart';
// ignore: must_be_immutable // ignore: must_be_immutable
class HistoryScreen extends StatelessWidget with ChangeNotifier { class HistoryScreen extends StatelessWidget with ChangeNotifier {
@ -21,6 +20,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
final _formKey = GlobalKey<FormState>(); final _formKey = GlobalKey<FormState>();
FocusNode _pubkeyFocus = FocusNode(); FocusNode _pubkeyFocus = FocusNode();
List cesiumData; List cesiumData;
final double avatarsSize = 80;
FetchMore fetchMore; FetchMore fetchMore;
FetchMoreOptions opts; FetchMoreOptions opts;
@ -55,39 +55,13 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
), ),
), ),
body: Column(children: <Widget>[ body: Column(children: <Widget>[
SizedBox(height: 20), SizedBox(height: 0),
TextField(
autofocus: false,
focusNode: _pubkeyFocus,
// Entrée de la pubkey
onChanged: (text) {
print("Clé tappxé: $text");
_historyProvider.isPubkey(text);
},
controller: this._outputPubkey,
maxLines: 1,
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: 'Tappez/Collez une clé publique, ou scannez',
hintStyle: TextStyle(fontSize: 14),
contentPadding:
EdgeInsets.symmetric(horizontal: 7, vertical: 15),
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
),
style: TextStyle(
fontSize: 14.0,
fontWeight: FontWeight.bold,
fontFamily: 'Monospace')),
if (_historyProvider.pubkey != '') if (_historyProvider.pubkey != '')
historyQuery(context, _historyProvider), historyQuery(context, _historyProvider),
])); ]));
} }
Widget historyQuery(context, _historyProvider) { Widget historyQuery(context, HistoryProvider _historyProvider) {
_pubkeyFocus.unfocus(); _pubkeyFocus.unfocus();
// HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context); // HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
CesiumPlusProvider _cesiumPlusProvider = CesiumPlusProvider _cesiumPlusProvider =
@ -148,7 +122,7 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
child: ListView( child: ListView(
controller: scrollController, controller: scrollController,
children: <Widget>[ children: <Widget>[
SizedBox(height: 15), SizedBox(height: 20),
if (_historyProvider.pubkey != '') if (_historyProvider.pubkey != '')
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
@ -157,7 +131,8 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
children: [ children: [
if (_isFirstExec) if (_isFirstExec)
Container( Container(
padding: const EdgeInsets.only(left: 30), padding:
const EdgeInsets.fromLTRB(12, 0, 5, 0),
child: FutureBuilder( child: FutureBuilder(
future: _cesiumPlusProvider future: _cesiumPlusProvider
.getAvatar(_historyProvider.pubkey), .getAvatar(_historyProvider.pubkey),
@ -174,71 +149,93 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
return Image.file( return Image.file(
File(appPath.path + File(appPath.path +
'/default_avatar.png'), '/default_avatar.png'),
height: 65); height: avatarsSize);
} }
if (_avatar.hasError) { if (_avatar.hasError) {
return Image.file( return Image.file(
File(appPath.path + File(appPath.path +
'/default_avatar.png'), '/default_avatar.png'),
height: 65); height: avatarsSize);
} }
if (_avatar.hasData) { if (_avatar.hasData) {
return SingleChildScrollView( return SingleChildScrollView(
padding: EdgeInsets.all(0.0), padding: EdgeInsets.all(0.0),
child: Image.file(_avatar.data[0], child: Image.file(_avatar.data[0],
height: 65)); height: avatarsSize));
} }
return Image.file( return Image.file(
File(appPath.path + File(appPath.path +
'/default_avatar.png'), '/default_avatar.png'),
height: 65); height: avatarsSize);
})), })),
if (_isFirstExec) GestureDetector(
Text(balance.toString() + ' Ğ1', onTap: () {
textAlign: TextAlign.center, Clipboard.setData(ClipboardData(
style: TextStyle(fontSize: 30.0)), text: _historyProvider.pubkey));
_historyProvider.snackCopyKey(context);
},
child: Text(_historyProvider.pubkeyShort,
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.w800,
fontFamily: 'Monospace')),
),
Container( Container(
padding: const EdgeInsets.fromLTRB( padding: const EdgeInsets.fromLTRB(
30, 0, 15, 0), // .only(right: 15), 30, 0, 5, 0), // .only(right: 15),
child: IconButton( child: Text('TODO')),
icon: Icon(Icons.payments), SizedBox(width: 0)
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return paymentPopup(context);
});
},
iconSize: 30,
color: Color(0xFFB16E16)))
]), ]),
SizedBox(height: 10),
if (_isFirstExec) if (_isFirstExec)
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceAround, mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Container( Container(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
// padding: const EdgeInsets., // padding: const EdgeInsets.,
child: FutureBuilder( child: FutureBuilder(
future: _cesiumPlusProvider future: _cesiumPlusProvider
.getName(_historyProvider.pubkey), .getName(_historyProvider.pubkey),
initialData: '', initialData: '...',
builder: (context, snapshot) { builder: (context, snapshot) {
return Text(snapshot.data); return Text(
snapshot.data != ''
? snapshot.data
: '-',
style: TextStyle(fontSize: 20));
})) }))
]), ]),
SizedBox(height: 18),
if (_isFirstExec)
Container(
padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
child: Text(balance.toString() + ' Ğ1',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18.0))),
SizedBox(height: 20), SizedBox(height: 20),
const Divider( ElevatedButton(
color: Colors.grey, style: ElevatedButton.styleFrom(
height: 5, elevation: 1,
thickness: 0.5, primary: Colors.grey[50], // background
indent: 0, onPrimary: Colors.black, // foreground
endIndent: 0, ),
), onPressed: () {
_historyProvider.transBC == null _historyProvider.switchProfileView();
? Text('Aucune transaction à afficher.') },
: loopTransactions(context, result), child: Text(_historyProvider.historySwitchButtun,
style: TextStyle(
fontSize: 15, color: Color(0xffD28928)))),
// const Divider(
// color: Colors.grey,
// height: 5,
// thickness: 0.5,
// indent: 0,
// endIndent: 0,
// ),
_historyProvider.isHistoryScreen
? historyView(context, result)
: payView(context),
], ],
)), )),
onNotification: (t) { onNotification: (t) {
@ -255,104 +252,114 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
)); ));
} }
Widget loopTransactions(context, result) { Widget payView(context) {
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context); TextEditingController payComment = new TextEditingController();
return Column(children: <Widget>[ return Stack(
for (var repository in _historyProvider.transBC) overflow: Overflow.visible,
Padding( children: <Widget>[
padding: const EdgeInsets.symmetric(horizontal: 8.0), Form(
child: ListTile( key: _formKey,
contentPadding: const EdgeInsets.all(5.0), child: Column(
leading: Text(repository[1].toString(), mainAxisSize: MainAxisSize.min,
style: TextStyle( children: <Widget>[
fontSize: 12, SizedBox(height: 20),
color: Colors.grey[800], Text('Commentaire:'),
fontWeight: FontWeight.w700), Padding(
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, fontFamily: 'Monospace'),
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 (_historyProvider.isTheEnd) // What I did before ...
if (!_historyProvider.pageInfo['hasPreviousPage'])
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), padding: EdgeInsets.all(8.0),
child: Text(this._outputPubkey.text, child: TextField(
controller: payComment,
maxLines: 2,
textAlign: TextAlign.center, textAlign: TextAlign.center,
style: decoration: InputDecoration(),
TextStyle(fontSize: 15, fontWeight: FontWeight.w500)), style: TextStyle(
fontSize: 14.0,
color: Colors.black,
fontWeight: FontWeight.bold))),
SizedBox(height: 20),
Text('Montant (Ğ1):'),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
textAlign: TextAlign.center,
maxLines: 1,
keyboardType: TextInputType.number,
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(RegExp(r'(^\d*\.?\d*)'))
],
), ),
SizedBox(height: 20), ),
Text('Montant (Ğ1):'), Padding(
Padding( padding: const EdgeInsets.only(top: 15),
padding: EdgeInsets.all(8.0), child: OutlineButton(
child: TextFormField( borderSide: BorderSide(width: 2, color: Color(0xffD28928)),
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: () { onPressed: () {
if (_formKey.currentState.validate()) { if (_formKey.currentState.validate()) {
_formKey.currentState.save(); _formKey.currentState.save();
} }
}, },
), child: Padding(
) padding: const EdgeInsets.all(12),
], child: Text("PAYER",
), style: TextStyle(
fontSize: 25, color: Colors.grey[850]))),
))
],
), ),
], ),
), ],
); );
} }
Widget historyView(context, result) {
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
return _historyProvider.transBC == null
? Text('Aucune transaction à afficher.')
: Column(children: <Widget>[
for (var repository in _historyProvider.transBC)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 5.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[3],
style: TextStyle(
fontSize: 15.0, fontFamily: 'Monospace'),
textAlign: TextAlign.center),
subtitle: Text(repository[6] != '' ? repository[6] : '-',
style: TextStyle(fontSize: 12.0),
textAlign: TextAlign.center),
trailing: Text("${repository[4]} Ğ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 (_historyProvider.isTheEnd) // What I did before ...
if (!_historyProvider.pageInfo['hasPreviousPage'])
Column(children: <Widget>[
SizedBox(height: 15),
Text("Début de l'historique.",
textAlign: TextAlign.center,
style: TextStyle(fontSize: 20)),
SizedBox(height: 15)
])
]);
}
} }

View File

@ -1,4 +1,5 @@
import 'package:gecko/globals.dart'; import 'package:gecko/globals.dart';
import 'package:gecko/models/history.dart';
import 'package:gecko/models/home.dart'; import 'package:gecko/models/home.dart';
import 'package:gecko/screens/history.dart'; import 'package:gecko/screens/history.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -14,6 +15,7 @@ class HomeScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
HomeProvider _homeProvider = Provider.of<HomeProvider>(context); HomeProvider _homeProvider = Provider.of<HomeProvider>(context);
HistoryProvider _historyProvider = Provider.of<HistoryProvider>(context);
return Scaffold( return Scaffold(
drawer: Drawer( drawer: Drawer(
child: Column( child: Column(
@ -65,12 +67,51 @@ class HomeScreen extends StatelessWidget {
icon: new Icon(Icons.menu, color: Colors.grey[850]), icon: new Icon(Icons.menu, color: Colors.grey[850]),
onPressed: () => Scaffold.of(context).openDrawer(), onPressed: () => Scaffold.of(context).openDrawer(),
)), )),
title: Text('Ğecko', style: TextStyle(color: Colors.grey[850])), title: _homeProvider.appBarTitle,
actions: [ actions: [
Padding( Padding(
padding: EdgeInsets.symmetric(horizontal: 16), padding: EdgeInsets.symmetric(horizontal: 16),
child: Icon(Icons.search, color: Colors.grey[850]), child: IconButton(
), icon: _homeProvider.searchIcon,
color: Colors.grey[850],
onPressed: () {
// Navigator.push(
// context,
// MaterialPageRoute(builder: (context) {
// return SearchList();
// }),
// );
if (_homeProvider.searchIcon.icon == Icons.search) {
_homeProvider.searchIcon = Icon(
Icons.close,
color: Colors.grey[850],
);
_homeProvider.appBarTitle = TextField(
autofocus: true,
controller: _homeProvider.searchQuery,
onChanged: (text) {
print("Clé tappé: $text");
final String searchResult =
_historyProvider.isPubkey(text);
if (searchResult != '') {
_homeProvider.currentIndex = 0;
}
},
style: TextStyle(
color: Colors.grey[850],
),
decoration: InputDecoration(
prefixIcon:
Icon(Icons.search, color: Colors.grey[850]),
hintText: "Rechercher ...",
hintStyle: TextStyle(color: Colors.grey[850])),
);
_homeProvider.handleSearchStart();
} else {
_homeProvider.handleSearchEnd();
}
}))
], ],
backgroundColor: Color(0xffFFD58D), backgroundColor: Color(0xffFFD58D),
), ),

View File

@ -91,7 +91,7 @@ class GenerateWalletsScreen extends StatelessWidget {
), ),
), ),
SizedBox(height: 20), SizedBox(height: 20),
new ElevatedButton( ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
primary: Color(0xffFFD68E), // background primary: Color(0xffFFD68E), // background
onPrimary: Colors.black, // foreground onPrimary: Colors.black, // foreground

View File

@ -100,7 +100,7 @@ packages:
source: hosted source: hosted
version: "2.1.1" version: "2.1.1"
crypto: crypto:
dependency: transitive dependency: "direct main"
description: description:
name: crypto name: crypto
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
@ -120,6 +120,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.2.0-nullsafety.1" version: "1.2.0-nullsafety.1"
fast_base58:
dependency: "direct main"
description:
name: fast_base58
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.9"
ffi: ffi:
dependency: transitive dependency: transitive
description: description:

View File

@ -32,6 +32,8 @@ dependencies:
printing: ^4.0.0 printing: ^4.0.0
shared_preferences: ^0.5.12+4 shared_preferences: ^0.5.12+4
sync_http: ^0.2.0 sync_http: ^0.2.0
crypto: ^2.1.5
fast_base58:
flutter_icons: flutter_icons: