Browse Source

support for MAX amounts

patch-4
Sander van Grieken 3 years ago
parent
commit
2907698c17
  1. 20
      electrum/gui/qml/components/ConfirmTxDialog.qml
  2. 3
      electrum/gui/qml/components/Send.qml
  3. 7
      electrum/gui/qml/qechannelopener.py
  4. 35
      electrum/gui/qml/qetxfinalizer.py

20
electrum/gui/qml/components/ConfirmTxDialog.qml

@ -35,6 +35,13 @@ Dialog {
color: "#aa000000" color: "#aa000000"
} }
function updateAmountText() {
btcValue.text = Config.formatSats(finalizer.effectiveAmount, false)
fiatValue.text = Daemon.fx.enabled
? '(' + Daemon.fx.fiatValue(finalizer.effectiveAmount, false) + ' ' + Daemon.fx.fiatCurrency + ')'
: ''
}
GridLayout { GridLayout {
id: layout id: layout
width: parent.width width: parent.width
@ -56,8 +63,8 @@ Dialog {
RowLayout { RowLayout {
Layout.fillWidth: true Layout.fillWidth: true
Label { Label {
id: btcValue
font.bold: true font.bold: true
text: Config.formatSats(satoshis, false)
} }
Label { Label {
@ -68,11 +75,16 @@ Dialog {
Label { Label {
id: fiatValue id: fiatValue
Layout.fillWidth: true Layout.fillWidth: true
text: Daemon.fx.enabled
? '(' + Daemon.fx.fiatValue(satoshis, false) + ' ' + Daemon.fx.fiatCurrency + ')'
: ''
font.pixelSize: constants.fontSizeMedium font.pixelSize: constants.fontSizeMedium
} }
Component.onCompleted: updateAmountText()
Connections {
target: finalizer
function onEffectiveAmountChanged() {
updateAmountText()
}
}
} }
Label { Label {

3
electrum/gui/qml/components/Send.qml

@ -79,6 +79,7 @@ Pane {
BtcField { BtcField {
id: amount id: amount
fiatfield: amountFiat fiatfield: amountFiat
enabled: !is_max.checked
Layout.preferredWidth: parent.width /3 Layout.preferredWidth: parent.width /3
onTextChanged: { onTextChanged: {
userEnteredPayment.amount = is_max.checked ? MAX : Config.unitsToSats(amount.text) userEnteredPayment.amount = is_max.checked ? MAX : Config.unitsToSats(amount.text)
@ -107,6 +108,7 @@ Pane {
id: amountFiat id: amountFiat
btcfield: amount btcfield: amount
visible: Daemon.fx.enabled visible: Daemon.fx.enabled
enabled: !is_max.checked
Layout.preferredWidth: parent.width /3 Layout.preferredWidth: parent.width /3
} }
@ -243,7 +245,6 @@ Pane {
title: qsTr('Confirm Payment') title: qsTr('Confirm Payment')
finalizer: TxFinalizer { finalizer: TxFinalizer {
wallet: Daemon.currentWallet wallet: Daemon.currentWallet
onAmountChanged: console.log(amount.satsInt)
} }
} }
} }

7
electrum/gui/qml/qechannelopener.py

@ -127,17 +127,20 @@ class QEChannelOpener(QObject):
return return
amount = '!' if self._amount.isMax else self._amount.satsInt amount = '!' if self._amount.isMax else self._amount.satsInt
self._logger.debug('amount = %s' % str(amount))
coins = self._wallet.wallet.get_spendable_coins(None, nonlocal_only=True) coins = self._wallet.wallet.get_spendable_coins(None, nonlocal_only=True)
mktx = lambda: lnworker.mktx_for_open_channel( mktx = lambda amt: lnworker.mktx_for_open_channel(
coins=coins, coins=coins,
funding_sat=amount, funding_sat=amt,
node_id=self._peer.pubkey, node_id=self._peer.pubkey,
fee_est=None) fee_est=None)
acpt = lambda tx: self.do_open_channel(tx, str(self._peer), None) acpt = lambda tx: self.do_open_channel(tx, str(self._peer), None)
self._finalizer = QETxFinalizer(self, make_tx=mktx, accept=acpt) self._finalizer = QETxFinalizer(self, make_tx=mktx, accept=acpt)
self._finalizer.amount = self._amount
self._finalizer.wallet = self._wallet self._finalizer.wallet = self._wallet
self.finalizerChanged.emit() self.finalizerChanged.emit()

35
electrum/gui/qml/qetxfinalizer.py

@ -21,6 +21,7 @@ class QETxFinalizer(QObject):
_address = '' _address = ''
_amount = QEAmount() _amount = QEAmount()
_effectiveAmount = QEAmount()
_fee = QEAmount() _fee = QEAmount()
_feeRate = '' _feeRate = ''
_wallet = None _wallet = None
@ -75,6 +76,11 @@ class QETxFinalizer(QObject):
self._amount = amount self._amount = amount
self.amountChanged.emit() self.amountChanged.emit()
effectiveAmountChanged = pyqtSignal()
@pyqtProperty(QEAmount, notify=effectiveAmountChanged)
def effectiveAmount(self):
return self._effectiveAmount
feeChanged = pyqtSignal() feeChanged = pyqtSignal()
@pyqtProperty(QEAmount, notify=feeChanged) @pyqtProperty(QEAmount, notify=feeChanged)
def fee(self): def fee(self):
@ -208,28 +214,34 @@ class QETxFinalizer(QObject):
self.update() self.update()
@profiler @profiler
def make_tx(self): def make_tx(self, amount):
self._logger.debug('make_tx amount = %s' % str(amount))
if self.f_make_tx: if self.f_make_tx:
tx = self.f_make_tx() tx = self.f_make_tx(amount)
return tx else:
# default impl
coins = self._wallet.wallet.get_spendable_coins(None)
outputs = [PartialTxOutput.from_address_and_value(self.address, amount)]
tx = self._wallet.wallet.make_unsigned_transaction(coins=coins,outputs=outputs, fee=None,rbf=self._rbf)
# default impl
coins = self._wallet.wallet.get_spendable_coins(None)
outputs = [PartialTxOutput.from_address_and_value(self.address, self._amount.satsInt)]
tx = self._wallet.wallet.make_unsigned_transaction(coins=coins,outputs=outputs, fee=None,rbf=self._rbf)
self._logger.debug('fee: %d, inputs: %d, outputs: %d' % (tx.get_fee(), len(tx.inputs()), len(tx.outputs()))) self._logger.debug('fee: %d, inputs: %d, outputs: %d' % (tx.get_fee(), len(tx.inputs()), len(tx.outputs())))
self._logger.debug(repr(tx.outputs()))
outputs = [] outputs = []
for o in tx.outputs(): for o in tx.outputs():
outputs.append(o.to_json()) outputs.append({
'address': o.get_ui_address_str(),
'value_sats': o.value
})
self.outputs = outputs self.outputs = outputs
return tx return tx
@pyqtSlot() @pyqtSlot()
def update(self): def update(self):
try: try:
# make unsigned transaction # make unsigned transaction
tx = self.make_tx() tx = self.make_tx(amount = '!' if self._amount.isMax else self._amount.satsInt)
except NotEnoughFunds: except NotEnoughFunds:
self.warning = _("Not enough funds") self.warning = _("Not enough funds")
self._valid = False self._valid = False
@ -246,6 +258,9 @@ class QETxFinalizer(QObject):
amount = self._amount.satsInt if not self._amount.isMax else tx.output_value() amount = self._amount.satsInt if not self._amount.isMax else tx.output_value()
self._effectiveAmount = QEAmount(amount_sat=amount)
self.effectiveAmountChanged.emit()
tx_size = tx.estimated_size() tx_size = tx.estimated_size()
fee = tx.get_fee() fee = tx.get_fee()
feerate = Decimal(fee) / tx_size # sat/byte feerate = Decimal(fee) / tx_size # sat/byte

Loading…
Cancel
Save