Search works fine for pubkey; Add checksum to short pubkey format
This commit is contained in:
parent
57cbcd2096
commit
3217be291e
|
@ -1,3 +1,5 @@
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:gecko/globals.dart';
|
import 'package:gecko/globals.dart';
|
||||||
|
@ -8,6 +10,8 @@ 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: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 = '';
|
||||||
|
@ -56,11 +60,20 @@ class HistoryProvider with ChangeNotifier {
|
||||||
print("C'est une pubkey !!!");
|
print("C'est une pubkey !!!");
|
||||||
|
|
||||||
this.pubkey = pubkey;
|
this.pubkey = 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,
|
pubkeyShort = truncate(pubkey, 5,
|
||||||
omission: ":", position: TruncatePosition.end) +
|
omission: String.fromCharCode(0x2026),
|
||||||
|
position: TruncatePosition.end) +
|
||||||
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
|
truncate(pubkey, 4, omission: "", position: TruncatePosition.start) +
|
||||||
':aaa';
|
':$pubkeyChecksumShort';
|
||||||
this.outputPubkey.text = pubkey;
|
this.outputPubkey.text = pubkey;
|
||||||
|
print(pubkeyShort);
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
return pubkey;
|
return pubkey;
|
||||||
|
@ -196,6 +209,14 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
// num getBalance(_pubkey) {
|
// num getBalance(_pubkey) {
|
||||||
// getBalance(_pubkey);
|
// getBalance(_pubkey);
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -56,32 +56,6 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
),
|
),
|
||||||
body: Column(children: <Widget>[
|
body: Column(children: <Widget>[
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
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),
|
||||||
]));
|
]));
|
||||||
|
@ -193,11 +167,18 @@ class HistoryScreen extends StatelessWidget with ChangeNotifier {
|
||||||
'/default_avatar.png'),
|
'/default_avatar.png'),
|
||||||
height: 65);
|
height: 65);
|
||||||
})),
|
})),
|
||||||
Text(_historyProvider.pubkeyShort,
|
GestureDetector(
|
||||||
style: TextStyle(
|
onTap: () {
|
||||||
fontSize: 22,
|
Clipboard.setData(ClipboardData(
|
||||||
fontWeight: FontWeight.w800,
|
text: _historyProvider.pubkey));
|
||||||
fontFamily: 'Monospace')),
|
_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, 15, 0), // .only(right: 15),
|
||||||
|
|
|
@ -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(
|
||||||
|
@ -73,21 +75,37 @@ class HomeScreen extends StatelessWidget {
|
||||||
icon: _homeProvider.searchIcon,
|
icon: _homeProvider.searchIcon,
|
||||||
color: Colors.grey[850],
|
color: Colors.grey[850],
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
// Navigator.push(
|
||||||
|
// context,
|
||||||
|
// MaterialPageRoute(builder: (context) {
|
||||||
|
// return SearchList();
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
if (_homeProvider.searchIcon.icon == Icons.search) {
|
if (_homeProvider.searchIcon.icon == Icons.search) {
|
||||||
_homeProvider.searchIcon = Icon(
|
_homeProvider.searchIcon = Icon(
|
||||||
Icons.close,
|
Icons.close,
|
||||||
color: Colors.grey[850],
|
color: Colors.grey[850],
|
||||||
);
|
);
|
||||||
TextField(
|
_homeProvider.appBarTitle = TextField(
|
||||||
|
autofocus: true,
|
||||||
controller: _homeProvider.searchQuery,
|
controller: _homeProvider.searchQuery,
|
||||||
style: new TextStyle(
|
onChanged: (text) {
|
||||||
color: Colors.white,
|
print("Clé tappé: $text");
|
||||||
|
final String searchResult =
|
||||||
|
_historyProvider.isPubkey(text);
|
||||||
|
if (searchResult != '') {
|
||||||
|
_homeProvider.currentIndex = 0;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[850],
|
||||||
),
|
),
|
||||||
decoration: new InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon:
|
prefixIcon:
|
||||||
new Icon(Icons.search, color: Colors.white),
|
Icon(Icons.search, color: Colors.grey[850]),
|
||||||
hintText: "Search...",
|
hintText: "Rechercher ...",
|
||||||
hintStyle: new TextStyle(color: Colors.white)),
|
hintStyle: TextStyle(color: Colors.grey[850])),
|
||||||
);
|
);
|
||||||
_homeProvider.handleSearchStart();
|
_homeProvider.handleSearchStart();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,33 +1,36 @@
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class SearchList extends StatefulWidget {
|
class SearchList extends StatefulWidget {
|
||||||
SearchList({ Key key }) : super(key: key);
|
SearchList({Key key}) : super(key: key);
|
||||||
@override
|
@override
|
||||||
_SearchListState createState() => new _SearchListState();
|
_SearchListState createState() => new _SearchListState();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SearchListState extends State<SearchList>
|
class _SearchListState extends State<SearchList> {
|
||||||
{
|
Widget appBarTitle = new Text(
|
||||||
Widget appBarTitle = new Text("Search Sample", style: new TextStyle(color: Colors.white),);
|
"Search Sample",
|
||||||
Icon actionIcon = new Icon(Icons.search, color: Colors.white,);
|
style: new TextStyle(color: Colors.white),
|
||||||
|
);
|
||||||
|
Icon actionIcon = new Icon(
|
||||||
|
Icons.search,
|
||||||
|
color: Colors.white,
|
||||||
|
);
|
||||||
final key = new GlobalKey<ScaffoldState>();
|
final key = new GlobalKey<ScaffoldState>();
|
||||||
final TextEditingController _searchQuery = new TextEditingController();
|
final TextEditingController _searchQuery = new TextEditingController();
|
||||||
List<String> _list;
|
List<String> _list;
|
||||||
bool _IsSearching;
|
bool _isSearching;
|
||||||
String _searchText = "";
|
String _searchText = "";
|
||||||
|
|
||||||
_SearchListState() {
|
_SearchListState() {
|
||||||
_searchQuery.addListener(() {
|
_searchQuery.addListener(() {
|
||||||
if (_searchQuery.text.isEmpty) {
|
if (_searchQuery.text.isEmpty) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_IsSearching = false;
|
_isSearching = false;
|
||||||
_searchText = "";
|
_searchText = "";
|
||||||
});
|
});
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
setState(() {
|
setState(() {
|
||||||
_IsSearching = true;
|
_isSearching = true;
|
||||||
_searchText = _searchQuery.text;
|
_searchText = _searchQuery.text;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -37,9 +40,8 @@ class _SearchListState extends State<SearchList>
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_IsSearching = false;
|
_isSearching = false;
|
||||||
init();
|
init();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
|
@ -64,7 +66,7 @@ class _SearchListState extends State<SearchList>
|
||||||
appBar: buildBar(context),
|
appBar: buildBar(context),
|
||||||
body: new ListView(
|
body: new ListView(
|
||||||
padding: new EdgeInsets.symmetric(vertical: 8.0),
|
padding: new EdgeInsets.symmetric(vertical: 8.0),
|
||||||
children: _IsSearching ? _buildSearchList() : _buildList(),
|
children: _isSearching ? _buildSearchList() : _buildList(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -75,70 +77,70 @@ class _SearchListState extends State<SearchList>
|
||||||
|
|
||||||
List<ChildItem> _buildSearchList() {
|
List<ChildItem> _buildSearchList() {
|
||||||
if (_searchText.isEmpty) {
|
if (_searchText.isEmpty) {
|
||||||
return _list.map((contact) => new ChildItem(contact))
|
return _list.map((contact) => new ChildItem(contact)).toList();
|
||||||
.toList();
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
List<String> _searchList = List();
|
List<String> _searchList = List();
|
||||||
for (int i = 0; i < _list.length; i++) {
|
for (int i = 0; i < _list.length; i++) {
|
||||||
String name = _list.elementAt(i);
|
String name = _list.elementAt(i);
|
||||||
if (name.toLowerCase().contains(_searchText.toLowerCase())) {
|
if (name.toLowerCase().contains(_searchText.toLowerCase())) {
|
||||||
_searchList.add(name);
|
_searchList.add(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _searchList.map((contact) => new ChildItem(contact))
|
return _searchList.map((contact) => new ChildItem(contact)).toList();
|
||||||
.toList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget buildBar(BuildContext context) {
|
Widget buildBar(BuildContext context) {
|
||||||
return new AppBar(
|
return new AppBar(centerTitle: true, title: appBarTitle, actions: <Widget>[
|
||||||
centerTitle: true,
|
new IconButton(
|
||||||
title: appBarTitle,
|
icon: actionIcon,
|
||||||
actions: <Widget>[
|
onPressed: () {
|
||||||
new IconButton(icon: actionIcon, onPressed: () {
|
setState(() {
|
||||||
setState(() {
|
if (this.actionIcon.icon == Icons.search) {
|
||||||
if (this.actionIcon.icon == Icons.search) {
|
this.actionIcon = new Icon(
|
||||||
this.actionIcon = new Icon(Icons.close, color: Colors.white,);
|
Icons.close,
|
||||||
this.appBarTitle = new TextField(
|
color: Colors.white,
|
||||||
controller: _searchQuery,
|
);
|
||||||
style: new TextStyle(
|
this.appBarTitle = new TextField(
|
||||||
color: Colors.white,
|
controller: _searchQuery,
|
||||||
|
style: new TextStyle(
|
||||||
),
|
color: Colors.white,
|
||||||
decoration: new InputDecoration(
|
),
|
||||||
prefixIcon: new Icon(Icons.search, color: Colors.white),
|
decoration: new InputDecoration(
|
||||||
hintText: "Search...",
|
prefixIcon: new Icon(Icons.search, color: Colors.white),
|
||||||
hintStyle: new TextStyle(color: Colors.white)
|
hintText: "Search...",
|
||||||
),
|
hintStyle: new TextStyle(color: Colors.white)),
|
||||||
);
|
);
|
||||||
_handleSearchStart();
|
_handleSearchStart();
|
||||||
}
|
} else {
|
||||||
else {
|
_handleSearchEnd();
|
||||||
_handleSearchEnd();
|
}
|
||||||
}
|
});
|
||||||
});
|
},
|
||||||
},),
|
),
|
||||||
]
|
]);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleSearchStart() {
|
void _handleSearchStart() {
|
||||||
setState(() {
|
setState(() {
|
||||||
_IsSearching = true;
|
_isSearching = true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void _handleSearchEnd() {
|
void _handleSearchEnd() {
|
||||||
setState(() {
|
setState(() {
|
||||||
this.actionIcon = new Icon(Icons.search, color: Colors.white,);
|
this.actionIcon = new Icon(
|
||||||
this.appBarTitle =
|
Icons.search,
|
||||||
new Text("Search Sample", style: new TextStyle(color: Colors.white),);
|
color: Colors.white,
|
||||||
_IsSearching = false;
|
);
|
||||||
|
this.appBarTitle = new Text(
|
||||||
|
"Search Sample",
|
||||||
|
style: new TextStyle(color: Colors.white),
|
||||||
|
);
|
||||||
|
_isSearching = false;
|
||||||
_searchQuery.clear();
|
_searchQuery.clear();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class ChildItem extends StatelessWidget {
|
class ChildItem extends StatelessWidget {
|
||||||
|
@ -148,5 +150,4 @@ class ChildItem extends StatelessWidget {
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return new ListTile(title: new Text(this.name));
|
return new ListTile(title: new Text(this.name));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Reference in New Issue