From 31ffeaf95f7bcb0cdd5589035c2affae8574f98c Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 23 Aug 2023 17:09:08 +0200 Subject: [PATCH] wizard: add coldcard --- electrum/plugins/coldcard/coldcard.py | 26 ++++++++++++++++++++++++++ electrum/plugins/coldcard/qt.py | 21 ++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/electrum/plugins/coldcard/coldcard.py b/electrum/plugins/coldcard/coldcard.py index 972e6def0..11c2aac18 100644 --- a/electrum/plugins/coldcard/coldcard.py +++ b/electrum/plugins/coldcard/coldcard.py @@ -612,6 +612,32 @@ class ColdcardPlugin(HW_PluginBase): keystore.handler.show_error(_('This function is only available for standard wallets when using {}.').format(self.device)) return + # new wizard + + def wizard_entry_for_device(self, device_info: 'DeviceInfo', *, new_wallet=True) -> str: + if new_wallet: + return 'coldcard_start' if device_info.initialized else 'coldcard_not_initialized' + else: + return 'coldcard_unlock' + + # insert coldcard pages in new wallet wizard + def extend_wizard(self, wizard: 'NewWalletWizard'): + views = { + 'coldcard_start': { + 'next': 'coldcard_xpub', + }, + 'coldcard_xpub': { + 'next': lambda d: wizard.wallet_password_view(d) if wizard.last_cosigner(d) else 'multisig_cosigner_keystore', + 'accept': wizard.maybe_master_pubkey, + 'last': lambda d: wizard.is_single_password() and wizard.last_cosigner(d) + }, + 'coldcard_not_initialized': {}, + 'coldcard_unlock': { + 'last': True + }, + } + wizard.navmap_merge(views) + def xfp_int_from_xfp_bytes(fp_bytes: bytes) -> int: return int.from_bytes(fp_bytes, byteorder="little", signed=False) diff --git a/electrum/plugins/coldcard/qt.py b/electrum/plugins/coldcard/qt.py index f94a970fe..0c9d24803 100644 --- a/electrum/plugins/coldcard/qt.py +++ b/electrum/plugins/coldcard/qt.py @@ -1,6 +1,6 @@ import time, os from functools import partial -import copy +from typing import TYPE_CHECKING from PyQt5.QtCore import Qt, pyqtSignal from PyQt5.QtWidgets import QPushButton, QLabel, QVBoxLayout, QWidget, QGridLayout @@ -18,10 +18,14 @@ from electrum.transaction import PartialTransaction from .coldcard import ColdcardPlugin, xfp2str from ..hw_wallet.qt import QtHandlerBase, QtPluginBase from ..hw_wallet.plugin import only_hook_if_libraries_available +from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWXPub, WCHWUninitialized, WCHWUnlock +if TYPE_CHECKING: + from electrum.gui.qt.wizard.wallet import QENewWalletWizard CC_DEBUG = False + class Plugin(ColdcardPlugin, QtPluginBase): icon_unpaired = "coldcard_unpaired.png" icon_paired = "coldcard.png" @@ -82,6 +86,21 @@ class Plugin(ColdcardPlugin, QtPluginBase): # - doesn't matter if device not connected, continue CKCCSettingsDialog(window, self, keystore).exec_() + @hook + def init_wallet_wizard(self, wizard: 'QENewWalletWizard'): + self.extend_wizard(wizard) + + # insert coldcard pages in new wallet wizard + def extend_wizard(self, wizard: 'QENewWalletWizard'): + super().extend_wizard(wizard) + views = { + 'coldcard_start': {'gui': WCScriptAndDerivation}, + 'coldcard_xpub': {'gui': WCHWXPub}, + 'coldcard_not_initialized': {'gui': WCHWUninitialized}, + 'coldcard_unlock': {'gui': WCHWUnlock} + } + wizard.navmap_merge(views) + class Coldcard_Handler(QtHandlerBase): MESSAGE_DIALOG_TITLE = _("Coldcard Status")