keyboard shortcut to send all the coins in a wallet, with fee

This commit is contained in:
thomasv 2013-04-05 18:03:52 +02:00
parent 84101a446b
commit ec901f54a4
2 changed files with 19 additions and 8 deletions

View File

@ -687,7 +687,8 @@ class ElectrumWindow(QMainWindow):
grid.addWidget(self.amount_e, 3, 1, 1, 2) grid.addWidget(self.amount_e, 3, 1, 1, 2)
grid.addWidget(HelpButton( grid.addWidget(HelpButton(
_('Amount to be sent.') + '\n\n' \ _('Amount to be sent.') + '\n\n' \
+ _('The amount will be displayed in red if you do not have enough funds in your wallet. Note that if you have frozen some of your addresses, the available funds will be lower than your total balance.')), 3, 3) + _('The amount will be displayed in red if you do not have enough funds in your wallet. Note that if you have frozen some of your addresses, the available funds will be lower than your total balance.')
+ _('Keyboard shortcut: type "!" to send all your coins.')), 3, 3)
self.fee_e = QLineEdit() self.fee_e = QLineEdit()
grid.addWidget(QLabel(_('Fee')), 4, 0) grid.addWidget(QLabel(_('Fee')), 4, 0)
@ -721,6 +722,16 @@ class ElectrumWindow(QMainWindow):
def entry_changed( is_fee ): def entry_changed( is_fee ):
self.funds_error = False self.funds_error = False
if self.amount_e.text() == '!':
c, u = self.wallet.get_balance()
inputs, total, fee = self.wallet.choose_tx_inputs( c + u, 0 )
fee = self.wallet.estimated_fee(inputs)
amount = c + u - fee
self.amount_e.setText( str( Decimal( amount ) / 100000000 ) )
self.fee_e.setText( str( Decimal( fee ) / 100000000 ) )
return
amount = numbify(self.amount_e) amount = numbify(self.amount_e)
fee = numbify(self.fee_e) fee = numbify(self.fee_e)
if not is_fee: fee = None if not is_fee: fee = None

View File

@ -555,14 +555,8 @@ class Wallet:
addr = item.get('address') addr = item.get('address')
v = item.get('value') v = item.get('value')
total += v total += v
inputs.append( item ) inputs.append( item )
if fixed_fee is None: fee = self.estimated_fee(inputs) if fixed_fee is None else fixed_fee
estimated_size = len(inputs) * 180 + 80 # this assumes non-compressed keys
fee = self.fee * int(round(estimated_size/1024.))
if fee == 0: fee = self.fee
else:
fee = fixed_fee
if total >= amount + fee: break if total >= amount + fee: break
else: else:
inputs = [] inputs = []
@ -570,6 +564,12 @@ class Wallet:
return inputs, total, fee return inputs, total, fee
def estimated_fee(self, inputs):
estimated_size = len(inputs) * 180 + 80 # this assumes non-compressed keys
fee = self.fee * int(round(estimated_size/1024.))
if fee == 0: fee = self.fee
return fee
def add_tx_change( self, outputs, amount, fee, total, change_addr=None ): def add_tx_change( self, outputs, amount, fee, total, change_addr=None ):
change_amount = total - ( amount + fee ) change_amount = total - ( amount + fee )