continue to swim ...

This commit is contained in:
poka 2020-12-21 21:57:26 +01:00
parent 1bcfa738cc
commit 24be168cd4
3 changed files with 169 additions and 168 deletions

View File

@ -78,174 +78,176 @@ Future getBalance(String pubkey) async {
return result.data["balance"]["amount"] / 100;
}
// Get history
Future getHistory(String pubkey) async {
print(pubkey);
var number = 20;
var query = """{
txsHistoryBc(
pubkeyOrScript: "$pubkey"
pagination: { pageSize: $number, ord: DESC }
) {
both {
pageInfo {
hasPreviousPage
hasNextPage
}
edges {
direction
node {
currency
issuers
outputs
comment
writtenTime
}
}
}
}
txsHistoryMp(pubkey: "$pubkey") {
receiving {
currency
issuers
comment
outputs
writtenTime
}
sending {
currency
issuers
comment
outputs
writtenTime
}
}
currentUd {
amount
base
}
}""";
// // Get history
// Future getHistory(String pubkey) async {
// print(pubkey);
// var number = 20;
// var query = """{
// txsHistoryBc(
// pubkeyOrScript: "$pubkey"
// pagination: { pageSize: $number, ord: DESC }
// ) {
// both {
// pageInfo {
// hasPreviousPage
// hasNextPage
// startCursor
// endCursor
// }
// edges {
// direction
// node {
// currency
// issuers
// outputs
// comment
// writtenTime
// }
// }
// }
// }
// txsHistoryMp(pubkey: "$pubkey") {
// receiving {
// currency
// issuers
// comment
// outputs
// writtenTime
// }
// sending {
// currency
// issuers
// comment
// outputs
// writtenTime
// }
// }
// currentUd {
// amount
// base
// }
// }""";
final res = await buildQ(query);
// final res = await buildQ(query);
// Parse history
var resBC, resMP;
print(res.toString());
try {
resBC = res.data["txsHistoryBc"]['both']['edges'];
resMP = res.data["txsHistoryMp"];
} catch (e) {
return false;
}
var i = 0;
// String outPubkey;
var transBC = [];
final currentBase = res.data['currentUd']['base'];
final currentUD = res.data['currentUd']['amount'] / 100;
// // Parse history
// var resBC, resMP;
// print(res.toString());
// try {
// resBC = res.data["txsHistoryBc"]['both']['edges'];
// resMP = res.data["txsHistoryMp"];
// } catch (e) {
// return false;
// }
// var i = 0;
// // String outPubkey;
// var transBC = [];
// final currentBase = res.data['currentUd']['base'];
// final currentUD = res.data['currentUd']['amount'] / 100;
// Get tx blockchain
for (final trans in resBC) {
var direction = trans['direction'];
// // Get tx blockchain
// for (final trans in resBC) {
// var direction = trans['direction'];
print(trans);
final transaction = trans['node'];
var output = transaction['outputs'][0];
// print(trans);
// final transaction = trans['node'];
// var output = transaction['outputs'][0];
print("DEBUG1 " + transaction['writtenTime'].toString());
transBC.add(i);
transBC[i] = [];
transBC[i].add(transaction['writtenTime']);
var amountBrut = int.parse(output.split(':')[0]);
final base = int.parse(output.split(':')[1]);
final applyBase = base - currentBase;
final amount = amountBrut * pow(10, applyBase) / 100;
var amountUD = amount / currentUD;
if (direction == "RECEIVED") {
transBC[i].add(transaction['issuers'][0]);
transBC[i].add(amount);
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);
transBC[i].add(amountUD.toStringAsFixed(2));
}
transBC[i].add(transaction['comment']);
transBC[i].add(base);
// print("DEBUG1 " + transaction['writtenTime'].toString());
// transBC.add(i);
// transBC[i] = [];
// transBC[i].add(transaction['writtenTime']);
// var amountBrut = int.parse(output.split(':')[0]);
// final base = int.parse(output.split(':')[1]);
// final applyBase = base - currentBase;
// final amount = amountBrut * pow(10, applyBase) / 100;
// var amountUD = amount / currentUD;
// if (direction == "RECEIVED") {
// transBC[i].add(transaction['issuers'][0]);
// transBC[i].add(amount);
// 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);
// transBC[i].add(amountUD.toStringAsFixed(2));
// }
// transBC[i].add(transaction['comment']);
// transBC[i].add(base);
i++;
}
// i++;
// }
// Get tx mempool
var transMP = [];
i = 0;
for (var transaction in resMP['receiving']) {
if (transMP == null) {
break;
}
var output = transaction['outputs'][0];
var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transMP.add(i);
transMP[i] = [];
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;
final amount = amountBrut * pow(10, applyBase) / 100;
transMP[i].add(amount);
final amountUD = amount / currentUD;
transMP[i].add(amountUD.toStringAsFixed(2));
transMP[i].add(transaction['comment']);
transMP[i].add(base);
transMP[i].add(outPubkey);
// // Get tx mempool
// var transMP = [];
// i = 0;
// for (var transaction in resMP['receiving']) {
// if (transMP == null) {
// break;
// }
// var output = transaction['outputs'][0];
// var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
// transMP.add(i);
// transMP[i] = [];
// 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;
// final amount = amountBrut * pow(10, applyBase) / 100;
// transMP[i].add(amount);
// final amountUD = amount / currentUD;
// transMP[i].add(amountUD.toStringAsFixed(2));
// transMP[i].add(transaction['comment']);
// transMP[i].add(base);
// transMP[i].add(outPubkey);
i++;
}
// i++;
// }
transMP = [];
i = 0;
for (var transaction in resMP['sending']) {
if (transMP == null) {
break;
}
var output = transaction['outputs'][0];
var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
transMP.add(i);
transMP[i] = [];
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;
final amount = amountBrut * pow(10, applyBase) / 100;
transMP[i].add(-amount);
final amountUD = amount / currentUD;
transMP[i].add(amountUD.toStringAsFixed(2));
transMP[i].add(transaction['comment']);
transMP[i].add(base);
transMP[i].add(outPubkey);
// transMP = [];
// i = 0;
// for (var transaction in resMP['sending']) {
// if (transMP == null) {
// break;
// }
// var output = transaction['outputs'][0];
// var outPubkey = output.split("SIG(")[1].replaceAll(')', '');
// transMP.add(i);
// transMP[i] = [];
// 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;
// final amount = amountBrut * pow(10, applyBase) / 100;
// transMP[i].add(-amount);
// final amountUD = amount / currentUD;
// transMP[i].add(amountUD.toStringAsFixed(2));
// transMP[i].add(transaction['comment']);
// transMP[i].add(base);
// transMP[i].add(outPubkey);
i++;
}
// i++;
// }
// Order transactions by date
transBC.sort((b, a) => Comparable.compare(a[0], b[0]));
transMP.sort((b, a) => Comparable.compare(a[0], b[0]));
// // Order transactions by date
// transBC.sort((b, a) => Comparable.compare(a[0], b[0]));
// transMP.sort((b, a) => Comparable.compare(a[0], b[0]));
// // Keep only base if there is base change
// var lastBase = 0;
// for (i in trans) {
// if (i[5] == lastBase){
// i[6] = null;
// }
// else {
// lastBase = i[6];
// }
// // // Keep only base if there is base change
// // var lastBase = 0;
// // for (i in trans) {
// // if (i[5] == lastBase){
// // i[6] = null;
// // }
// // else {
// // lastBase = i[6];
// // }
// print(trans);
return [transBC, transMP];
}
// // print(trans);
// return [transBC, transMP];
// }
// NEW WAY //
@ -261,11 +263,11 @@ List parseHistory(txs) {
for (final trans in txs) {
var direction = trans['direction'];
print(trans);
// print(trans);
final transaction = trans['node'];
var output = transaction['outputs'][0];
print("DEBUG1 " + transaction['writtenTime'].toString());
print("DEBUG comment: " + transaction['comment'].toString());
transBC.add(i);
transBC[i] = [];
final dateBrut =

View File

@ -70,7 +70,7 @@ class _HistoryListScreenState extends State<HistoryListScreen> {
onChanged: (text) {
print("Clé tappé: $text");
// pubkey = text;
isPubkey(text);
pubkey = isPubkey(text);
},
controller: this._outputPubkey,
maxLines: 1,
@ -116,10 +116,11 @@ class _HistoryListScreenState extends State<HistoryListScreen> {
options: QueryOptions(
documentNode: gql(getMyRepositories),
variables: <String, dynamic>{
'pubkey': pubkey, // this._outputPubkey,
'pubkey':
'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU', // pubkey,
'number': nRepositories,
// set cursor to null so as to start at the beginning
// 'cursor': 10
// 'cursor': 0
},
),
builder: (QueryResult result,
@ -169,7 +170,7 @@ class _HistoryListScreenState extends State<HistoryListScreen> {
fetchMoreResultData['txsHistoryBc']['both']
['edges'] = repos;
print('A: ' + fetchMoreCursor + ' B');
return fetchMoreResultData;
},
);
@ -316,11 +317,9 @@ class _HistoryListScreenState extends State<HistoryListScreen> {
print("C'est une pubkey !!!");
showHistory(pubkey);
setState(({pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'}) {
pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU';
});
// setState(() {});
// return pubkey;
return pubkey;
// print(pubkey);
// setState(({pubkey = 'D2meevcAHFTS2gQMvmRW5Hzi25jDdikk4nC4u1FkwRaU'}) {
@ -328,10 +327,8 @@ class _HistoryListScreenState extends State<HistoryListScreen> {
// print('setState : ' + pubkey);
// });
} else {
// return '';
return '';
}
return '';
}
Future showHistory(pubkey) async {

View File

@ -8,6 +8,8 @@ const String getMyRepositories = r'''
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
edges {
direction