Merge pull request #623 from dpdtex/master

Add ability to specify fiat amount when sending bitcoin
This commit is contained in:
ThomasV 2014-03-25 18:44:23 +01:00
commit 437fdf4760
2 changed files with 80 additions and 0 deletions

View File

@ -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)

View File

@ -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,11 @@ class Plugin(BasePlugin):
def toggle(self):
out = BasePlugin.toggle(self)
self.win.update_status()
if self.config.get('use_exchange_rate'):
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
@ -396,6 +402,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 +430,12 @@ class Plugin(BasePlugin):
hist_checkbox.setChecked(False)
hist_checkbox.setEnabled(False)
self.win.update_status()
try:
self.fiat_button
except:
pass
else:
self.fiat_button.setText(cur_request)
def disable_check():
hist_checkbox.setChecked(False)
@ -511,3 +524,69 @@ 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
if not self.gui.main_window.network.is_connected():
self.gui.main_window.show_message(_("To use this feature, you must have a network connection."))
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 = str(fiat_e.text())
if str(fiat) == "" or str(fiat) == ".":
fiat = "0"
r = {}
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 network 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):
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)