Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor tweaks and ui improvements for qr scan failures and exiting #63

Merged
merged 1 commit into from
Aug 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/seedsigner/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,19 +596,21 @@ def live_preview(camera, decoder):
self.camera.stop_video_stream_mode()
break

if self.buttons.check_for_low(B.KEY_RIGHT):
if self.buttons.check_for_low(B.KEY_RIGHT) or self.buttons.check_for_low(B.KEY_LEFT):
self.camera.stop_video_stream_mode()
return Path.MAIN_MENU
break

time.sleep(0.2) # time to let live preview thread complete to avoid race condition on display

if decoder.isComplete() and decoder.isPSBT():
self.menu_view.draw_modal(["Parsing PSBT"])
psbt = decoder.getPSBT()

else:
self.menu_view.draw_modal(["PSBT Parsing Failed"], "", "Right to Exit")
elif ( decoder.isComplete() and not decoder.isPSBT() ) or decoder.isInvalid():
self.menu_view.draw_modal(["Not a valid PSBT QR"], "", "Right to Exit")
input = self.buttons.wait_for([B.KEY_RIGHT])
return Path.MAIN_MENU
else:
return Path.MAIN_MENU

# show transaction information before sign
p = PSBTParser(psbt,seed_phrase,passphrase,self.wallet.network)
Expand Down
5 changes: 5 additions & 0 deletions src/seedsigner/models/decode_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def getPercentComplete(self) -> int:
def isComplete(self) -> bool:
return self.complete

def isInvalid(self) -> bool:
if self.qr_type == QRType.INVALID:
return True
return False

def isPSBT(self) -> bool:
if self.qr_type in (QRType.PSBTUR2, QRType.PSBTSPECTER, QRType.PSBTURLEGACY, QRType.PSBTBASE64):
return True
Expand Down
4 changes: 2 additions & 2 deletions src/seedsigner/models/encode_qr.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ def __init__(self, p, qr_density):
if qr_density == EncodeQRDensity.LOW:
self.qr_max_fragement_size = 10
elif qr_density == EncodeQRDensity.MEDIUM:
self.qr_max_fragement_size = 20
self.qr_max_fragement_size = 30
elif qr_density == EncodeQRDensity.HIGH:
self.qr_max_fragement_size = 80
self.qr_max_fragement_size = 120

self.ur2_encode = UREncoder(qr_ur_bytes,self.qr_max_fragement_size,0)

Expand Down
1 change: 0 additions & 1 deletion src/seedsigner/models/qr_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class QRType(IntEnum):
SEEDUR2 = 7
SEEDMNEMONIC = 8
SEED4LETTERMNEMONIC = 9
SEEDXPRV = 10
XPUBQR = 20
SPECTERXPUBQR = 21
INVALID = 100
14 changes: 6 additions & 8 deletions src/seedsigner/views/seed_tools_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -1447,26 +1447,24 @@ def read_seed_phrase_qr(self):
while True:
frame = self.controller.camera.read_video_stream(as_image=True)
if frame is not None:
View.DispShowImageWithText(frame.resize((240,240)), "Scan QR", text_color=View.color, text_background=(0,0,0,225))
View.DispShowImageWithText(frame.resize((240,240)), "Scan Seed QR", font=View.IMPACT22, text_color=View.color, text_background=(0,0,0,225))
status = decoder.addImage(frame)

if status in (DecodeQRStatus.COMPLETE, DecodeQRStatus.INVALID):
break

if self.buttons.check_for_low(B.KEY_LEFT):
if self.buttons.check_for_low(B.KEY_RIGHT) or self.buttons.check_for_low(B.KEY_LEFT):
self.controller.camera.stop_video_stream_mode()
self.words = []
return self.words[:]

if decoder.isComplete() and decoder.isSeed():
if decoder.qrType() not in (QRType.SEEDSSQR, QRType.SEEDMNEMONIC, QRType.SEED4LETTERMNEMONIC):
self.draw_modal(["Not a Seed QR"], "", "Right to Exit")
self.words = decoder.getSeedPhrase()
elif not decoder.isPSBT():
self.draw_modal(["Not a valid Seed QR"], "", "Right to Exit")
input = self.buttons.wait_for([B.KEY_RIGHT])
else:
print(decoder.qrType())
print(decoder.isSeed())
print(decoder.isComplete())
self.draw_modal(["Seed Parsing Failed"], "", "Right to Exit")
self.draw_modal(["QR Parsing Failed"], "", "Right to Exit")
input = self.buttons.wait_for([B.KEY_RIGHT])
self.words = []

Expand Down