kivy: cache gui list items
This commit is contained in:
parent
016d733c0f
commit
03bd6a092b
|
@ -106,6 +106,7 @@ class HistoryScreen(CScreen):
|
|||
|
||||
tab = ObjectProperty(None)
|
||||
kvname = 'history'
|
||||
cards = {}
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.ra_dialog = None
|
||||
|
@ -129,48 +130,41 @@ class HistoryScreen(CScreen):
|
|||
d = LabelDialog(_('Enter Transaction Label'), text, callback)
|
||||
d.open()
|
||||
|
||||
|
||||
def parse_history(self, items):
|
||||
for item in items:
|
||||
tx_hash, height, conf, timestamp, value, balance = item
|
||||
status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
|
||||
icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
|
||||
label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
|
||||
date = timestamp_to_datetime(timestamp)
|
||||
quote_text = ''
|
||||
if self.app.fiat_unit and date:
|
||||
rate = run_hook('history_rate', date)
|
||||
if rate:
|
||||
s = run_hook('value_str', value, rate)
|
||||
quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
|
||||
yield (conf, icon, status_str, label, value, tx_hash, quote_text)
|
||||
def get_card(self, tx_hash, height, conf, timestamp, value, balance):
|
||||
status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
|
||||
icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
|
||||
label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
|
||||
date = timestamp_to_datetime(timestamp)
|
||||
ri = self.cards.get(tx_hash)
|
||||
if ri is None:
|
||||
ri = Factory.HistoryItem()
|
||||
ri.screen = self
|
||||
ri.tx_hash = tx_hash
|
||||
self.cards[tx_hash] = ri
|
||||
ri.icon = icon
|
||||
ri.date = status_str
|
||||
ri.message = label
|
||||
ri.value = value or 0
|
||||
ri.value_known = value is not None
|
||||
ri.confirmations = conf
|
||||
if self.app.fiat_unit and date:
|
||||
rate = run_hook('history_rate', date)
|
||||
if rate:
|
||||
s = run_hook('value_str', value, rate)
|
||||
ri.quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
|
||||
return ri
|
||||
|
||||
def update(self, see_all=False):
|
||||
if self.app.wallet is None:
|
||||
return
|
||||
|
||||
history = self.parse_history(reversed(
|
||||
self.app.wallet.get_history(self.app.current_account)))
|
||||
# repopulate History Card
|
||||
history = reversed(self.app.wallet.get_history(self.app.current_account))
|
||||
history_card = self.screen.ids.history_container
|
||||
history_card.clear_widgets()
|
||||
count = 0
|
||||
for item in history:
|
||||
ri = self.get_card(*item)
|
||||
count += 1
|
||||
conf, icon, date_time, message, value, tx, quote_text = item
|
||||
ri = Factory.HistoryItem()
|
||||
ri.icon = icon
|
||||
ri.date = date_time
|
||||
ri.message = message
|
||||
ri.value = value or 0
|
||||
ri.value_known = value is not None
|
||||
ri.quote_text = quote_text
|
||||
ri.confirmations = conf
|
||||
ri.tx_hash = tx
|
||||
ri.screen = self
|
||||
history_card.add_widget(ri)
|
||||
if count == 8 and not see_all:
|
||||
break
|
||||
|
||||
if count == 0:
|
||||
msg = _('This screen shows your list of transactions. It is currently empty.')
|
||||
|
@ -425,32 +419,40 @@ pr_icon = {
|
|||
|
||||
class InvoicesScreen(CScreen):
|
||||
kvname = 'invoices'
|
||||
cards = {}
|
||||
|
||||
def get_card(self, pr):
|
||||
key = pr.get_id()
|
||||
ci = self.cards.get(key)
|
||||
if ci is None:
|
||||
ci = Factory.InvoiceItem()
|
||||
ci.key = key
|
||||
ci.screen = self
|
||||
self.cards[key] = ci
|
||||
|
||||
ci.requestor = pr.get_requestor()
|
||||
ci.memo = pr.get_memo()
|
||||
amount = pr.get_amount()
|
||||
if amount:
|
||||
ci.amount = self.app.format_amount_and_units(amount)
|
||||
status = self.app.invoices.get_status(ci.key)
|
||||
ci.status = invoice_text[status]
|
||||
ci.icon = pr_icon[status]
|
||||
else:
|
||||
ci.amount = _('No Amount')
|
||||
ci.status = ''
|
||||
exp = pr.get_expiration_date()
|
||||
ci.date = format_time(exp) if exp else _('Never')
|
||||
return ci
|
||||
|
||||
def update(self):
|
||||
self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
|
||||
invoices_list = self.screen.ids.invoices_container
|
||||
invoices_list.clear_widgets()
|
||||
|
||||
_list = self.app.invoices.sorted_list()
|
||||
for pr in _list:
|
||||
ci = Factory.InvoiceItem()
|
||||
ci.key = pr.get_id()
|
||||
ci.requestor = pr.get_requestor()
|
||||
ci.memo = pr.get_memo()
|
||||
amount = pr.get_amount()
|
||||
if amount:
|
||||
ci.amount = self.app.format_amount_and_units(amount)
|
||||
status = self.app.invoices.get_status(ci.key)
|
||||
ci.status = invoice_text[status]
|
||||
ci.icon = pr_icon[status]
|
||||
else:
|
||||
ci.amount = _('No Amount')
|
||||
ci.status = ''
|
||||
exp = pr.get_expiration_date()
|
||||
ci.date = format_time(exp) if exp else _('Never')
|
||||
ci.screen = self
|
||||
ci = self.get_card(pr)
|
||||
invoices_list.add_widget(ci)
|
||||
|
||||
if not _list:
|
||||
msg = _('This screen shows the list of payment requests that have been sent to you. You may also use it to store contact addresses.')
|
||||
invoices_list.add_widget(EmptyLabel(text=msg))
|
||||
|
@ -475,6 +477,34 @@ class InvoicesScreen(CScreen):
|
|||
|
||||
class RequestsScreen(CScreen):
|
||||
kvname = 'requests'
|
||||
cards = {}
|
||||
|
||||
def get_card(self, req):
|
||||
address = req['address']
|
||||
timestamp = req.get('time', 0)
|
||||
amount = req.get('amount')
|
||||
expiration = req.get('exp', None)
|
||||
status = req.get('status')
|
||||
signature = req.get('sig')
|
||||
|
||||
ci = self.cards.get(address)
|
||||
if ci is None:
|
||||
ci = Factory.RequestItem()
|
||||
ci.screen = self
|
||||
ci.address = address
|
||||
self.cards[address] = ci
|
||||
|
||||
ci.memo = self.app.wallet.get_label(address)
|
||||
if amount:
|
||||
status = req.get('status')
|
||||
ci.status = request_text[status]
|
||||
else:
|
||||
received = self.app.wallet.get_addr_received(address)
|
||||
ci.status = self.app.format_amount_and_units(amount)
|
||||
ci.icon = pr_icon[status]
|
||||
ci.amount = self.app.format_amount_and_units(amount) if amount else _('No Amount')
|
||||
ci.date = format_time(timestamp)
|
||||
return ci
|
||||
|
||||
def update(self):
|
||||
self.menu_actions = [('Show', self.do_show), ('Details', self.do_view), ('Delete', self.do_delete)]
|
||||
|
@ -482,29 +512,8 @@ class RequestsScreen(CScreen):
|
|||
requests_list.clear_widgets()
|
||||
_list = self.app.wallet.get_sorted_requests(self.app.electrum_config) if self.app.wallet else []
|
||||
for req in _list:
|
||||
address = req['address']
|
||||
timestamp = req.get('time', 0)
|
||||
amount = req.get('amount')
|
||||
expiration = req.get('exp', None)
|
||||
status = req.get('status')
|
||||
signature = req.get('sig')
|
||||
|
||||
ci = Factory.RequestItem()
|
||||
ci.address = address
|
||||
ci.memo = self.app.wallet.get_label(address)
|
||||
if amount:
|
||||
status = req.get('status')
|
||||
ci.status = request_text[status]
|
||||
else:
|
||||
received = self.app.wallet.get_addr_received(address)
|
||||
ci.status = self.app.format_amount_and_units(amount)
|
||||
|
||||
ci.icon = pr_icon[status]
|
||||
ci.amount = self.app.format_amount_and_units(amount) if amount else _('No Amount')
|
||||
ci.date = format_time(timestamp)
|
||||
ci.screen = self
|
||||
ci = self.get_card(req)
|
||||
requests_list.add_widget(ci)
|
||||
|
||||
if not _list:
|
||||
msg = _('This screen shows the list of payment requests you made.')
|
||||
requests_list.add_widget(EmptyLabel(text=msg))
|
||||
|
|
Loading…
Reference in New Issue