Skip to content

Commit

Permalink
Added (configurable) timeout to preview panel.
Browse files Browse the repository at this point in the history
Switched primary row widget to QPanel instead of QWidget for better styling options.
Added summary and mine/their highlighting to transaction preview window.
  • Loading branch information
ben-abraham committed Jun 13, 2021
1 parent c220041 commit 9a02556
Show file tree
Hide file tree
Showing 6 changed files with 138 additions and 29 deletions.
1 change: 1 addition & 0 deletions app_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def load_defaults(self):
self.init_setting("active_rpc", 0)
self.init_setting("update_interval", 5000)
self.init_setting("server_url", "https://raventrader.net")
self.init_setting("preview_timeout", 3)

return first_launch
#
Expand Down
105 changes: 87 additions & 18 deletions ui/preview_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ def __init__(self, partial_swap, final_swap, preview_title="Confirm Transaction"
self.swap = partial_swap
self.setWindowTitle(preview_title)
self.txtRawFinal.setText(final_swap)

decoded = do_rpc("decoderawtransaction", hexstring=final_swap)

for vin in decoded["vin"]:

self.decoded = do_rpc("decoderawtransaction", hexstring=final_swap)
self.transaction_deltas = {}
self.input_sent = 0
self.output_sent = 0

for vin in self.decoded["vin"]:
#Have to use explorer API here because there is no guarantee that these transactions are local
#vin_tx = do_rpc("getrawtransaction", txid=vin["txid"], verbose=True)
local_vout = do_rpc("gettxout", txid=vin["txid"], n=int(vin["vout"]))
Expand All @@ -35,30 +39,95 @@ def __init__(self, partial_swap, final_swap, preview_title="Confirm Transaction"
vin_tx = decode_full(vin["txid"])
src_vout = vin_tx["vout"][vin["vout"]]
src_addr = src_vout["scriptPubKey"]["addresses"][0]
is_my_utxo = False
is_my_utxo = AppInstance.wallet.search_utxo(make_utxo(vin)) != None

for my_utxo in AppInstance.wallet.utxos:
if my_utxo["txid"] == vin["txid"] and my_utxo["vout"] == vin["vout"]:
is_my_utxo = True
break
for my_asset in AppInstance.wallet.my_asset_names:
for my_a_utxo in AppInstance.wallet.assets[my_asset]["outpoints"]:
if my_a_utxo["txid"] == vin["txid"] and my_a_utxo["vout"] == vin["vout"]:
is_my_utxo = True
break
utxo_data = vout_to_utxo(src_vout, vin["txid"], vin["vout"])
vin_type = "rvn" if utxo_data["type"] == "rvn" else utxo_data["asset"]

self.add_swap_item(self.lstInputs, src_vout, is_my_utxo)
if is_my_utxo:
if vin_type not in self.transaction_deltas:
self.transaction_deltas[vin_type] = 0
self.transaction_deltas[vin_type] -= utxo_data["amount"] #If we provided the input, subtract from total

if vin_type == "rvn":
self.input_sent += utxo_data["amount"]

self.add_tx_item(self.lstInputs, src_vout, is_my_utxo)

for vout in decoded["vout"]:
for vout in self.decoded["vout"]:
vout_addr = vout["scriptPubKey"]["addresses"][0]
addr_check = do_rpc("validateaddress", address=vout_addr)
is_my_out = addr_check["ismine"]

self.add_swap_item(self.lstOutputs, vout, is_my_out)
utxo_data = vout_to_utxo(vout, self.decoded["txid"], vout["n"])
vout_type = "rvn" if utxo_data["type"] == "rvn" else utxo_data["asset"]

if is_my_out:
if vout_type not in self.transaction_deltas:
self.transaction_deltas[vout_type] = 0
self.transaction_deltas[vout_type] += utxo_data["amount"] #If we received the output, keep it positive

if vout_type == "rvn":
self.output_sent += utxo_data["amount"]

def add_swap_item(self, list, vout, mine):
voutListWidget = QTwoLineRowWidget.from_vout(vout, mine)
self.add_tx_item(self.lstOutputs, vout, is_my_out)

debits = [(name, self.transaction_deltas[name]) for name in self.transaction_deltas.keys() if self.transaction_deltas[name] > 0]
credits = [(name, self.transaction_deltas[name]) for name in self.transaction_deltas.keys() if self.transaction_deltas[name] < 0]

final_text = ""
if len(credits):
final_text += "== Total Sent ==\n\n"
for (credit_type, credit_amt) in credits:
if credit_type == "rvn":
final_text += "\t{:.8g} RVN\n".format(credit_amt)
else:
final_text += "\t{:.8g}x [{}]\n".format(credit_amt, credit_type)
final_text += "\n\n"
if len(debits):
final_text += "== Total Received ==\n\n"
for (debit_type, debit_amt) in debits:
if debit_type == "rvn":
final_text += "\t{:.8g} RVN\n".format(debit_amt)
else:
final_text += "\t{:.8g}x [{}]\n".format(debit_amt, debit_type)

#This is just a dumb diff, ignores ownership
final_text += "\n\nTotal Fees: {:.8g} RVN".format(self.input_sent - self.output_sent)

self.lblTransactionSummary.setText(final_text)

logging.info("Transaction Deltas: {}".format(self.transaction_deltas))
self.timeout_start()


def timeout_start(self):
self.timeout_remaining = AppInstance.settings.read("preview_timeout")
if self.timeout_remaining <= 0:
self.timeout_remaining = 0
else:
self.tmrTimeout = QTimer(self)
self.tmrTimeout.timeout.connect(self.timer_timeout)
self.tmrTimeout.start(1000)

self.update_timer_display()

def timer_timeout(self):
self.timeout_remaining -= 1
self.update_timer_display()

def update_timer_display(self):
if self.timeout_remaining > 0:
self.btnDialogButtons.button(QDialogButtonBox.Ok).setEnabled(False)
self.btnDialogButtons.button(QDialogButtonBox.Ok).setText("Send ({})".format(self.timeout_remaining))
else:
self.btnDialogButtons.button(QDialogButtonBox.Ok).setEnabled(True)
self.btnDialogButtons.button(QDialogButtonBox.Ok).setText("Send")
self.tmrTimeout.stop()

def add_tx_item(self, list, vout, mine):
voutListItem = QListWidgetItem(list)
voutListWidget = QTwoLineRowWidget.from_vout(vout, mine)
voutListItem.setSizeHint(voutListWidget.sizeHint())
list.addItem(voutListItem)
list.setItemWidget(voutListItem, voutListWidget)
23 changes: 22 additions & 1 deletion ui/qt/preview_order.ui
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,1,1">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
Expand All @@ -66,6 +66,27 @@
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_3" stretch="1,5">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Summary</string>
</property>
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblTransactionSummary">
<property name="alignment">
<set>Qt::AlignHCenter|Qt::AlignTop</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
Expand Down
25 changes: 18 additions & 7 deletions ui/qt/style.qss
Original file line number Diff line number Diff line change
Expand Up @@ -636,22 +636,22 @@ QListView::disabled
}


QListView::item
QListView::item
{
background-color: #2d2d2d;
padding: 1px;

}


QListView::item:alternate
QListView::item:alternate
{
background-color: #3a3a3a;

}


QListView::item:selected
QListView::item:selected
{
background-color: #b78620;
border: 1px solid #b78620;
Expand All @@ -660,7 +660,7 @@ QListView::item:selected
}


QListView::item:selected:!active
QListView::item:selected:!active
{
background-color: #b78620;
border: 1px solid #b78620;
Expand All @@ -669,7 +669,7 @@ QListView::item:selected:!active
}


QListView::item:selected:active
QListView::item:selected:active
{
background-color: #b78620;
border: 1px solid #b78620;
Expand All @@ -678,7 +678,8 @@ QListView::item:selected:active
}


QListView::item:hover {
QListView::item:hover
{
background-color: #262626;
border: none;
color: white;
Expand Down Expand Up @@ -998,7 +999,17 @@ QLabel[status="confirmed"]
color: #4aa96c;
}

/* Vout row, owed not by us */
QListView::item *[external="yes"]
{
background-color: #440000;
}
QListView::item *[external="no"]
{
background-color: #004400;
}

#txtSigned
{
background-color: #101010;
}
}
9 changes: 8 additions & 1 deletion util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def b64_to_hex(b64_str):
#Helper Classes
#

class QTwoLineRowWidget (QWidget):
class QTwoLineRowWidget (QFrame):
def __init__ (self, parent = None):
super(QTwoLineRowWidget, self).__init__(parent)
self.textQVBoxLayout = QVBoxLayout()
Expand Down Expand Up @@ -203,13 +203,20 @@ def from_vout(vout, ismine):
else:
row.setTextUp("{:.8g} RVN".format(float(row.vout["value"])))

row.setProperty("external", "no" if ismine else "yes")
if(ismine):
row.setTextDown("** {}".format(spk["addresses"][0]))
else:
row.setTextDown(spk["addresses"][0])


return row

def writeProp(self, name, value):
current_value = self.allQHBoxLayout.property(name)
if value != current_value:
self.allQHBoxLayout.setProperty(name, value)

def get_data(self):
for data_prop in ["swap", "trade", "asset_data"]:
if hasattr(self, data_prop):
Expand Down
4 changes: 2 additions & 2 deletions wallet_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,8 +452,8 @@ def swap_utxo_spent(self, utxo, in_mempool=True, check_cache=True):
return txout == None

#return ({type, utxo}, amount)
def search_utxo(self, utxo):
(txid, vout) = split_utxo(utxo)
def search_utxo(self, utxo_str):
(txid, vout) = split_utxo(utxo_str)
for utxo in self.utxos:
if utxo["txid"] == txid and utxo["vout"] == vout:
return utxo
Expand Down

0 comments on commit 9a02556

Please sign in to comment.