mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-29 08:21:27 +00:00
kivy: cache gui list items
This commit is contained in:
parent
016d733c0f
commit
03bd6a092b
1 changed files with 81 additions and 72 deletions
|
@ -106,6 +106,7 @@ class HistoryScreen(CScreen):
|
||||||
|
|
||||||
tab = ObjectProperty(None)
|
tab = ObjectProperty(None)
|
||||||
kvname = 'history'
|
kvname = 'history'
|
||||||
|
cards = {}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
self.ra_dialog = None
|
self.ra_dialog = None
|
||||||
|
@ -129,48 +130,41 @@ class HistoryScreen(CScreen):
|
||||||
d = LabelDialog(_('Enter Transaction Label'), text, callback)
|
d = LabelDialog(_('Enter Transaction Label'), text, callback)
|
||||||
d.open()
|
d.open()
|
||||||
|
|
||||||
|
def get_card(self, tx_hash, height, conf, timestamp, value, balance):
|
||||||
def parse_history(self, items):
|
status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
|
||||||
for item in items:
|
icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
|
||||||
tx_hash, height, conf, timestamp, value, balance = item
|
label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
|
||||||
status, status_str = self.app.wallet.get_tx_status(tx_hash, height, conf, timestamp)
|
date = timestamp_to_datetime(timestamp)
|
||||||
icon = "atlas://gui/kivy/theming/light/" + TX_ICONS[status]
|
ri = self.cards.get(tx_hash)
|
||||||
label = self.app.wallet.get_label(tx_hash) if tx_hash else _('Pruned transaction outputs')
|
if ri is None:
|
||||||
date = timestamp_to_datetime(timestamp)
|
ri = Factory.HistoryItem()
|
||||||
quote_text = ''
|
ri.screen = self
|
||||||
if self.app.fiat_unit and date:
|
ri.tx_hash = tx_hash
|
||||||
rate = run_hook('history_rate', date)
|
self.cards[tx_hash] = ri
|
||||||
if rate:
|
ri.icon = icon
|
||||||
s = run_hook('value_str', value, rate)
|
ri.date = status_str
|
||||||
quote_text = '' if s is None else s + ' ' + self.app.fiat_unit
|
ri.message = label
|
||||||
yield (conf, icon, status_str, label, value, tx_hash, quote_text)
|
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):
|
def update(self, see_all=False):
|
||||||
if self.app.wallet is None:
|
if self.app.wallet is None:
|
||||||
return
|
return
|
||||||
|
history = reversed(self.app.wallet.get_history(self.app.current_account))
|
||||||
history = self.parse_history(reversed(
|
|
||||||
self.app.wallet.get_history(self.app.current_account)))
|
|
||||||
# repopulate History Card
|
|
||||||
history_card = self.screen.ids.history_container
|
history_card = self.screen.ids.history_container
|
||||||
history_card.clear_widgets()
|
history_card.clear_widgets()
|
||||||
count = 0
|
count = 0
|
||||||
for item in history:
|
for item in history:
|
||||||
|
ri = self.get_card(*item)
|
||||||
count += 1
|
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)
|
history_card.add_widget(ri)
|
||||||
if count == 8 and not see_all:
|
|
||||||
break
|
|
||||||
|
|
||||||
if count == 0:
|
if count == 0:
|
||||||
msg = _('This screen shows your list of transactions. It is currently empty.')
|
msg = _('This screen shows your list of transactions. It is currently empty.')
|
||||||
|
@ -425,32 +419,40 @@ pr_icon = {
|
||||||
|
|
||||||
class InvoicesScreen(CScreen):
|
class InvoicesScreen(CScreen):
|
||||||
kvname = 'invoices'
|
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):
|
def update(self):
|
||||||
self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
|
self.menu_actions = [('Pay', self.do_pay), ('Details', self.do_view), ('Delete', self.do_delete)]
|
||||||
invoices_list = self.screen.ids.invoices_container
|
invoices_list = self.screen.ids.invoices_container
|
||||||
invoices_list.clear_widgets()
|
invoices_list.clear_widgets()
|
||||||
|
|
||||||
_list = self.app.invoices.sorted_list()
|
_list = self.app.invoices.sorted_list()
|
||||||
for pr in _list:
|
for pr in _list:
|
||||||
ci = Factory.InvoiceItem()
|
ci = self.get_card(pr)
|
||||||
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
|
|
||||||
invoices_list.add_widget(ci)
|
invoices_list.add_widget(ci)
|
||||||
|
|
||||||
if not _list:
|
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.')
|
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))
|
invoices_list.add_widget(EmptyLabel(text=msg))
|
||||||
|
@ -475,6 +477,34 @@ class InvoicesScreen(CScreen):
|
||||||
|
|
||||||
class RequestsScreen(CScreen):
|
class RequestsScreen(CScreen):
|
||||||
kvname = 'requests'
|
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):
|
def update(self):
|
||||||
self.menu_actions = [('Show', self.do_show), ('Details', self.do_view), ('Delete', self.do_delete)]
|
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()
|
requests_list.clear_widgets()
|
||||||
_list = self.app.wallet.get_sorted_requests(self.app.electrum_config) if self.app.wallet else []
|
_list = self.app.wallet.get_sorted_requests(self.app.electrum_config) if self.app.wallet else []
|
||||||
for req in _list:
|
for req in _list:
|
||||||
address = req['address']
|
ci = self.get_card(req)
|
||||||
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
|
|
||||||
requests_list.add_widget(ci)
|
requests_list.add_widget(ci)
|
||||||
|
|
||||||
if not _list:
|
if not _list:
|
||||||
msg = _('This screen shows the list of payment requests you made.')
|
msg = _('This screen shows the list of payment requests you made.')
|
||||||
requests_list.add_widget(EmptyLabel(text=msg))
|
requests_list.add_widget(EmptyLabel(text=msg))
|
||||||
|
|
Loading…
Add table
Reference in a new issue