small optimisations for history tab refresh (and related)
This commit is contained in:
parent
6b42e8448c
commit
7307c800d7
@ -101,6 +101,9 @@ class AddressSynchronizer(PrintError):
|
|||||||
h.append((tx_hash, tx_height))
|
h.append((tx_hash, tx_height))
|
||||||
return h
|
return h
|
||||||
|
|
||||||
|
def get_address_history_len(self, addr: str) -> int:
|
||||||
|
return len(self._history_local.get(addr, ()))
|
||||||
|
|
||||||
def get_txin_address(self, txi):
|
def get_txin_address(self, txi):
|
||||||
addr = txi.get('address')
|
addr = txi.get('address')
|
||||||
if addr and addr != "(pubkey)":
|
if addr and addr != "(pubkey)":
|
||||||
|
|||||||
@ -93,8 +93,9 @@ class AddressList(MyTreeWidget):
|
|||||||
else:
|
else:
|
||||||
addr_list = self.wallet.get_addresses()
|
addr_list = self.wallet.get_addresses()
|
||||||
self.clear()
|
self.clear()
|
||||||
|
fx = self.parent.fx
|
||||||
for address in addr_list:
|
for address in addr_list:
|
||||||
num = len(self.wallet.get_address_history(address))
|
num = self.wallet.get_address_history_len(address)
|
||||||
label = self.wallet.labels.get(address, '')
|
label = self.wallet.labels.get(address, '')
|
||||||
c, u, x = self.wallet.get_addr_balance(address)
|
c, u, x = self.wallet.get_addr_balance(address)
|
||||||
balance = c + u + x
|
balance = c + u + x
|
||||||
@ -106,7 +107,6 @@ class AddressList(MyTreeWidget):
|
|||||||
if self.show_used == 3 and not is_used_and_empty:
|
if self.show_used == 3 and not is_used_and_empty:
|
||||||
continue
|
continue
|
||||||
balance_text = self.parent.format_amount(balance, whitespaces=True)
|
balance_text = self.parent.format_amount(balance, whitespaces=True)
|
||||||
fx = self.parent.fx
|
|
||||||
# create item
|
# create item
|
||||||
if fx and fx.get_fiat_address_config():
|
if fx and fx.get_fiat_address_config():
|
||||||
rate = fx.exchange_rate()
|
rate = fx.exchange_rate()
|
||||||
|
|||||||
@ -229,6 +229,9 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
|||||||
current_tx = item.data(0, Qt.UserRole) if item else None
|
current_tx = item.data(0, Qt.UserRole) if item else None
|
||||||
self.clear()
|
self.clear()
|
||||||
if fx: fx.history_used_spot = False
|
if fx: fx.history_used_spot = False
|
||||||
|
blue_brush = QBrush(QColor("#1E1EFF"))
|
||||||
|
red_brush = QBrush(QColor("#BC1E1E"))
|
||||||
|
monospace_font = QFont(MONOSPACE_FONT)
|
||||||
for tx_item in self.transactions:
|
for tx_item in self.transactions:
|
||||||
tx_hash = tx_item['txid']
|
tx_hash = tx_item['txid']
|
||||||
height = tx_item['height']
|
height = tx_item['height']
|
||||||
@ -263,12 +266,12 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop):
|
|||||||
if i>3:
|
if i>3:
|
||||||
item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter)
|
item.setTextAlignment(i, Qt.AlignRight | Qt.AlignVCenter)
|
||||||
if i!=2:
|
if i!=2:
|
||||||
item.setFont(i, QFont(MONOSPACE_FONT))
|
item.setFont(i, monospace_font)
|
||||||
if value and value < 0:
|
if value and value < 0:
|
||||||
item.setForeground(3, QBrush(QColor("#BC1E1E")))
|
item.setForeground(3, red_brush)
|
||||||
item.setForeground(4, QBrush(QColor("#BC1E1E")))
|
item.setForeground(4, red_brush)
|
||||||
if fiat_value and not tx_item['fiat_default']:
|
if fiat_value and not tx_item['fiat_default']:
|
||||||
item.setForeground(6, QBrush(QColor("#1E1EFF")))
|
item.setForeground(6, blue_brush)
|
||||||
if tx_hash:
|
if tx_hash:
|
||||||
item.setData(0, Qt.UserRole, tx_hash)
|
item.setData(0, Qt.UserRole, tx_hash)
|
||||||
self.insertTopLevelItem(0, item)
|
self.insertTopLevelItem(0, item)
|
||||||
|
|||||||
@ -26,7 +26,6 @@ from collections import namedtuple
|
|||||||
import traceback
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import imp
|
|
||||||
import pkgutil
|
import pkgutil
|
||||||
import time
|
import time
|
||||||
import threading
|
import threading
|
||||||
|
|||||||
@ -33,6 +33,7 @@ import threading
|
|||||||
import hmac
|
import hmac
|
||||||
import stat
|
import stat
|
||||||
import inspect
|
import inspect
|
||||||
|
from locale import localeconv
|
||||||
|
|
||||||
from .i18n import _
|
from .i18n import _
|
||||||
|
|
||||||
@ -120,6 +121,8 @@ class UserCancelled(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class Satoshis(object):
|
class Satoshis(object):
|
||||||
|
__slots__ = ('value',)
|
||||||
|
|
||||||
def __new__(cls, value):
|
def __new__(cls, value):
|
||||||
self = super(Satoshis, cls).__new__(cls)
|
self = super(Satoshis, cls).__new__(cls)
|
||||||
self.value = value
|
self.value = value
|
||||||
@ -132,6 +135,8 @@ class Satoshis(object):
|
|||||||
return format_satoshis(self.value) + " BTC"
|
return format_satoshis(self.value) + " BTC"
|
||||||
|
|
||||||
class Fiat(object):
|
class Fiat(object):
|
||||||
|
__slots__ = ('value', 'ccy')
|
||||||
|
|
||||||
def __new__(cls, value, ccy):
|
def __new__(cls, value, ccy):
|
||||||
self = super(Fiat, cls).__new__(cls)
|
self = super(Fiat, cls).__new__(cls)
|
||||||
self.ccy = ccy
|
self.ccy = ccy
|
||||||
@ -477,8 +482,10 @@ def format_satoshis_plain(x, decimal_point = 8):
|
|||||||
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.')
|
return "{:.8f}".format(Decimal(x) / scale_factor).rstrip('0').rstrip('.')
|
||||||
|
|
||||||
|
|
||||||
|
DECIMAL_POINT = localeconv()['decimal_point']
|
||||||
|
|
||||||
|
|
||||||
def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=False, whitespaces=False):
|
def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=False, whitespaces=False):
|
||||||
from locale import localeconv
|
|
||||||
if x is None:
|
if x is None:
|
||||||
return 'unknown'
|
return 'unknown'
|
||||||
if precision is None:
|
if precision is None:
|
||||||
@ -488,7 +495,7 @@ def format_satoshis(x, num_zeros=0, decimal_point=8, precision=None, is_diff=Fal
|
|||||||
decimal_format = '+' + decimal_format
|
decimal_format = '+' + decimal_format
|
||||||
result = ("{:" + decimal_format + "f}").format(x / pow (10, decimal_point)).rstrip('0')
|
result = ("{:" + decimal_format + "f}").format(x / pow (10, decimal_point)).rstrip('0')
|
||||||
integer_part, fract_part = result.split(".")
|
integer_part, fract_part = result.split(".")
|
||||||
dp = localeconv()['decimal_point']
|
dp = DECIMAL_POINT
|
||||||
if len(fract_part) < num_zeros:
|
if len(fract_part) < num_zeros:
|
||||||
fract_part += "0" * (num_zeros - len(fract_part))
|
fract_part += "0" * (num_zeros - len(fract_part))
|
||||||
result = integer_part + dp + fract_part
|
result = integer_part + dp + fract_part
|
||||||
|
|||||||
@ -43,7 +43,7 @@ from .i18n import _
|
|||||||
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
from .util import (NotEnoughFunds, PrintError, UserCancelled, profiler,
|
||||||
format_satoshis, format_fee_satoshis, NoDynamicFeeEstimates,
|
format_satoshis, format_fee_satoshis, NoDynamicFeeEstimates,
|
||||||
TimeoutException, WalletFileException, BitcoinException,
|
TimeoutException, WalletFileException, BitcoinException,
|
||||||
InvalidPassword)
|
InvalidPassword, format_time)
|
||||||
|
|
||||||
from .bitcoin import *
|
from .bitcoin import *
|
||||||
from .version import *
|
from .version import *
|
||||||
@ -386,11 +386,12 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
fiat_income = Decimal(0)
|
fiat_income = Decimal(0)
|
||||||
fiat_expenditures = Decimal(0)
|
fiat_expenditures = Decimal(0)
|
||||||
h = self.get_history(domain)
|
h = self.get_history(domain)
|
||||||
|
now = time.time()
|
||||||
for tx_hash, tx_mined_status, value, balance in h:
|
for tx_hash, tx_mined_status, value, balance in h:
|
||||||
timestamp = tx_mined_status.timestamp
|
timestamp = tx_mined_status.timestamp
|
||||||
if from_timestamp and (timestamp or time.time()) < from_timestamp:
|
if from_timestamp and (timestamp or now) < from_timestamp:
|
||||||
continue
|
continue
|
||||||
if to_timestamp and (timestamp or time.time()) >= to_timestamp:
|
if to_timestamp and (timestamp or now) >= to_timestamp:
|
||||||
continue
|
continue
|
||||||
item = {
|
item = {
|
||||||
'txid': tx_hash,
|
'txid': tx_hash,
|
||||||
@ -398,10 +399,10 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
'confirmations': tx_mined_status.conf,
|
'confirmations': tx_mined_status.conf,
|
||||||
'timestamp': timestamp,
|
'timestamp': timestamp,
|
||||||
'value': Satoshis(value),
|
'value': Satoshis(value),
|
||||||
'balance': Satoshis(balance)
|
'balance': Satoshis(balance),
|
||||||
|
'date': timestamp_to_datetime(timestamp),
|
||||||
|
'label': self.get_label(tx_hash),
|
||||||
}
|
}
|
||||||
item['date'] = timestamp_to_datetime(timestamp)
|
|
||||||
item['label'] = self.get_label(tx_hash)
|
|
||||||
if show_addresses:
|
if show_addresses:
|
||||||
tx = self.transactions.get(tx_hash)
|
tx = self.transactions.get(tx_hash)
|
||||||
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
|
item['inputs'] = list(map(lambda x: dict((k, x[k]) for k in ('prevout_hash', 'prevout_n')), tx.inputs()))
|
||||||
@ -416,10 +417,9 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
income += value
|
income += value
|
||||||
# fiat computations
|
# fiat computations
|
||||||
if fx and fx.is_enabled():
|
if fx and fx.is_enabled():
|
||||||
date = timestamp_to_datetime(timestamp)
|
|
||||||
fiat_value = self.get_fiat_value(tx_hash, fx.ccy)
|
fiat_value = self.get_fiat_value(tx_hash, fx.ccy)
|
||||||
fiat_default = fiat_value is None
|
fiat_default = fiat_value is None
|
||||||
fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate)
|
fiat_value = fiat_value if fiat_value is not None else value / Decimal(COIN) * self.price_at_timestamp(tx_hash, fx.timestamp_rate) #
|
||||||
item['fiat_value'] = Fiat(fiat_value, fx.ccy)
|
item['fiat_value'] = Fiat(fiat_value, fx.ccy)
|
||||||
item['fiat_default'] = fiat_default
|
item['fiat_default'] = fiat_default
|
||||||
if value < 0:
|
if value < 0:
|
||||||
@ -487,7 +487,6 @@ class Abstract_Wallet(AddressSynchronizer):
|
|||||||
return ''
|
return ''
|
||||||
|
|
||||||
def get_tx_status(self, tx_hash, tx_mined_status):
|
def get_tx_status(self, tx_hash, tx_mined_status):
|
||||||
from .util import format_time
|
|
||||||
extra = []
|
extra = []
|
||||||
height = tx_mined_status.height
|
height = tx_mined_status.height
|
||||||
conf = tx_mined_status.conf
|
conf = tx_mined_status.conf
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user