Improve 'send all coins' function:
* do use coin chooser when sending all coins (fixes #2000) * allow "!" syntax for multiple outputs (fixes #1698)
This commit is contained in:
@@ -994,27 +994,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
vbox.addWidget(self.invoices_label)
|
||||
vbox.addWidget(self.invoice_list)
|
||||
vbox.setStretchFactor(self.invoice_list, 1000)
|
||||
|
||||
# Defer this until grid is parented to avoid ugly flash during startup
|
||||
self.update_fee_edit()
|
||||
|
||||
run_hook('create_send_tab', grid)
|
||||
return w
|
||||
|
||||
|
||||
def spend_max(self):
|
||||
inputs = self.get_coins()
|
||||
sendable = sum(map(lambda x:x['value'], inputs))
|
||||
fee = self.fee_e.get_amount() if self.fee_e.isModified() else None
|
||||
r = self.get_payto_or_dummy()
|
||||
amount, fee = self.wallet.get_max_amount(self.config, inputs, r, fee)
|
||||
if not self.fee_e.isModified():
|
||||
self.fee_e.setAmount(fee)
|
||||
self.amount_e.setAmount(amount)
|
||||
self.not_enough_funds = (fee + amount > sendable)
|
||||
# emit signal for fiat_amount update
|
||||
self.amount_e.textEdited.emit("")
|
||||
self.is_max = True
|
||||
self.do_update_fee()
|
||||
|
||||
def reset_max(self):
|
||||
self.is_max = False
|
||||
@@ -1034,14 +1021,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
'''
|
||||
freeze_fee = (self.fee_e.isModified()
|
||||
and (self.fee_e.text() or self.fee_e.hasFocus()))
|
||||
amount = self.amount_e.get_amount()
|
||||
amount = '!' if self.is_max else self.amount_e.get_amount()
|
||||
if amount is None:
|
||||
if not freeze_fee:
|
||||
self.fee_e.setAmount(None)
|
||||
self.not_enough_funds = False
|
||||
else:
|
||||
fee = self.fee_e.get_amount() if freeze_fee else None
|
||||
outputs = self.payto_e.get_outputs()
|
||||
outputs = self.payto_e.get_outputs(self.is_max)
|
||||
if not outputs:
|
||||
_type, addr = self.get_payto_or_dummy()
|
||||
outputs = [(_type, addr, amount)]
|
||||
@@ -1054,6 +1041,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
fee = None if self.not_enough_funds else self.wallet.get_tx_fee(tx)
|
||||
self.fee_e.setAmount(fee)
|
||||
|
||||
if self.is_max:
|
||||
amount = tx.output_value()
|
||||
self.amount_e.setAmount(amount)
|
||||
self.amount_e.textEdited.emit("")
|
||||
|
||||
|
||||
def update_fee_edit(self):
|
||||
b = self.config.get('dynamic_fees', True)
|
||||
self.fee_slider.setVisible(b)
|
||||
@@ -1132,7 +1125,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
if errors:
|
||||
self.show_warning(_("Invalid Lines found:") + "\n\n" + '\n'.join([ _("Line #") + str(x[0]+1) + ": " + x[1] for x in errors]))
|
||||
return
|
||||
outputs = self.payto_e.get_outputs()
|
||||
outputs = self.payto_e.get_outputs(self.is_max)
|
||||
|
||||
if self.payto_e.is_alias and self.payto_e.validated is False:
|
||||
alias = self.payto_e.toPlainText()
|
||||
@@ -1174,7 +1167,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
if not r:
|
||||
return
|
||||
outputs, fee, tx_desc, coins = r
|
||||
amount = sum(map(lambda x:x[2], outputs))
|
||||
try:
|
||||
tx = self.wallet.make_unsigned_transaction(coins, outputs, self.config, fee)
|
||||
except NotEnoughFunds:
|
||||
@@ -1185,6 +1177,8 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
|
||||
self.show_message(str(e))
|
||||
return
|
||||
|
||||
amount = tx.output_value() if self.is_max else sum(map(lambda x:x[2], outputs))
|
||||
|
||||
use_rbf = self.rbf_checkbox.isChecked()
|
||||
if use_rbf:
|
||||
tx.set_sequence(0)
|
||||
|
||||
@@ -98,6 +98,8 @@ class PayToEdit(ScanQRTextEdit):
|
||||
return script
|
||||
|
||||
def parse_amount(self, x):
|
||||
if x.strip() == '!':
|
||||
return '!'
|
||||
p = pow(10, self.amount_edit.decimal_point())
|
||||
return int(p * Decimal(x.strip()))
|
||||
|
||||
@@ -138,12 +140,19 @@ class PayToEdit(ScanQRTextEdit):
|
||||
continue
|
||||
|
||||
outputs.append((_type, to_address, amount))
|
||||
total += amount
|
||||
if amount == '!':
|
||||
self.win.is_max = True
|
||||
else:
|
||||
total += amount
|
||||
|
||||
self.outputs = outputs
|
||||
self.payto_address = None
|
||||
self.amount_edit.setAmount(total if outputs else None)
|
||||
self.win.lock_amount(total or len(lines)>1)
|
||||
|
||||
if self.win.is_max:
|
||||
self.win.do_update_fee()
|
||||
else:
|
||||
self.amount_edit.setAmount(total if outputs else None)
|
||||
self.win.lock_amount(total or len(lines)>1)
|
||||
|
||||
def get_errors(self):
|
||||
return self.errors
|
||||
@@ -151,12 +160,13 @@ class PayToEdit(ScanQRTextEdit):
|
||||
def get_recipient(self):
|
||||
return self.payto_address
|
||||
|
||||
def get_outputs(self):
|
||||
def get_outputs(self, is_max):
|
||||
if self.payto_address:
|
||||
try:
|
||||
if is_max:
|
||||
amount = '!'
|
||||
else:
|
||||
amount = self.amount_edit.get_amount()
|
||||
except:
|
||||
amount = None
|
||||
|
||||
_type, addr = self.payto_address
|
||||
self.outputs = [(_type, addr, amount)]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user