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