Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Transaction fee confirmation #108

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from PyQt5.QtCore import QSettings

import app


class Settings(QSettings):
def __init__(self):
super().__init__(app.ORG_NAME, app.APP_NAME)
18 changes: 18 additions & 0 deletions app/ui/proto.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,24 @@ QLabel[enabled="true"] {
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="reset_suppressed_warnings">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<family>Roboto Light</family>
</font>
</property>
<property name="text">
<string>Re-enable all suppressed warnings</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
Expand Down
127 changes: 127 additions & 0 deletions app/ui/transaction_confirmation_dialog.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>transaction_confirmation_dialog</class>
<widget class="QDialog" name="transaction_confirmation_dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>119</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<property name="modal">
<bool>true</bool>
</property>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>290</x>
<y>80</y>
<width>161</width>
<height>32</height>
</rect>
</property>
<property name="font">
<font>
<family>Roboto Light</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>441</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<family>Roboto Light</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>You are about to send a transaction to the network. For this a transaction fee of {fee} CHM will be deducted from your balance.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="checkBox">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>181</width>
<height>31</height>
</rect>
</property>
<property name="font">
<font>
<family>Roboto Light</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Don't show again</string>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>transaction_confirmation_dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>transaction_confirmation_dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
12 changes: 10 additions & 2 deletions app/widgets/change_alias.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# -*- coding: utf-8 -*-
import logging

from PyQt5.QtWidgets import QDialog
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QDialogButtonBox
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QWidget
from peewee import fn

from app.backend.rpc import get_active_rpc_client
from app.models import Address
from app.ui.dialog_change_alias import Ui_dialog_change_alias
from app.models import Profile
from app.signals import signals
from app.tools.validators import username_regex
from app.ui.dialog_change_alias import Ui_dialog_change_alias
from app.widgets.transaction_confirmation_dialog import TransactionConfirmationDialog

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -54,7 +55,14 @@ def on_alias_changed(self, text):
is_valid = True
self.buttonBox.button(QDialogButtonBox.Save).setDisabled(not is_valid)


def save(self):
confirmation_dialog = TransactionConfirmationDialog(self)
confirmation_dialog.fee = "approximately 0.00074"
confirmation_dialog.callback = self.do_save
confirmation_dialog.exec()

def do_save(self):
client = get_active_rpc_client()
try:
response = client.publish(
Expand Down
6 changes: 6 additions & 0 deletions app/widgets/proto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from app import models
from app.models import Profile, Permission, CurrentVote
from app.responses import Getblockchaininfo
from app.settings import Settings
from app.signals import signals
from app.ui.proto import Ui_MainWindow
from app.widgets.apply import ApplyDialog
Expand Down Expand Up @@ -92,6 +93,7 @@ def __init__(self, **kwargs):
self.check_manage_node.setChecked(self.profile.manage_node)
self.check_manage_node.stateChanged['int'].connect(self.setting_changed_manage_node)
self.btn_alias_change.clicked.connect(self.on_change_alias)
self.reset_suppressed_warnings.clicked.connect(self.on_reset_suppressed_warnings_click)

# Connections
signals.getblockchaininfo.connect(self.getblockchaininfo)
Expand Down Expand Up @@ -151,6 +153,10 @@ def setting_changed_manage_node(self, state):
if self.profile.manage_node:
self.node.start()

def on_reset_suppressed_warnings_click(self):
settings = Settings()
settings.setValue('suppress_transaction_fee_warning', False)

def node_started(self):
self.updater.start()

Expand Down
33 changes: 33 additions & 0 deletions app/widgets/transaction_confirmation_dialog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from PyQt5.QtWidgets import QDialog, QDialogButtonBox

from app.models import Profile
from app.settings import Settings
from app.ui.transaction_confirmation_dialog import Ui_transaction_confirmation_dialog
from typing import Callable


class TransactionConfirmationDialog(QDialog, Ui_transaction_confirmation_dialog):

fee = "YOU SHOULD NEVER SEE THIS"
callback = None
__settings = Settings()

def __init__(self, parent=None):
super().__init__(parent)

self.setupUi(self)
self.setFixedSize(self.size())

def exec(self):
if self.__settings.value('suppress_transaction_fee_warning', type=bool):
self.callback()
else:
self.label.setText(self.label.text().replace("{fee}", self.fee))
self.buttonBox.button(QDialogButtonBox.Ok).clicked.connect(self.__on_ok_click)
super().exec()

def __on_ok_click(self):

if not self.__settings.value('suppress_transaction_fee_warning', type=bool) and self.checkBox.isChecked():
self.__settings.setValue('suppress_transaction_fee_warning', True)
self.callback()