diff --git a/electrum/gui/qml/components/ConfirmTxDialog.qml b/electrum/gui/qml/components/ConfirmTxDialog.qml index 2123e2749..a6394bf1a 100644 --- a/electrum/gui/qml/components/ConfirmTxDialog.qml +++ b/electrum/gui/qml/components/ConfirmTxDialog.qml @@ -35,6 +35,13 @@ Dialog { 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 { id: layout width: parent.width @@ -56,8 +63,8 @@ Dialog { RowLayout { Layout.fillWidth: true Label { + id: btcValue font.bold: true - text: Config.formatSats(satoshis, false) } Label { @@ -68,11 +75,16 @@ Dialog { Label { id: fiatValue Layout.fillWidth: true - text: Daemon.fx.enabled - ? '(' + Daemon.fx.fiatValue(satoshis, false) + ' ' + Daemon.fx.fiatCurrency + ')' - : '' font.pixelSize: constants.fontSizeMedium } + + Component.onCompleted: updateAmountText() + Connections { + target: finalizer + function onEffectiveAmountChanged() { + updateAmountText() + } + } } Label { diff --git a/electrum/gui/qml/components/Send.qml b/electrum/gui/qml/components/Send.qml index 5dcfde0d8..77f605f58 100644 --- a/electrum/gui/qml/components/Send.qml +++ b/electrum/gui/qml/components/Send.qml @@ -79,6 +79,7 @@ Pane { BtcField { id: amount fiatfield: amountFiat + enabled: !is_max.checked Layout.preferredWidth: parent.width /3 onTextChanged: { userEnteredPayment.amount = is_max.checked ? MAX : Config.unitsToSats(amount.text) @@ -107,6 +108,7 @@ Pane { id: amountFiat btcfield: amount visible: Daemon.fx.enabled + enabled: !is_max.checked Layout.preferredWidth: parent.width /3 } @@ -243,7 +245,6 @@ Pane { title: qsTr('Confirm Payment') finalizer: TxFinalizer { wallet: Daemon.currentWallet - onAmountChanged: console.log(amount.satsInt) } } } diff --git a/electrum/gui/qml/qechannelopener.py b/electrum/gui/qml/qechannelopener.py index cadd54855..e6e185171 100644 --- a/electrum/gui/qml/qechannelopener.py +++ b/electrum/gui/qml/qechannelopener.py @@ -127,17 +127,20 @@ class QEChannelOpener(QObject): return 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) - mktx = lambda: lnworker.mktx_for_open_channel( + mktx = lambda amt: lnworker.mktx_for_open_channel( coins=coins, - funding_sat=amount, + funding_sat=amt, node_id=self._peer.pubkey, fee_est=None) acpt = lambda tx: self.do_open_channel(tx, str(self._peer), None) self._finalizer = QETxFinalizer(self, make_tx=mktx, accept=acpt) + self._finalizer.amount = self._amount self._finalizer.wallet = self._wallet self.finalizerChanged.emit() diff --git a/electrum/gui/qml/qetxfinalizer.py b/electrum/gui/qml/qetxfinalizer.py index 25f2c2d95..4467ef1fa 100644 --- a/electrum/gui/qml/qetxfinalizer.py +++ b/electrum/gui/qml/qetxfinalizer.py @@ -21,6 +21,7 @@ class QETxFinalizer(QObject): _address = '' _amount = QEAmount() + _effectiveAmount = QEAmount() _fee = QEAmount() _feeRate = '' _wallet = None @@ -75,6 +76,11 @@ class QETxFinalizer(QObject): self._amount = amount self.amountChanged.emit() + effectiveAmountChanged = pyqtSignal() + @pyqtProperty(QEAmount, notify=effectiveAmountChanged) + def effectiveAmount(self): + return self._effectiveAmount + feeChanged = pyqtSignal() @pyqtProperty(QEAmount, notify=feeChanged) def fee(self): @@ -208,28 +214,34 @@ class QETxFinalizer(QObject): self.update() @profiler - def make_tx(self): + def make_tx(self, amount): + self._logger.debug('make_tx amount = %s' % str(amount)) + if self.f_make_tx: - tx = self.f_make_tx() - return tx + tx = self.f_make_tx(amount) + 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(repr(tx.outputs())) + 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 + return tx @pyqtSlot() def update(self): try: # make unsigned transaction - tx = self.make_tx() + tx = self.make_tx(amount = '!' if self._amount.isMax else self._amount.satsInt) except NotEnoughFunds: self.warning = _("Not enough funds") self._valid = False @@ -246,6 +258,9 @@ class QETxFinalizer(QObject): 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() fee = tx.get_fee() feerate = Decimal(fee) / tx_size # sat/byte