From 669d8041e4d11c14b03145a82f3f9e4f204677fd Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Sat, 22 Mar 2014 23:04:06 -0500 Subject: [PATCH 1/6] Add ability to specify fiat amount when sending bitcoin. --- gui/qt/main_window.py | 1 + plugins/exchange_rate.py | 62 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py index 3fe045fd0..82ca5fbb5 100644 --- a/gui/qt/main_window.py +++ b/gui/qt/main_window.py @@ -724,6 +724,7 @@ class ElectrumWindow(QMainWindow): + _('The amount of fee can be decided freely by the sender. However, transactions with low fees take more time to be processed.') + '\n\n'\ + _('A suggested fee is automatically added to this field. You may override it. The suggested fee increases with the size of the transaction.')), 5, 3) + run_hook('exchange_rate_button', grid) self.send_button = EnterButton(_("Send"), self.do_send) grid.addWidget(self.send_button, 6, 1) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index e7de219d0..336168d13 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -11,6 +11,7 @@ from decimal import Decimal from electrum.plugins import BasePlugin from electrum.i18n import _ from electrum_gui.qt.util import * +from electrum_gui.qt.amountedit import AmountEdit EXCHANGES = ["BitcoinAverage", @@ -335,6 +336,8 @@ class Plugin(BasePlugin): def toggle(self): out = BasePlugin.toggle(self) self.win.update_status() + if self.config.get('use_exchange_rate'): + self.gui.main_window.show_message("To see fiat amount when sending bitcoin, please restart Electrum to activate the new GUI settings.") return out @@ -396,6 +399,7 @@ class Plugin(BasePlugin): def settings_dialog(self): d = QDialog() + d.setWindowTitle("Settings") layout = QGridLayout(d) layout.addWidget(QLabel(_('Exchange rate API: ')), 0, 0) layout.addWidget(QLabel(_('Currency: ')), 1, 0) @@ -423,6 +427,7 @@ class Plugin(BasePlugin): hist_checkbox.setChecked(False) hist_checkbox.setEnabled(False) self.win.update_status() + self.fiat_button.setText(cur_request) def disable_check(): hist_checkbox.setChecked(False) @@ -511,3 +516,60 @@ class Plugin(BasePlugin): + def fiat_unit(self): + r = {} + self.set_quote_text(100000000, r) + quote = r.get(0) + if quote: + return quote[-3:] + else: + return "???" + + def fiat_dialog(self): + if not self.config.get('use_exchange_rate'): + self.gui.main_window.show_message("To use this feature, first enable the exchange rate plugin.") + return + + quote_currency = self.config.get("currency", "EUR") + + d = QDialog(self.gui.main_window) + d.setWindowTitle("Fiat") + vbox = QVBoxLayout(d) + text = "Amount to Send in " + quote_currency + vbox.addWidget(QLabel(_(text)+':')) + + grid = QGridLayout() + fiat_e = AmountEdit(self.fiat_unit) + grid.addWidget(fiat_e, 1, 0) + + r = {} + self.set_quote_text(100000000, r) + quote = r.get(0) + if quote: + text = " 1 BTC=%s"%quote + grid.addWidget(QLabel(_(text)), 4, 0, 3, 0) + + vbox.addLayout(grid) + vbox.addLayout(ok_cancel_buttons(d)) + + if not d.exec_(): + return + + fiat = self.gui.main_window.read_amount(str(fiat_e.text())) + + if str(fiat) == "None" or str(fiat) == "0": + self.gui.main_window.amount_e.setText( "" ) + return + + r = {} + self.set_quote_text(100000000, r) + quote = r.get(0) + quote = quote[:-4] + quote = str(Decimal(fiat) / (Decimal(quote)*100000000)) + if quote: + self.gui.main_window.amount_e.setText( quote ) + + def exchange_rate_button(self, grid): + quote_currency = self.config.get("currency", "EUR") + self.fiat_button = EnterButton(_(quote_currency), self.fiat_dialog) + grid.addWidget(self.fiat_button, 4, 3, Qt.AlignHCenter) From bc3bcc20dcbc6a54d5f499bb363b04119d24422c Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Sun, 23 Mar 2014 12:58:42 -0500 Subject: [PATCH 2/6] check to see if fiat button already exists on send tab before telling user they must restart Electrum to see it --- plugins/exchange_rate.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 336168d13..a8f65f282 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -337,7 +337,10 @@ class Plugin(BasePlugin): out = BasePlugin.toggle(self) self.win.update_status() if self.config.get('use_exchange_rate'): - self.gui.main_window.show_message("To see fiat amount when sending bitcoin, please restart Electrum to activate the new GUI settings.") + try: + self.fiat_button + except: + self.gui.main_window.show_message("To see fiat amount when sending bitcoin, please restart Electrum to activate the new GUI settings.") return out From 7bfd170ad9c6c53115c221f9d6f01d8f13c8072c Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Sun, 23 Mar 2014 13:33:54 -0500 Subject: [PATCH 3/6] check if fiat button exists on send tab before updating its caption with the newly selected fiat currency --- plugins/exchange_rate.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index a8f65f282..06a5822a4 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -430,7 +430,12 @@ class Plugin(BasePlugin): hist_checkbox.setChecked(False) hist_checkbox.setEnabled(False) self.win.update_status() - self.fiat_button.setText(cur_request) + try: + self.fiat_button + except: + pass + else: + self.fiat_button.setText(cur_request) def disable_check(): hist_checkbox.setChecked(False) From 284bcc1e5bb4725ca0404944779b9e83d709f217 Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Sun, 23 Mar 2014 23:17:20 -0500 Subject: [PATCH 4/6] better handling of very small fiat numbers and mBTC --- plugins/exchange_rate.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 06a5822a4..a43e699d3 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -563,17 +563,19 @@ class Plugin(BasePlugin): if not d.exec_(): return - fiat = self.gui.main_window.read_amount(str(fiat_e.text())) + fiat = str(fiat_e.text()) - if str(fiat) == "None" or str(fiat) == "0": - self.gui.main_window.amount_e.setText( "" ) - return + if str(fiat) == "" or str(fiat) == ".": + fiat = "0" r = {} self.set_quote_text(100000000, r) quote = r.get(0) quote = quote[:-4] - quote = str(Decimal(fiat) / (Decimal(quote)*100000000)) + btcamount = Decimal(fiat) / Decimal(quote) + if str(self.gui.main_window.base_unit()) == "mBTC": + btcamount = btcamount * 1000 + quote = "%.8f"%btcamount if quote: self.gui.main_window.amount_e.setText( quote ) From dea58fcb496ebc7ac7fda096aec03eefec90fe69 Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Mon, 24 Mar 2014 11:06:20 -0500 Subject: [PATCH 5/6] fixed issue when exchange rate not available (eg, no connection) --- plugins/exchange_rate.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index a43e699d3..8cc14ff93 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -537,6 +537,10 @@ class Plugin(BasePlugin): if not self.config.get('use_exchange_rate'): self.gui.main_window.show_message("To use this feature, first enable the exchange rate plugin.") return + + if not self.gui.main_window.network.is_connected(): + self.gui.main_window.show_message("To use this feature, you must have a connection.") + return quote_currency = self.config.get("currency", "EUR") @@ -571,12 +575,15 @@ class Plugin(BasePlugin): r = {} self.set_quote_text(100000000, r) quote = r.get(0) - quote = quote[:-4] - btcamount = Decimal(fiat) / Decimal(quote) - if str(self.gui.main_window.base_unit()) == "mBTC": - btcamount = btcamount * 1000 - quote = "%.8f"%btcamount - if quote: + if not quote: + self.gui.main_window.show_message("Exchange rate not available. Please check your connection.") + return + else: + quote = quote[:-4] + btcamount = Decimal(fiat) / Decimal(quote) + if str(self.gui.main_window.base_unit()) == "mBTC": + btcamount = btcamount * 1000 + quote = "%.8f"%btcamount self.gui.main_window.amount_e.setText( quote ) def exchange_rate_button(self, grid): From eccb78c3e65f1815e7b9482e99fee9f472f94266 Mon Sep 17 00:00:00 2001 From: Darrin Daigle Date: Tue, 25 Mar 2014 11:43:21 -0500 Subject: [PATCH 6/6] wrapped strings with _("string text") to enable language translation --- plugins/exchange_rate.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/exchange_rate.py b/plugins/exchange_rate.py index 8cc14ff93..d07c69447 100644 --- a/plugins/exchange_rate.py +++ b/plugins/exchange_rate.py @@ -340,7 +340,7 @@ class Plugin(BasePlugin): try: self.fiat_button except: - self.gui.main_window.show_message("To see fiat amount when sending bitcoin, please restart Electrum to activate the new GUI settings.") + self.gui.main_window.show_message(_("To see fiat amount when sending bitcoin, please restart Electrum to activate the new GUI settings.")) return out @@ -535,11 +535,11 @@ class Plugin(BasePlugin): def fiat_dialog(self): if not self.config.get('use_exchange_rate'): - self.gui.main_window.show_message("To use this feature, first enable the exchange rate plugin.") + self.gui.main_window.show_message(_("To use this feature, first enable the exchange rate plugin.")) return if not self.gui.main_window.network.is_connected(): - self.gui.main_window.show_message("To use this feature, you must have a connection.") + self.gui.main_window.show_message(_("To use this feature, you must have a network connection.")) return quote_currency = self.config.get("currency", "EUR") @@ -576,7 +576,7 @@ class Plugin(BasePlugin): self.set_quote_text(100000000, r) quote = r.get(0) if not quote: - self.gui.main_window.show_message("Exchange rate not available. Please check your connection.") + self.gui.main_window.show_message(_("Exchange rate not available. Please check your network connection.")) return else: quote = quote[:-4]