exchange rate plugin: bi-directional conversion
This commit is contained in:
parent
efa35d9ec2
commit
cff3d6ce31
|
@ -641,7 +641,7 @@ class ElectrumWindow(QMainWindow):
|
|||
def create_send_tab(self):
|
||||
w = QWidget()
|
||||
|
||||
grid = QGridLayout(w)
|
||||
self.send_grid = grid = QGridLayout(w)
|
||||
grid.setSpacing(8)
|
||||
grid.setColumnMinimumWidth(3,300)
|
||||
grid.setColumnStretch(5,1)
|
||||
|
@ -694,8 +694,6 @@ 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)
|
||||
|
||||
|
|
|
@ -332,6 +332,7 @@ class Plugin(BasePlugin):
|
|||
self.exchanger = Exchanger(self)
|
||||
self.exchanger.start()
|
||||
self.gui.exchanger = self.exchanger #
|
||||
self.add_fiat_edit()
|
||||
|
||||
def set_currencies(self, currency_options):
|
||||
self.currencies = sorted(currency_options)
|
||||
|
@ -391,12 +392,14 @@ class Plugin(BasePlugin):
|
|||
|
||||
|
||||
def toggle(self):
|
||||
out = BasePlugin.toggle(self)
|
||||
enabled = BasePlugin.toggle(self)
|
||||
self.win.update_status()
|
||||
self.win.tabs.removeTab(1)
|
||||
new_send_tab = self.gui.main_window.create_send_tab()
|
||||
self.win.tabs.insertTab(1, new_send_tab, _('Send'))
|
||||
return out
|
||||
if enabled:
|
||||
self.add_fiat_edit()
|
||||
return enabled
|
||||
|
||||
|
||||
def close(self):
|
||||
|
@ -634,15 +637,27 @@ class Plugin(BasePlugin):
|
|||
def fiat_unit(self):
|
||||
return self.config.get("currency", "EUR")
|
||||
|
||||
def exchange_rate_button(self, grid):
|
||||
def add_fiat_edit(self):
|
||||
self.fiat_e = AmountEdit(self.fiat_unit)
|
||||
self.btc_e = self.win.amount_e
|
||||
grid = self.btc_e.parent()
|
||||
def fiat_changed():
|
||||
fiat_amount = str(self.fiat_e.text())
|
||||
if fiat_amount in ["", "."]:
|
||||
fiat_amount = "0"
|
||||
self.btc_e.setText("")
|
||||
return
|
||||
exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit())
|
||||
if exchange_rate is not None:
|
||||
btc_amount = Decimal(fiat_amount) / exchange_rate
|
||||
self.gui.main_window.amount_e.setAmount(int(btc_amount*Decimal(100000000)))
|
||||
self.fiat_e.textChanged.connect(fiat_changed)
|
||||
grid.addWidget(self.fiat_e, 4, 3, Qt.AlignHCenter)
|
||||
self.btc_e.setAmount(int(btc_amount*Decimal(100000000)))
|
||||
self.fiat_e.textEdited.connect(fiat_changed)
|
||||
def btc_changed():
|
||||
btc_amount = self.btc_e.get_amount()
|
||||
if btc_amount is None:
|
||||
self.fiat_e.setText("")
|
||||
return
|
||||
fiat_amount = self.exchanger.exchange(Decimal(btc_amount)/Decimal(100000000), self.fiat_unit())
|
||||
if fiat_amount is not None:
|
||||
self.fiat_e.setText(str(fiat_amount))
|
||||
self.btc_e.textEdited.connect(btc_changed)
|
||||
self.win.send_grid.addWidget(self.fiat_e, 4, 3, Qt.AlignHCenter)
|
||||
|
|
Loading…
Reference in New Issue