plugins: psbt_nostr: move can_send_psbt logic from GUI to backend, fix qml wallet switch bug
This commit is contained in:
@@ -218,6 +218,14 @@ class CosignerWallet(Logger):
|
|||||||
# note that tx could also be unrelated from wallet?... (not ismine inputs)
|
# note that tx could also be unrelated from wallet?... (not ismine inputs)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def can_send_psbt(self, tx: Union[Transaction, PartialTransaction]) -> bool:
|
||||||
|
if tx.is_complete() or self.wallet.can_sign(tx):
|
||||||
|
return False
|
||||||
|
for xpub, pubkey in self.cosigner_list:
|
||||||
|
if self.cosigner_can_sign(tx, xpub):
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def mark_pending_event_rcvd(self, event_id):
|
def mark_pending_event_rcvd(self, event_id):
|
||||||
self.logger.debug('marking event rcvd')
|
self.logger.debug('marking event rcvd')
|
||||||
self.known_events[event_id] = now()
|
self.known_events[event_id] = now()
|
||||||
|
|||||||
@@ -58,23 +58,30 @@ class QReceiveSignalObject(QObject):
|
|||||||
def loader(self):
|
def loader(self):
|
||||||
return 'main.qml'
|
return 'main.qml'
|
||||||
|
|
||||||
|
@pyqtSlot(QEWallet, str, result=bool)
|
||||||
|
def canSendPsbt(self, wallet: 'QEWallet', tx: str) -> bool:
|
||||||
|
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
|
||||||
|
if not cosigner_wallet:
|
||||||
|
return False
|
||||||
|
return cosigner_wallet.can_send_psbt(tx_from_any(tx, deserialize=True))
|
||||||
|
|
||||||
@pyqtSlot(QEWallet, str)
|
@pyqtSlot(QEWallet, str)
|
||||||
def sendPsbt(self, wallet: 'QEWallet', tx: str):
|
def sendPsbt(self, wallet: 'QEWallet', tx: str):
|
||||||
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
|
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
|
||||||
if not cosigner_wallet:
|
if not cosigner_wallet:
|
||||||
return
|
return
|
||||||
cosigner_wallet.send_psbt(tx_from_any(tx, deserialize=True))
|
cosigner_wallet.send_psbt(tx_from_any(tx, deserialize=True))
|
||||||
|
|
||||||
@pyqtSlot(QEWallet, str)
|
@pyqtSlot(QEWallet, str)
|
||||||
def acceptPsbt(self, wallet: 'QEWallet', event_id: str):
|
def acceptPsbt(self, wallet: 'QEWallet', event_id: str):
|
||||||
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
|
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
|
||||||
if not cosigner_wallet:
|
if not cosigner_wallet:
|
||||||
return
|
return
|
||||||
cosigner_wallet.accept_psbt(event_id)
|
cosigner_wallet.accept_psbt(event_id)
|
||||||
|
|
||||||
@pyqtSlot(QEWallet, str)
|
@pyqtSlot(QEWallet, str)
|
||||||
def rejectPsbt(self, wallet: 'QEWallet', event_id: str):
|
def rejectPsbt(self, wallet: 'QEWallet', event_id: str):
|
||||||
cosigner_wallet = self._plugin.cosigner_wallets[wallet.wallet]
|
cosigner_wallet = self._plugin.cosigner_wallets.get(wallet.wallet)
|
||||||
if not cosigner_wallet:
|
if not cosigner_wallet:
|
||||||
return
|
return
|
||||||
cosigner_wallet.reject_psbt(event_id)
|
cosigner_wallet.reject_psbt(event_id)
|
||||||
@@ -98,8 +105,8 @@ class Plugin(PsbtNostrPlugin):
|
|||||||
@hook
|
@hook
|
||||||
def load_wallet(self, wallet: 'Abstract_Wallet'):
|
def load_wallet(self, wallet: 'Abstract_Wallet'):
|
||||||
# remove existing, only foreground wallet active
|
# remove existing, only foreground wallet active
|
||||||
if len(self.cosigner_wallets):
|
for wallet in self.cosigner_wallets.copy().keys():
|
||||||
self.remove_cosigner_wallet(self.cosigner_wallets[0])
|
self.remove_cosigner_wallet(wallet)
|
||||||
if not isinstance(wallet, Multisig_Wallet):
|
if not isinstance(wallet, Multisig_Wallet):
|
||||||
return
|
return
|
||||||
self.add_cosigner_wallet(wallet, QmlCosignerWallet(wallet, self))
|
self.add_cosigner_wallet(wallet, QmlCosignerWallet(wallet, self))
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ Item {
|
|||||||
property variant dialog
|
property variant dialog
|
||||||
text: qsTr('Nostr')
|
text: qsTr('Nostr')
|
||||||
icon.source: Qt.resolvedUrl('../../../gui/icons/network.png')
|
icon.source: Qt.resolvedUrl('../../../gui/icons/network.png')
|
||||||
visible: Daemon.currentWallet.isMultisig && Daemon.currentWallet.walletType != '2fa'
|
visible: AppController.plugin('psbt_nostr').canSendPsbt(Daemon.currentWallet, dialog.text)
|
||||||
onClicked: {
|
onClicked: {
|
||||||
console.log('about to psbt nostr send')
|
console.log('about to psbt nostr send')
|
||||||
psbt_nostr_send_button.enabled = false
|
psbt_nostr_send_button.enabled = false
|
||||||
|
|||||||
@@ -77,15 +77,7 @@ class Plugin(PsbtNostrPlugin):
|
|||||||
def transaction_dialog_update(self, d: 'TxDialog'):
|
def transaction_dialog_update(self, d: 'TxDialog'):
|
||||||
if cw := self.cosigner_wallets.get(d.wallet):
|
if cw := self.cosigner_wallets.get(d.wallet):
|
||||||
assert isinstance(cw, QtCosignerWallet)
|
assert isinstance(cw, QtCosignerWallet)
|
||||||
if d.tx.is_complete() or d.wallet.can_sign(d.tx):
|
d.cosigner_send_button.setVisible(cw.can_send_psbt(d.tx))
|
||||||
d.cosigner_send_button.setVisible(False)
|
|
||||||
return
|
|
||||||
for xpub, pubkey in cw.cosigner_list:
|
|
||||||
if cw.cosigner_can_sign(d.tx, xpub):
|
|
||||||
d.cosigner_send_button.setVisible(True)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
d.cosigner_send_button.setVisible(False)
|
|
||||||
|
|
||||||
|
|
||||||
class QtCosignerWallet(EventListener, CosignerWallet):
|
class QtCosignerWallet(EventListener, CosignerWallet):
|
||||||
|
|||||||
Reference in New Issue
Block a user