Skip to content

Commit

Permalink
Merge pull request #366 from Foundation-Devices/SFT-2471-fix-toggle-h…
Browse files Browse the repository at this point in the history
…idden-button

SFT-2471: fix toggle hidden button
  • Loading branch information
mjg-foundation authored Jul 28, 2023
2 parents 368f301 + 8ea8f93 commit a6c4a20
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 86 deletions.
2 changes: 0 additions & 2 deletions ports/stm32/boards/Passport/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
'flows/flow.py',
'flows/format_microsd_flow.py',
'flows/get_seed_words_flow.py',
'flows/hide_derived_key_flow.py',
'flows/import_multisig_wallet_flow.py',
'flows/import_multisig_wallet_from_microsd_flow.py',
'flows/import_multisig_wallet_from_qr_flow.py',
Expand Down Expand Up @@ -259,7 +258,6 @@
'tasks/get_backup_code_task.py',
'tasks/get_security_words_task.py',
'tasks/get_seed_words_task.py',
'tasks/hide_derived_key_task.py',
'tasks/login_task.py',
'tasks/lvgl_task.py',
'tasks/main_task.py',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
'menu_item': {
'icon': icon,
'label': 'Casa',
'action': lambda item: toggle_extension_enabled(name),
'action': lambda item, context: toggle_extension_enabled(name),
'is_toggle': True,
'value': lambda: is_extension_enabled(name),
'value': lambda context: is_extension_enabled(name),
},
'card': {
'right_icon': icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
'menu_item': {
'icon': icon,
'label': label,
'action': lambda item: toggle_extension_enabled(name),
'action': lambda item, context: toggle_extension_enabled(name),
'is_toggle': True,
'value': lambda: is_extension_enabled(name),
'value': lambda context: is_extension_enabled(name),
},
'card': {
'right_icon': icon,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
'menu_item': {
'icon': icon,
'label': 'Postmix',
'action': lambda item: toggle_extension_enabled(name),
'action': lambda item, context: toggle_extension_enabled(name),
'is_toggle': True,
'value': lambda: is_extension_enabled(name),
'value': lambda context: is_extension_enabled(name),
},
'card': {
'right_icon': icon,
Expand Down
1 change: 0 additions & 1 deletion ports/stm32/boards/Passport/modules/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
from .file_picker_flow import *
from .format_microsd_flow import *
from .get_seed_words_flow import *
from .hide_derived_key_flow import *
from .import_multisig_wallet_flow import *
from .import_multisig_wallet_from_microsd_flow import *
from .import_multisig_wallet_from_qr_flow import *
Expand Down
47 changes: 0 additions & 47 deletions ports/stm32/boards/Passport/modules/flows/hide_derived_key_flow.py

This file was deleted.

5 changes: 3 additions & 2 deletions ports/stm32/boards/Passport/modules/flows/menu_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ async def show_menu(self):
statusbar=self.statusbar,
left_micron=microns.Back,
right_micron=microns.Checkmark,
is_top_level=self.is_top_level
is_top_level=self.is_top_level,
context=self.context,
).show()
if result is None:
if ui.is_top_level():
Expand Down Expand Up @@ -123,7 +124,7 @@ async def show_menu(self):
elif item.get('action') is not None:
action = item.get('action')
if callable(action):
action(item)
action(item, self.context)

self.cleanup()

Expand Down
15 changes: 10 additions & 5 deletions ports/stm32/boards/Passport/modules/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,21 @@ def backup_menu():


def key_item_menu():
from utils import toggle_key_hidden, is_key_hidden

from flows import (
ViewDerivedKeyDetailsFlow,
RenameDerivedKeyFlow,
ExportDerivedKeyFlow,
HideDerivedKeyFlow)
ExportDerivedKeyFlow)
return [
{'icon': 'ICON_ONE_KEY', 'label': 'View Details', 'flow': ViewDerivedKeyDetailsFlow},
{'icon': 'ICON_INFO', 'label': 'Rename', 'flow': RenameDerivedKeyFlow, 'auto_card_header': False},
{'icon': 'ICON_SCAN_QR', 'label': 'Export', 'flow': ExportDerivedKeyFlow},
{'icon': 'ICON_ERASE', 'label': 'Toggle Hidden', 'flow': HideDerivedKeyFlow},
{'icon': 'ICON_ERASE',
'label': 'Hide Key',
'action': lambda item, context: toggle_key_hidden(item, context),
'is_toggle': True,
'value': lambda context: is_key_hidden(context)},
]


Expand All @@ -172,9 +177,9 @@ def manage_keys():
return [
{'icon': 'ICON_TWO_KEYS',
'label': 'Show Hidden',
'action': lambda item: toggle_showing_hidden_keys(),
'action': lambda item, context: toggle_showing_hidden_keys(),
'is_toggle': True,
'value': lambda: are_hidden_keys_showing()},
'value': lambda context: are_hidden_keys_showing()},
]


Expand Down
5 changes: 4 additions & 1 deletion ports/stm32/boards/Passport/modules/pages/menu_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def __init__(self,
item_descs=[],
focus_idx=0,
is_top_level=None,
context=None,
card_header=None,
statusbar=None,
left_micron=None,
Expand All @@ -33,6 +34,7 @@ def __init__(self,

self.focus_idx = focus_idx
self.is_top_level = is_top_level
self.context = context

with Stylize(self) as default:
default.flex_fill()
Expand Down Expand Up @@ -64,7 +66,8 @@ def mount(self, lvgl_parent):
label=item_desc.get('label'),
is_toggle=item_desc.get('is_toggle'),
value=item_desc.get('value'),
desc=item_desc)
desc=item_desc,
context=self.context)
is_visible = item_desc.get('is_visible')
if is_visible is None or (callable(is_visible) and is_visible()):
self.visible_items.append(item)
Expand Down
1 change: 0 additions & 1 deletion ports/stm32/boards/Passport/modules/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
from .get_security_words_task import get_security_words_task
from .get_seed_words_task import get_seed_words_task
from .get_backup_code_task import get_backup_code_task
from .hide_derived_key_task import hide_derived_key_task
from .login_task import login_task
from .lvgl_task import lvgl_task
from .main_task import main_task
Expand Down
19 changes: 0 additions & 19 deletions ports/stm32/boards/Passport/modules/tasks/hide_derived_key_task.py

This file was deleted.

18 changes: 18 additions & 0 deletions ports/stm32/boards/Passport/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,4 +1413,22 @@ def derive_icon(icon):
return icon


def toggle_key_hidden(item, key):
from common import settings
from utils import get_derived_keys

keys = get_derived_keys()
keys.remove(key)
key['hidden'] = not key['hidden']
keys.append(key)
settings.set('derived_keys', keys)


def is_key_hidden(key):
from utils import get_derived_key_by_index

updated = get_derived_key_by_index(key['index'], key['tn'], key['xfp'])
return updated['hidden']


# EOF
5 changes: 3 additions & 2 deletions ports/stm32/boards/Passport/modules/views/menu_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


class MenuItem(View):
def __init__(self, icon='', label='', is_toggle=False, value=False, desc=None):
def __init__(self, icon='', label='', is_toggle=False, value=False, desc=None, context=None):
from views import Switch

super().__init__(flex_flow=lv.FLEX_FLOW.ROW)
Expand All @@ -23,6 +23,7 @@ def __init__(self, icon='', label='', is_toggle=False, value=False, desc=None):
self.is_toggle = is_toggle
self.value = value
self.desc = desc
self.context = context

# Default style
with Stylize(self) as default:
Expand Down Expand Up @@ -60,7 +61,7 @@ def __init__(self, icon='', label='', is_toggle=False, value=False, desc=None):
# Value can be a simple value or a callable, which allows its value to be updated
value = self.value
if callable(value):
value = value()
value = value(self.context)
self.switch_view = Switch(value=value)
self.switch_view.set_size(46, 24)
self.add_child(self.switch_view)

0 comments on commit a6c4a20

Please sign in to comment.