+ block sorting even for unconfirmed empty blocks

* code for transactions table moved to separate unit
This commit is contained in:
Taegus
2018-12-25 15:27:02 +01:00
parent a32b746e4f
commit ff68252e62
8 changed files with 288 additions and 64 deletions

View File

@@ -1,6 +1,7 @@
const {app, ipcMain} = require('electron');
const storage = require('electron-storage');
const datastore = require('nedb');
const moment = require('moment');
const path = require('path');
const dbPath = path.join(app.getPath('userData'), 'storage.db');
@@ -26,9 +27,22 @@ ipcMain.on('storeTransaction', (event, arg) => {
});
ipcMain.on('getTransactions', (event, arg) => {
db.find({}).sort({ block: 1 }).exec(function (err, docs) {
db.find({}).exec(function (err, docs) {
ResultData = [];
// sort the data
docs.sort((a, b)=>{
if ((!b.block) && (a.block)) {
return 1;
} else if ((b.block) && (!a.block)) {
return -1;
} else if ((!b.block) && (!a.block)) {
return moment(b.timestamp, "YYYY-MM-DD HH:mm:ss").toDate() - moment(a.timestamp, "YYYY-MM-DD HH:mm:ss").toDate();
} else {
return b.block - a.block;
}
});
for (i = 0; i < Math.min(docs.length, 500); i++) {
ResultData.push([
docs[i].block,