Skip to content
Snippets Groups Projects
Commit 26ef0e79 authored by inso's avatar inso
Browse files

Fix display in transfer window

parent 401e2c9b
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,7 @@ async def parse_responses(responses): ...@@ -17,6 +17,7 @@ async def parse_responses(responses):
result = (False, "") result = (False, "")
for r in responses: for r in responses:
if not result[0]: if not result[0]:
try:
if isinstance(r, BaseException): if isinstance(r, BaseException):
result = (False, str(r)) result = (False, str(r))
elif r.status == 400: elif r.status == 400:
...@@ -29,6 +30,8 @@ async def parse_responses(responses): ...@@ -29,6 +30,8 @@ async def parse_responses(responses):
result = (True, (await r.json())) result = (True, (await r.json()))
elif not result[0]: elif not result[0]:
result = (False, (await r.text())) result = (False, (await r.text()))
except BaseException as e:
result = (False, str(e))
else: else:
await r.release() await r.release()
return result return result
......
...@@ -4,6 +4,7 @@ import logging ...@@ -4,6 +4,7 @@ import logging
from PyQt5.QtCore import Qt, QObject from PyQt5.QtCore import Qt, QObject
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from sakia.money import Quantitative
from sakia.data.processors import ConnectionsProcessor from sakia.data.processors import ConnectionsProcessor
from sakia.decorators import asyncify from sakia.decorators import asyncify
from sakia.gui.password_asker import PasswordAskerDialog from sakia.gui.password_asker import PasswordAskerDialog
...@@ -58,6 +59,8 @@ class TransferController(QObject): ...@@ -58,6 +59,8 @@ class TransferController(QObject):
search_user.identity_selected.connect(user_information.search_identity) search_user.identity_selected.connect(user_information.search_identity)
view.set_keys(transfer.model.available_connections()) view.set_keys(transfer.model.available_connections())
view.radio_pubkey.toggle()
return transfer return transfer
@classmethod @classmethod
...@@ -144,7 +147,7 @@ class TransferController(QObject): ...@@ -144,7 +147,7 @@ class TransferController(QObject):
recipient = self.selected_pubkey() recipient = self.selected_pubkey()
amount = self.view.spinbox_amount.value() * 100 amount = self.view.spinbox_amount.value() * 100
#TODO: Handle other amount base than 0 #TODO: Handle other amount base than 0
amount_base = 0 amount_base = self.model.current_base()
logging.debug("Showing password dialog...") logging.debug("Showing password dialog...")
password = await PasswordAskerDialog(self.model.connection).async_exec() password = await PasswordAskerDialog(self.model.connection).async_exec()
...@@ -178,6 +181,8 @@ class TransferController(QObject): ...@@ -178,6 +181,8 @@ class TransferController(QObject):
def refresh(self): def refresh(self):
amount = self.model.wallet_value() amount = self.model.wallet_value()
current_base = self.model.current_base()
current_base_amount = amount / pow(10, current_base)
total_text = self.model.localized_amount(amount) total_text = self.model.localized_amount(amount)
self.view.refresh_labels(total_text) self.view.refresh_labels(total_text)
...@@ -186,18 +191,14 @@ class TransferController(QObject): ...@@ -186,18 +191,14 @@ class TransferController(QObject):
else: else:
self.view.set_button_box(TransferView.ButtonBoxState.OK) self.view.set_button_box(TransferView.ButtonBoxState.OK)
max_relative = self.model.quant_to_rel(amount/100) max_relative = self.model.quant_to_rel(current_base_amount/100)
current_base = self.model.current_base() self.view.spinbox_amount.setSuffix(Quantitative.base_str(current_base))
self.view.set_spinboxes_parameters(pow(10, current_base), amount, max_relative) self.view.set_spinboxes_parameters(current_base_amount / 100, max_relative)
def handle_amount_change(self, value): def handle_amount_change(self, value):
relative = self.model.quant_to_rel(value) relative = self.model.quant_to_rel(value)
self.view.change_relative_amount(relative) self.view.change_relative_amount(relative)
self.refresh_amount_suffix()
def refresh_amount_suffix(self):
self.view.spinbox_amount.setSuffix(" " + self.model.connection.currency)
def handle_relative_change(self, value): def handle_relative_change(self, value):
amount = self.model.rel_to_quant(value) amount = self.model.rel_to_quant(value)
......
...@@ -33,10 +33,10 @@ class TransferModel(QObject): ...@@ -33,10 +33,10 @@ class TransferModel(QObject):
:rtype: int :rtype: int
""" """
dividend, base = self._blockchain_processor.last_ud(self.connection.currency) dividend, base = self._blockchain_processor.last_ud(self.connection.currency)
amount = rel_value * dividend * pow(10, base) amount = rel_value * dividend
# amount is rounded to the nearest power of 10 depending of last ud base # amount is rounded to the nearest power of 10 depending of last ud base
rounded = int(pow(10, base) * round(float(amount) / pow(10, base))) # rounded = int(pow(10, base) * round(float(amount) / pow(10, base)))
return rounded / 100 return int(amount) / 100
def quant_to_rel(self, amount): def quant_to_rel(self, amount):
""" """
...@@ -45,7 +45,7 @@ class TransferModel(QObject): ...@@ -45,7 +45,7 @@ class TransferModel(QObject):
:rtype: float :rtype: float
""" """
dividend, base = self._blockchain_processor.last_ud(self.connection.currency) dividend, base = self._blockchain_processor.last_ud(self.connection.currency)
relative = amount * 100 / (dividend * pow(10, base)) relative = amount * 100 / dividend
return relative return relative
def wallet_value(self): def wallet_value(self):
...@@ -65,7 +65,6 @@ class TransferModel(QObject): ...@@ -65,7 +65,6 @@ class TransferModel(QObject):
""" """
Get the value of the current referential Get the value of the current referential
""" """
localized = self.app.current_ref.instance(amount, self.connection.currency, self.app).diff_localized(True, True) localized = self.app.current_ref.instance(amount, self.connection.currency, self.app).diff_localized(True, True)
return localized return localized
......
...@@ -97,17 +97,15 @@ class TransferView(QDialog, Ui_TransferMoneyDialog): ...@@ -97,17 +97,15 @@ class TransferView(QDialog, Ui_TransferMoneyDialog):
self.spinbox_relative.setValue(relative) self.spinbox_relative.setValue(relative)
self.spinbox_relative.blockSignals(False) self.spinbox_relative.blockSignals(False)
def set_spinboxes_parameters(self, tick_quant, max_quant, max_rel): def set_spinboxes_parameters(self, max_quant, max_rel):
""" """
Configure the spinboxes Configure the spinboxes
It should depend on what the last UD base is It should depend on what the last UD base is
:param int tick_quant:
:param int max_quant: :param int max_quant:
:param float max_rel: :param float max_rel:
""" """
self.spinbox_amount.setMaximum(max_quant/100) self.spinbox_amount.setMaximum(max_quant)
self.spinbox_relative.setMaximum(max_rel) self.spinbox_relative.setMaximum(max_rel)
self.spinbox_amount.setSingleStep(tick_quant)
def refresh_labels(self, total_text): def refresh_labels(self, total_text):
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment