UNPKG

burst-whale-watch

Version:

An account watcher for Burstcoin

95 lines 3.57 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const chalk_1 = require("chalk"); const blessed = require("neo-blessed"); const selectors_1 = require("../state/selectors"); const constants_1 = require("../constants"); class HeaderView { constructor() { this.box = blessed.box({ top: 0, left: 'center', width: '100%', height: 6, tags: true, label: { text: `{bold}BURST Whale Watch by ohager{/}`, side: 'right' }, border: { type: 'line' }, style: { bg: 'black', border: { fg: 'white', bold: true, }, } }); const textBaseSettings = { parent: this.box, top: 0, width: '40%', tags: true, style: { fg: 'yellow', bold: true, bg: 'black', border: { fg: '#ffffff' }, } }; this.leftText = blessed.text(Object.assign(Object.assign({}, textBaseSettings), { left: 0 })); this.rightText = blessed.text(Object.assign(Object.assign({}, textBaseSettings), { left: '50%+1' })); } get element() { return this.box; } update(state) { this.updateLeft(state); this.updateRight(state); } static formatChangeText(changeValue) { let formatted; if (changeValue.indexOf('-') > -1) { formatted = chalk_1.default.redBright(changeValue.replace('-', '↓ ')); } else { formatted = chalk_1.default.greenBright('↑ ' + changeValue); } return formatted + '%'; } updateRight(state) { let target = this.rightText; const isLoading = selectors_1.selectIsLoadingMarketInfo(state); const infoSourceName = selectors_1.selectInfoSourceName(state); if (isLoading) { target.setLine(0, `BTC/BURST: ${constants_1.LOADING_TEXT}`); target.setLine(1, `USD/BTC: ${constants_1.LOADING_TEXT}`); return; } const btcBurst = selectors_1.selectGetBtcBurst(state); const btcBurstChange = selectors_1.selectGetBtcBurstChange(state); const usdBurst = selectors_1.selectGetUsdBurst(state); target.setLine(0, `BTC/BURST: ${btcBurst} ${HeaderView.formatChangeText(btcBurstChange)}`); target.setLine(1, `USD/BURST: ${usdBurst}`); target.setLine(2, chalk_1.default.gray(`Source: ${infoSourceName}`)); } updateLeft(state) { let target = this.leftText; const isLoading = selectors_1.selectIsLoadingBalances(state); if (isLoading) { target.setLine(0, `Total [BURST]: ${constants_1.LOADING_TEXT}`); target.setLine(1, `Total [BTC]: ${constants_1.LOADING_TEXT}`); target.setLine(2, `Total [USD]: ${constants_1.LOADING_TEXT}`); return; } const totalBalance = selectors_1.selectGetTotalBalance(state); const totalBalanceBtc = selectors_1.selectGetBalanceInBtc(state); const totalBalanceUsd = selectors_1.selectGetBalanceInUsd(state); target.setLine(0, `Total [BURST]: ${totalBalance}`); target.setLine(1, `Total [BTC]: ${totalBalanceBtc}`); target.setLine(2, `Total [USD]: ${totalBalanceUsd}`); } } exports.HeaderView = HeaderView; //# sourceMappingURL=header.view.js.map