forked from axiom-team/gecko
History with new GVA version: pagination
This commit is contained in:
parent
1cd2d63fe0
commit
a1acc6a796
68
lib/api.dart
68
lib/api.dart
|
@ -80,21 +80,43 @@ Future getBalance(String pubkey) async {
|
||||||
// Get history
|
// Get history
|
||||||
Future getHistory(String pubkey) async {
|
Future getHistory(String pubkey) async {
|
||||||
print(pubkey);
|
print(pubkey);
|
||||||
|
var number = 3;
|
||||||
var query = """{
|
var query = """{
|
||||||
txsHistoryBc(pubkeyOrScript: "$pubkey") {
|
txsHistoryBc(
|
||||||
received {
|
pubkeyOrScript: "$pubkey"
|
||||||
writtenTime
|
pagination: { pageSize: $number, ord: DESC }
|
||||||
|
) {
|
||||||
|
both {
|
||||||
|
pageInfo {
|
||||||
|
hasPreviousPage
|
||||||
|
hasNextPage
|
||||||
|
}
|
||||||
|
edges {
|
||||||
|
direction
|
||||||
|
node {
|
||||||
|
currency
|
||||||
issuers
|
issuers
|
||||||
outputs
|
outputs
|
||||||
comment
|
comment
|
||||||
|
writtenTime
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
txsHistoryMp(pubkey: "$pubkey") {
|
txsHistoryMp(pubkey: "$pubkey") {
|
||||||
receiving {
|
receiving {
|
||||||
writtenTime
|
currency
|
||||||
issuers
|
issuers
|
||||||
outputs
|
|
||||||
comment
|
comment
|
||||||
|
outputs
|
||||||
|
writtenTime
|
||||||
|
}
|
||||||
|
receiving {
|
||||||
|
currency
|
||||||
|
issuers
|
||||||
|
comment
|
||||||
|
outputs
|
||||||
|
writtenTime
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentUd {
|
currentUd {
|
||||||
|
@ -107,12 +129,11 @@ Future getHistory(String pubkey) async {
|
||||||
|
|
||||||
// Parse history
|
// Parse history
|
||||||
var resBC, resMP;
|
var resBC, resMP;
|
||||||
|
print(res.toString());
|
||||||
try {
|
try {
|
||||||
resBC = res.data["txsHistoryBc"]["received"];
|
resBC = res.data["txsHistoryBc"]['both']['edges'];
|
||||||
resMP = res.data["txsHistoryMp"]["receiving"];
|
resMP = res.data["txsHistoryMp"];
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
print("DEBUG: " + e.toString());
|
|
||||||
print(res.data);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
@ -122,13 +143,17 @@ Future getHistory(String pubkey) async {
|
||||||
final currentUD = res.data['currentUd']['amount'] / 100;
|
final currentUD = res.data['currentUd']['amount'] / 100;
|
||||||
|
|
||||||
// Get tx received
|
// Get tx received
|
||||||
for (var bloc in resBC) {
|
for (final trans in resBC) {
|
||||||
var output = bloc['outputs'][0];
|
// var direction = transBC[i]['direction'];
|
||||||
|
print(trans);
|
||||||
|
final transaction = trans['node'];
|
||||||
|
var output = transaction['outputs'][0];
|
||||||
// outPubkey = output.split("SIG(")[1].replaceAll(')', '');
|
// outPubkey = output.split("SIG(")[1].replaceAll(')', '');
|
||||||
|
print("DEBUG1 " + transaction['writtenTime'].toString());
|
||||||
transBC.add(i);
|
transBC.add(i);
|
||||||
transBC[i] = [];
|
transBC[i] = [];
|
||||||
transBC[i].add(bloc['writtenTime']);
|
transBC[i].add(transaction['writtenTime']);
|
||||||
transBC[i].add(bloc['issuers'][0]);
|
transBC[i].add(transaction['issuers'][0]);
|
||||||
var amountBrut = int.parse(output.split(':')[0]);
|
var amountBrut = int.parse(output.split(':')[0]);
|
||||||
final base = int.parse(output.split(':')[1]);
|
final base = int.parse(output.split(':')[1]);
|
||||||
final applyBase = base - currentBase;
|
final applyBase = base - currentBase;
|
||||||
|
@ -136,7 +161,7 @@ Future getHistory(String pubkey) async {
|
||||||
transBC[i].add(amount);
|
transBC[i].add(amount);
|
||||||
final amountUD = amount / currentUD;
|
final amountUD = amount / currentUD;
|
||||||
transBC[i].add(amountUD.toStringAsFixed(2));
|
transBC[i].add(amountUD.toStringAsFixed(2));
|
||||||
transBC[i].add(bloc['comment']);
|
transBC[i].add(transaction['comment']);
|
||||||
transBC[i].add(base);
|
transBC[i].add(base);
|
||||||
|
|
||||||
i++;
|
i++;
|
||||||
|
@ -146,17 +171,20 @@ Future getHistory(String pubkey) async {
|
||||||
var transMP = [];
|
var transMP = [];
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
for (var bloc in resMP) {
|
print('DEBUG2');
|
||||||
|
print(resMP);
|
||||||
|
|
||||||
|
for (var transaction in resMP['receiving']) {
|
||||||
if (transMP == null) {
|
if (transMP == null) {
|
||||||
print("DEBUG:: " + resMP.toString());
|
print("DEBUG3 " + resMP.toString());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var output = bloc['outputs'][0];
|
var output = transaction['outputs'][0];
|
||||||
var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
|
var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
|
||||||
transMP.add(i);
|
transMP.add(i);
|
||||||
transMP[i] = [];
|
transMP[i] = [];
|
||||||
transMP[i].add(bloc['writtenTime']);
|
transMP[i].add(transaction['writtenTime']);
|
||||||
transMP[i].add(bloc['issuers'][0]);
|
transMP[i].add(transaction['issuers'][0]);
|
||||||
var amountBrut = int.parse(output.split(':')[0]);
|
var amountBrut = int.parse(output.split(':')[0]);
|
||||||
final base = int.parse(output.split(':')[1]);
|
final base = int.parse(output.split(':')[1]);
|
||||||
final applyBase = base - currentBase;
|
final applyBase = base - currentBase;
|
||||||
|
@ -164,7 +192,7 @@ Future getHistory(String pubkey) async {
|
||||||
transMP[i].add(amount);
|
transMP[i].add(amount);
|
||||||
final amountUD = amount / currentUD;
|
final amountUD = amount / currentUD;
|
||||||
transMP[i].add(amountUD.toStringAsFixed(2));
|
transMP[i].add(amountUD.toStringAsFixed(2));
|
||||||
transMP[i].add(bloc['comment']);
|
transMP[i].add(transaction['comment']);
|
||||||
transMP[i].add(base);
|
transMP[i].add(base);
|
||||||
transMP[i].add(outPubkey);
|
transMP[i].add(outPubkey);
|
||||||
|
|
||||||
|
|
|
@ -54,44 +54,64 @@ class _MyAppState extends State<MyApp> {
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
TextField(
|
TextField(
|
||||||
enabled: false,
|
// enabled: false,
|
||||||
|
onChanged: (text) {
|
||||||
|
print("Clé tappé: $text");
|
||||||
|
isPubkey(text);
|
||||||
|
},
|
||||||
controller: this._outputPubkey,
|
controller: this._outputPubkey,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Clé publique scanné',
|
hintText:
|
||||||
|
'Tappez/Collez une clé publique, ou scannez',
|
||||||
hintStyle: TextStyle(fontSize: 15),
|
hintStyle: TextStyle(fontSize: 15),
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(
|
||||||
horizontal: 7, vertical: 15),
|
horizontal: 7, vertical: 15),
|
||||||
|
border: InputBorder.none,
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
errorBorder: InputBorder.none,
|
||||||
|
disabledBorder: InputBorder.none,
|
||||||
),
|
),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 15.0,
|
fontSize: 15.0,
|
||||||
color: Colors.black,
|
color: Colors.black,
|
||||||
fontWeight: FontWeight.bold)),
|
fontWeight: FontWeight.bold)),
|
||||||
TextField(
|
TextField(
|
||||||
|
// Affichage balance
|
||||||
enabled: false,
|
enabled: false,
|
||||||
controller: this._outputBalance,
|
controller: this._outputBalance,
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
hintText: 'Solde du compte scanné',
|
hintText: '',
|
||||||
hintStyle: TextStyle(fontSize: 15),
|
hintStyle: TextStyle(fontSize: 15),
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(
|
||||||
horizontal: 7, vertical: 15),
|
horizontal: 7, vertical: 15),
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
errorBorder: InputBorder.none,
|
||||||
|
disabledBorder: InputBorder.none,
|
||||||
),
|
),
|
||||||
style:
|
style:
|
||||||
TextStyle(fontSize: 30.0, color: Colors.black)),
|
TextStyle(fontSize: 30.0, color: Colors.black)),
|
||||||
TextField(
|
TextField(
|
||||||
|
// Affichage history
|
||||||
enabled: false,
|
enabled: false,
|
||||||
controller: this._outputHistory,
|
controller: this._outputHistory,
|
||||||
maxLines: null,
|
maxLines: null,
|
||||||
keyboardType: TextInputType.multiline,
|
keyboardType: TextInputType.multiline,
|
||||||
decoration: InputDecoration(
|
decoration: InputDecoration(
|
||||||
prefixIcon: Icon(Icons.wrap_text),
|
prefixIcon: Icon(Icons.wrap_text),
|
||||||
hintText: 'Historique du compte scanné',
|
hintText: '',
|
||||||
hintStyle: TextStyle(fontSize: 15),
|
hintStyle: TextStyle(fontSize: 15),
|
||||||
contentPadding: EdgeInsets.symmetric(
|
contentPadding: EdgeInsets.symmetric(
|
||||||
horizontal: 7, vertical: 15),
|
horizontal: 7, vertical: 15),
|
||||||
|
focusedBorder: InputBorder.none,
|
||||||
|
enabledBorder: InputBorder.none,
|
||||||
|
errorBorder: InputBorder.none,
|
||||||
|
disabledBorder: InputBorder.none,
|
||||||
),
|
),
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontSize: 13.0,
|
fontSize: 13.0,
|
||||||
|
@ -161,30 +181,54 @@ class _MyAppState extends State<MyApp> {
|
||||||
|
|
||||||
Future checkNode() async {
|
Future checkNode() async {
|
||||||
final response = await Dio().post(graphqlEndpoint);
|
final response = await Dio().post(graphqlEndpoint);
|
||||||
|
showHistory(response);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future _scan() async {
|
Future _scan() async {
|
||||||
await Permission.camera.request();
|
await Permission.camera.request();
|
||||||
String barcode = await scanner.scan();
|
String barcode = await scanner.scan();
|
||||||
if (barcode == null) {
|
this._outputPubkey.text = "";
|
||||||
|
isPubkey(barcode);
|
||||||
|
return barcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future isPubkey(pubkey) async {
|
||||||
|
// final validCharacters = RegExp(r'^[a-zA-Z0-9]+$');
|
||||||
|
RegExp regExp = new RegExp(
|
||||||
|
r'^[a-zA-Z0-9]+$',
|
||||||
|
caseSensitive: false,
|
||||||
|
multiLine: false,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (regExp.hasMatch(pubkey) == true &&
|
||||||
|
pubkey.length > 42 &&
|
||||||
|
pubkey.length < 45) {
|
||||||
|
print("C'est une pubkey !!!");
|
||||||
|
print(pubkey.length);
|
||||||
|
showHistory(pubkey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future showHistory(pubkey) async {
|
||||||
|
// String pubkey = await _scan();
|
||||||
|
if (pubkey == null) {
|
||||||
print('nothing return.');
|
print('nothing return.');
|
||||||
} else {
|
} else {
|
||||||
this._outputPubkey.text = "";
|
this._outputPubkey.text = "";
|
||||||
this._outputBalance.text = "";
|
this._outputBalance.text = "";
|
||||||
this._outputHistory.text = "";
|
this._outputHistory.text = "";
|
||||||
// final udValue = await getUD();
|
// final udValue = await getUD();
|
||||||
this._outputPubkey.text = barcode;
|
this._outputPubkey.text = pubkey;
|
||||||
final myBalance = await getBalance(barcode.toString());
|
final myBalance = await getBalance(pubkey.toString());
|
||||||
this._outputBalance.text = myBalance.toString() + " Ğ1";
|
this._outputBalance.text = myBalance.toString() + " Ğ1";
|
||||||
|
|
||||||
final myHistory = await getHistory(barcode.toString());
|
final myHistory = await getHistory(pubkey.toString());
|
||||||
if (myHistory == false) {
|
if (myHistory == false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String historyBC = "";
|
String historyBC = "";
|
||||||
var j = 0;
|
|
||||||
for (var i in myHistory[0]) {
|
for (var i in myHistory[0]) {
|
||||||
var dateBrut = i[0];
|
var dateBrut = i[0];
|
||||||
dateBrut = DateTime.fromMillisecondsSinceEpoch(dateBrut * 1000);
|
dateBrut = DateTime.fromMillisecondsSinceEpoch(dateBrut * 1000);
|
||||||
|
@ -202,14 +246,9 @@ class _MyAppState extends State<MyApp> {
|
||||||
" Ğ1\n " +
|
" Ğ1\n " +
|
||||||
comment.toString() +
|
comment.toString() +
|
||||||
"\n---\n";
|
"\n---\n";
|
||||||
j++;
|
|
||||||
if (j >= 10) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String historyMP = "";
|
String historyMP = "";
|
||||||
j = 0;
|
|
||||||
for (var i in myHistory[1]) {
|
for (var i in myHistory[1]) {
|
||||||
if (i == null) {
|
if (i == null) {
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue