def __init__(self, tx, parent):
        self.tx = tx
        tx_dict = tx.as_dict()
        self.parent = parent
        self.wallet = parent.wallet
        self.saved = True

        QDialog.__init__(self)
        self.setMinimumWidth(600)
        self.setWindowTitle(_("Transaction"))
        self.setModal(1)

        vbox = QVBoxLayout()
        self.setLayout(vbox)

        vbox.addWidget(QLabel(_("Transaction ID:")))
        self.tx_hash_e  = ButtonsLineEdit()
        qr_show = lambda: self.parent.show_qrcode(str(self.tx_hash_e.text()), 'Transaction ID')
        self.tx_hash_e.addButton(":icons/qrcode.png", qr_show, _("Show as QR code"))
        self.tx_hash_e.setReadOnly(True)
        vbox.addWidget(self.tx_hash_e)
        self.status_label = QLabel()
        vbox.addWidget(self.status_label)

        self.date_label = QLabel()
        vbox.addWidget(self.date_label)
        self.amount_label = QLabel()
        vbox.addWidget(self.amount_label)
        self.fee_label = QLabel()
        vbox.addWidget(self.fee_label)

        self.add_io(vbox)

        vbox.addStretch(1)

        self.sign_button = b = QPushButton(_("Sign"))
        b.clicked.connect(self.sign)

        self.broadcast_button = b = QPushButton(_("Broadcast"))
        b.clicked.connect(self.do_broadcast)
        b.hide()

        self.save_button = b = QPushButton(_("Save"))
        b.clicked.connect(self.save)

        self.cancel_button = b = QPushButton(_("Close"))
        b.clicked.connect(self.close)
        b.setDefault(True)

        self.qr_button = b = QPushButton()
        b.setIcon(QIcon(":icons/qrcode.png"))
        b.clicked.connect(self.show_qr)

        self.copy_button = CopyButton(lambda: str(self.tx), self.parent.app)

        self.buttons = [self.copy_button, self.qr_button, self.sign_button, self.broadcast_button, self.save_button, self.cancel_button]
        run_hook('transaction_dialog', self)

        vbox.addLayout(Buttons(*self.buttons))
        self.update()
    def update(self):
        is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(self.tx)
        tx_hash = self.tx.hash()
        if self.wallet.can_sign(self.tx):
            self.sign_button.show()
        else:
            self.sign_button.hide()

        if self.tx.is_complete():
            status = _("Signed")

            if tx_hash in self.wallet.transactions.keys():
                conf, timestamp = self.wallet.get_confirmations(tx_hash)
                if timestamp:
                    time_str = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
                else:
                    time_str = 'pending'
                status = _("%d confirmations")%conf
                self.broadcast_button.hide()
            else:
                time_str = None
                conf = 0
                self.broadcast_button.show()
        else:
            s, r = self.tx.signature_count()
            status = _("Unsigned") if s == 0 else _('Partially signed') + ' (%d/%d)'%(s,r)
            time_str = None
            self.broadcast_button.hide()
            tx_hash = 'unknown'

        self.tx_hash_e.setText(tx_hash)
        self.status_label.setText(_('Status:') + ' ' + status)

        if time_str is not None:
            self.date_label.setText(_("Date: %s")%time_str)
            self.date_label.show()
        else:
            self.date_label.hide()

        # if we are not synchronized, we cannot tell
        if self.parent.network is None or not self.parent.network.is_running() or not self.parent.network.is_connected():
            self.broadcast_button.hide()  # cannot broadcast when offline
            return
        if not self.wallet.up_to_date:
            return

        if is_relevant:
            if is_mine:
                if fee is not None:
                    self.amount_label.setText(_("Amount sent:")+' %s'% self.parent.format_amount(-v+fee) + ' ' + self.parent.base_unit())
                    self.fee_label.setText(_("Transaction fee")+': %s'% self.parent.format_amount(-fee) + ' ' + self.parent.base_unit())
                else:
                    self.amount_label.setText(_("Amount sent:")+' %s'% self.parent.format_amount(-v) + ' ' + self.parent.base_unit())
                    self.fee_label.setText(_("Transaction fee")+': '+ _("unknown"))
            else:
                self.amount_label.setText(_("Amount received:")+' %s'% self.parent.format_amount(v) + ' ' + self.parent.base_unit())
        else:
            self.amount_label.setText(_("Transaction unrelated to your wallet"))

        run_hook('transaction_dialog_update', self)
Exemplo n.º 3
0
 def create_quote_text(self, btc_balance):
     """Return a string copy of the amount fiat currency the
     user has in bitcoins."""
     from electrum_pkb.plugins import run_hook
     r = {}
     run_hook('get_fiat_balance_text', btc_balance, r)
     return r.get(0,'')
Exemplo n.º 4
0
 def create_quote_text(self, btc_balance):
     """Return a string copy of the amount fiat currency the
     user has in bitcoins."""
     from electrum_pkb.plugins import run_hook
     r = {}
     run_hook('get_fiat_balance_text', btc_balance, r)
     return r.get(0, '')
Exemplo n.º 5
0
    def update(self, h):
        self.wallet = self.parent.wallet
        item = self.currentItem()
        current_tx = item.data(0, Qt.UserRole).toString() if item else None
        self.clear()
        for item in h:
            tx_hash, conf, value, timestamp, balance = item
            time_str = _("unknown")
            if conf is None and timestamp is None:
                continue  # skip history in offline mode
            if conf > 0:
                time_str = format_time(timestamp)
            if conf == -1:
                time_str = 'unverified'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf == 0:
                time_str = 'pending'
                icon = QIcon(":icons/unconfirmed.png")
            elif conf < 6:
                icon = QIcon(":icons/clock%d.png"%conf)
            else:
                icon = QIcon(":icons/confirmed.png")
            v_str = self.parent.format_amount(value, True, whitespaces=True)
            balance_str = self.parent.format_amount(balance, whitespaces=True)
            label, is_default_label = self.wallet.get_label(tx_hash)
            item = QTreeWidgetItem( [ '', time_str, label, v_str, balance_str] )
            item.setFont(2, QFont(MONOSPACE_FONT))
            item.setFont(3, QFont(MONOSPACE_FONT))
            item.setFont(4, QFont(MONOSPACE_FONT))
            if value < 0:
                item.setForeground(3, QBrush(QColor("#BC1E1E")))
            if tx_hash:
                item.setData(0, Qt.UserRole, tx_hash)
            if is_default_label:
                item.setForeground(2, QBrush(QColor('grey')))
            item.setIcon(0, icon)
            self.insertTopLevelItem(0, item)
            if current_tx == tx_hash:
                self.setCurrentItem(item)

        run_hook('history_tab_update')
Exemplo n.º 6
0
 def __init__(self, text=""):
     ButtonsTextEdit.__init__(self, text)
     self.setReadOnly(0)
     self.addButton(":icons/file.png", self.file_input, _("Read file"))
     self.addButton(":icons/qrcode.png", self.qr_input, _("Read QR code"))
     run_hook('scan_text_edit', self)
Exemplo n.º 7
0
 def __init__(self, text=None):
     ButtonsTextEdit.__init__(self, text)
     self.setReadOnly(1)
     self.addButton(":icons/qrcode.png", self.qr_show, _("Show as QR code"))
     run_hook('show_text_edit', self)
Exemplo n.º 8
0
    def main(self, url):

        last_wallet = self.config.get('gui_last_wallet')
        if last_wallet is not None and self.config.get('wallet_path') is None:
            if os.path.exists(last_wallet):
                self.config.read_only_options[
                    'default_wallet_path'] = last_wallet
        try:
            storage = WalletStorage(self.config.get_wallet_path())
        except BaseException as e:
            QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
            self.config.set_key('gui_last_wallet', None)
            return

        if storage.file_exists:
            try:
                wallet = Wallet(storage)
            except BaseException as e:
                QMessageBox.warning(None, _('Warning'), str(e), _('OK'))
                return
            action = wallet.get_action()
        else:
            action = 'new'

        if action is not None:
            wallet = self.run_wizard(storage, action)
            if not wallet:
                return
        else:
            wallet.start_threads(self.network)

        # init tray
        self.dark_icon = self.config.get("dark_icon", False)
        icon = QIcon(
            ":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(
                ':icons/electrum_light_icon.png')
        self.tray = QSystemTrayIcon(icon, None)
        self.tray.setToolTip('Electrum-PKB')
        self.tray.activated.connect(self.tray_activated)
        self.build_tray_menu()
        self.tray.show()

        # main window
        self.main_window = w = ElectrumWindow(self.config, self.network, self)
        self.current_window = self.main_window

        #lite window
        self.init_lite()

        # plugins interact with main window
        run_hook('init_qt', self)

        w.load_wallet(wallet)

        # initial configuration
        if self.config.get('hide_gui') is True and self.tray.isVisible():
            self.main_window.hide()
            self.lite_window.hide()
        else:
            if self.config.get('lite_mode') is True:
                self.go_lite()
            else:
                self.go_full()

        s = Timer()
        s.start()

        self.windows.append(w)
        if url:
            self.set_url(url)

        w.connect_slots(s)

        signal.signal(signal.SIGINT, lambda *args: self.app.quit())
        self.app.exec_()
        if self.tray:
            self.tray.hide()

        # clipboard persistence
        # see http://www.mail-archive.com/[email protected]/msg17328.html
        event = QtCore.QEvent(QtCore.QEvent.Clipboard)
        self.app.sendEvent(self.app.clipboard(), event)

        w.close_wallet()
Exemplo n.º 9
0
    def main(self, url):

        last_wallet = self.config.get("gui_last_wallet")
        if last_wallet is not None and self.config.get("wallet_path") is None:
            if os.path.exists(last_wallet):
                self.config.read_only_options["default_wallet_path"] = last_wallet
        try:
            storage = WalletStorage(self.config.get_wallet_path())
        except BaseException as e:
            QMessageBox.warning(None, _("Warning"), str(e), _("OK"))
            self.config.set_key("gui_last_wallet", None)
            return

        if storage.file_exists:
            try:
                wallet = Wallet(storage)
            except BaseException as e:
                QMessageBox.warning(None, _("Warning"), str(e), _("OK"))
                return
            action = wallet.get_action()
        else:
            action = "new"

        if action is not None:
            wallet = self.run_wizard(storage, action)
            if not wallet:
                return
        else:
            wallet.start_threads(self.network)

        # init tray
        self.dark_icon = self.config.get("dark_icon", False)
        icon = QIcon(":icons/electrum_dark_icon.png") if self.dark_icon else QIcon(":icons/electrum_light_icon.png")
        self.tray = QSystemTrayIcon(icon, None)
        self.tray.setToolTip("Electrum-PKB")
        self.tray.activated.connect(self.tray_activated)
        self.build_tray_menu()
        self.tray.show()

        # main window
        self.main_window = w = ElectrumWindow(self.config, self.network, self)
        self.current_window = self.main_window

        # lite window
        self.init_lite()

        # plugins interact with main window
        run_hook("init_qt", self)

        w.load_wallet(wallet)

        # initial configuration
        if self.config.get("hide_gui") is True and self.tray.isVisible():
            self.main_window.hide()
            self.lite_window.hide()
        else:
            if self.config.get("lite_mode") is True:
                self.go_lite()
            else:
                self.go_full()

        s = Timer()
        s.start()

        self.windows.append(w)
        if url:
            self.set_url(url)

        w.connect_slots(s)

        signal.signal(signal.SIGINT, lambda *args: self.app.quit())
        self.app.exec_()
        if self.tray:
            self.tray.hide()

        # clipboard persistence
        # see http://www.mail-archive.com/[email protected]/msg17328.html
        event = QtCore.QEvent(QtCore.QEvent.Clipboard)
        self.app.sendEvent(self.app.clipboard(), event)

        w.close_wallet()