99
1010import PySimpleGUI as sg
1111
12- from .. import Account , create , group_parser , random_secret , cryptopaths_parser
12+ from ..api import Account , create , group_parser , random_secret , cryptopaths_parser , paper_wallet_available
1313from ..recovery import recover , recover_bip39
1414from ..util import log_level , log_cfg , ordinal , chunker
1515from ..layout import write_pdfs
@@ -48,6 +48,7 @@ def groups_layout(
4848 groups ,
4949 passphrase = None ,
5050 cryptocurrency = None ,
51+ paper_wallet = True , # Should we include Paper Wallet config in layout?
5152):
5253 """Return a layout for the specified number of SLIP-39 groups.
5354
@@ -80,6 +81,9 @@ def groups_layout(
8081 ),
8182 ]
8283
84+ if not paper_wallet :
85+ log .warning ( "Disabling Paper Wallets capability: API unavailable" )
86+
8387 layout = [
8488 [
8589 sg .Frame ( '1. Location for output PDF File(s) (Preferably removable media, such as a USB drive)' , [
@@ -229,7 +233,7 @@ def groups_layout(
229233 ],
230234 ], ** F_kwds ),
231235 ],
232- ], key = '-WALLET-F-' , visible = True , ** F_kwds ),
236+ ], key = '-WALLET-F-' , visible = paper_wallet , ** F_kwds ), # noqa: E126
233237 ],
234238 ] + [
235239 [
@@ -535,13 +539,16 @@ def app(
535539
536540 sg .user_settings_set_entry ( '-target folder-' , os .getcwd () )
537541
542+ paper_wallet = paper_wallet_available ()
543+
538544 # Compute initial App window layout, from the supplied groups.
539545 layout = groups_layout (
540546 names = names ,
541547 group_threshold = group_threshold ,
542548 groups = groups ,
543549 passphrase = passphrase ,
544550 cryptocurrency = cryptocurrency ,
551+ paper_wallet = paper_wallet ,
545552 )
546553
547554 window = None
@@ -563,7 +570,8 @@ def app(
563570 window ['-SE-SEED-F-' ].expand ( expand_x = True )
564571 window ['-SEED-F-' ].expand ( expand_x = True )
565572 window ['-OUTPUT-F-' ].expand ( expand_x = True )
566- window ['-WALLET-F-' ].expand ( expand_x = True )
573+ if paper_wallet :
574+ window ['-WALLET-F-' ].expand ( expand_x = True )
567575 window ['-SUMMARY-F-' ].expand ( expand_x = True )
568576 window ['-STATUS-F-' ].expand ( expand_x = True )
569577 window ['-RECOVERED-F-' ].expand ( expand_x = True )
@@ -756,6 +764,7 @@ def app(
756764 # time we recompute -- even without any changes -- the SLIP-39 Mnemonics will change, due to the use
757765 # of entropy in the SLIP-39 process.
758766 if slip39_update or not details :
767+ log .info ( f"SLIP39 details for { names } ..." )
759768 try :
760769 details = {}
761770 for n ,name in enumerate ( names ):
@@ -779,8 +788,15 @@ def app(
779788 continue
780789
781790 # Display the computed SLIP-39 Mnemonics for the first name.
782- if status := update_seed_recovered ( window , values , details [names [0 ]], passphrase = passphrase ):
783- groups_recovered = {}
791+ try :
792+ if status := update_seed_recovered ( window , values , details [names [0 ]], passphrase = passphrase ):
793+ groups_recovered = {}
794+ continue
795+ except Exception as exc :
796+ status = f"Error recovering: { exc } "
797+ logging .exception ( f"{ status } " )
798+ update_seed_recovered ( window , values , None )
799+ groups_recovered = {}
784800 continue
785801
786802 # If all has gone well -- display the resultant <name>/<filename>, and some derived account details
@@ -795,10 +811,10 @@ def app(
795811 # details is now { "<filename>": <details> })
796812 if event == '-SAVE-' :
797813 try :
798- card = next ( c for c in CARD_SIZES if values [f"-CS-{ c } " ] )
814+ card_format = next ( c for c in CARD_SIZES if values [f"-CS-{ c } " ] )
799815 details = write_pdfs (
800816 names = details ,
801- card = card ,
817+ card_format = card_format ,
802818 cryptocurrency = cryptocurrency ,
803819 edit = edit ,
804820 wallet_pwd = values ['-WALLET-PASS-' ], # Produces Paper Wallet(s) iff set
0 commit comments