From 974f2ccdaaaa2624847cb0f693fde879b4cb3c69 Mon Sep 17 00:00:00 2001 From: Toporin Date: Wed, 13 Jan 2021 14:01:36 +0100 Subject: [PATCH] Patch error when trying to connect to satochip 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. --- electroncash_plugins/satochip/satochip.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/electroncash_plugins/satochip/satochip.py b/electroncash_plugins/satochip/satochip.py index fbc3b9ddeaea..31708dae517d 100644 --- a/electroncash_plugins/satochip/satochip.py +++ b/electroncash_plugins/satochip/satochip.py @@ -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): @@ -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",