2020-12-13 18:31:17 +01:00
|
|
|
import 'dart:math';
|
2020-12-21 03:59:25 +01:00
|
|
|
import 'package:intl/intl.dart';
|
2020-12-13 05:43:52 +01:00
|
|
|
|
2021-01-09 10:48:06 +01:00
|
|
|
num removeDecimalZero(double n) {
|
|
|
|
String result = n.toStringAsFixed(n.truncateToDouble() == n ? 0 : 1);
|
|
|
|
return num.parse(result);
|
|
|
|
}
|
|
|
|
|
2020-12-21 03:59:25 +01:00
|
|
|
List parseHistory(txs) {
|
|
|
|
var transBC = [];
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
final currentBase = 0;
|
|
|
|
double currentUD = 10.54;
|
|
|
|
|
|
|
|
for (final trans in txs) {
|
|
|
|
var direction = trans['direction'];
|
|
|
|
final transaction = trans['node'];
|
|
|
|
var output = transaction['outputs'][0];
|
|
|
|
|
|
|
|
transBC.add(i);
|
|
|
|
transBC[i] = [];
|
|
|
|
final dateBrut =
|
|
|
|
DateTime.fromMillisecondsSinceEpoch(transaction['writtenTime'] * 1000);
|
2021-01-29 14:21:57 +01:00
|
|
|
final DateFormat formatter = DateFormat('dd-MM-yy\nHH:mm');
|
2020-12-21 03:59:25 +01:00
|
|
|
final date = formatter.format(dateBrut);
|
|
|
|
transBC[i].add(transaction['writtenTime']);
|
|
|
|
transBC[i].add(date);
|
2021-01-01 21:47:43 +01:00
|
|
|
print(
|
|
|
|
"DEBUG date et comment: ${date.toString()} -- ${transaction['comment'].toString()}");
|
2021-01-09 10:48:06 +01:00
|
|
|
int amountBrut = int.parse(output.split(':')[0]);
|
2020-12-21 03:59:25 +01:00
|
|
|
final base = int.parse(output.split(':')[1]);
|
2021-01-09 10:48:06 +01:00
|
|
|
final int applyBase = base - currentBase;
|
|
|
|
final num amount = removeDecimalZero(amountBrut * pow(10, applyBase) / 100);
|
|
|
|
num amountUD = amount / currentUD;
|
2020-12-21 03:59:25 +01:00
|
|
|
if (direction == "RECEIVED") {
|
|
|
|
transBC[i].add(transaction['issuers'][0]);
|
2021-01-29 14:21:57 +01:00
|
|
|
transBC[i].add(amount.toString());
|
2020-12-21 03:59:25 +01:00
|
|
|
transBC[i].add(amountUD.toStringAsFixed(2));
|
|
|
|
} else if (direction == "SENT") {
|
|
|
|
final outPubkey = output.split("SIG(")[1].replaceAll(')', '');
|
|
|
|
transBC[i].add(outPubkey);
|
2021-01-29 14:21:57 +01:00
|
|
|
transBC[i].add(amount.toString());
|
2020-12-21 03:59:25 +01:00
|
|
|
transBC[i].add(amountUD.toStringAsFixed(2));
|
|
|
|
}
|
|
|
|
transBC[i].add(transaction['comment']);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2020-12-23 18:18:47 +01:00
|
|
|
// transBC.sort((b, a) => Comparable.compare(a[0], b[0]));
|
2020-12-21 03:59:25 +01:00
|
|
|
return transBC;
|
|
|
|
}
|