Skip to content

Commit

Permalink
Merge branch 'feature/ticket80_overview_toolbar_balance_refactoring' …
Browse files Browse the repository at this point in the history
…into develop

fixes #80
  • Loading branch information
AndreMiras committed Aug 3, 2017
2 parents f563780 + 7262fae commit b8201c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
37 changes: 22 additions & 15 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,18 +390,13 @@ def setup(self):
# triggers the update
self.current_account = self.controller.current_account

def is_selected(self):
def on_current_account(self, instance, account):
"""
Returns True if the overview sub-screen is selected,
otherwise returns False.
Updates current_account_string and fetches the new account balance.
"""
return self.parent.manager.current == 'overview'

def on_current_account(self, instance, account):
address = "0x" + account.address.encode("hex")
self.current_account_string = address
if self.is_selected():
self.controller.fetch_and_update_balance()
self.controller.fetch_balance()


class PWSelectList(BoxLayout):
Expand Down Expand Up @@ -916,6 +911,18 @@ def screen_manager(self):
def set_toolbar_title(self, title):
self.toolbar.title_property = title

def bind_current_account_balance(self):
"""
Binds the current_account_balance to the Toolbar title.
"""
self.bind(current_account_balance=self.update_toolbar_title_balance)

def unbind_current_account_balance(self):
"""
Unbinds the current_account_balance from the Toolbar title.
"""
self.unbind(current_account_balance=self.update_toolbar_title_balance)

def screen_manager_current(self, current, direction=None):
screens = {
'overview': OverviewScreen,
Expand Down Expand Up @@ -1047,7 +1054,7 @@ def show_not_implemented_dialog():
dialog.open()

@mainthread
def update_toolbar_title_balance(self):
def update_toolbar_title_balance(self, instance=None, value=None):
title = "%s ETH" % (self.current_account_balance)
self.set_toolbar_title(title)

Expand All @@ -1067,21 +1074,17 @@ def load_landing_page(self):
except IndexError:
self.load_create_new_account()

@run_in_thread
def fetch_and_update_balance(self):
def fetch_balance(self):
"""
Fetches the new balance and updates the UI.
Fetches the new balance and current_account_balance property.
"""
# pre-updates balance with last known value
self.update_toolbar_title_balance()
account = self.current_account
try:
self.current_account_balance = self.pywalib.get_balance(
account.address.encode("hex"))
except ConnectionError:
Controller.on_balance_connection_error()
return
self.update_toolbar_title_balance()

def load_switch_account(self):
"""
Expand Down Expand Up @@ -1164,4 +1167,8 @@ def configure_sentry(in_debug=False):
try:
PyWalletApp().run()
except:
if type(client) == Client:
Logger.info(
'Errors will be sent to Sentry, run with "--debug" if you '
'are a developper and want to the error in the shell.')
client.captureException()
15 changes: 11 additions & 4 deletions src/pywallet.kv
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,14 @@
text: "Overview"
icon: 'format-list-bulleted'
on_pre_enter:
root.parent.set_title("0 ETH")
# TODO: not necessarily, e.g. probably not if the account didn't change
# TODO: but update title
app.controller.fetch_and_update_balance()
# sets to the last known value
app.controller.update_toolbar_title_balance()
# and binds on update
app.controller.bind_current_account_balance()
on_pre_leave:
# makes ure the title doesn't get updated async
# if we're not in this screen
app.controller.unbind_current_account_balance()
Overview:
id: overview_id
MDBottomNavigationItem:
Expand Down Expand Up @@ -358,6 +362,9 @@
# restores title,
# e.g. when coming back from the account selection screen
app.controller.set_toolbar_title(root.title_property)
overview_bnavigation_id.ids.tab_manager.current_screen.dispatch('on_pre_enter')
on_pre_leave:
overview_bnavigation_id.ids.tab_manager.current_screen.dispatch('on_pre_leave')
on_title_property:
app.controller.set_toolbar_title(root.title_property)
OverviewBottomNavigation:
Expand Down

0 comments on commit b8201c0

Please sign in to comment.