burst-whale-watch
Version:
An account watcher for Burstcoin
107 lines • 3.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const blessed = require("neo-blessed");
const selectors_1 = require("../state/selectors");
const util_1 = require("@burstjs/util");
const constants_1 = require("../constants");
const chalk_1 = require("chalk");
class TransactionTableView {
constructor(parentView) {
this.parentView = parentView;
this.loadingText = blessed.text({
parent: parentView,
top: 'center',
left: 'center',
tags: true,
style: {
fg: 'gray',
bold: true,
bg: 'black',
border: {
fg: '#ffffff'
},
}
});
this.titleText = blessed.text({
parent: parentView,
top: 3,
right: 0,
tags: true,
style: {
fg: 'gray',
bold: true,
bg: 'black',
border: {
fg: '#ffffff'
},
}
});
this.table = blessed.table({
parent: parentView,
top: 4,
left: 'center',
data: null,
border: 'line',
align: 'center',
tags: true,
width: '100%-2',
height: 'shrink',
style: {
border: {
fg: 'white'
},
header: {
fg: 'white',
bold: true
},
cell: {
fg: 'white'
}
}
});
this.table.hide();
}
get element() {
return this.table;
}
update(state, accountId, transactions) {
const isLoading = selectors_1.selectIsLoadingTransactions(state);
if (isLoading) {
this.loadingText.setLine(0, constants_1.LOADING_TEXT);
this.loadingText.show();
this.titleText.hide();
this.table.hide();
return;
}
this.loadingText.hide();
this.titleText.setLine(0, 'Most recent transactions');
this.titleText.show();
this.table.show();
let data = [
['Id', 'Date', 'Amount', 'Receiver/Sender'],
].concat(this.getPrintableTransactions(accountId, transactions));
this.table.setData(data);
}
getRecipientSenderId(accountId, t) {
const accountAddress = t.sender === accountId ? t.recipientRS : t.senderRS;
if (!accountAddress)
return '-';
return accountAddress.replace('BURST-', '');
}
getAmount(accountId, transaction) {
return transaction.sender === accountId
? chalk_1.default.red(`-${util_1.convertNQTStringToNumber(transaction.amountNQT).toFixed(3)}`)
: chalk_1.default.green(`${util_1.convertNQTStringToNumber(transaction.amountNQT).toFixed(3)}`);
}
getPrintableTransactions(accountId, transactions) {
const visibleTransactions = transactions.slice(0, Math.floor(this.parentView.height / 3));
return visibleTransactions.map(t => ([
t.transaction,
util_1.convertBurstTimeToDate(t.timestamp).toLocaleDateString(),
this.getAmount(accountId, t),
this.getRecipientSenderId(accountId, t)
]));
}
}
exports.TransactionTableView = TransactionTableView;
//# sourceMappingURL=transactionTable.view.js.map