forked from Foundation-Devices/passport-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
choosers.py
127 lines (95 loc) · 3.21 KB
/
choosers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# SPDX-FileCopyrightText: 2020 Foundation Devices, Inc. <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
#
# SPDX-FileCopyrightText: 2018 Coinkite, Inc. <coldcardwallet.com>
# SPDX-License-Identifier: GPL-3.0-only
#
# (c) Copyright 2018 by Coinkite Inc. This file is part of Coldcard <coldcardwallet.com>
# and is covered by GPLv3 license found in COPYING.
#
# choosers.py - various interactive menus for setting config values.
#
from common import settings
def shutdown_timeout_chooser():
DEFAULT_SHUTDOWN_TIMEOUT = (2*60) # 2 minutes
timeout = settings.get('shutdown_timeout', DEFAULT_SHUTDOWN_TIMEOUT) # in seconds
ch = [' 1 minute',
' 2 minutes',
' 5 minutes',
'15 minutes',
'30 minutes',
'60 minutes',
'Never']
va = [1*60, 2*60, 5*60, 15*60, 30*60, 60*60, 0]
try:
which = va.index(timeout)
except ValueError:
which = 1
def set_shutdown_timeout(idx, text):
settings.set('shutdown_timeout', va[idx])
return which, ch, set_shutdown_timeout
def brightness_chooser():
screen_brightness = settings.get('screen_brightness', 100)
ch = ['Off', '25%', '50%', '75%', '100%'] # , 'Automatic']
va = [0, 25, 50, 75, 100] # , 999]
try:
which = va.index(screen_brightness)
except ValueError:
which = 4
def set(idx, text):
from common import dis
dis.set_brightness(va[idx])
settings.set('screen_brightness', va[idx])
return which, ch, set
def enable_passphrase_chooser():
# Should the Passphrase menu be enabled in the main menu?
ch = ['Disabled', 'Enabled']
va = [False, True]
assert len(ch) == len(va)
enable_passphrase = settings.get('enable_passphrase', False)
try:
which = va.index(enable_passphrase)
except ValueError:
which = 0
def set_enable_passphrase(idx, text):
settings.set('enable_passphrase', va[idx])
return which, ch, set_enable_passphrase
def chain_chooser():
from chains import AllChains
chain = settings.get('chain', 'BTC')
ch = [(i.ctype, i.menu_name or i.name) for i in AllChains ]
# find index of current choice
try:
which = [n for n, (k,v) in enumerate(ch) if k == chain][0]
except IndexError:
which = 0
def set_chain(idx, text):
val = ch[idx][0]
assert ch[idx][1] == text
settings.set_volatile('chain', val)
try:
# update xpub stored in settings
import stash
with stash.SensitiveValues() as sv:
sv.capture_xpub()
except ValueError:
# no secrets yet, not an error
pass
return which, [t for _,t in ch], set_chain
def units_chooser():
import chains
from constants import UNIT_TYPE_BTC, UNIT_TYPE_SATS
chain = chains.current_chain()
units = settings.get('units', UNIT_TYPE_BTC)
ch = [chain.ctype,
chain.ctype_sats]
val = [UNIT_TYPE_BTC,
UNIT_TYPE_SATS]
try:
which = val.index(units)
except ValueError:
which = UNIT_TYPE_BTC
def set_units(idx, text):
settings.set('units', val[idx])
return which, ch, set_units
# EOF