diff --git a/ports/stm32/boards/Passport/modules/actions.py b/ports/stm32/boards/Passport/modules/actions.py index cffb83ee..23ae8135 100644 --- a/ports/stm32/boards/Passport/modules/actions.py +++ b/ports/stm32/boards/Passport/modules/actions.py @@ -23,7 +23,7 @@ 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) @@ -2065,3 +2071,23 @@ async def remove_user_firmware_pubkey(*a): center=True, center_vertically=True) clear_cached_pubkey() + +async def show_testnet_warning(*a): + 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 test_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 (user selected something) + if new_chain != old_chain: + # Let the user know that using Testnet is potentially dangerous + await show_testnet_warning() \ No newline at end of file diff --git a/ports/stm32/boards/Passport/modules/chains.py b/ports/stm32/boards/Passport/modules/chains.py index be1ff3ae..c9f1589e 100644 --- a/ports/stm32/boards/Passport/modules/chains.py +++ b/ports/stm32/boards/Passport/modules/chains.py @@ -150,29 +150,30 @@ def hash_message(cls, msg=None, msg_len=0): @classmethod def render_value(cls, val, unpad=False): - from common import settings - # convert nValue from a transaction into either BTC or sats # - always be precise # - return (string, units label) + 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', 'BTC') - if units == 'BTC': + 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: # all the zeros txt = '%d.%08d' % (val // 1E8, val % 1E8) else: + label = cls.ctype_sats txt = ('%d' % (val)) - return txt, units + return txt, label @classmethod def render_address(cls, script): @@ -202,6 +203,7 @@ def render_address(cls, script): class BitcoinMain(ChainsBase): # see ctype = 'BTC' + ctype_sats = 'sats' name = 'Bitcoin' core_name = 'Bitcoin Core' menu_name = 'Bitcoin Mainnet' @@ -224,6 +226,7 @@ class BitcoinMain(ChainsBase): class BitcoinTestnet(BitcoinMain): ctype = 'TBTC' + ctype_sats = 'tsats' name = 'Bitcoin Testnet' menu_name = 'Bitcoin Testnet' diff --git a/ports/stm32/boards/Passport/modules/choosers.py b/ports/stm32/boards/Passport/modules/choosers.py index 60417666..b144e409 100644 --- a/ports/stm32/boards/Passport/modules/choosers.py +++ b/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 @@ -103,14 +103,16 @@ def set_chain(idx, text): return which, [t for _,t in ch], set_chain def units_chooser(): - DEFAULT_UNITS = "BTC" + import chains + from constants import UNIT_TYPE_BTC, UNIT_TYPE_SATS - units = settings.get('units', DEFAULT_UNITS) + chain = chains.current_chain() + units = settings.get('units', UNIT_TYPE_BTC) - ch = ['BTC', - 'sats'] - val = ['BTC', - 'sats'] + ch = [chain.ctype, + chain.ctype_sats] + val = [UNIT_TYPE_BTC, + UNIT_TYPE_SATS] try: which = val.index(units) diff --git a/ports/stm32/boards/Passport/modules/constants.py b/ports/stm32/boards/Passport/modules/constants.py index 8f22c3f9..ee060cab 100644 --- a/ports/stm32/boards/Passport/modules/constants.py +++ b/ports/stm32/boards/Passport/modules/constants.py @@ -39,3 +39,7 @@ 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 \ No newline at end of file diff --git a/ports/stm32/boards/Passport/modules/flow.py b/ports/stm32/boards/Passport/modules/flow.py index b3d86423..f12241d9 100644 --- a/ports/stm32/boards/Passport/modules/flow.py +++ b/ports/stm32/boards/Passport/modules/flow.py @@ -19,7 +19,7 @@ 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 @@ -70,7 +70,7 @@ def has_pubkey(): 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=test_chooser), MenuItem('Units', chooser=units_chooser), MenuItem('Erase Passport', f=erase_wallet, arg=True) ] diff --git a/ports/stm32/boards/Passport/modules/stash.py b/ports/stm32/boards/Passport/modules/stash.py index 3a404322..d2d217fd 100644 --- a/ports/stm32/boards/Passport/modules/stash.py +++ b/ports/stm32/boards/Passport/modules/stash.py @@ -221,7 +221,7 @@ def capture_xpub(self): 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):