fix exchange_rate plugin behavior when typing amounts
This commit is contained in:
parent
89ba1d7b0e
commit
bc3013caf0
|
@ -1008,29 +1008,9 @@ class ElectrumWindow(QMainWindow):
|
||||||
|
|
||||||
self.amount_e.shortcut.connect(on_shortcut)
|
self.amount_e.shortcut.connect(on_shortcut)
|
||||||
|
|
||||||
def text_edited(is_fee):
|
self.payto_e.textChanged.connect(lambda: self.update_fee(False))
|
||||||
outputs = self.payto_e.get_outputs()
|
self.amount_e.textEdited.connect(lambda: self.update_fee(False))
|
||||||
amount = self.amount_e.get_amount()
|
self.fee_e.textEdited.connect(lambda: self.update_fee(True))
|
||||||
fee = self.fee_e.get_amount() if is_fee else None
|
|
||||||
if amount is None:
|
|
||||||
self.fee_e.setAmount(None)
|
|
||||||
self.not_enough_funds = False
|
|
||||||
else:
|
|
||||||
if not outputs:
|
|
||||||
addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address
|
|
||||||
outputs = [('address', addr, amount)]
|
|
||||||
try:
|
|
||||||
tx = self.wallet.make_unsigned_transaction(outputs, fee, coins = self.get_coins())
|
|
||||||
self.not_enough_funds = False
|
|
||||||
except NotEnoughFunds:
|
|
||||||
self.not_enough_funds = True
|
|
||||||
if not is_fee:
|
|
||||||
fee = None if self.not_enough_funds else self.wallet.get_tx_fee(tx)
|
|
||||||
self.fee_e.setAmount(fee)
|
|
||||||
|
|
||||||
self.payto_e.textChanged.connect(lambda:text_edited(False))
|
|
||||||
self.amount_e.textEdited.connect(lambda:text_edited(False))
|
|
||||||
self.fee_e.textEdited.connect(lambda:text_edited(True))
|
|
||||||
|
|
||||||
def entry_changed():
|
def entry_changed():
|
||||||
if not self.not_enough_funds:
|
if not self.not_enough_funds:
|
||||||
|
@ -1053,6 +1033,26 @@ class ElectrumWindow(QMainWindow):
|
||||||
run_hook('create_send_tab', grid)
|
run_hook('create_send_tab', grid)
|
||||||
return w
|
return w
|
||||||
|
|
||||||
|
def update_fee(self, is_fee):
|
||||||
|
outputs = self.payto_e.get_outputs()
|
||||||
|
amount = self.amount_e.get_amount()
|
||||||
|
fee = self.fee_e.get_amount() if is_fee else None
|
||||||
|
if amount is None:
|
||||||
|
self.fee_e.setAmount(None)
|
||||||
|
self.not_enough_funds = False
|
||||||
|
else:
|
||||||
|
if not outputs:
|
||||||
|
addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address
|
||||||
|
outputs = [('address', addr, amount)]
|
||||||
|
try:
|
||||||
|
tx = self.wallet.make_unsigned_transaction(outputs, fee, coins = self.get_coins())
|
||||||
|
self.not_enough_funds = False
|
||||||
|
except NotEnoughFunds:
|
||||||
|
self.not_enough_funds = True
|
||||||
|
if not is_fee:
|
||||||
|
fee = None if self.not_enough_funds else self.wallet.get_tx_fee(tx)
|
||||||
|
self.fee_e.setAmount(fee)
|
||||||
|
|
||||||
def update_fee_edit(self):
|
def update_fee_edit(self):
|
||||||
b = self.config.get('can_edit_fees', False)
|
b = self.config.get('can_edit_fees', False)
|
||||||
self.fee_e.setVisible(b)
|
self.fee_e.setVisible(b)
|
||||||
|
|
|
@ -742,12 +742,13 @@ class Plugin(BasePlugin):
|
||||||
fiat_amount = Decimal(str(self.fiat_e.text()))
|
fiat_amount = Decimal(str(self.fiat_e.text()))
|
||||||
except:
|
except:
|
||||||
self.btc_e.setText("")
|
self.btc_e.setText("")
|
||||||
|
self.win.fee_e.setText("")
|
||||||
return
|
return
|
||||||
exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit())
|
exchange_rate = self.exchanger.exchange(Decimal("1.0"), self.fiat_unit())
|
||||||
if exchange_rate is not None:
|
if exchange_rate is not None:
|
||||||
btc_amount = fiat_amount/exchange_rate
|
btc_amount = fiat_amount/exchange_rate
|
||||||
self.btc_e.setAmount(int(btc_amount*Decimal(100000000)))
|
self.btc_e.setAmount(int(btc_amount*Decimal(100000000)))
|
||||||
self.btc_e.textEdited.emit("")
|
self.win.update_fee(False)
|
||||||
self.fiat_e.textEdited.connect(fiat_changed)
|
self.fiat_e.textEdited.connect(fiat_changed)
|
||||||
def btc_changed():
|
def btc_changed():
|
||||||
btc_amount = self.btc_e.get_amount()
|
btc_amount = self.btc_e.get_amount()
|
||||||
|
|
Loading…
Reference in New Issue