Skip to content
Snippets Groups Projects
Commit 41970ce4 authored by Vincent Texier's avatar Vincent Texier
Browse files

[enh] #798 add send as source menu for all transactions and dividend in expert mode

Check is source exists before display menu
parent 317b41e0
No related branches found
No related tags found
1 merge request!778Release 0.51.0
...@@ -7,7 +7,7 @@ from duniterpy.constants import PUBKEY_REGEX ...@@ -7,7 +7,7 @@ from duniterpy.constants import PUBKEY_REGEX
from duniterpy.documents.crc_pubkey import CRCPubkey from duniterpy.documents.crc_pubkey import CRCPubkey
from sakia.app import Application from sakia.app import Application
from sakia.data.entities import Identity, Transaction, Dividend, Connection from sakia.data.entities import Identity, Transaction, Dividend, Connection, Source
from sakia.data.processors import BlockchainProcessor, TransactionsProcessor from sakia.data.processors import BlockchainProcessor, TransactionsProcessor
from sakia.decorators import asyncify from sakia.decorators import asyncify
from sakia.gui.sub.certification.controller import CertificationController from sakia.gui.sub.certification.controller import CertificationController
...@@ -106,7 +106,7 @@ class ContextMenu(QObject): ...@@ -106,7 +106,7 @@ class ContextMenu(QObject):
menu.qmenu.addAction(copy_selfcert) menu.qmenu.addAction(copy_selfcert)
@staticmethod @staticmethod
def _add_transfers_actions(menu, transfer): def _add_transfer_actions(menu, transfer):
""" """
:param ContextMenu menu: the qmenu to add actions to :param ContextMenu menu: the qmenu to add actions to
:param Transfer transfer: the transfer :param Transfer transfer: the transfer
...@@ -132,16 +132,26 @@ class ContextMenu(QObject): ...@@ -132,16 +132,26 @@ class ContextMenu(QObject):
) )
menu.qmenu.addAction(cancel) menu.qmenu.addAction(cancel)
# if special lock condition on transaction... # if special lock condition on transaction or
if transfer.conditions is not None: # all transaction received in expert mode...
send_as_source = QAction( if transfer.conditions is not None or (
QCoreApplication.translate("ContextMenu", "Send as source"), transfer.pubkey in transfer.receivers and menu._app.parameters.expert_mode
menu.qmenu.parent(), ):
) # get source from conditions and transaction hash
send_as_source.triggered.connect( source = menu._app.sources_service.get_one(
lambda checked, tr=transfer: menu.send_as_source(tr) identifier=transfer.sha_hash, conditions=transfer.conditions
) )
menu.qmenu.addAction(send_as_source) if source:
# add send as source menu
send_as_source = QAction(
QCoreApplication.translate("ContextMenu", "Send as source"),
menu.qmenu.parent(),
)
send_as_source.triggered.connect(
lambda checked, src=source: menu.send_as_source(src)
)
menu.qmenu.addAction(send_as_source)
if menu._app.parameters.expert_mode: if menu._app.parameters.expert_mode:
copy_doc = QAction( copy_doc = QAction(
QCoreApplication.translate( QCoreApplication.translate(
...@@ -168,6 +178,32 @@ class ContextMenu(QObject): ...@@ -168,6 +178,32 @@ class ContextMenu(QObject):
) )
menu.qmenu.addAction(copy_doc) menu.qmenu.addAction(copy_doc)
@staticmethod
def _add_dividend_actions(menu, dividend):
"""
:param ContextMenu menu: the qmenu to add actions to
:param Transfer transfer: the transfer
"""
menu.qmenu.addSeparator().setText(
QCoreApplication.translate("ContextMenu", "Dividend")
)
if menu._app.parameters.expert_mode:
# get dividend source from block number and type
source = menu._app.sources_service.get_one(
noffset=dividend.block_number, type=Source.TYPE_DIVIDEND
)
if source:
# add send as source menu
send_as_source = QAction(
QCoreApplication.translate("ContextMenu", "Send as source"),
menu.qmenu.parent(),
)
send_as_source.triggered.connect(
lambda checked, src=source: menu.send_dividend_as_source(src)
)
menu.qmenu.addAction(send_as_source)
@staticmethod @staticmethod
def _add_string_actions(menu, str_value): def _add_string_actions(menu, str_value):
if re.match(PUBKEY_REGEX, str_value): if re.match(PUBKEY_REGEX, str_value):
...@@ -219,8 +255,8 @@ class ContextMenu(QObject): ...@@ -219,8 +255,8 @@ class ContextMenu(QObject):
menu = cls(QMenu(parent), app, connection) menu = cls(QMenu(parent), app, connection)
build_actions = { build_actions = {
Identity: ContextMenu._add_identity_actions, Identity: ContextMenu._add_identity_actions,
Transaction: ContextMenu._add_transfers_actions, Transaction: ContextMenu._add_transfer_actions,
Dividend: lambda m, d: None, Dividend: ContextMenu._add_dividend_actions,
str: ContextMenu._add_string_actions, str: ContextMenu._add_string_actions,
dict: lambda m, d: None, dict: lambda m, d: None,
type(None): lambda m, d: None, type(None): lambda m, d: None,
...@@ -298,11 +334,24 @@ This money transfer will be removed and not sent.""", ...@@ -298,11 +334,24 @@ This money transfer will be removed and not sent.""",
self._app.db.commit() self._app.db.commit()
self._app.transaction_state_changed.emit(transfer) self._app.transaction_state_changed.emit(transfer)
def send_as_source(self, transfer: Transaction): def send_as_source(self, source: Source):
# get source from conditions and transaction hash """
source = self._app.sources_service.get_one( Open transfer dialog with a transaction as source
identifier=transfer.sha_hash, conditions=transfer.conditions
:param Source source: Source entity to send
:return:
"""
TransferController.send_money_to_pubkey(
None, self._app, self._connection, None, source
) )
def send_dividend_as_source(self, source: Source):
"""
Open transfer dialog with a dividend as source
:param Source source: Source entity to send
:return:
"""
TransferController.send_money_to_pubkey( TransferController.send_money_to_pubkey(
None, self._app, self._connection, None, source None, self._app, self._connection, None, source
) )
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment