From 34ef93b2b584b9ae733b3f413e9453cc2ba2d840 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Tue, 12 Apr 2022 16:48:32 +0200 Subject: [PATCH] add confirm payment dialog/feepicker and qobject backing --- electrum/gui/icons/paste.png | Bin 0 -> 1309 bytes .../qml/components/ConfirmPaymentDialog.qml | 195 +++++++++++++++ electrum/gui/qml/components/Send.qml | 120 +++++++-- electrum/gui/qml/qeapp.py | 6 + electrum/gui/qml/qetxfinalizer.py | 228 ++++++++++++++++++ 5 files changed, 523 insertions(+), 26 deletions(-) create mode 100644 electrum/gui/icons/paste.png create mode 100644 electrum/gui/qml/components/ConfirmPaymentDialog.qml create mode 100644 electrum/gui/qml/qetxfinalizer.py diff --git a/electrum/gui/icons/paste.png b/electrum/gui/icons/paste.png new file mode 100644 index 0000000000000000000000000000000000000000..e70bb37f9759eb6093c41b80e0b6ff4ab37f950b GIT binary patch literal 1309 zcmV+&1>*XNP)7??yYfXc=G+XUTEBba>@6p-J%gB+)-nBXpPej85I71%(m+(6n%&veCE>r>~|;a{d`(-b=+}fPN2@N*80Y-J}r0cJjd>p10LKSd8Pkr-PJ@vC>HW z9$;)fO)=mzc33u>kF_#tFsiX?7~FFCIDXet@iw4$pqDlg!`?XBTWoX^`V<Iv~^+TS-csFeo%^heqcUhqj9mr691U7JJ z?=Q+}goR9-7B9KHjeICO_Itp51yC*#rOpxy(K%WOvA72d!(-P@+ljZNZ5)_Ij$Vq4 zbkYZJ1GWHcA;R{NI6x^xByd#jTu2x@fysAIllzD<$&X?$FWexrVYv{k+lN{D24L*0-{ujMb*KQhuw(; z7V>Rc{}ONgn5U5I`kw|LDlNF~xl~N4Fg)hir_k6tV4gzRomijuC<57?SRbP7POOhl zzo@vEO<5dcRDR^$z6ogC5XK=FlzE3fyWp(9O|1K=hJ4&;M+=e~ 0 + mempool = self._method == 2 + return dynfees, mempool + + def update_slider(self): + dynfees, mempool = self.get_method() + maxp, pos, fee_rate = self.config.get_fee_slider(dynfees, mempool) + self._sliderSteps = maxp + self._sliderPos = pos + self.sliderStepsChanged.emit() + self.sliderPosChanged.emit() + + def read_config(self): + mempool = self.config.use_mempool_fees() + dynfees = self.config.is_dynfee() + self._method = (2 if mempool else 1) if dynfees else 0 + self.update_slider() + self.methodChanged.emit() + self.update(False) + + def save_config(self): + value = int(self._sliderPos) + dynfees, mempool = self.get_method() + self.config.set_key('dynamic_fees', dynfees, False) + self.config.set_key('mempool_fees', mempool, False) + if dynfees: + if mempool: + self.config.set_key('depth_level', value, True) + else: + self.config.set_key('fee_level', value, True) + else: + self.config.set_key('fee_per_kb', self.config.static_fee(value), True) + self.update(False) + + @profiler + def make_tx(self, rbf: bool): + coins = self._wallet.wallet.get_spendable_coins(None) + outputs = [PartialTxOutput.from_address_and_value(self.address, int(self.amount))] + tx = self._wallet.wallet.make_unsigned_transaction(coins=coins,outputs=outputs, fee=None) + self._logger.debug('fee: %d, inputs: %d, outputs: %d' % (tx.get_fee(), len(tx.inputs()), len(tx.outputs()))) + return tx + + @pyqtSlot(bool) + def update(self, rbf): + #rbf = not bool(self.ids.final_cb.active) if self.show_final else False + try: + # make unsigned transaction + tx = self.make_tx(rbf) + except NotEnoughFunds: + self.warning = _("Not enough funds") + self._valid = False + self.validChanged.emit() + return + except Exception as e: + self._logger.error(str(e)) + self.warning = repr(e) + self._valid = False + self.validChanged.emit() + return + + amount = int(self.amount) if self.amount != '!' else tx.output_value() + tx_size = tx.estimated_size() + fee = tx.get_fee() + feerate = Decimal(fee) / tx_size # sat/byte + + self.fee = str(fee) + self.feeRate = f'{feerate:.1f}' + + #x_fee = run_hook('get_tx_extra_fee', self._wallet.wallet, tx) + fee_warning_tuple = self._wallet.wallet.get_tx_fee_warning( + invoice_amt=amount, tx_size=tx_size, fee=fee) + if fee_warning_tuple: + allow_send, long_warning, short_warning = fee_warning_tuple + self.warning = long_warning + else: + self.warning = '' + + target, tooltip, dyn = self.config.get_fee_target() + self.target = target + + self._valid = True + self.validChanged.emit()