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

View File

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

View File

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