Browse Source

PASS1-67: Change unit to sats in settings (#46)

* PASS1-67: Change unit to sats in settings

* Added warnings for Testnet and made the setting volatile

* Added 'chain' removal to schema_evolution and moved Units menu to top

* Moved Units below Change Pin in menu
PASS1-140
Corey Lakey 4 years ago
committed by GitHub
parent
commit
6fde0803c4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      ports/stm32/boards/Passport/modules/actions.py
  2. 32
      ports/stm32/boards/Passport/modules/chains.py
  3. 24
      ports/stm32/boards/Passport/modules/choosers.py
  4. 4
      ports/stm32/boards/Passport/modules/constants.py
  5. 5
      ports/stm32/boards/Passport/modules/flow.py
  6. 2
      ports/stm32/boards/Passport/modules/schema_evolution.py
  7. 2
      ports/stm32/boards/Passport/modules/stash.py

28
ports/stm32/boards/Passport/modules/actions.py

@ -23,7 +23,7 @@ from common import settings, system, noise, dis
from utils import (UXStateMachine, imported, pretty_short_delay, xfp2str, to_str,
truncate_string_to_width, set_next_addr, scan_for_address, get_accounts, run_chooser,
make_account_name_num, is_valid_address, save_next_addr, needs_microsd, format_btc_address,
is_all_zero, bytes_to_hex_str, split_to_lines, is_valid_btc_address, do_address_verify)
is_all_zero, bytes_to_hex_str, split_to_lines, is_valid_btc_address, do_address_verify, run_chooser)
from wallets.utils import get_export_mode, get_addr_type_from_address, get_deriv_path_from_addr_type_and_acct
from ux import (the_ux, ux_confirm, ux_enter_pin,
ux_enter_text, ux_scan_qr_code, ux_shutdown,
@ -1128,6 +1128,9 @@ async def sign_tx_from_sd(*a):
import stash
# Let the user know that using Testnet is potentially dangerous
await show_testnet_warning()
if stash.bip39_passphrase:
title = '[%s]' % xfp2str(settings.get('xfp'))
else:
@ -1323,6 +1326,9 @@ async def magic_scan(menu, label, item):
title = item.arg
# Let the user know that using Testnet is potentially dangerous
await show_testnet_warning()
while True:
system.turbo(True)
data = await ux_scan_qr_code(title)
@ -2072,3 +2078,23 @@ async def remove_user_firmware_pubkey(*a):
center=True,
center_vertically=True)
clear_cached_pubkey()
async def show_testnet_warning():
chain = settings.get('chain', 'BTC')
if chain == 'TBTC':
await ux_show_story('Passport is in Testnet mode. Use a separate seed to avoid issues with malicious software wallets.',
title='Warning',
center=True,
center_vertically=True)
async def testnet_chooser(*a):
from choosers import chain_chooser
old_chain = settings.get('chain', 'BTC')
await run_chooser(chain_chooser, 'Passport', show_checks=True)
new_chain = settings.get('chain', 'BTC')
# Only display the warning if the chain changed
if new_chain != old_chain:
# Let the user know that using Testnet is potentially dangerous
await show_testnet_warning()

32
ports/stm32/boards/Passport/modules/chains.py

@ -150,20 +150,30 @@ class ChainsBase:
@classmethod
def render_value(cls, val, unpad=False):
# convert nValue from a transaction into human form.
# convert nValue from a transaction into either BTC or sats
# - always be precise
# - return (string, units label)
if unpad:
if (val % 1E8):
# precise but unpadded
txt = ('%d.%08d' % (val // 1E8, val % 1E8)).rstrip('0')
from common import settings
from constants import UNIT_TYPE_BTC, UNIT_TYPE_SATS
# BTC is the default if not set yet
units = settings.get('units', UNIT_TYPE_BTC)
if units == UNIT_TYPE_BTC:
label = cls.ctype
if unpad:
if (val % 1E8):
# precise but unpadded
txt = ('%d.%08d' % (val // 1E8, val % 1E8)).rstrip('0')
else:
# round BTC amount, show no decimal
txt = '%d' % (val // 1E8)
else:
# round BTC amount, show no decimal
txt = '%d' % (val // 1E8)
# all the zeros
txt = '%d.%08d' % (val // 1E8, val % 1E8)
else:
# all the zeros
txt = '%d.%08d' % (val // 1E8, val % 1E8)
return txt, cls.ctype
label = cls.ctype_sats
txt = ('%d' % (val))
return txt, label
@classmethod
def render_address(cls, script):
@ -193,6 +203,7 @@ class ChainsBase:
class BitcoinMain(ChainsBase):
# see <https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp#L140>
ctype = 'BTC'
ctype_sats = 'sats'
name = 'Bitcoin'
core_name = 'Bitcoin Core'
menu_name = 'Bitcoin Mainnet'
@ -215,6 +226,7 @@ class BitcoinMain(ChainsBase):
class BitcoinTestnet(BitcoinMain):
ctype = 'TBTC'
ctype_sats = 'tsats'
name = 'Bitcoin Testnet'
menu_name = 'Bitcoin Testnet'

24
ports/stm32/boards/Passport/modules/choosers.py

@ -89,7 +89,7 @@ def chain_chooser():
def set_chain(idx, text):
val = ch[idx][0]
assert ch[idx][1] == text
settings.set('chain', val)
settings.set_volatile('chain', val)
try:
# update xpub stored in settings
@ -102,4 +102,26 @@ def chain_chooser():
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

4
ports/stm32/boards/Passport/modules/constants.py

@ -40,5 +40,9 @@ MAX_MULTISIG_NAME_LEN = 20
DEFAULT_ACCOUNT_ENTRY = {'name': 'Primary', 'acct_num': 0}
# Unit types for labeling conversions
UNIT_TYPE_BTC = 0
UNIT_TYPE_SATS = 1
# Maximum amount of characters in a text entry screen
MAX_MESSAGE_LEN = 64

5
ports/stm32/boards/Passport/modules/flow.py

@ -19,7 +19,7 @@ from public_constants import AF_P2WPKH
from multisig import make_multisig_menu
from wallets.utils import has_export_mode
from export import view_backup_password
from utils import is_new_wallet_in_progress, get_accounts, is_screenshot_mode_enabled
from utils import is_new_wallet_in_progress, get_accounts, is_screenshot_mode_enabled, run_chooser
from new_wallet import pair_new_wallet
from ie import show_browser
@ -65,12 +65,13 @@ DeveloperPubkeyMenu = [
AdvancedMenu = [
MenuItem('Change PIN', f=change_pin),
MenuItem('Units', chooser=units_chooser),
MenuItem('Passphrase', menu_title='Passphrase', menu=PassphraseMenu),
MenuItem('Sign Text File', predicate=has_secrets, f=sign_message_on_sd),
MenuItem('MicroSD Settings', menu=SDCardMenu),
MenuItem('View Seed Words', f=view_seed_words, predicate=lambda: settings.get('words', True)),
MenuItem('Developer PubKey', menu=DeveloperPubkeyMenu, menu_title='Developer'),
MenuItem('Testnet', chooser=chain_chooser),
MenuItem('Testnet', f=testnet_chooser),
MenuItem('Erase Passport', f=erase_wallet, arg=True)
]

2
ports/stm32/boards/Passport/modules/schema_evolution.py

@ -34,6 +34,8 @@ async def handle_schema_evolutions(update_from_to):
# This no longer used, so clean it out
settings.remove('backup_num')
# This is now volatile, so clean it out
settings.remove('chain')
from_version = to_version
continue

2
ports/stm32/boards/Passport/modules/stash.py

@ -221,7 +221,7 @@ class SensitiveValues:
settings.set_volatile('xfp', xfp)
settings.set_volatile('xpub', xpub)
settings.set('chain', self.chain.ctype)
settings.set_volatile('chain', self.chain.ctype)
settings.set('words', (self.mode == 'words'))
def register(self, item):

Loading…
Cancel
Save