2019-02-11 20:21:24 +01:00
|
|
|
from functools import partial
|
2023-08-23 17:09:19 +02:00
|
|
|
from typing import TYPE_CHECKING
|
2019-02-11 20:21:24 +01:00
|
|
|
|
2024-09-05 16:20:01 +00:00
|
|
|
from PyQt6.QtCore import pyqtSignal
|
|
|
|
|
from PyQt6.QtWidgets import QInputDialog, QLineEdit
|
2019-02-11 20:21:24 +01:00
|
|
|
|
2016-01-11 15:08:12 +09:00
|
|
|
from electrum.i18n import _
|
2018-07-11 17:38:47 +02:00
|
|
|
from electrum.plugin import hook
|
2018-01-11 04:37:41 +11:00
|
|
|
from electrum.wallet import Standard_Wallet
|
2025-04-10 10:13:24 +02:00
|
|
|
from electrum.hw_wallet.qt import QtHandlerBase, QtPluginBase
|
|
|
|
|
from electrum.hw_wallet.plugin import only_hook_if_libraries_available
|
2018-03-20 14:15:54 +01:00
|
|
|
|
2020-10-24 23:32:18 +02:00
|
|
|
from .ledger import LedgerPlugin, Ledger_Client
|
2023-08-23 17:09:19 +02:00
|
|
|
from electrum.gui.qt.wizard.wallet import WCScriptAndDerivation, WCHWUninitialized, WCHWUnlock, WCHWXPub
|
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from electrum.gui.qt.wizard.wallet import QENewWalletWizard
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2016-12-21 12:52:54 +07:00
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
class Plugin(LedgerPlugin, QtPluginBase):
|
2019-02-01 19:01:21 +01:00
|
|
|
icon_unpaired = "ledger_unpaired.png"
|
|
|
|
|
icon_paired = "ledger.png"
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
def create_handler(self, window):
|
|
|
|
|
return Ledger_Handler(window)
|
|
|
|
|
|
2018-09-19 20:02:03 +02:00
|
|
|
@only_hook_if_libraries_available
|
2018-09-30 00:25:36 +02:00
|
|
|
@hook
|
2018-01-11 04:37:41 +11:00
|
|
|
def receive_menu(self, menu, addrs, wallet):
|
|
|
|
|
if type(wallet) is not Standard_Wallet:
|
|
|
|
|
return
|
|
|
|
|
keystore = wallet.get_keystore()
|
|
|
|
|
if type(keystore) == self.keystore_class and len(addrs) == 1:
|
|
|
|
|
def show_address():
|
2022-10-18 15:29:03 +02:00
|
|
|
keystore.thread.add(partial(self.show_address, wallet, addrs[0], keystore=keystore))
|
2018-01-11 04:37:41 +11:00
|
|
|
menu.addAction(_("Show on Ledger"), show_address)
|
|
|
|
|
|
2023-08-23 17:09:19 +02:00
|
|
|
@hook
|
|
|
|
|
def init_wallet_wizard(self, wizard: 'QENewWalletWizard'):
|
|
|
|
|
self.extend_wizard(wizard)
|
|
|
|
|
|
|
|
|
|
# insert ledger pages in new wallet wizard
|
|
|
|
|
def extend_wizard(self, wizard: 'QENewWalletWizard'):
|
|
|
|
|
super().extend_wizard(wizard)
|
|
|
|
|
views = {
|
|
|
|
|
'ledger_start': {'gui': WCScriptAndDerivation},
|
|
|
|
|
'ledger_xpub': {'gui': WCHWXPub},
|
|
|
|
|
'ledger_not_initialized': {'gui': WCHWUninitialized},
|
|
|
|
|
'ledger_unlock': {'gui': WCHWUnlock}
|
|
|
|
|
}
|
|
|
|
|
wizard.navmap_merge(views)
|
|
|
|
|
|
|
|
|
|
|
2016-08-31 11:50:19 +02:00
|
|
|
class Ledger_Handler(QtHandlerBase):
|
2015-11-23 19:38:48 +01:00
|
|
|
|
2022-11-09 21:09:02 +00:00
|
|
|
MESSAGE_DIALOG_TITLE = _("Ledger Status")
|
|
|
|
|
|
2015-11-23 19:38:48 +01:00
|
|
|
def __init__(self, win):
|
2016-08-31 11:50:19 +02:00
|
|
|
super(Ledger_Handler, self).__init__(win, 'Ledger')
|
2015-11-23 19:38:48 +01:00
|
|
|
|