diff --git a/silkaj/tx_history.py b/silkaj/tx_history.py index b331c8ec5c3c2dc46c5603321d67b2c4c9bdea47..4f4950ac6072f01a641ee1c78f988e99e406deaa 100644 --- a/silkaj/tx_history.py +++ b/silkaj/tx_history.py @@ -13,7 +13,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Silkaj. If not, see <https://www.gnu.org/licenses/>. -import shutil from operator import eq, itemgetter, ne, neg from typing import Any, List, Optional, Tuple from urllib.error import HTTPError @@ -24,7 +23,6 @@ from duniterpy.api.client import Client from duniterpy.documents.transaction import OutputSource, Transaction from duniterpy.grammars.output import Condition from pendulum import from_timestamp, now -from texttable import Texttable from silkaj import wot_tools as wt from silkaj.constants import ALL, ALL_DIGITAL @@ -32,7 +30,7 @@ from silkaj.crypto_tools import check_pubkey_format, validate_checksum from silkaj.money import amount_in_current_base, get_amount_from_pubkey, get_ud_value from silkaj.network_tools import client_instance from silkaj.tools import get_currency_symbol -from silkaj.tui import gen_pubkey_checksum +from silkaj.tui import Table, gen_pubkey_checksum @command("history", help="Display transaction history") @@ -51,11 +49,19 @@ def transaction_history(pubkey: str, uids: bool, full_pubkey: bool) -> None: received_txs, sent_txs = [], [] # type: List[Transaction], List[Transaction] get_transactions_history(client, pubkey, received_txs, sent_txs) remove_duplicate_txs(received_txs, sent_txs) + txs_list = generate_table( received_txs, sent_txs, pubkey, ud_value, currency_symbol, uids, full_pubkey ) - table = Texttable(max_width=shutil.get_terminal_size().columns) - table.add_rows(txs_list) + table_headers = [ + "Date", + "Issuers/Recipients", + f"Amounts {currency_symbol}", + f"Amounts UD{currency_symbol}", + "Comment", + ] + table = Table() + table.fill_rows(txs_list, table_headers) echo_via_pager(header + table.draw()) @@ -109,9 +115,8 @@ def generate_table( full_pubkey: bool, ) -> List: """ - Generate information in a list of lists for texttabe + Generate information in a list of lists for texttable Merge received and sent txs - Insert table header at the end not to disturb its generation Sort txs temporarily """ @@ -125,15 +130,6 @@ def generate_table( parse_sent_tx(sent_txs_table, sent_txs, pubkey, ud_value, uids, full_pubkey) txs_table = received_txs_table + sent_txs_table - table_titles = [ - "Date", - "Issuers/Recipients", - f"Amounts {currency_symbol}", - f"Amounts UD{currency_symbol}", - "Comment", - ] - txs_table.insert(0, table_titles) - txs_table.sort(key=itemgetter(0), reverse=True) return txs_table