Skip to content

Commit

Permalink
Patch error when trying to connect to satochip
Browse files Browse the repository at this point in the history
During wallet creation, the following error sometimes pops to the user:
"Failed to create a client for this device. Make sure it is in a correct state".

This error does not always show, and even when it does, it does not stop the wallet creation.

This issue is generated in the method 'has_usable_connection_with_device()'.
The reason is that sometimes the card is not ready when the wizard tries to connect to it.
Retrying after a short delay is enough to solve the issue.
  • Loading branch information
Toporin authored and PiRK committed Jan 31, 2021
1 parent 6acf114 commit 974f2cc
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions electroncash_plugins/satochip/satochip.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,15 @@ def has_usable_connection_with_device(self):
atr= self.cc.card_get_ATR() # (response, sw1, sw2)= self.cc.card_select() #TODO: something else? get ATR?
self.print_error("Card ATR: " + bytes(atr).hex() )
except Exception as e: #except SWException as e:
self.print_error(f"Exception in has_usable_connection_with_device: {str(e)}")
return False
try:
self.print_error(f"giving more time for the card to get ready...")
import time
time.sleep(1) #sometimes the card needs a bit delay to get ready, otherwise it throws "Card not connected"
atr= self.cc.card_get_ATR() # (response, sw1, sw2)= self.cc.card_select() #TODO: something else? get ATR?
self.print_error("Card ATR: " + bytes(atr).hex() )
except Exception as e:
self.print_error(f"Exception in has_usable_connection_with_device: {str(e)}")
return False
return True

def get_xpub(self, bip32_path, xtype):
Expand Down Expand Up @@ -509,7 +516,7 @@ def detect_smartcard_reader(self):
self.print_error("detect_smartcard_reader")#debugSatochip
self.cardtype = AnyCardType()
try:
cardrequest = CardRequest(timeout=0.1, cardType=self.cardtype)
cardrequest = CardRequest(timeout=0, cardType=self.cardtype)
cardservice = cardrequest.waitforcard()
self.print_error("detect_smartcard_reader: found card!")#debugSatochip
return [Device(path="/satochip",
Expand Down

0 comments on commit 974f2cc

Please sign in to comment.